0

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) 
Nick_h
  • 21
  • 4
  • 1
    Do you have the debug info for `/lib32/libc.so.6`? – ssbssa Nov 08 '22 at 17:11
  • @ssbssa It's the same for the x86, x86-64 versions, i.e. GNU C Library (Ubuntu GLIBC 2.27-3ubuntu1.6) stable release version 2.27. I thought maybe glibc for 32-bit is compiled by different c source code but I could not find something relevant in google – Nick_h Nov 08 '22 at 17:21
  • $/lib/x86_64-linux-gnu/libc.so.6 GNU C Library (Ubuntu GLIBC 2.27-3ubuntu1.6) stable release version 2.27. $/lib32/libc.so.6 GNU C Library (Ubuntu GLIBC 2.27-3ubuntu1.6) stable release version 2.27. – Nick_h Nov 08 '22 at 17:25
  • 1
    That didn't really answer my question. What does it say if you do `gdb -q /lib32/libc.so.6`? – ssbssa Nov 08 '22 at 17:37
  • @ssbssa `$ gdb -q /lib32/libc.so.6` `Reading symbols from /lib32/libc.so.6...(no debugging symbols found)...done.` So, that means that I am out of luck unless I compile glibc myself with debug info? – Nick_h Nov 08 '22 at 18:00
  • 3
    Maybe try [this answer](https://stackoverflow.com/a/20019999/1983398). – ssbssa Nov 08 '22 at 18:08

0 Answers0