《专业嵌入式软件开发》笔记-第5章addr2line
2012-02-18 20:38
218 查看
binutils工具集
5.1
addr2line指令地址翻译器,编译时加上-g选项,addr2line才有作用
$gcc -g main.c -o test
$./test
the address of foo() is 0x401090.
$addr2line 0x401090 -f -e test
foo/home/ALTA/study/binutils/main.c:4
输出了程序地址所对应的函数名、文件名和行号
Usage: addr2line [option(s)] [addr(s)]
Convert addresses into line number/file name pairs.
If no addresses are specified on the command line, they will be read from stdin
The options are:
@<file> Read options from <file>
-a --addresses Show addresses
-b --target=<bfdname> Set the binary file format
-e --exe=<executable> Set the input file name (default is a.out)
-i --inlines Unwind inlined functions
-j --section=<name> Read section-relative offsets instead of addresses
-p --pretty-print Make the output easier to read for humans
-s --basenames Strip directory names
-f --functions Show function names
-C --demangle[=style] Demangle function names
-h --help Display this information -v --version Display the program's version
例子中的地址是通过打印知晓的。实际中在程序崩溃时通过某种方式获得。另外,nm工具可以得到如下信息
----显示有删减---
00401090 t .text
00401090 T _foo004010ac T _main
004010e4 t .text004010e4 T ___chkstk
实际发现addr2line addr -f -e test,当addr∈[0x401090,0x4010ac)时,显示的结果都是foo,这说明foo函数的大小就是0x4010ac-0x401090
C++程序的不同,主要是c++对函数重载,所以addr2line 获得的函数名可能经过mangling(win中称decorating)
--demangle=gnu-v3选项可以获得我们所书写的函数名,但是cygwin下无效
$ addr2line 0x401190--demangle=gnu-v3-f -e main.exe
Z3foov
/home/ALTA/study/binutils/main.cpp:5
5.1
addr2line指令地址翻译器,编译时加上-g选项,addr2line才有作用
main.c #include <stdio.h> void foo(void) { printf("The address of foo() is %p.\n", foo); } int main(void) { foo(); return 0; }
$gcc -g main.c -o test
$./test
the address of foo() is 0x401090.
$addr2line 0x401090 -f -e test
foo/home/ALTA/study/binutils/main.c:4
输出了程序地址所对应的函数名、文件名和行号
Usage: addr2line [option(s)] [addr(s)]
Convert addresses into line number/file name pairs.
If no addresses are specified on the command line, they will be read from stdin
The options are:
@<file> Read options from <file>
-a --addresses Show addresses
-b --target=<bfdname> Set the binary file format
-e --exe=<executable> Set the input file name (default is a.out)
-i --inlines Unwind inlined functions
-j --section=<name> Read section-relative offsets instead of addresses
-p --pretty-print Make the output easier to read for humans
-s --basenames Strip directory names
-f --functions Show function names
-C --demangle[=style] Demangle function names
-h --help Display this information -v --version Display the program's version
例子中的地址是通过打印知晓的。实际中在程序崩溃时通过某种方式获得。另外,nm工具可以得到如下信息
----显示有删减---
00401090 t .text
00401090 T _foo004010ac T _main
004010e4 t .text004010e4 T ___chkstk
实际发现addr2line addr -f -e test,当addr∈[0x401090,0x4010ac)时,显示的结果都是foo,这说明foo函数的大小就是0x4010ac-0x401090
C++程序的不同,主要是c++对函数重载,所以addr2line 获得的函数名可能经过mangling(win中称decorating)
main.cpp
#include <iostream> using namespace std; int foo(void) { cout<<"the addr of foo() is "<<hex<<int(foo)<<endl; } int main(void) { foo(); return 0; }
$g++ -g main.cpp -o main
$ ./main.exe the addr of foo() is 401190
$ addr2line 0x401190 -f -e main.exe _Z3foov /home/ALTA/study/binutils/main.cpp:5
--demangle=gnu-v3选项可以获得我们所书写的函数名,但是cygwin下无效
$ addr2line 0x401190--demangle=gnu-v3-f -e main.exe
Z3foov
/home/ALTA/study/binutils/main.cpp:5
相关文章推荐
- 嵌入式软件开发培训笔记——ARM架构Linux系统下交叉编译环境搭建、NFS、TFTP服务配置及Nandflash的读写
- 嵌入式软件开发培训笔记——基于S5PC100的课程设计
- 嵌入式软件开发培训笔记——java第四天(高级类特性——接口/多态/抽象类/内部类以及异常处理)
- 嵌入式软件开发培训笔记——Makefile编写
- 嵌入式软件开发培训笔记——C高级 结构体与共用体
- 嵌入式软件开发培训笔记——交叉工具链的安装arm-cortex_a8-linux-gnueabi-
- 嵌入式linux软件开发学习笔记--uboot
- 嵌入式软件开发培训笔记——c编程基础
- 嵌入式软件开发培训笔记——shell基本命令
- 嵌入式软件开发培训笔记——C高级 存储类、链接和内存管理
- 嵌入式软件开发培训笔记——u-boot-2011.09的移植
- 嵌入式软件开发培训笔记——boot原理与u-boot 基于Cortex_A8核的S5PC100芯片
- 嵌入式软件开发精解 阅读笔记(这本书内容有点太初级了)
- 嵌入式软件开发培训笔记——java第五天(API——math/string/集合/日期时间以及java线程)
- 嵌入式软件开发培训笔记——linux标准I/O库
- 嵌入式软件开发培训笔记——Java第一天(开发环境搭建、入门引导)
- 专业嵌入式软件开发——全面走向高质高效编程(含DVD光盘1张)
- 嵌入式软件开发培训笔记——C高级 预处理&类型重定义
- 专业嵌入式软件开发——全面走向高质高效编程(含DVD光盘1张)
- 嵌入式软件开发培训笔记——Linux网络编程及I/O模型