|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <iostream>
- using namespace std;
- int main(void) {
- cout << "hello world" << endl;
- return 0;
- }
复制代码
在使用gdb调试以上代码的时侯, 运行到最后一个花括号上出现了下列的报错信息,是怎么情况?
- __libc_start_main (main=0x5555555551a9 <main()>, argc=1, argv=0x7fffffffdf98,
- init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>,
- stack_end=0x7fffffffdf88) at ../csu/libc-start.c:342
- 342 ../csu/libc-start.c: No such file or directory.
复制代码
你用的是单步步入指令 s 吧
这会在最后让程序停在调用 main 函数的下一条语句
main 函数是在 libc-start.c 文件中调用的,你用 s 指令就返回到这个文件了
一般 gcc 不提供这个文件,当然就找不到了
这不算是错误
你可以自己编译 gcc 的源代码,这个文件在 gcc 的源代码中
要在源代码级别调试库函数,你需要自己编译一个带源代码版本且不开优化的 gcc 编译器,当然还有依赖的库
- # gdb main
- GNU gdb (GDB) 10.2
- Copyright (C) 2021 Free Software Foundation, Inc.
- License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
- This is free software: you are free to change and redistribute it.
- There is NO WARRANTY, to the extent permitted by law.
- Type "show copying" and "show warranty" for details.
- This GDB was configured as "x86_64-pc-linux-gnu".
- Type "show configuration" for configuration details.
- For bug reporting instructions, please see:
- <https://www.gnu.org/software/gdb/bugs/>.
- Find the GDB manual and other documentation resources online at:
- <http://www.gnu.org/software/gdb/documentation/>.
- For help, type "help".
- Type "apropos word" to search for commands related to "word"...
- Reading symbols from main...
- (gdb) b main
- Breakpoint 1 at 0x4011ac: file main.cpp, line 6.
- (gdb) r
- Starting program: /tmp/main
- warning: File "/usr/lib/libstdc++.so.6.0.29-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
- To enable execution of this file add
- add-auto-load-safe-path /usr/lib/libstdc++.so.6.0.29-gdb.py
- line to your configuration file "/root/.gdbinit".
- To completely disable this security protection add
- set auto-load safe-path /
- line to your configuration file "/root/.gdbinit".
- For more information about this security protection see the
- "Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
- info "(gdb)Auto-loading safe path"
- Breakpoint 1, main () at main.cpp:6
- 6 cout << "hello world" << endl;
- (gdb) n
- hello world
- 7 return 0;
- (gdb) s
- 8 }
- (gdb) s
- __libc_start_main (main=0x4011a8 <main()>, argc=1, argv=0x7fffffffeae8, init=0x401222 <__libc_csu_init>,
- fini=0x40129a <__libc_csu_fini>, rtld_fini=0x7ffff7fd32b6 <_dl_fini>, stack_end=0x7fffffffead8)
- at ../csu/libc-start.c:366
- 366 exit (result);
- (gdb) l
- 361 #else
- 362 /* Nothing fancy, just call the function. */
- 363 result = main (argc, argv, __environ MAIN_AUXVEC_PARAM);
- 364 #endif
- 365
- 366 exit (result);
- 367 }
- (gdb)
复制代码
- # gdb main
- GNU gdb (GDB) 10.2
- Copyright (C) 2021 Free Software Foundation, Inc.
- License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
- This is free software: you are free to change and redistribute it.
- There is NO WARRANTY, to the extent permitted by law.
- Type "show copying" and "show warranty" for details.
- This GDB was configured as "x86_64-pc-linux-gnu".
- Type "show configuration" for configuration details.
- For bug reporting instructions, please see:
- <https://www.gnu.org/software/gdb/bugs/>.
- Find the GDB manual and other documentation resources online at:
- <http://www.gnu.org/software/gdb/documentation/>.
- For help, type "help".
- Type "apropos word" to search for commands related to "word"...
- Reading symbols from main...
- (gdb) b main
- Breakpoint 1 at 0x4011ac: file main.cpp, line 6.
- (gdb) r
- Starting program: /tmp/main
- warning: File "/usr/lib/libstdc++.so.6.0.29-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
- To enable execution of this file add
- add-auto-load-safe-path /usr/lib/libstdc++.so.6.0.29-gdb.py
- line to your configuration file "/root/.gdbinit".
- To completely disable this security protection add
- set auto-load safe-path /
- line to your configuration file "/root/.gdbinit".
- For more information about this security protection see the
- "Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
- info "(gdb)Auto-loading safe path"
- Breakpoint 1, main () at main.cpp:6
- 6 cout << "hello world" << endl;
- (gdb) n
- hello world
- 7 return 0;
- (gdb) s
- 8 }
- (gdb) s
- __libc_start_main (main=0x4011a8 <main()>, argc=1, argv=0x7fffffffeae8, init=0x401222 <__libc_csu_init>,
- fini=0x40129a <__libc_csu_fini>, rtld_fini=0x7ffff7fd32b6 <_dl_fini>, stack_end=0x7fffffffead8)
- at ../csu/libc-start.c:366
- 366 exit (result);
- (gdb) l
- 361 #else
- 362 /* Nothing fancy, just call the function. */
- 363 result = main (argc, argv, __environ MAIN_AUXVEC_PARAM);
- 364 #endif
- 365
- 366 exit (result);
- 367 }
- (gdb) kill
- Kill the program being debugged? (y or n) y
- [Inferior 1 (process 854883) killed]
- (gdb) b _start
- Breakpoint 2 at 0x401090: file ../sysdeps/x86_64/start.S, line 63.
- (gdb) r
- Starting program: /tmp/main
- warning: File "/usr/lib/libstdc++.so.6.0.29-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
- Breakpoint 2, _start () at ../sysdeps/x86_64/start.S:63
- 63 xorl %ebp, %ebp
- (gdb) l
- 58 ENTRY (_start)
- 59 /* Clearing frame pointer is insufficient, use CFI. */
- 60 cfi_undefined (rip)
- 61 /* Clear the frame pointer. The ABI suggests this be done, to mark
- 62 the outermost frame obviously. */
- 63 xorl %ebp, %ebp
- 64
- 65 /* Extract the arguments as encoded on the stack and set up
- 66 the arguments for __libc_start_main (int (*main) (int, char **, char **),
- 67 int argc, char *argv,
- (gdb) n
- 79 mov %RDX_LP, %R9_LP /* Address of the shared library termination
- (gdb)
- 85 popq %rsi /* Pop the argument count. */
- (gdb)
- 88 mov %RSP_LP, %RDX_LP
- (gdb)
- 90 and $~15, %RSP_LP
- (gdb)
- 93 pushq %rax
- (gdb)
- 97 pushq %rsp
- (gdb)
- 101 mov __libc_csu_fini@GOTPCREL(%rip), %R8_LP
- (gdb)
- 102 mov __libc_csu_init@GOTPCREL(%rip), %RCX_LP
- (gdb)
- 104 mov main@GOTPCREL(%rip), %RDI_LP
- (gdb)
- 120 call *__libc_start_main@GOTPCREL(%rip)
- (gdb)
- Breakpoint 1, main () at main.cpp:6
- 6 cout << "hello world" << endl;
- (gdb) kill
- Kill the program being debugged? (y or n) y
- [Inferior 1 (process 855406) killed]
- (gdb) r
- Starting program: /tmp/main
- warning: File "/usr/lib/libstdc++.so.6.0.29-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
- Breakpoint 2, _start () at ../sysdeps/x86_64/start.S:63
- 63 xorl %ebp, %ebp
- (gdb) n
- 79 mov %RDX_LP, %R9_LP /* Address of the shared library termination
- (gdb)
- 85 popq %rsi /* Pop the argument count. */
- (gdb)
- 88 mov %RSP_LP, %RDX_LP
- (gdb)
- 90 and $~15, %RSP_LP
- (gdb)
- 93 pushq %rax
- (gdb)
- 97 pushq %rsp
- (gdb)
- 101 mov __libc_csu_fini@GOTPCREL(%rip), %R8_LP
- (gdb)
- 102 mov __libc_csu_init@GOTPCREL(%rip), %RCX_LP
- (gdb)
- 104 mov main@GOTPCREL(%rip), %RDI_LP
- (gdb)
- 120 call *__libc_start_main@GOTPCREL(%rip)
- (gdb) s
- __libc_start_main (main=0x4011a8 <main()>, argc=1, argv=0x7fffffffeae8, init=0x401222 <__libc_csu_init>,
- fini=0x40129a <__libc_csu_fini>, rtld_fini=0x7ffff7fd32b6 <_dl_fini>, stack_end=0x7fffffffead8)
- at ../csu/libc-start.c:248
- 248 if (__glibc_likely (rtld_fini != NULL))
- (gdb) n
- 249 __cxa_atexit ((void (*) (void *)) rtld_fini, NULL, NULL);
- (gdb)
- 275 if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_IMPCALLS, 0))
- (gdb)
- 278 if (init)
- (gdb)
- 279 (*init) (argc, argv, __environ MAIN_AUXVEC_PARAM);
- (gdb)
- 283 if (__glibc_unlikely (GLRO(dl_naudit) > 0))
- (gdb)
- 298 if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_IMPCALLS))
- (gdb)
- 318 not_first_call = setjmp ((struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf);
- (gdb)
- 320 if (__glibc_likely (! not_first_call))
- (gdb)
- 322 struct pthread *self = THREAD_SELF;
- (gdb)
- 325 unwind_buf.priv.data.prev = THREAD_GETMEM (self, cleanup_jmp_buf);
- (gdb)
- 326 unwind_buf.priv.data.cleanup = THREAD_GETMEM (self, cleanup);
- (gdb)
- 329 THREAD_SETMEM (self, cleanup_jmp_buf, &unwind_buf);
- (gdb)
- 332 result = main (argc, argv, __environ MAIN_AUXVEC_PARAM);
- (gdb) s
- Breakpoint 1, main () at main.cpp:6
- 6 cout << "hello world" << endl;
- (gdb) n
- hello world
- 7 return 0;
- (gdb)
- 8 }
- (gdb)
- __libc_start_main (main=0x4011a8 <main()>, argc=1, argv=0x7fffffffeae8, init=0x401222 <__libc_csu_init>,
- fini=0x40129a <__libc_csu_fini>, rtld_fini=0x7ffff7fd32b6 <_dl_fini>, stack_end=0x7fffffffead8)
- at ../csu/libc-start.c:366
- 366 exit (result);
- (gdb) l
- 361 #else
- 362 /* Nothing fancy, just call the function. */
- 363 result = main (argc, argv, __environ MAIN_AUXVEC_PARAM);
- 364 #endif
- 365
- 366 exit (result);
- 367 }
- (gdb) n
- [Inferior 1 (process 855505) exited normally]
- (gdb)
复制代码
|
|