0

To see the start up process of a C++ program (with one console application and a shared library), first I installed CodeBlocks IDE on Ubuntu 18.04, but it only show main as the first entry in the call stack.

Then I use gdb to run the program and set a break point at "_start" (supposed to be the default Unix application entry point) then "main", but when break at "main", the backtrace command only show one frame.

How to see the call stack before main and further how to setup dgb for the symbols/sources for system libraries to view the source?

jw_
  • 1,663
  • 18
  • 32
  • `main` is called from Crt0. and the code of Crt0 is open source (in [GCC](http://gcc.gnu.org/) or [GNU libc](https://www.gnu.org/software/libc/)). Read also the ABI specification relevant to your architecture (e.g. [this](https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf) for x86-64) – Basile Starynkevitch Apr 06 '21 at 11:14

1 Answers1

3

The GDB setting you need is set backtrace past-main on:

Backtraces will continue past the user entry point.

(gdb) set backtrace past-main on
(gdb) start
(gdb) bt
#0  main (argc=argc@entry=1, argv=argv@entry=0x7ffffffee1a8) at hoist.c:7
#1  0x00007fffff0802e1 in __libc_start_main (main=0x8000580 <main>, argc=1, argv=0x7ffffffee1a8, init=<optimized out>,
    fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffffffee198) at ../csu/libc-start.c:291
#2  0x000000000800069a in _start ()

(gdb) fr 1
#1  0x00007fffff0802e1 in __libc_start_main (main=0x8000580 <main>, argc=1, argv=0x7ffffffee1a8, init=<optimized out>,
    fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffffffee198) at ../csu/libc-start.c:291
291     ../csu/libc-start.c: No such file or directory.

After installing the glibc source as described in GDB complaining about missing raise.c :

(gdb) fr 1
#1  0x00007fffff0802e1 in __libc_start_main (main=0x8000580 <main>, argc=1, argv=0x7ffffffee1a8, init=<optimized out>,
    fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffffffee198) at ../csu/libc-start.c:291
291           result = main (argc, argv, __environ MAIN_AUXVEC_PARAM);
Mark Plotnick
  • 9,598
  • 1
  • 24
  • 40