gdb调试libtool封装的可执行文件

http://www.gnu.org/software/libtool/manual/html_node/Debugging-executables.html

3.4 Debugging executables

Ifhellwas a complicated program, you would certainly want to test and debug it before installing it on your system. In the above section, you saw how the libtool wrapper script makes it possible to run the program directly, but unfortunately, this mechanism interferes with the debugger:

     burger$ gdb hell
     GDB is free software and you are welcome to distribute copies of it
      under certain conditions; type "show copying" to see the conditions.
     There is no warranty for GDB; type "show warranty" for details.
     GDB 4.16 (i386-unknown-netbsd), (C) 1996 Free Software Foundation, Inc.
     
     "hell": not in executable format: File format not recognized
     
     (gdb) quit
     burger$

Sad. It doesn't work because GDB doesn't know where the executable lives. So, let's try again, by invoking GDB directly on the executable:

     burger$ gdb .libs/hell
     GNU gdb 5.3 (i386-unknown-netbsd)
     Copyright 2002 Free Software Foundation, Inc.
     GDB is free software, covered by the GNU General Public License,
     and you are welcome to change it and/or distribute copies of it
     under certain conditions.  Type "show copying" to see the conditions.
     There is no warranty for GDB.  Type "show warranty" for details.
     (gdb) break main
     Breakpoint 1 at 0x8048547: file main.c, line 29.
     (gdb) run
     Starting program: /home/src/libtool/demo/.libs/hell
     /home/src/libtool/demo/.libs/hell: can't load library 'libhello.so.0'
     
     Program exited with code 020.
     (gdb) quit
     burger$

Argh. Now GDB complains because it cannot find the shared library thathellis linked against. So, we must use libtool in order to properly set the library path and run the debugger. Fortunately, we can forget all about the.libsdirectory, and just run it on the executable wrapper (see Execute mode):

     burger$ libtool --mode=execute gdb hell
     GNU gdb 5.3 (i386-unknown-netbsd)
     Copyright 2002 Free Software Foundation, Inc.
     GDB is free software, covered by the GNU General Public License,
     and you are welcome to change it and/or distribute copies of it
     under certain conditions.  Type "show copying" to see the conditions.
     There is no warranty for GDB.  Type "show warranty" for details.
     (gdb) break main
     Breakpoint 1 at 0x8048547: file main.c, line 29.
     (gdb) run
     Starting program: /home/src/libtool/demo/.libs/hell
     
     Breakpoint 1, main (argc=1, argv=0xbffffc40) at main.c:29
     29        printf ("Welcome to GNU Hell!\n");
     (gdb) quit
     The program is running.  Quit anyway (and kill it)? (y or n) y
     burger$

转载于:https://www.cnblogs.com/ericsun/p/3168842.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值