ELF文件之八——使用链接脚本-2个函数-data-bss-temp-call-debug信息
gcc编译选项可以设置生成调试信息,
debug信息格式有stabs,coff,xcoff,dwarf。
常用的有两种格式,stab和dwarf,stab较早,dwarf较新。两种格式介绍:https://www.ibm.com/developerworks/cn/opensource/os-debugging/
单独-g可以生成只有gdb能识别的额外辅助信息,如果不想生成这些辅助信息,可以使用-gstabs等选项,只生成stabs调试信息,不生成额外辅助信息。
调试选项-g和优化选项-O一起使用的话,可能会导致调试信息与最终不一致,比如,定义的变量被优化掉了等,因此,-g时最好不用-O。
-g生成操作系统固有的格式,对于sparc来说,使用-g会生成stab格式。
如果使用-g -gdwarf-2,则会生成dwarf-2格式的调试信息,不再生成stab格式的。这两个选项允许同时存在。
如果使用-gstabs -dwarf-2,则后一个-dwarf-2会并忽略,因为和stabs冲突,即生成stabs格式的调试信息。这两个是同时存在是不允许的。
-g
Produce debugging information in the operating system's native format (stabs, COFF,
XCOFF, or DWARF). GDB can work with this debugging information. On most systems that use stabs format, `-g' enables use of extra debugging information
that only GDB can use; this extra information makes debugging work better in GDB but
will probably make other debuggers crash or refuse to read the program. If you want to
control for certain whether to generate the extra information, use `-gstabs+' , `-gstabs' ,
`-gxcoff+' , `-gxcoff' , `-gdwarf-+' , or `-gdwarf-1' (see below).
Unlike most other C compilers, GCC allows you to use `-g' with `-O' . The shortcuts taken
by optimized code may occasionally produce surprising results: some variables you
declared may not exist at all; flow of control may briefly move where you did not expect it;
some statements may not be executed because they compute constant results or their values
were already at hand; some statements may execute in different places because they were
moved out of loops.
添加-g选项后,生成的elf文件节头表如下:stab长度为0x240=576,stabstr长度为0x4de=1246,共1822字节
原来的elf为839字节,新elf为2787字节。增加的debug信息比原来的全部elf还多,1822>839。
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ ] NULL
[ ] .text PROGBITS AX
[ ] .data PROGBITS 0000a4 WA
[ ] .bss NOBITS 0000a8 WA
[ ] .stab PROGBITS 0000a8 0c
[ ] .comment PROGBITS 0002e8
[ ] .stabstr STRTAB 0002fa 0004de
[ ] .shstrtab STRTAB 0007d8
[ ] .symtab SYMTAB 0009ac c
[ ] .strtab STRTAB 000abc
没有-g的节头表
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ ] NULL
[ ] .text PROGBITS AX
[ ] .data PROGBITS 0000a4 WA
[ ] .bss NOBITS 0000a8 WA
[ ] .comment PROGBITS 0000a8
[ ] .shstrtab STRTAB 0000ba
[ ] .symtab SYMTAB 0000f0 a
[ ] .strtab STRTAB
shstrtab symtab section hdr
旧elf,839 0x35=53 0xf0=240 320
新elf,2787 0x44=68 0x110=272 400
增加量, 15 32 80
debug 1822+15+32+80=1949
2787-839=1948
stab大小为0x240=578,每个项目12字节,如下,共48个项目
struct internal_nlist {
unsigned long n_strx; /* index into string table of name */
unsigned char n_type; /* type of symbol */
unsigned char n_other; /* misc info (usually empty) */
unsigned short n_desc; /* description field */
bfd_vma n_value; /* value of symbol */
};
stab段,0x8a开始,12字节一个项目,看不明白。
The “stabs” debug format: http://www.sm.luth.se/csee/courses/smd/D0013E/doc/stabs.pdf
链接:https://pan.baidu.com/s/1Fv3zcqNhScUdaHp4PyAYsQ
提取码:by76
增加-gdwarf选项后,生成的dwarf格式的节多了5个。
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ ] NULL
[ ] .text PROGBITS AX
[ ] .data PROGBITS 0000f8 WA
[ ] .bss NOBITS 0000fc WA
[ ] .rodata PROGBITS A
[ ] .line PROGBITS 0000fc 00009e
[ ] .debug_pubnames PROGBITS 00019a 00002d
[ ] .debug_aranges PROGBITS 0001c7
[ ] .debug PROGBITS 0001f8 00025c
[ ] .comment PROGBITS
[] .shstrtab STRTAB
[] .symtab SYMTAB 0006d8 f
[] .strtab STRTAB
可以用objdump输出stab信息,以下是某个elf文件输出的stab信息,但有一堆看着没用的东西,使用如下命令
objdump -G main.elf > debug.txt
main.elf: file format elf32-sparc Contents of .stab section: Symnum n_type n_othr n_desc n_value n_strx String - HdrSym
SO ../src/main.c
OPT gcc2_compiled.
LSYM int:t(,)=r(,);-;;
LSYM char:t(,)=r(,);;;
LSYM long int:t(,)=r(,);-;;
LSYM unsigned int:t(,)=r(,);;-;
LSYM long unsigned int:t(,)=r(,);;-;
LSYM long long int:t(,)=r(,);;-;
LSYM long long unsigned int:t(,)=r(,);;-;
LSYM short int:t(,)=r(,);-;;
LSYM short unsigned int:t(,)=r(,);;;
LSYM signed char:t(,)=r(,);-;;
LSYM unsigned char:t(,)=r(,);;;
LSYM float:t(,)=r(,);;;
LSYM double:t(,)=r(,);;;
LSYM long double:t(,)=r(,);;;
LSYM complex int:t(,)=s8real:(,),,;imag:(,),,;;
LSYM complex float:t(,)=R3;;;
LSYM complex double:t(,)=R4;;;
LSYM complex long double:t(,)=R4;;;
LSYM __builtin_va_list:t(,)=*(,)=(,)
LSYM _Bool:t(,)=eFalse:,True:,;
BINCL 00000ce2 ../src/main.c
FUN main:F(,)
SLINE
SLINE
SLINE
LSYM fffffff0 d:(,)
LBRAC
RBRAC
GSYM var_data:G(,)
GSYM var_bss:G(,)
SO
最新文章
- webconfig中配置各种数据库的连接字符串(转)
- 背水一战 Windows 10 (9) - 资源: 资源限定符概述, 资源限定符示例
- IOS 在http请求中使用cookie
- 一个在mac上编译c++程序的低级失误
- redmine配置邮件
- MySQL的变量分类总结
- DW自动换行
- Go语言学习笔记-流程控制(二)
- mysqlslap 压力测试使用总结
- Failed to execute aapt:Process 'command '/build-tools/28.0.2/aapt'' finished with non-zero exit value 1
- JDK8新特性02 Lambda表达式02_Lambda语法规则
- TMS 控件测试
- Libre 6013 「网络流 24 题」负载平衡 (网络流,最小费用最大流)
- Java知多少(58)线程Runnable接口和Thread类详解
- linux 系统监控和进程管理
- [UE4]隐藏对象Set Visibility
- 流媒体技术学习笔记之(四)解决问题video.js 播放m3u8格式的文件,根据官方的文档添加videojs-contrib-hls也不行的原因解决了
- 为什么不要 ";lock(this)"; ? lock object 并是readonly(转载)
- 课上实践练习——MyOd
- dede上传文件乱码问题解决