From 4b02c772dcf6f5ba8c7f7ee5e9732114147a9c8c Mon Sep 17 00:00:00 2001 From: Martin Karsten <mkarsten@uwaterloo.ca> Date: Tue, 24 Jul 2018 22:19:01 -0400 Subject: [PATCH] - fix bug in gdb support: script hook masks python hook? --- src/libfibre/libfibre.so-gdb.py | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/libfibre/libfibre.so-gdb.py b/src/libfibre/libfibre.so-gdb.py index 2f42dce..d41ef12 100644 --- a/src/libfibre/libfibre.so-gdb.py +++ b/src/libfibre/libfibre.so-gdb.py @@ -6,21 +6,17 @@ import gdb from contextlib import contextmanager class FibreSupport(): - def __init__(self): - FibreSupport.list = [] - FibreSupport.active = {} - FibreSupport.saved = False - def stop_handler(event): if (gdb.lookup_symbol("_globalStackList")[0] == None): print("WARNING: no fibre debugging support - did you enable TESTING_ENABLE_DEBUGGING?") return + FibreSupport.list = [] + FibreSupport.active = {} # 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")) - FibreSupport.saved = True # traverse runtime stack list to build internal list of fibres _globalStackList = gdb.parse_and_eval("_globalStackList") first = _globalStackList['anchor'].address @@ -41,21 +37,14 @@ class FibreSupport(): } orig_thread.switch() - def cont_handler(event): - FibreSupport.list = [] - FibreSupport.active = {} - - # ideally restore() would be hooked up with cont_handler, - # but gdb currently fails with segmentation fault when trying + # restore() is hooked to continue events via basic script hooks def restore(): - if (FibreSupport.saved): - 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)) - FibreSupport.saved = False + 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)) def prep_frame(): # walk stack down to innermost frame @@ -234,4 +223,3 @@ FibreSetPtr() FibreSetIdx() FibreReset() gdb.events.stop.connect(FibreSupport.stop_handler) -gdb.events.cont.connect(FibreSupport.cont_handler) -- GitLab