I have a virtual Ubuntu 18.04 and try to see the functions call-chain in action for 32 bit executables along with the c code that generated the glibc binary using gdb. In particular I want to see the very first call to __libc_start_main
, step into the function along with the c source code for __libc_start_main
. I have successfully done this with 64 bit-executables but the 32-bit case is giving me a hard time..
The test c source I am using is the the simple:
#include <stdio.h>
int main(int argc, char * argv[]){
printf("hello %d, %s\n",argc,argv[1]);
return 0;
}
I have installed glibc source and set the source path in gdb with (gdb) dir glibc-2.27/csu
where csu is the directory containing the file libc-start.c
where __libc_start_main
is defined.
Here is a successful sample, fiddling with gdb:
gdb -q test
Reading symbols from test...done.
(gdb) dir glibc-2.27/csu
Source directories searched: /home/nick/c_programs/x86-64/glibc-2.27/csu:$cdir:$cwd
(gdb) br __libc_start_main
Function "__libc_start_main" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (__libc_start_main) pending.
(gdb) run nikos
Starting program: /home/nick/c_programs/x86-64/test nikos
Breakpoint 1, __libc_start_main (main=0x55555555464a <main>, argc=2,
argv=0x7fffffffe068, init=0x555555554690 <__libc_csu_init>,
fini=0x555555554700 <__libc_csu_fini>,
rtld_fini=0x7ffff7de3b40 <_dl_fini>, stack_end=0x7fffffffe058)
at ../csu/libc-start.c:137
warning: Source file is more recent than executable.
137 {
I have tried the same approach with a 32 bit version of my test code (I compiled with gcc -m32 -g -o test test.c
, but the debugger isn't showing the c source code:
gdb -q test
Reading symbols from test...done.
(gdb) dir glibc-2.27/csu
Source directories searched: /home/nick/c_programs/x86/glibc-2.27/csu:$cdir:$cwd
(gdb) br __libc_start_main
Breakpoint 1 at 0x3c0
(gdb) run nikos
Starting program: /home/nick/c_programs/x86/test nikos
Breakpoint 1, 0xf7dfaeb0 in __libc_start_main () from /lib32/libc.so.6
(gdb)