Skip to content

Disable thread switch when cuda-gdb focus on a cuda thread #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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