8

I am using EDB and stepping through the program but I do not even know what the difference in behavior is when doing this. I feel like this is something I should know if I ever have hope of reverse engineering this program.

10

The gdb terms (and commands) are step and next and the difference is that step continues to run until it changes line of source code, while next doesn't trace into a subroutine, but rather skips over it. The stepi and nexti commands are similar but operate at the machine instruction level rather than source code level. Read more in The Fine Manual.

Here's an example that may help clarify. Let's say you have a simple project with three simple files:

main.c

#include "squareit.h"
#include <stdio.h>

int main(void) {
    int x = 5;
    printf("%d squared is %d\n", x, squareit(x));
}

squareit.h

#ifndef SQUAREIT_H
#define SQUAREIT_H
// return the square of an integer
int squareit(int x);
#endif // SQUAREIT_H

squareit.c

#include "squareit.h"

int squareit(int x) {
    return x*x;
}

We compile the program with debugging flags enabled (gcc -g main.c squareit.c -o simple) and then run gdb simple. If we are sitting on the printf line and execute step, we will find ourselves in the squareit() function. If instead at that same point we execute next, the squareit() function and the printf() functions will both execute and we will find ourselves on the last line of main().

The session follows:

(gdb) b main
Breakpoint 1 at 0x40113d: file ./main.c, line 5.
(gdb) run
Starting program: ./simple 

Breakpoint 1, main () at ./main.c:5
5       int x = 5;
(gdb) step
6       printf("%d squared is %d\n", x, squareit(x));
(gdb) s
squareit (x=5) at ./squareit.c:4
4       return x*x;
(gdb) s
5   }
(gdb) s
5 squared is 25
main () at ./main.c:7
7   }
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: ./simple 

Breakpoint 1, main () at ./main.c:5
5       int x = 5;
(gdb) s
6       printf("%d squared is %d\n", x, squareit(x));
(gdb) next
5 squared is 25
7   }

The gdb commands used here are b to set a breakpoint, s which is an alias of step, next (has an alias of n) and run (has an alias of r).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.