【问题标题】:GDB and opcodesGDB 和操作码
【发布时间】:2013-10-22 16:59:04
【问题描述】:

来自 Windows 环境,当我进行内核调试甚至在用户模式下,我可以以非常详细的方式看到反汇编代码,例如:

80526db2 6824020000 推224h 80526db7 6808a14d80 推送偏移量 nt!ObWatchHandles+0x8dc (804da108) 80526dbc e81f030100 调用 nt!_SEH_prolog (805370e0) 80526dc1 a140a05480 mov eax,dword ptr [nt!__security_cookie (8054a040)]

第一个数字很明显是地址,但第二个数字代表操作码字节,GDB 缺少,或者至少,我不知道如何获得类似的结果。

我通常会这样做:

(gdb): 显示 /i $pc

但我得到的只是这样的:

x/i $pc 0x21c4c: 弹出 %eax

我可以看到代码字节是什么,这有时对我来说有点问题。我可以用 display 做些什么来提供帮助吗?

编辑:有问题的 GDB 在 Mac OS X 10.8.3 上是 6.3.50。

【问题讨论】:

    标签: macos debugging assembly gdb


    【解决方案1】:

    我认为disassemble /r 应该会给你你想要的东西:

    (gdb) help disass
    Disassemble a specified section of memory.
    Default is the function surrounding the pc of the selected frame.
    With a /m modifier, source lines are included (if available).
    With a /r modifier, raw instructions in hex are included.
    With a single argument, the function surrounding that address is dumped.
    Two arguments (separated by a comma) are taken as a range of memory to dump,
      in the form of "start,end", or "start,+length".
    (gdb) disass /r main
    Dump of assembler code for function main:
       0x004004f8 <+0>:      55     push   %ebp
       0x004004f9 <+1>:      48     dec    %eax
       0x004004fa <+2>:      89 e5  mov    %esp,%ebp
       0x004004fc <+4>:      48     dec    %eax
       0x004004fd <+5>:      83 ec 10       sub    $0x10,%esp
       0x00400500 <+8>:      89 7d fc       mov    %edi,-0x4(%ebp)
       0x00400503 <+11>:     48     dec    %eax
       0x00400504 <+12>:     89 75 f0       mov    %esi,-0x10(%ebp)
       0x00400507 <+15>:     bf 0c 06 40 00 mov    $0x40060c,%edi
       0x0040050c <+20>:     b8 00 00 00 00 mov    $0x0,%eax
       0x00400511 <+25>:     e8 0a ff ff ff call   0x400420
       0x00400516 <+30>:     bf 00 00 00 00 mov    $0x0,%edi
       0x0040051b <+35>:     e8 10 ff ff ff call   0x400430
    End of assembler dump.
    (gdb) 
    

    GDB disassemble command documentation

    【讨论】:

    • 谢谢。我确实看到了。不过,我没有提供所有信息。这是在 Mac OS Mountain Lion 上使用 GDB,我有 GDB 6.3.50,顺便说一下没有 /r
    • @E.T - 不知道为什么 OSX 会打包这么旧版本的 GDB。无论如何,前进的一种方法是引入更新的 GDB:stackoverflow.com/questions/8336433/gdb-on-macosx-lion
    • 会调查的。我在 GDB 中找到了执行字节码的代码部分,所以我最终会从 GDB for Linux 中提取该代码并在 Mac OS 上更新我自己的 GDB,重新编译,签名并从那里开始 :) 谢谢!很有帮助。
    【解决方案2】:

    如果你使用lldb,可以使用-b选项反汇编得到同样的效果:

    (lldb) disassemble -b -p
    Sketch`main + 46 at SKTMain.m:17:
    -> 0x10001aa0e:  48 89 c7              movq   %rax, %rdi
       0x10001aa11:  b0 00                 movb   $0, %al
       0x10001aa13:  e8 f2 48 00 00        callq  0x10001f30a               ; symbol stub for: NSLog
       0x10001aa18:  48 8d 35 99 fa 00 00  leaq   64153(%rip), %rsi         ; @Sketch`.str3
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 2015-07-31
      • 1970-01-01
      相关资源
      最近更新 更多