开发学院软件开发Shell 如何在 Linux 下调试动态链接库 阅读

如何在 Linux 下调试动态链接库

 2009-06-30 03:44:00 来源:WEB开发网   
核心提示: (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",


(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        return 0;
(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 at 0x804853c: 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
zhoulifa@linux#

本次实验的环境是:
CPU:AMD Athlon(tm) 64 Processor 3000+
内存:512M
OS:Ubuntu GNU/Linux 6.06 dapper LTS
gcc:gcc 版本 4.0.3 (Ubuntu 4.0.3-1ubuntu5)

上一页  1 2 3 

Tags:如何 Linux 调试

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接