如何在 Linux 下调试动态链接库 2
来源:互联网 发布:淘宝网店活体开店费用 编辑:程序博客网 时间:2024/05/17 01:04
下面我们就开始调试上面命令生成的 app程序吧。如果已经把上面生成的 libggg.so放到了库文件搜索路径指定的文件目录,比如/lib或/usr/lib之类的,调试就顺利完成,如下
:
QUOTE:
linux#gdb">zhoulifa@linux#gdb ./app
GNU gdb 6.4-debian
Copyright 2005 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 theconditions.
There is absolutely no warranty for GDB.
Type "show warranty"for details.This GDB was configured as"i486-linux-
gnu"...Using host libthread_db library"/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) b main /* 这是在程序的 main 处设置断点 */
Breakpoint 1 at0x804853c: file pk.cpp,line7.
(gdb) b set /* 这是在程序的 set 处设置断点 */
Function "set" not defined.
Make breakpoint pending on future shared
library load?(y or[n]) y/* 这里必须选择 y 调试程序才会跟踪到动态链接库内部去
*/Breakpoint 2(set) pending.
(gdb) run/* 开始运行我们的程序,直到遇见断点时暂停 */
Starting program:/data/example/c/app
Breakpoint 3 at0xb7f665f8: file get.cpp,line11.
Pending breakpoint "set" resolved
Breakpoint 1, main(argc=1,argv=0xbf990504) at pk.cpp:7
7 int a=100;
(gdb) n /* 继续执行程序的下一行代码
*/
8 int b= get();
(gdb) n /* 程序执行到了我们断点所在的动态链接库了 */
get x=0
9 int c= set(a);(gdb) n
Breakpoint 3, set(a=100) at get.cpp:11
11 printf ("set a=%d\n", a);
(gdb) list /* 查看当前代码行周围的代码,证明我们已经跟踪到动态链接库的源代码里面了 */
6 printf("get x=%d\n", x);
7 return x;
8 }
9 int set(int a)
10 {
11 printf("set a=%d\n", a);
12 x= a;
13 return x;
14 }
(gdb) n
set a=100
12 x = a;(gdb) n
13 return x;(gdb) n
14 }
(gdb) n
main (argc=1, argv=0xbf990504) at
pk.cpp:10
10 int d= get();
(gdb) n
get x=100
11 printf ("a=%d,b=%d,c=%
d,d=%d\n",a,b,c,d);
(gdb) n
a=100,b=0,c=100,d=100
12 return0;
(gdb) c
Continuing.
Program exited normally.
(gdb) quit/* 程序顺利执行结束 */zhoulifa@linux#
如果我们没有把动态链接库放到指定目录,比如/lib里面,调试就会失败,过程如下:
QUOTE:
zhoulifa@linux# gdb ./app
GNU gdb 6.4-debian
Copyright 2005 Free Software Foundation,
Inc.
GDB is free software, covered by the GNU
General Public License, and you arewelcome to change it and/or distribute
copies of it under certain conditions.
Type "show copying" to see theconditions.
There is absolutely no warranty for GDB.
Type "show warranty"for details.
This GDB was configured as "i486-linux-
gnu"...Using host libthread_db library
"/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) b main
Breakpoint 1 at0x804853c: file pk.cpp,
line 7.
(gdb) b set
Function "set" not defined.
Make breakpoint pending on future shared
library load?(y or[n]) y
Breakpoint 2(set) pending.
(gdb) run/* 虽然调试操作都一样,但程序执行失败 */
Starting program:/data/example/c/app
/data/example/c/app: error while loading
shared libraries: libggg.so: cannot open
shared object file: No such file or
directory
Program exited with code 0177.
(gdb) quit
:
QUOTE:
linux#gdb">zhoulifa@linux#gdb ./app
GNU gdb 6.4-debian
Copyright 2005 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 theconditions.
There is absolutely no warranty for GDB.
Type "show warranty"for details.This GDB was configured as"i486-linux-
gnu"...Using host libthread_db library"/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) b main /* 这是在程序的 main 处设置断点 */
Breakpoint 1 at0x804853c: file pk.cpp,line7.
(gdb) b set /* 这是在程序的 set 处设置断点 */
Function "set" not defined.
Make breakpoint pending on future shared
library load?(y or[n]) y/* 这里必须选择 y 调试程序才会跟踪到动态链接库内部去
*/Breakpoint 2(set) pending.
(gdb) run/* 开始运行我们的程序,直到遇见断点时暂停 */
Starting program:/data/example/c/app
Breakpoint 3 at0xb7f665f8: file get.cpp,line11.
Pending breakpoint "set" resolved
Breakpoint 1, main(argc=1,argv=0xbf990504) at pk.cpp:7
7 int a=100;
(gdb) n /* 继续执行程序的下一行代码
*/
8 int b= get();
(gdb) n /* 程序执行到了我们断点所在的动态链接库了 */
get x=0
9 int c= set(a);(gdb) n
Breakpoint 3, set(a=100) at get.cpp:11
11 printf ("set a=%d\n", a);
(gdb) list /* 查看当前代码行周围的代码,证明我们已经跟踪到动态链接库的源代码里面了 */
6 printf("get x=%d\n", x);
7 return x;
8 }
9 int set(int a)
10 {
11 printf("set a=%d\n", a);
12 x= a;
13 return x;
14 }
(gdb) n
set a=100
12 x = a;(gdb) n
13 return x;(gdb) n
14 }
(gdb) n
main (argc=1, argv=0xbf990504) at
pk.cpp:10
10 int d= get();
(gdb) n
get x=100
11 printf ("a=%d,b=%d,c=%
d,d=%d\n",a,b,c,d);
(gdb) n
a=100,b=0,c=100,d=100
12 return0;
(gdb) c
Continuing.
Program exited normally.
(gdb) quit/* 程序顺利执行结束 */zhoulifa@linux#
如果我们没有把动态链接库放到指定目录,比如/lib里面,调试就会失败,过程如下:
QUOTE:
zhoulifa@linux# gdb ./app
GNU gdb 6.4-debian
Copyright 2005 Free Software Foundation,
Inc.
GDB is free software, covered by the GNU
General Public License, and you arewelcome to change it and/or distribute
copies of it under certain conditions.
Type "show copying" to see theconditions.
There is absolutely no warranty for GDB.
Type "show warranty"for details.
This GDB was configured as "i486-linux-
gnu"...Using host libthread_db library
"/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) b main
Breakpoint 1 at0x804853c: file pk.cpp,
line 7.
(gdb) b set
Function "set" not defined.
Make breakpoint pending on future shared
library load?(y or[n]) y
Breakpoint 2(set) pending.
(gdb) run/* 虽然调试操作都一样,但程序执行失败 */
Starting program:/data/example/c/app
/data/example/c/app: error while loading
shared libraries: libggg.so: cannot open
shared object file: No such file or
directory
Program exited with code 0177.
(gdb) quit
- 如何在 Linux 下调试动态链接库 2
- 转贴 - 如何在 Linux 下调试动态链接库
- 如何在 Linux 下调试动态链接库
- 【转】如何在_Linux_下调试动态链接库
- linux下如何编写动态链接库
- 在linux下编写动态链接库
- 如何调试动态链接库
- VS2008下如何调试matlab使用的动态链接库
- linux下动态链接库使用与单步调试
- 如何让自己的动态链接库文件能够在linux下被调用
- 如何在linux下写动态链接库并卖给别人?
- linux下Unity3d下如何使用动态链接库
- linux下如何生成静态、动态链接库文件
- linux下如何编译自己的动态链接库
- 如何调试DLL动态链接库
- gdb如何调试动态链接库问题
- 在linux下编写动态链接库的步骤:
- 在linux下编写动态链接库的步骤
- 批量编译指定的无效对象【JOB】
- Servlet错误页面跳转同一个页面
- 如何在 Linux 下调试动态链接库
- extjs tbar 换行 多行
- DICOM标准之三_信息对象定义2
- 如何在 Linux 下调试动态链接库 2
- uw cse331 hw2
- windows下maven与eclipse部署
- 如何在android应用程序中启动其他apk程序,被启动程序退出后返回之前的程序
- Emacs+Python
- android悬浮窗--获取内存
- Exception loading sessions from persistent storage解决
- jsp中的Jstl中“$”与JQuery中的“$”冲突问题
- MFC 自定义消息的一般过程