Skip to main content
1 of 4
w s
  • 8.5k
  • 1
  • 25
  • 40

To arrive to your _init function just continue execution. This will stop once again in the intended place.

    gdb -q test.out
    Reading symbols from test.out...done.
    (gdb) b _init
    Breakpoint 1 at 0x4003e0
    (gdb) run
    Starting program: /home/[censored]/stk/test.out 
    
    Breakpoint 1, _init (argc=1, argv=0x7fffffffe008, envp=0x7fffffffe018) at ../csu/init-first.c:52
    52  ../csu/init-first.c: No such file or directory.
    (gdb) bt
    #0  _init (argc=1, argv=0x7fffffffe008, envp=0x7fffffffe018) at ../csu/init-first.c:52
    #1  0x00007ffff7dea0fd in call_init (l=0x7ffff7ff74c0, argc=argc@entry=1, argv=argv@entry=0x7fffffffe008, env=env@entry=0x7fffffffe018) at dl-init.c:64
    #2  0x00007ffff7dea223 in call_init (env=<optimized out>, argv=<optimized out>, argc=<optimized out>, l=<optimized out>) at dl-init.c:36
    #3  _dl_init (main_map=0x7ffff7ffe1c8, argc=1, argv=0x7fffffffe008, env=0x7fffffffe018) at dl-init.c:126
    #4  0x00007ffff7ddb30a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
    #5  0x0000000000000001 in ?? ()
    #6  0x00007fffffffe364 in ?? ()
    #7  0x0000000000000000 in ?? ()
    (gdb) c
    Continuing.
    
    Breakpoint 1, 0x00000000004003e0 in _init ()
    (gdb) bt
    #0  0x00000000004003e0 in _init ()
    #1  0x0000000000400593 in __libc_csu_init ()
    #2  0x00007ffff7a36e55 in __libc_start_main (main=0x40052d <main>, argc=1, argv=0x7fffffffe008, init=0x400560 <__libc_csu_init>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdff8)
        at libc-start.c:246
    #3  0x0000000000400469 in _start ()
    (gdb) info shared
    From                To                  Syms Read   Shared Object Library
    0x00007ffff7ddaae0  0x00007ffff7df54e0  Yes         /lib64/ld-linux-x86-64.so.2
    0x00007ffff7a344a0  0x00007ffff7b79583  Yes         /lib/x86_64-linux-gnu/libc.so.6
    (gdb) x/10i $pc
=> 0x4003e0 <_init>:    sub    $0x8,%rsp
   0x4003e4 <_init+4>:  mov    0x200c0d(%rip),%rax        # 0x600ff8
   0x4003eb <_init+11>: test   %rax,%rax
   0x4003ee <_init+14>: je     0x4003f5 <_init+21>
   0x4003f0 <_init+16>: callq  0x400430 <__gmon_start__@plt>
   0x4003f5 <_init+21>: add    $0x8,%rsp
   0x4003f9 <_init+25>: retq 
(gdb) info breakpoints
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   <MULTIPLE>         
    breakpoint already hit 2 times
1.1                         y     0x00000000004003e0 <_init>
1.2                         y     0x00007ffff7a36c20 in _init at ../csu/init-first.c:52

According to information about shared libraries, it stopped first time in address area of libc.so , which looks like also has _init function, which caused gdb to set this breakpoint there too (see breakpoint definition at the end of the listing).

Good luck.

w s
  • 8.5k
  • 1
  • 25
  • 40