使用gdb debbuger我可以执行什么命令来执行单步并显示将要执行的下一条指令?我熟悉 windbg ,这项操作非常简单。
例如,我有以下功能,当我通过 si 进入代码时,我想显示下一条将被执行的指令而无需通过反汇编进行完整的反汇编。我怎么能做到这一点?
Dump of assembler code for function isEven:
0x0000000100000f20 <+0>: push %rbp
0x0000000100000f21 <+1>: mov %rsp,%rbp
0x0000000100000f24 <+4>: mov $0x2,%eax
0x0000000100000f29 <+9>: mov %edi,-0x4(%rbp)
=> 0x0000000100000f2c <+12>: mov -0x4(%rbp),%edi
0x0000000100000f2f <+15>: mov %eax,-0xc(%rbp)
0x0000000100000f32 <+18>: mov %edi,%eax
0x0000000100000f34 <+20>: cltd
0x0000000100000f35 <+21>: mov -0xc(%rbp),%edi
0x0000000100000f38 <+24>: idiv %edi
0x0000000100000f3a <+26>: cmp $0x0,%edx
0x0000000100000f3d <+29>: jne 0x100000f4f <isEven+47>
0x0000000100000f43 <+35>: movl $0x1,-0x8(%rbp)
0x0000000100000f4a <+42>: jmpq 0x100000f56 <isEven+54>
0x0000000100000f4f <+47>: movl $0x0,-0x8(%rbp)
0x0000000100000f56 <+54>: mov -0x8(%rbp),%eax
0x0000000100000f59 <+57>: pop %rbp
0x0000000100000f5a <+58>: retq
End of assembler dump.
(gdb)
答案 0 :(得分:4)
我发现以下指令序列完成了我的目标。
(gdb) si
0x0000000100000f32 27 if(num % 2 == 0 )
0x0000000100000f2c <isEven+12>: 8b 7d fc mov -0x4(%rbp),%edi
0x0000000100000f2f <isEven+15>: 89 45 f4 mov %eax,-0xc(%rbp)
=> 0x0000000100000f32 <isEven+18>: 89 f8 mov %edi,%eax
0x0000000100000f34 <isEven+20>: 99 cltd
0x0000000100000f35 <isEven+21>: 8b 7d f4 mov -0xc(%rbp),%edi
0x0000000100000f38 <isEven+24>: f7 ff idiv %edi
0x0000000100000f3a <isEven+26>: 83 fa 00 cmp $0x0,%edx
0x0000000100000f3d <isEven+29>: 0f 85 0c 00 00 00 jne 0x100000f4f <isEven+47>
谢谢奥拉夫!
{{1}}