Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Disable thread switch when cuda-gdb focus on a cuda thread
when enter a cuda thread, thread.switch() will return CPU thread
and make the following command next, step, ... invalid.
It also fix #333
  • Loading branch information
Freed-Wu committed Jun 10, 2025
commit 4bfdd43e46fcdc6e618e3fb5dc38fe7875595908
42 changes: 28 additions & 14 deletions .gdbinit
Original file line number Diff line number Diff line change
Expand Up @@ -2113,13 +2113,25 @@ class Threads(Dashboard.Module):
def label(self):
return 'Threads'

@staticmethod
def if_enter_cuda_thread():
'''when enter cuda thread, shouldn't switch to CPU thread'''
try:
from gdb import cuda

return cuda.get_focus_physical() is not None
except ImportError:
return False

def lines(self, term_width, term_height, style_changed):
out = []
selected_thread = gdb.selected_thread()
switch = not self.if_enter_cuda_thread()
# do not restore the selected frame if the thread is not stopped
restore_frame = gdb.selected_thread().is_stopped()
if restore_frame:
selected_frame = gdb.selected_frame()
if switch:
restore_frame = gdb.selected_thread().is_stopped()
if restore_frame:
selected_frame = gdb.selected_frame()
# fetch the thread list
threads = []
for inferior in gdb.inferiors():
Expand All @@ -2140,18 +2152,20 @@ class Threads(Dashboard.Module):
info = '[{}] id {}'.format(number, tid)
if thread.name:
info += ' name {}'.format(ansi(thread.name, style))
# switch thread to fetch info (unless is running in non-stop mode)
try:
thread.switch()
frame = gdb.newest_frame()
info += ' ' + Stack.get_pc_line(frame, style)
except gdb.error:
info += ' (running)'
if switch:
# switch thread to fetch info (unless is running in non-stop mode)
try:
thread.switch()
frame = gdb.newest_frame()
info += ' ' + Stack.get_pc_line(frame, style)
except gdb.error:
info += ' (running)'
out.append(info)
# restore thread and frame
selected_thread.switch()
if restore_frame:
selected_frame.select()
if switch:
# restore thread and frame
selected_thread.switch()
if restore_frame:
selected_frame.select()
return out

def attributes(self):
Expand Down