diff --git a/src/libfibre/libfibre.so-gdb.py b/src/libfibre/libfibre.so-gdb.py index b82c43e7565a88bf59abfada7c85b21a0d14fc85..efff11a971416959b1de419119bad9949844c36f 100644 --- a/src/libfibre/libfibre.so-gdb.py +++ b/src/libfibre/libfibre.so-gdb.py @@ -15,12 +15,8 @@ class FibreSupport(): return FibreSupport.list = [] FibreSupport.active = {} + FibreSupport.threads = {} FibreSupport.saved = True - # save register context for later continuation - FibreSupport.rsp = str(gdb.parse_and_eval("$rsp")).split(None, 1)[0] - FibreSupport.rbp = str(gdb.parse_and_eval("$rbp")).split(None, 1)[0] - FibreSupport.rip = str(gdb.parse_and_eval("$rip")).split(None, 1)[0] - FibreSupport.currStack = str(gdb.parse_and_eval("Context::currStack")) # traverse runtime stack list to build internal list of fibres _globalStackList = gdb.parse_and_eval("_globalStackList") first = _globalStackList['anchor'].address @@ -34,21 +30,39 @@ class FibreSupport(): currStack = str(gdb.parse_and_eval("Context::currStack")) # Cache the registers for this thread, in case it represents # a fibre + rsp = str(gdb.parse_and_eval("$rsp")).split(None, 1)[0] + rbp = str(gdb.parse_and_eval("$rbp")).split(None, 1)[0] + rip = str(gdb.parse_and_eval("$rip")).split(None, 1)[0] + FibreSupport.threads[thread.num] = { + 'rsp': rsp, + 'rbp': rbp, + 'rip': rip, + 'currStack': currStack + } FibreSupport.active[currStack] = { - 'rsp': str(gdb.parse_and_eval("$rsp")).split(None, 1)[0], - 'rbp': str(gdb.parse_and_eval("$rbp")).split(None, 1)[0], - 'rip': str(gdb.parse_and_eval("$rip")).split(None, 1)[0] + 'rsp': rsp, + 'rbp': rbp, + 'rip': rip } orig_thread.switch() # restore() is hooked to continue events via script hooks to 'fibre reset' def restore(): - FibreSupport.prep_frame() - # restore original register context - gdb.execute("set $rsp = " + str(FibreSupport.rsp)) - gdb.execute("set $rbp = " + str(FibreSupport.rbp)) - gdb.execute("set $rip = " + str(FibreSupport.rip)) - gdb.execute("set Context::currStack = " + str(FibreSupport.currStack)) + orig_thread = gdb.selected_thread() + for thread in gdb.selected_inferior().threads(): + thread.switch() + rsp = FibreSupport.threads[thread.num]['rsp'] + rbp = FibreSupport.threads[thread.num]['rbp'] + rip = FibreSupport.threads[thread.num]['rip'] + currStack = FibreSupport.threads[thread.num]['currStack'] + + FibreSupport.prep_frame() + # restore original register context + gdb.execute("set $rsp = " + str(rsp)) + gdb.execute("set $rbp = " + str(rbp)) + gdb.execute("set $rip = " + str(rip)) + gdb.execute("set Context::currStack = " + str(currStack)) + orig_thread.switch() FibreSupport.saved = False def prep_frame():