有人能告诉我如何在共享库上进行运行时调试吗?

我需要在共享库中运行调试一个函数,但它被另一个程序调用.

我在AIX上使用dbx.

推荐答案

您只需要使用可执行文件调用gdb(不管它是您的还是第三方的).下面是我调试ls命令并在(共享)c library中设置断点的示例.本例使用gdb 6.8,它支持延迟(挂起)断点,这使操作变得简单:

gdb /bin/ls
GNU gdb 6.8-debian
Copyright (C) 2008 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-linux-gnu"...
(no debugging symbols found)
(gdb) b write
Function "write" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (write) pending.
(gdb) r
Starting program: /bin/ls
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
(no debugging symbols found)
(no debugging symbols found)
[New Thread 0x7f98d2d23780 (LWP 7029)]
[Switching to Thread 0x7f98d2d23780 (LWP 7029)]

Breakpoint 1, 0x00007f98d2264bb0 in write () from /lib/libc.so.6
(gdb)

正如您所见,gdb自动管理可执行文件使用的所有线程.你不必为那里的线程做任何特殊的事情.断点将在任何线程中工作.

或者,如果您想将调试器附加到一个已经运行的应用程序(我这里使用tail -f /tmp/ttt作为示例):

ps ux | grep tail
lothar    8496  0.0  0.0   9352   804 pts/3    S+   12:38   0:00 tail -f /tmp/ttt
lothar    8510  0.0  0.0   5164   840 pts/4    S+   12:39   0:00 grep tail

gdb
GNU gdb 6.8-debian
Copyright (C) 2008 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-linux-gnu"...
(no debugging symbols found)
(gdb) attach 8496
Attaching to program: /usr/bin/tail, process 8496
Reading symbols from /lib/librt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/librt.so.1
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/libpthread.so.0...(no debugging symbols found)...done.
[Thread debugging using libthread_db enabled]
[New Thread 0x7f24853f56e0 (LWP 8496)]
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/ld-linux-x86-64.so.2...
(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
(no debugging symbols found)
0x00007f2484d2bb50 in nanosleep () from /lib/libc.so.6
(gdb) b write
Breakpoint 1 at 0x7f2484d57bb0
(gdb) c
Continuing.
[Switching to Thread 0x7f24853f56e0 (LWP 8496)]

Breakpoint 1, 0x00007f2484d57bb0 in write () from /lib/libc.so.6
(gdb)

Linux相关问答推荐

无法分析nasm中的单词

如何使 awk 输出更具可读性?

替换前 3 个字符范围内的所有整数

使用 bash 命令将文件从子文件夹复制到另一个

根据文件名对目录中的文件进行 chgrp

当接收端未从套接字读取时,通过 Unix 套接字发送的消息会发生什么情况?

进程Forking 后 pthread_key_create() 生成的密钥会发生什么?

使用 awk 将 csv 拆分为带有标题的多个文件

对一个命令使用不同的 PHP 版本 CLI 可执行文件

用于判断进程是否正在运行并对结果采取行动的 Linux 脚本

如何在python中检索进程开始时间(或正常运行时间)

从 Linux 到 Windows 交叉编译 C++ 应用程序的手册?

通过写入 /dev/input/mice 来控制鼠标

对一行的最后一个字段进行排序

在亚马逊 ec2 linux 微型实例上的 virtualenv 中安装 scipy 时遇到问题

使用 cmake 构建错误:找不到 -lpthreads

是否有一个 linux 命令来确定与给定进程 ID 关联的窗口 ID?

try 使用 sudo 将文件附加到根拥有的文件时权限被拒绝

卸载从源代码构建的python?

在tmux中绑定Ctrl+Tab和Ctrl+Shift+Tab