Printing Symbols on the stack using GDB

782 Views Asked by At

I was trying to debug a program that has a corrupted stack and seems too big (it has multiple threads) to manually debug. So I was wondering if there was a way to print out the symbols that correspond to the addresses on the stack after the corruption to try and get a better idea of how it got there.

I noticed the "info symbol" command (which normally prints out the symbol at a given address) only accepts one address at a time. So, I tried to write a script to do what I wanted, but when I tried to store the addresses in convenience variables so I could iterate through the stack manually, the info symbol command wouldn't work.

I know on WinDBG there is the dds command which does what I'm looking for, but I have not been able to find an equivalent in GDB. Does anyone know an equivalent?

2

There are 2 best solutions below

0
On

This might not answer your question but could help you with identifying the place where you have the stack corruption. Have you tried compiling with -fstack-protectorxxx flags on ?

https://en.wikibooks.org/wiki/Linux_Applications_Debugging_Techniques/Stack_corruption

0
On

x command with a flag will decode memory as address and will try to lookup for the symbols

given code:

int func3(int a)
{
   return a+a;
}
int func2(int b)
{
   return func3(b+b);
}
int func1(int c)
{
  return func2(c+c);
}
int main(int argc, char** argv)
{
  return func1(argc);
}

and breakpoint at func3 output will be:

(gdb) x /16ga $rsp
0x7fffffffe150: 0x7fffffffe168  0x5555555545fa <func2+23>
0x7fffffffe160: 0x2000000c2     0x7fffffffe180
0x7fffffffe170: 0x555555554613 <func1+23>       0x100000000
0x7fffffffe180: 0x7fffffffe1a0  0x55555555462e <main+25>
0x7fffffffe190: 0x7fffffffe288  0x100000000
0x7fffffffe1a0: 0x555555554630 <__libc_csu_init>        0x7ffff7a05b97 <__libc_start_main+231>
0x7fffffffe1b0: 0x1     0x7fffffffe288
0x7fffffffe1c0: 0x100008000     0x555555554615