I am playing around with the debugger. The actual task I am working on is in watching how the instruction pointer changes as I run through the code.
However, I am having difficulty understanding something else. I set breakpoints at line 6, strcpy (which is at line 7) and line 8. After setting the breakpoints I run it.
Why does it go through the breakpoints in a different order? Breakpoint 2, breakpoint 1 and breakpoint 3?
The other question I have... breakpoint 1 was set at line 6. Yet when we get to that breakpoint it says "char_array2.c:7". I am aware that line 6 is empty, does the breakpoint stop before reading any part of line 7?
(gdb) list
1 #include <stdio.h>
2 #include <string.h>
3
4 int main() {
5 char str_a[20];
6
7 strcpy(str_a, "Hello World!\n");
8 printf(str_a);
9 }
(gdb)
Line number 10 out of range; char_array2.c has 9 lines.
(gdb) break 6
Breakpoint 1 at 0x100000ec8: file char_array2.c, line 6.
(gdb) break strcpy
Breakpoint 2 at 0x20c49ba5c77e20
(gdb) break 8
Breakpoint 3 at 0x100000edd: file char_array2.c, line 8.
(gdb) run
Starting program: /Users/Guest1/Desktop/Hacking files/char_array2
Reading symbols for shared libraries +. done
Breakpoint 2, 0x00007fff8601ce20 in strcpy ()
(gdb) continue
Continuing.
Breakpoint 1, main () at char_array2.c:7
7 strcpy(str_a, "Hello World!\n");
(gdb) continue
Continuing.
Breakpoint 3, main () at char_array2.c:8
8 printf(str_a);