linux下调试工具

本文介绍了几种常用的Linux调试工具,包括lsof、strace、GDB、Valgrind和binutils等,详细阐述了这些工具的经典用法及高级应用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

工作中常用的linux调试工具,与大家分享

一、lsof 查找系统打开的文件

经典用法。查看进程打开的文件句柄。

案例:我的一个服务进程,运行一段时间后,在64位机器上运行正常,在32位机器上运行不正常。用lsof一看。有打开的文件未关闭,因64位机器默认进程打开文件数是100万,因而没有出现问题。

其他用法。

1、查看某个文件被哪个进程打开。

2、查看某个文件系统被哪个进程使用。

更多用法查看:http://www.ibm.com/developerworks/cn/aix/library/au-lsof.html

二、strace ltraceftrace

经典用法。进程无法启动,软件运行速度突然变慢,程序的"SegmentFault"的检查。

更多用法查看:http://doggou.javaeye.com/blog/543046

三、GDB

这个大家经常用,只讲高级用法。

调试多进程程序,

http://www.ibm.com/developerworks/cn/linux/l-cn-gdbmp/

调试多线程

http://luckyclouds.javaeye.com/blog/493464

GDB对信号的处理

http://linux.chinaunix.net/techdoc/develop/2006/09/28/941197.shtml

Electric-Fence

Electric-Fence 是一组用于在基于 gdb的环境中检测缓冲区上溢出或下溢出的库。在发生错误的内存访问时,这个工具(与 gdb 结合)会准确地指出源代码中导致问题的指令。

http://www.ibm.com/developerworks/cn/aix/library/au-aixnirvana/

四、Valgrind

很好的工具,发现一切与内存有关的问题。

小提示:–db-attach=yes 在首次遇到内存问题时,将调用gdb进行调试。

http://www.ibm.com/developerworks/cn/linux/l-pow-debug/

五、 binutil
binutil是一系列的工具,你可能根本不知道它们的存在,但是没有它们你却寸步难行。Binutil包括下列工具:
ld - the GNU linker.
as - the GNU assembler.
addr2line - Converts addresses into filenames and linenumbers.
ar - A utility for creating, modifying and extracting fromarchives.
c++filt - Filter to demangle encoded C++ symbols.
gprof - Displays profiling information.
nlmconv - Converts object code into an NLM.
nm - Lists symbols from object files.
objcopy - Copys and translates object files.
objdump - Displays information from object files.
ranlib - Generates an index to the contents of an archive.
readelf - Displays information from any ELF format objectfile.
size - Lists the section sizes of an object or archive file.
strings - Lists printable strings from files.
strip - Discards symbols.
windres - A compiler for Windows resource files.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值