C++(Qt)软件调试---binutils工具集详解

1. 概述

2. binutils包含的工具

3. 主要工具详细说明

4. 其它工具详细说明

将地址转换为文件名和行号

addr2line -e myprogram 0x400526

显示地址、函数名和源码位置

addr2line -a -f -e myprogram 0x400526

只显示文件名(不包含路径)和行号

addr2line -s -e myprogram 0x400526

ar [选项] 归档文件名 [成员文件...]

创建一个包含多个目标文件的静态库

ar rcs libmylib.a file1.o file2.o file3.o

列出库中包含的所有文件

ar t libmylib.a

从库中提取特定文件

ar x libmylib.a file1.o

向已存在的库中添加新文件

ar r libmylib.a newfile.o

c++filt [options] [mangled_names...]

echo "_ZNSsD1Ev" | c++filt # 通过管道解码

nm executable | c++filt # 解码nm输出中的符号

dlltool [options] [--input-def def-file] [--output-lib lib-file] [--dllname dll-name]

dlltool --def mydll.def --dllname mydll.dll --output-lib libmydll.a

elfedit [options] elf-file

修改 ELF 文件的机器类型

elfedit --input-mach i386 --output-mach x86_64 program.elf

修改 ELF 文件的 OSABI

elfedit --output-osabi linux program.elf

启用 x86 特性

elfedit --enable-x86-feature feature_name program.elf

4.6 gprof

1. 编译程序时添加 -pg 选项

gcc -pg -o myprogram myprogram.c

2. 运行程序生成 gmon.out

./myprogram

3. 使用 gprof 分析性能

gprof myprogram gmon.out > analysis.txt

只显示扁平性能分析,不显示调用图

gprof -p myprogram gmon.out

设置最小调用次数阈值

gprof -m 10 myprogram gmon.out

排除特定函数

gprof -e init_function myprogram gmon.out

显示所有函数包括未调用的

gprof -z myprogram gmon.out

生成带注释的源代码

gprof -S myprogram gmon.out

4.7 gprofng

收集指定程序的性能数据

gprofng collect your_program

收集正在运行的进程数据

gprofng collect -p PID

收集系统范围的性能数据

gprofng collect -s

分析收集到的数据

gprofng display experiment_name

生成火焰图

gprofng display -flamegraph experiment_name

生成调用树

gprofng display -calltree experiment_name

4.8 nlmconv

nlmconv [options] input-file

nlmconv -T nlm32-i386 input.o output.nlm

4.9 nm

nm [options] object-file...

nm executable # 显示所有符号

nm -D shared_library.so # 显示动态符号表

nm -g executable # 只显示全局符号

4.10 objcopy

objcopy [options] infile outfile

objcopy -O binary executable bootsect.bin # 转换为原始二进制格式

objcopy --strip-debug executable stripped # 去除调试信息

objcopy --only-section=.text input output # 只保留.text段

4.11 objdump

objdump [options] object-file...

反汇编可执行文件

objdump -d program

显示文件头信息

objdump -f program

显示所有节头信息

objdump -h program

混合显示源码和反汇编

objdump -S program

只反汇编特定函数

objdump --disassemble=main program

4.12 ranlib

ranlib archive-file

ar rcs libname.a *.o # ar的s选项会自动调用ranlib

4.13 readelf

readelf [options] elf-file

显示文件头信息

readelf -h a.out

显示所有节区信息

readelf -S a.out

显示符号表

readelf -s a.out

显示动态段信息

readelf -d a.out

以十六进制显示 .text 节内容

readelf -x .text a.out

显示所有调试信息

readelf -w a.out

4.14 size

size [options] object-file...

基本用法,显示默认格式

size a.out

使用 System V 格式显示详细节区信息

size -A a.out

以十六进制显示数值

size -x a.out

显示多个文件并计算总计(Berkeley 格式)

size -t *.o

显示 COMMON 符号大小

size --common test.o

指定特定目标格式

size --target=elf32-i386 program.bin

4.15 strings

strings [options] file...

提取文件中的所有字符串(至少4个字符)

strings myfile

提取至少8个字符长度的字符串

strings -n 8 myfile

显示字符串在文件中的位置(十六进制)

strings -t x myfile

只扫描数据段并显示文件名

strings -d -f myfile

指定字符编码(16位小端)

strings -e l myfile

4.16 strip

strip [options] file...

基本使用:移除所有符号信息

strip program

保留调试信息

strip --only-keep-debug program.debug

移除调试信息但保留符号表

strip --strip-debug program

保留特定符号

strip -K main -K important_func program

移除指定节区

strip -R .comment -R .note program

4.17 windmc

windmc [options] msgfile.mc

基本编译

windmc messages.mc

指定头文件输出目录

windmc -h include messages.mc

指定资源文件输出目录

windmc -r resources messages.mc

使用UTF16输入和详细模式

windmc -u -v messages.mc

4.18 windres

windres [options] input-file output-file

windres resource.rc resource.o # 编译资源文件

windres -i input.rc -o output.o # 指定输入输出文件

https://sourceware.org/binutils/

https://www.gnu.org/software/binutils/

https://sourceware.org/pub/binutils/releases/

相关推荐
毕设源码-赖学姐3 分钟前
【开题答辩全过程】以 基于python的电影推荐系统为例,包含答辩的问题和答案
开发语言·python
星辰_mya9 分钟前
Elasticsearch线上问题之慢查询
java·开发语言·jvm
Yu_Lijing10 分钟前
网络复习篇——网络基础(一)
网络·c++·笔记
前端小菜袅12 分钟前
PC端原样显示移动端页面方案
开发语言·前端·javascript·postcss·px-to-viewport·移动端适配pc端
Bella的成长园地12 分钟前
为什么c++中的条件变量的 wait() 函数需要配合while 循环或谓词?
c++·面试
Highcharts.js13 分钟前
如何使用Highcharts SVG渲染器?
开发语言·javascript·python·svg·highcharts·渲染器
charlee4413 分钟前
为什么现代 C++ 库都用 PIMPL?一场关于封装、依赖与安全的演进
c++·智能指针·raii·pimpl·编译防火墙·封装设计
郝学胜-神的一滴18 分钟前
超越Spring的Summer(一): PackageScanner 类实现原理详解
java·服务器·开发语言·后端·spring·软件构建
摇滚侠19 分钟前
Java,举例说明,函数式接口,函数式接口实现类,通过匿名内部类实现函数式接口,通过 Lambda 表达式实现函数式接口,演变的过程
java·开发语言·python
阿里嘎多学长20 分钟前
2026-02-03 GitHub 热点项目精选
开发语言·程序员·github·代码托管