Lelouch Lamperouge
Lelouch Lamperouge

Reputation: 8421

Jumping to the next "instruction" using gdb

I am attempting to figure the canary value setting and checking mechanism.

#include 
int main(void)
{
        return printf("Hi!\n");
}

When disassemble the main, I get

(gdb) disas main
0x080483f4 :    lea    0x4(%esp),%ecx
0x080483f8 :    and    $0xfffffff0,%esp
0x080483fb :    pushl  -0x4(%ecx)
0x080483fe :   push   %ebp
0x080483ff :   mov    %esp,%ebp
0x08048401 :   push   %ecx
0x08048402 :   sub    $0x14,%esp
0x08048405 :   mov    %gs:0x14,%eax
0x0804840b :   mov    %eax,-0x8(%ebp)
0x0804840e :   xor    %eax,%eax
0x08048410 :   movl   $0x8048500,(%esp)
0x08048417 :   call   0x8048320 
0x0804841c :   mov    -0x8(%ebp),%edx
0x0804841f :   xor    %gs:0x14,%edx
0x08048426 :   je     0x804842d 
0x08048428 :   call   0x8048330 
0x0804842d :   add    $0x14,%esp
0x08048430 :   pop    %ecx
0x08048431 :   pop    %ebp
0x08048432 :   lea    -0x4(%ecx),%esp
0x08048435 :   ret

I set a breakpoint at 0x0804840e using

b *0x0804840e

After the program flow stops at this breakpoint I would like gdb to go to the next instruction instead of next line of c code. I don't think I can use next for this. So what other option do I have apart from setting a breakpoint at every instruction?

Upvotes: 35

Views: 30014

Answers (1)

Foo Bah
Foo Bah

Reputation: 26281

You want to use stepi, aka si. it steps by one machine instruction.
(Or ni to step over call instructions.)

Check the GDB manual's section on continuing and stepping, which has an entry for it.
Or inside GDB, help / help running will show you that si exists, and help stepi will show you more about it.

Upvotes: 56

Related Questions