C/C++符号解析
objdump --- 反汇编
// 解析二进制文件获取符号信息
objdump -d [input object files] > 汇编文件.asm
// 如果object文件很大,可以只解析局部的内容
objdump -d --start-address=[address] --stop-address=[address] [input object files] > 汇编文件.asm
- 示例
C语言可以通过汇编文件直接获取到符号信息,C++的符号信息一般比较复杂,需要借助工具解析:
12e4e: 1f f0 28 ea >b>--#10731644 <_ZGVN4OHOS21ISystemAbilityManager25SAMANAGER_INTERFACE_TOKENE+0xa17b92>
使用c++filt 解析上述符号:
$ c++filt _ZGVN4OHOS21ISystemAbilityManager25SAMANAGER_INTERFACE_TOKENE
guard variable for OHOS::ISystemAbilityManager::SAMANAGER_INTERFACE_TOKEN
add2line --- 解析代码具体位置
add2line [addr] -e [input object files] -f -C -s -p
- 示例
// libxpower_event.asm
00004888 <_ZN4OHOS9HiviewDFX11InnerWriter10InnerWriteIJPKcNSt3__h12basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEEEEvRNS1_9EventBaseERKSB_SF_DpT_>:
4888: 2d e9 f0 4f push.w {r4, r5, r6, r7, r8, r9, r10, r11, lr}
488c: 87 b0 sub sp, #28
488e: 04 46 mov r4, r0
4890: 57 48 ldr r0, [pc, #348]
4892: 9a 46 mov r10, r3
4894: 17 46 mov r7, r2
4896: 78 44 add r0, pc
4898: 0e 46 mov r6, r1
489a: 00 68 ldr r0, [r0]
489c: 00 68 ldr r0, [r0]
489e: 06 90 str r0, [sp, #24]
48a0: 08 46 mov r0, r1
48a2: 04 f0 0e ec blx #18460
48a6: 21 46 mov r1, r4
48a8: 04 f0 12 ec blx #18468
48ac: 00 28 cmp r0, #0
48ae: 5f d1 bne #190 <_ZN4OHOS9HiviewDFX11InnerWriter10InnerWriteIJPKcNSt3__h12basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEEEEvRNS1_9EventBaseERKSB_SF_DpT_+0xec>
48b0: 20 46 mov r0, r4
48b2: 04 f0 16 ec blx #18476
48b6: 00 28 cmp r0, #0
48b8: 5a d1 bne #180 <_ZN4OHOS9HiviewDFX11InnerWriter10InnerWriteIJPKcNSt3__h12basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEEEEEvRNS1_9EventBaseERKSB_SF_DpT_+0xec>
48ba: 38 46 mov r0, r7
...
$ addr2line 0x48ac -e libxpower_event.z.so -f -C -s -p
OHOS::HiviewDFX::InnerWriter::CheckParamValidity(OHOS::HiviewDFX::InnerWriter::EventBase&, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char> > const&) at inner_writer.h:81