Skip to content
Snippets Groups Projects
Commit c642cfcb authored by Avi Kivity's avatar Avi Kivity
Browse files

gdb: put thread list into a vmstate object

We'll collect more osv state there.
parent dab69183
No related branches found
No related tags found
No related merge requests found
...@@ -105,22 +105,27 @@ class osv_info(gdb.Command): ...@@ -105,22 +105,27 @@ class osv_info(gdb.Command):
gdb.Command.__init__(self, 'osv info', gdb.COMMAND_USER, gdb.Command.__init__(self, 'osv info', gdb.COMMAND_USER,
gdb.COMPLETE_COMMAND, True) gdb.COMPLETE_COMMAND, True)
def thread_list(): class vmstate(object):
ret = [] def __init__(self):
thread_list = gdb.lookup_global_symbol('sched::thread_list').value() self.reload()
root = thread_list['data_']['root_plus_size_']['root_'] def reload(self):
node = root['next_'] self.load_thread_list()
thread_type = gdb.lookup_type('sched::thread') def load_thread_list(self):
void_ptr = gdb.lookup_type('void').pointer() ret = []
for f in thread_type.fields(): thread_list = gdb.lookup_global_symbol('sched::thread_list').value()
if f.name == '_thread_list_link': root = thread_list['data_']['root_plus_size_']['root_']
link_offset = f.bitpos / 8 node = root['next_']
while node != root.address: thread_type = gdb.lookup_type('sched::thread')
t = node.cast(void_ptr) - link_offset void_ptr = gdb.lookup_type('void').pointer()
t = t.cast(thread_type.pointer()) for f in thread_type.fields():
ret.append(t.dereference()) if f.name == '_thread_list_link':
node = node['next_'] link_offset = f.bitpos / 8
return ret while node != root.address:
t = node.cast(void_ptr) - link_offset
t = t.cast(thread_type.pointer())
ret.append(t.dereference())
node = node['next_']
self.thread_list = ret
class thread_context(object): class thread_context(object):
def __init__(self, thread): def __init__(self, thread):
...@@ -156,7 +161,8 @@ class osv_info_threads(gdb.Command): ...@@ -156,7 +161,8 @@ class osv_info_threads(gdb.Command):
gdb.Command.__init__(self, 'osv info threads', gdb.Command.__init__(self, 'osv info threads',
gdb.COMMAND_USER, gdb.COMPLETE_NONE) gdb.COMMAND_USER, gdb.COMPLETE_NONE)
def invoke(self, arg, for_tty): def invoke(self, arg, for_tty):
for t in thread_list(): state = vmstate()
for t in state.thread_list:
with thread_context(t): with thread_context(t):
cpu = t['_cpu'] cpu = t['_cpu']
fr = gdb.selected_frame() fr = gdb.selected_frame()
...@@ -199,7 +205,8 @@ class osv_thread_apply_all(gdb.Command): ...@@ -199,7 +205,8 @@ class osv_thread_apply_all(gdb.Command):
gdb.Command.__init__(self, 'osv thread apply all', gdb.COMMAND_USER, gdb.Command.__init__(self, 'osv thread apply all', gdb.COMMAND_USER,
gdb.COMPLETE_NONE) gdb.COMPLETE_NONE)
def invoke(self, arg, from_tty): def invoke(self, arg, from_tty):
for t in thread_list(): state = vmstate()
for t in state.thread_list:
gdb.write('thread %s\n\n' % t.address) gdb.write('thread %s\n\n' % t.address)
with thread_context(t): with thread_context(t):
gdb.execute(arg, from_tty) gdb.execute(arg, from_tty)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment