分类分类
关注+2011-07-12作者:清晨
3. 如何通过目标文件.o或者可执行文件得知是否有debugging information?
可通过如下命令查看debugguing information。
objdump -g filename
objdump -h filename(查看有无debug section)
nm -l filename
重新编译gcc-4.1.2的源文件tree.cc,观看结果。
# cd /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src
# g++ -o tree.o -c tree.cc //without debugging information
# objdump -h tree.o
tree.o: file format elf32-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .group 00000008 00000000 00000000 00000034 2**2
CONTENTS, READONLY, EXCLUDE, GROUP, LINK_ONCE_DISCARD
1 .group 00000008 00000000 00000000 0000003c 2**2
CONTENTS, READONLY, EXCLUDE, GROUP, LINK_ONCE_DISCARD
2 .group 00000008 00000000 00000000 00000044 2**2
CONTENTS, READONLY, EXCLUDE, GROUP, LINK_ONCE_DISCARD
3 .text 00000952 00000000 00000000 0000004c 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
4 .data 00000000 00000000 00000000 000009a0 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .bss 00000000 00000000 00000000 000009a0 2**2
ALLOC
6 .text._ZNSt18_Rb_tree_node_base10_S_minimumEPS_ 00000022 00000000 00000000 000009a0 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
7 .text._ZNSt18_Rb_tree_node_base10_S_maximumEPS_ 00000022 00000000 00000000 000009c2 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
8 .text._ZSt4swapISt14_Rb_tree_colorEvRT_S2_ 00000022 00000000 00000000 000009e4 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
9 .comment 00000024 00000000 00000000 00000a06 2**0
CONTENTS, READONLY
10 .note.GNU-stack 00000000 00000000 00000000 00000a2a 2**0
CONTENTS, READONLY
11 .eh_frame 0000016c 00000000 00000000 00000a2c 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
# cd /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src
# g++ -g -o tree.d.o -c tree.cc //with debugging information
# objdump -h tree.d.o
tree.d.o: file format elf32-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .group 00000008 00000000 00000000 00000034 2**2
CONTENTS, READONLY, EXCLUDE, GROUP, LINK_ONCE_DISCARD
1 .group 00000008 00000000 00000000 0000003c 2**2
CONTENTS, READONLY, EXCLUDE, GROUP, LINK_ONCE_DISCARD
2 .group 00000008 00000000 00000000 00000044 2**2
CONTENTS, READONLY, EXCLUDE, GROUP, LINK_ONCE_DISCARD
3 .text 00000952 00000000 00000000 0000004c 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
4 .data 00000000 00000000 00000000 000009a0 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .bss 00000000 00000000 00000000 000009a0 2**2
ALLOC
6 .debug_abbrev 000001d0 00000000 00000000 000009a0 2**0
CONTENTS, READONLY, DEBUGGING
7 .debug_info 000006fd 00000000 00000000 00000b70 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
8 .debug_line 00000258 00000000 00000000 0000126d 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
9 .text._ZNSt18_Rb_tree_node_base10_S_minimumEPS_ 00000022 00000000 00000000 000014c5 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
10 .text._ZNSt18_Rb_tree_node_base10_S_maximumEPS_ 00000022 00000000 00000000 000014e7 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
11 .text._ZSt4swapISt14_Rb_tree_colorEvRT_S2_ 00000022 00000000 00000000 00001509 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
12 .debug_loc 00000210 00000000 00000000 0000152b 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
13 .debug_pubnames 0000019d 00000000 00000000 0000173b 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
14 .debug_aranges 00000038 00000000 00000000 000018d8 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
15 .debug_ranges 00000070 00000000 00000000 00001910 2**0
CONTENTS, RELOC, READONLY, DEBUGGING
16 .debug_str 00000533 00000000 00000000 00001980 2**0
CONTENTS, READONLY, DEBUGGING
17 .comment 00000024 00000000 00000000 00001eb3 2**0
CONTENTS, READONLY
18 .note.GNU-stack 00000000 00000000 00000000 00001ed7 2**0
CONTENTS, READONLY
19 .eh_frame 0000016c 00000000 00000000 00001ed8 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
以下是nm命令的结果。
-l, --line-numbers Use debugging information to find a filename and
line number for each symbol
# cd /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src
# nm -l tree.o
00000000 W _ZNSt18_Rb_tree_node_base10_S_maximumEPS_
00000000 W _ZNSt18_Rb_tree_node_base10_S_minimumEPS_
0000011a T _ZSt18_Rb_tree_decrementPKSt18_Rb_tree_node_base
00000088 T _ZSt18_Rb_tree_decrementPSt18_Rb_tree_node_base
00000075 T _ZSt18_Rb_tree_incrementPKSt18_Rb_tree_node_base
00000000 T _ZSt18_Rb_tree_incrementPSt18_Rb_tree_node_base
00000910 T _ZSt20_Rb_tree_black_countPKSt18_Rb_tree_node_baseS1_
0000012d T _ZSt20_Rb_tree_rotate_leftPSt18_Rb_tree_node_baseRS0_
000001ba T _ZSt21_Rb_tree_rotate_rightPSt18_Rb_tree_node_baseRS0_
0000046f T _ZSt28_Rb_tree_rebalance_for_erasePSt18_Rb_tree_node_baseRS_
00000247 T _ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_
00000000 W _ZSt4swapISt14_Rb_tree_colorEvRT_S2_
U __gxx_personality_v0
# cd /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src
# nm -l tree.d.o //tree.d.o有debugging information
00000000 W _ZNSt18_Rb_tree_node_base10_S_maximumEPS_ /usr/include/c++/4.4/bits/stl_tree.h:112
00000000 W _ZNSt18_Rb_tree_node_base10_S_minimumEPS_ /usr/include/c++/4.4/bits/stl_tree.h:98
0000011a T _ZSt18_Rb_tree_decrementPKSt18_Rb_tree_node_base /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src/tree.cc:119
00000088 T _ZSt18_Rb_tree_decrementPSt18_Rb_tree_node_base /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src/tree.cc:93
00000075 T _ZSt18_Rb_tree_incrementPKSt18_Rb_tree_node_base /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src/tree.cc:87
00000000 T _ZSt18_Rb_tree_incrementPSt18_Rb_tree_node_base /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src/tree.cc:64
00000910 T _ZSt20_Rb_tree_black_countPKSt18_Rb_tree_node_baseS1_ /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src/tree.cc:416
0000012d T _ZSt20_Rb_tree_rotate_leftPSt18_Rb_tree_node_baseRS0_ /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src/tree.cc:126
000001ba T _ZSt21_Rb_tree_rotate_rightPSt18_Rb_tree_node_baseRS0_ /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src/tree.cc:147
0000046f T _ZSt28_Rb_tree_rebalance_for_erasePSt18_Rb_tree_node_baseRS_ /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src/tree.cc:259
00000247 T _ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_ /mnt/hgfs/edisk/opensource/gcc-4.1.2/libstdc++-v3/src/tree.cc:170
00000000 W _ZSt4swapISt14_Rb_tree_colorEvRT_S2_ /usr/include/c++/4.4/bits/move.h:76
# c++filt _ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_
std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)
从以上结果可以看出,在tree.d.o中,每个函数都有对应的调试信息,例如在源文件(tree.cc)中的行号。
相关文章
更多+相同厂商
热门推荐
点击查看更多
点击查看更多
点击查看更多
说两句网友评论