用gcc编译了一个简单的hello world程序。
int main( int argc, char** argv )
{
printf( "hello, world!\n" );
printf( "Vale!\n" );
return 0;
}
otool -lV a给了我以下内容:
Section
sectname __stubs
segname __TEXT
addr 0x0000000100000f7a
size 0x0000000000000006
offset 3962
align 2^1 (2)
reloff 0
nreloc 0
type S_SYMBOL_STUBS
attributes PURE_INSTRUCTIONS SOME_INSTRUCTIONS
reserved1 0 (index into indirect symbol table)
reserved2 6 (size of stubs)
当我使用gdb时,我得到:
gdb ./a
(gdb) x/2i 0x0000000100000f7a
0x100000f7a: jmpq *0x90(%rip) # 0x100001010
0x100000f80: lea 0x81(%rip),%r11 # 0x100001008
使用lldb时我感兴趣的是值#0x100001010和#0x100001008,但是当我使用lldb时,我看到了:
lldb ./a
(lldb) x/2i 0x0000000100000f7a
0x100000f7a: ff 25 90 00 00 00 jmpq *0x90(%rip)
0x100000f80: 00 00 addb %al, (%rax)
有没有办法让lldb提供gdb所能提供的相同值(#0x100001010和#0x100001008)?
答案 0 :(得分:0)
例如,使用disassemble -s
查找&转储STUBS部分。您可以提供计数和起始地址,但由于某些原因,当我构建您的小示例时,存根部分中只有一个外部引用。
所以,例如:
(lldb) image dump sections foo
Sections for '/private/tmp/foo' (x86_64):
SectID Type File Address File Off. File Size Flags Section Name
---------- ---------------- --------------------------------------- ---------- ---------- ---------- ----------------------------
0x00000100 container [0x0000000000000000-0x0000000100000000) 0x00000000 0x00000000 0x00000000 foo.__PAGEZERO
0x00000200 container [0x0000000100000000-0x0000000100001000) 0x00000000 0x00001000 0x00000000 foo.__TEXT
0x00000001 code [0x0000000100000f20-0x0000000100000f68) 0x00000f20 0x00000048 0x80000400 foo.__TEXT.__text
0x00000002 code [0x0000000100000f68-0x0000000100000f6e) 0x00000f68 0x00000006 0x80000408 foo.__TEXT.__stubs
0x00000003 code [0x0000000100000f70-0x0000000100000f8a) 0x00000f70 0x0000001a 0x80000400 foo.__TEXT.__stub_helper
0x00000004 data-cstr [0x0000000100000f8a-0x0000000100000fa0) 0x00000f8a 0x00000016 0x00000002 foo.__TEXT.__cstring
0x00000005 regular [0x0000000100000fa0-0x0000000100000fe8) 0x00000fa0 0x00000048 0x00000000 foo.__TEXT.__unwind_info
0x00000006 eh-frame [0x0000000100000fe8-0x0000000100001000) 0x00000fe8 0x00000018 0x00000000 foo.__TEXT.__eh_frame
0x00000300 container [0x0000000100001000-0x0000000100002000) 0x00001000 0x00001000 0x00000000 foo.__DATA
0x00000007 data-ptrs [0x0000000100001000-0x0000000100001010) 0x00001000 0x00000010 0x00000006 foo.__DATA.__nl_symbol_ptr
0x00000008 data-ptrs [0x0000000100001010-0x0000000100001018) 0x00001010 0x00000008 0x00000007 foo.__DATA.__la_symbol_ptr
0x00000400 container [0x0000000100002000-0x0000000100003000) 0x00002000 0x00000200 0x00000000 foo.__LINKEDIT
0x00000200 container [0x0000000100003000-0x0000000100004000) 0x00002000 0x000002ce 0x00000000 foo.__DWARF
0x00000001 dwarf-abbrev [0x0000000100003000-0x000000010000304c) 0x00002000 0x0000004c 0x00000000 foo.__DWARF.__debug_abbrev
0x00000002 dwarf-aranges [0x000000010000304c-0x000000010000307c) 0x0000204c 0x00000030 0x00000000 foo.__DWARF.__debug_aranges
0x00000003 dwarf-info [0x000000010000307c-0x00000001000030f8) 0x0000207c 0x0000007c 0x00000000 foo.__DWARF.__debug_info
0x00000004 dwarf-line [0x00000001000030f8-0x0000000100003137) 0x000020f8 0x0000003f 0x00000000 foo.__DWARF.__debug_line
0x00000005 dwarf-pubnames [0x0000000100003137-0x0000000100003152) 0x00002137 0x0000001b 0x00000000 foo.__DWARF.__debug_pubnames
0x00000006 dwarf-pubtypes [0x0000000100003152-0x0000000100003175) 0x00002152 0x00000023 0x00000000 foo.__DWARF.__debug_pubtypes
0x00000007 dwarf-str [0x0000000100003175-0x00000001000031d8) 0x00002175 0x00000063 0x00000000 foo.__DWARF.__debug_str
0x00000008 apple-names [0x00000001000031d8-0x0000000100003214) 0x000021d8 0x0000003c 0x00000000 foo.__DWARF.__apple_names
0x00000009 apple-types [0x0000000100003214-0x0000000100003286) 0x00002214 0x00000072 0x00000000 foo.__DWARF.__apple_types
0x0000000a apple-namespaces [0x0000000100003286-0x00000001000032aa) 0x00002286 0x00000024 0x00000000 foo.__DWARF.__apple_namespac
0x0000000b apple-objc [0x00000001000032aa-0x00000001000032ce) 0x000022aa 0x00000024 0x00000000 foo.__DWARF.__apple_objc
(lldb) disassemble -s 0x0000000100000f68
foo`symbol stub for: printf:
foo[0x100000f68]: jmpq *0xa2(%rip) ; (void *)0x0000000100000f80