Improving GDB Macros

I have this gdb macro that is used to print meaningful stacks when debugging a mono executable version. It iterates over all stack frames, indicates whether this frame is native or managed. If it is managed, it uses the information from mono_pmip () to print a decent description of this frame. If it is native, it calls gdb "frame" to describe the frame.

define mono_backtrace select-frame 0 set $i = 0 while ($i < $arg0) set $foo = mono_pmip ($pc) if ($foo == 0x00) frame else printf "#%d %p in %s\n", $i, $pc, $foo end up-silently set $i = $i + 1 end end 

Two questions related to this:

How can I remove the $ arg0 argument and pass it through all the frames until it reaches the top of the stack?

How can I get a "frame" (or an alternative) only to print the name of the function (for example, bt), and not the actual line of source code in this function ?. Current output:

 #1 0x000c21f6 in mono_handle_exception (ctx=0xbfffe7f0, obj=0x64bf18, original_ip=0x65024a, test_only=0) at mini-exceptions.c:1504 1504 return mono_handle_exception_internal (ctx, obj, original_ip, test_only, NULL, NULL); #2 0x00115b92 in mono_x86_throw_exception (regs=0xbfffe850, exc=0x64bf18, eip=6619722, rethrow=0) at exceptions-x86.c:438 438 mono_handle_exception (&ctx, exc, (gpointer)eip, FALSE); 

While I want the result to match what bt does:

 #1 0x000c21f6 in mono_handle_exception (ctx=0xbfffe7f0, obj=0x64bf18, original_ip=0x65024a, test_only=0) at mini-exceptions.c:1504 #2 0x00115b92 in mono_x86_throw_exception (regs=0xbfffe850, exc=0x64bf18, eip=6619722, rethrow=0) at exceptions-x86.c:438 
+4
source share
2 answers

How can I remove the $ arg0 argument and pass it through all the frames until it reaches the top of the stack?

Just do while (1) . Eventually, up-silently will fail, and evaluation will stop.

How can I get a "frame" (or an alternative) only to print the name of the function (for example, bt), and not the actual line of source code in this function?

In GDB 7.3 frames exposed to Python , giving you finer programmatic control over them.

0
source

up-silently does not work with thread apply all , because it actually stops all processing of commands from errors. Thus, it is not possible to get backtracking for all threads this way.

I managed to process it using a small amount of Python code.

 python class Frame_Valid (gdb.Function): def __init__ (self): super (Frame_Valid, self).__init__ ("frame_valid") def invoke (self): return gdb.selected_frame().is_valid() Frame_Valid () end define mono_backtrace set $i = 0 select-frame $i while ($frame_valid()) set $foo = (char*) mono_pmip ($pc) if ($foo) printf "#%d %p in %s\n", $i, $pc, $foo else frame end set $i = $i + 1 select-frame $i end end 
0
source

Source: https://habr.com/ru/post/1310467/


All Articles