Quality of life patches for qemu coroutine debugging
v2 cover Quality of life patches for qemu coroutine debugging
These are two patches that improve a bit the qemu gdb scripts in regard to coroutines.
First patch fixes a bug in 'qemu coroutine' in regard to usage on non topmost stack frame.
Second patch implements 'qemu bt' as Stefan suggested.
V2, because after hitting 'send' I noticed a few bugs:
1. Switch to try/catch around bt, so that when regular bt fails, we print the same message as original bt.
2. Print the correct co-routine address
Best regards,
Maxim Levitsky
Maxim Levitsky (2):
scripts/gdb: fix 'qemu coroutine' when users selects a non topmost
stack frame
scripts/gdb: implement 'qemu bt'
scripts/qemu-gdb.py | 1 + scripts/qemugdb/coroutine.py | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-)
Signature · 1 line
2.26.2
PATCH v2 1/2 scripts/gdb: fix 'qemu coroutine' when users selects a non topmost stack frame
The code that dumps the stack frame works like that:
* save current registers
* overwrite current registers (including rip/rsp) with coroutine snapshot in the jmpbuf
* print backtrace
* restore the saved registers.
If the user has currently selected a non topmost stack frame in gdb, the above code will still restore the selected frame registers, but the gdb will then lose the selected frame index, which makes it impossible to switch back to frame 0, to continue debugging the executable.
Therefore switch temporarily to the topmost frame of the stack for the above code.
--- scripts/qemugdb/coroutine.py | 7 +++++++ 1 file changed, 7 insertions(+)
scripts/qemugdb/coroutine.py +7 -0
@@ -70,6 +70,11 @@ def bt_jmpbuf(jmpbuf): regs = get_jmpbuf_regs(jmpbuf) old = dict() + # remember current stack frame and select the topmost + # so that register modifications don't wreck it + selected_frame = gdb.selected_frame() + gdb.newest_frame().select() + for i in regs: old[i] = gdb.parse_and_eval('(uint64_t)$%s' % i)
@@ -81,6 +86,8 @@ def bt_jmpbuf(jmpbuf): for i in regs: gdb.execute('set $%s = %s' % (i, old[i])) + selected_frame.select() + def coroutine_to_jmpbuf(co): coroutine_pointer = co.cast(gdb.lookup_type('CoroutineUContext').pointer()) return coroutine_pointer['env']['__jmpbuf']
Signature · 1 line
2.26.2
PATCH v2 2/2 scripts/gdb: implement 'qemu bt'
In reply to Maxim LevitskyThis script first runs the regular gdb's 'bt' command, and then if we are in a coroutine it prints the coroutines backtraces in the order in which they were called.
--- scripts/qemu-gdb.py | 1 + scripts/qemugdb/coroutine.py | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-)
scripts/qemu-gdb.py +1 -0
@@ -40,6 +40,7 @@ timers.TimersCommand() coroutine.CoroutineSPFunction() coroutine.CoroutinePCFunction() +coroutine.CoroutineBt() # Default to silently passing through SIGUSR1, because QEMU sends it # to itself a lot.
scripts/qemugdb/coroutine.py +27 -1
@@ -88,8 +88,11 @@ def bt_jmpbuf(jmpbuf): selected_frame.select() +def co_cast(co): + return co.cast(gdb.lookup_type('CoroutineUContext').pointer()) + def coroutine_to_jmpbuf(co): - coroutine_pointer = co.cast(gdb.lookup_type('CoroutineUContext').pointer()) + coroutine_pointer = co_cast(co) return coroutine_pointer['env']['__jmpbuf']
@@ -107,6 +110,29 @@ class CoroutineCommand(gdb.Command): bt_jmpbuf(coroutine_to_jmpbuf(gdb.parse_and_eval(argv[0]))) +class CoroutineBt(gdb.Command): + '''Display backtrace including coroutine switches''' + def __init__(self): + gdb.Command.__init__(self, 'qemu bt', gdb.COMMAND_STACK, + gdb.COMPLETE_NONE) + + def invoke(self, arg, from_tty): + + gdb.execute("bt") + + if gdb.parse_and_eval("qemu_in_coroutine()") == False: + return + + co_ptr = gdb.parse_and_eval("qemu_coroutine_self()") + + while True: + co = co_cast(co_ptr) + co_ptr = co["base"]["caller"] + if co_ptr == 0: + break + gdb.write("Coroutine at " + str(co_ptr) + ":\n") + bt_jmpbuf(coroutine_to_jmpbuf(co_ptr)) + class CoroutineSPFunction(gdb.Function): def __init__(self): gdb.Function.__init__(self, 'qemu_coroutine_sp')
Signature · 1 line
2.26.2
Quoted 16 lines · Maxim Levitsky
These are two patches that improve a bit the qemu gdb scripts in regard to coroutines.
First patch fixes a bug in 'qemu coroutine' in regard to usage on non topmost stack frame.
Second patch implements 'qemu bt' as Stefan suggested.
V2, because after hitting 'send' I noticed a few bugs:
1. Switch to try/catch around bt, so that when regular bt fails, we print the same message as original bt.
2. Print the correct co-routine addressBest regards,
Maxim Levitsky
Quoted 14 lines
Maxim Levitsky (2):
scripts/gdb: fix 'qemu coroutine' when users selects a non topmost
stack frame
scripts/gdb: implement 'qemu bt'scripts/qemu-gdb.py | 1 + scripts/qemugdb/coroutine.py | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-)Signature · 1 line
2.26.2
Any update on this?
Best regards,
Maxim Levitsky
Quoted 26 lines · Maxim Levitsky
Quoted 25 lines · Maxim Levitsky
These are two patches that improve a bit the qemu gdb scripts in regard to coroutines.
First patch fixes a bug in 'qemu coroutine' in regard to usage on non topmost stack frame.
Second patch implements 'qemu bt' as Stefan suggested.
V2, because after hitting 'send' I noticed a few bugs:
1. Switch to try/catch around bt, so that when regular bt fails, we print the same message as original bt.
2. Print the correct co-routine addressBest regards,
Maxim LevitskyMaxim Levitsky (2):
scripts/gdb: fix 'qemu coroutine' when users selects a non topmost
stack frame
scripts/gdb: implement 'qemu bt'scripts/qemu-gdb.py | 1 + scripts/qemugdb/coroutine.py | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-)
Quoted 10 lines
Quoted 5 lines
Signature · 1 line
2.26.2Any update on this?
Best regards,
Maxim Levitsky
I'll queue them myself, thanks.
Paolo
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Maxim Levitsky
Quoted 3 lines · Maxim Levitsky
These are two patches that improve a bit the qemu gdb scripts in regard to coroutines.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
First patch fixes a bug in 'qemu coroutine' in regard to usage on non topmost stack frame.
Second patch implements 'qemu bt' as Stefan suggested.
V2, because after hitting 'send' I noticed a few bugs:
1. Switch to try/catch around bt, so that when regular bt fails, we print the same message as original bt.
Note that I forgot to 'git add' this bit, but it is only a cosmetic thing, so I'll guess I'll just leave it like that.
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
2. Print the correct co-routine address
Best regards,
Maxim LevitskyMaxim Levitsky (2):
scripts/gdb: fix 'qemu coroutine' when users selects a non topmost
stack frame
scripts/gdb: implement 'qemu bt'scripts/qemu-gdb.py | 1 + scripts/qemugdb/coroutine.py | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-)Signature · 1 line
2.26.2
Quoted 7 lines
Quoted 5 lines
Any update on this?
Best regards,
Maxim LevitskyI'll queue them myself, thanks.
Thanks!
Best regards,
Maxim Levitsky
Quoted 3 lines
Paolo