c - GDB single stepping assembly and displaying the next instruction which will be executed. -
this question has answer here:
- show current assembly instruction in gdb 6 answers
using gdb debbuger command can execute single step , display next instruction executed? i'm familiar windbg operation pretty straight forward.
so example have following function , step code via si want display next instruction executed without having full disassembly via disassemble. how can accomplish this?
dump of assembler code 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)
i found following sequence of instructions accomplishes objective.
(gdb) show disassemble-next-line debugger's willingness use disassemble-next-line off. (gdb) set disassemble-next-line on (gdb) show disassemble-next-line debugger's willingness use disassemble-next-line on.
thanks olaf!
(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>
Comments
Post a Comment