【问题标题】:Getting GDB x command output in lldb在 lldb 中获取 GDB x 命令输出
【发布时间】:2014-08-12 13:05:34
【问题描述】:

用 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)?

【问题讨论】:

    标签: macos gcc gdb lldb


    【解决方案1】:

    使用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
    

    【讨论】:

      猜你喜欢
      • 2019-07-19
      • 1970-01-01
      • 2021-03-07
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多