I'm having this simple c++ code:
int main() {
int x = 1;
int y = 2;
int z = x + y;
return 0;
}
Then I do g++ -g main.cpp -o main
, then gdb main
into gdb mode. Then I set break point by b 2
, then r
, then type n
, immedately I get
Program received signal SIGSEGV, Segmentation fault.
0x000055555555513a in main () at main.cpp:4
4 int z = x + y;
I am very confused as this code is too simple and having nothing wrong.
Could somebody help? Thank you so much!
When I input backtrace
, I got
#0 0x000055555555513a in main () at main.cpp:4
I don't know in which way it is incorrect.
If I set break point b 4
, then r
, then the program safely comes to line 4, but same thing happens if I use n
. Very confused.
I'm running it in Debian virtual box but I don't think it's related.