Reputation: 41
I am learning assembly language. I am using gdb to learn about how to get information from the C code that is written. I am trying to see the rip register at the beginning of each line and see how many bytes of machine code are in each of the C statements in this program? Can anyone show me the commands in gdb to find these?
#include <stdio.h>
int main(void) {
register int wye;
int *ptr;
int ex;
ptr = &ex;
ex = 305441741;
wye = -1;
printf("Enter an integer: ");
scanf("%i", ptr);
wye += *ptr;
printf("The result is %i\n", wye);
return 0;
}
Upvotes: 4
Views: 168
Reputation: 126110
Short example of stuff you can do to see some things about your program. $
is the shell prompt and gdb>
is the gdb prompt, so don't type those:
$ gdb myprogram
... info about gdb and myprogram
gdb> disas main
... disassembly of the main function
gdb> break main
... sets a breakpoint in main; you see a message about this probably calling it breakpoint 1
gdb> run
... program starts and stops immediately at the start of main
gdb> i r
... lots of info about register contents
gdb> p $rip
... current instruction pointer (assuming x86_64)
gdb> s
... program runs for one source line.
gdb> p $rip
... ip has advanced a bit.
Upvotes: 1