【问题标题】:GDB Dis-Flavor set to Intel, but showing AT&T-styleGDB Dis-Flavor 设置为 Intel,但显示 AT&T 风格
【发布时间】:2015-09-09 18:59:21
【问题描述】:

我已将 gdb-debuggerdisassembly-flavor 设置为 Intel(两者:su 和普通用户),但无论如何它仍然以 AT&T 表示法显示汇编代码:

patrick@localhost:~/Dokumente/Projekte$ gdb -q ./a.out
Reading symbols from ./a.out...done.
(gdb) break main
Breakpoint 1 at 0x40050e: file firstprog.c, line 5.
(gdb) run
Starting program: /home/patrick/Dokumente/Projekte/a.out 

Breakpoint 1, main () at firstprog.c:5
5   for(i=0; i < 10; i++)
(gdb) show disassembly
The disassembly flavor is "intel".
(gdb) info registers
rax            0x400506 4195590
rbx            0x0  0
rcx            0x0  0
rdx            0x7fffffffe2d8   140737488347864
rsi            0x7fffffffe2c8   140737488347848
rdi            0x1  1
rbp            0x7fffffffe1e0   0x7fffffffe1e0
(gdb) info register eip
Invalid register `eip'

确实重新启动了计算机。我的操作系统是 Kali Linux amd64。 我有以下问题:

  • 为什么 gdb 仍然显示 AT&amp;T 符号?
  • 为什么寄存器EIP指令指针)显示为无效寄存器

【问题讨论】:

  • 因为 1) 反汇编风格在 GDB 调用 (you need to set it in a gdbinit script run by GDB when it starts) 中 保存和 2) eip 寄存器在 GDB 中的正确名称是 @987654330 @ 或 $pc.
  • @IwillnotexistIdonotexist 我知道,我通过这样做设置了风格。 patrick@localhost:~/Dokumente/Projekte$ cat ~/.gdbinit set disassembly-flavor intel 对于根用户:patrick@localhost:~/Dokumente/Projekte$ su Passwort: root@localhost:/home/patrick/Dokumente/Projekte# cat ~/.gdbinit set disassembly intel

标签: c++ c debugging gdb


【解决方案1】:

您误解了反汇编风味的含义。这意味着:当您以人类可读的(ish)形式查看机器代码时,反汇编的样子。

要打印寄存器(或在任何其他上下文中使用寄存器),您需要使用$reg,例如$rip$pc$eax等。

如果我用 at&t 语法反汇编我的一个程序,gdb 会显示:

   0x00000000007378f0 <+0>: push   %rbp
   0x00000000007378f1 <+1>: mov    %rsp,%rbp
   0x00000000007378f4 <+4>: sub    $0x20,%rsp
   0x00000000007378f8 <+8>: movl   $0x0,-0x4(%rbp)
   0x00000000007378ff <+15>:    mov    %edi,-0x8(%rbp)
   0x0000000000737902 <+18>:    mov    %rsi,-0x10(%rbp)
=> 0x0000000000737906 <+22>:    mov    -0x10(%rbp),%rsi
   0x000000000073790a <+26>:    mov    (%rsi),%rdi
   0x000000000073790d <+29>:    callq  0x737950 <FindLibPath(char const*)>
   0x0000000000737912 <+34>:    xor    %eax,%eax

然后这样做:

(gdb) set disassembly-flavor intel 
(gdb) disass main
Dump of assembler code for function main(int, char**):
   0x00000000007378f0 <+0>: push   rbp
   0x00000000007378f1 <+1>: mov    rbp,rsp
   0x00000000007378f4 <+4>: sub    rsp,0x20
   0x00000000007378f8 <+8>: mov    DWORD PTR [rbp-0x4],0x0
   0x00000000007378ff <+15>:    mov    DWORD PTR [rbp-0x8],edi
   0x0000000000737902 <+18>:    mov    QWORD PTR [rbp-0x10],rsi
=> 0x0000000000737906 <+22>:    mov    rsi,QWORD PTR [rbp-0x10]
   0x000000000073790a <+26>:    mov    rdi,QWORD PTR [rsi]
   0x000000000073790d <+29>:    call   0x737950 <FindLibPath(char const*)>
   0x0000000000737912 <+34>:    xor    eax,eax

你可以看到区别。但是寄存器的名称以及在 gdb 命令行中使用寄存器的方式并没有改变,在这两种情况下都需要 $reg

【讨论】:

    猜你喜欢
    • 2014-03-14
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    相关资源
    最近更新 更多