GDB: how to print function argument values ​​when no character names are available

I check the core dump and need to print the values ​​of the function arguments when only their types are known (without the characters of the argument name):

(gdb) frame 7 #7 0x00007f201a269e82 in f1(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char*, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*) () from /usr/lib64/libsome.so (gdb) info args No symbol table info available. (gdb) info f Stack level 7, frame at 0x7f200ebf9e50: rip = 0x7f201a269e82 in f1(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned char*, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*); saved rip 0x7f201b430905 called by frame at 0x7f200ebfa1c0, caller of frame at 0x7f200ebf9e00 Arglist at 0x7f200ebf9df8, args: Locals at 0x7f200ebf9df8, Previous frame sp is 0x7f200ebf9e50 Saved registers: rbx at 0x7f200ebf9e28, rbp at 0x7f200ebf9e30, r12 at 0x7f200ebf9e38, r13 at 0x7f200ebf9e40, rip at 0x7f200ebf9e48 

In particular, I need to know what is in the first argument (std :: string) and in the last (std :: string *). Argist and local residents in this frame point to the same address ...

+5
source share
1 answer

There is no easy way to do this.

What you need to do is find the ABI for your platform and then use this to understand the argument passing convention. This is not always easy, but it can be done. This will show you how to find the arguments, regardless of whether they are in registers or in memory; and then you can use casting to the appropriate types to print them. A.

Of course, casting can also be difficult if you don't have debuginfo. Although there is a trick: compile a dummy file with -g that has the types you need, and then symbol-file in gdb to access these types. This, of course, has reservations, you must use the correct compiler and library versions, fix the compiler target and flags that change the ABI, etc.

In fact, it’s much, much better to plan ahead and always have debugging information. Which will not help you now, but maybe in the future. The ability to send a program, but save debugging information that is available later, is mainly the reason why the debuginfo delimiter was developed.

In addition, it is worth noting that the output of gdb frame not changed much since the days that are long gone are deleted. I think the arglist and locals information is really pointless with DWARF and modern ABIs. There the gdb error is open about fixing this.

+4
source

All Articles