0

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.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • 1
    Can you run the program without the debugger? – n. m. could be an AI Jan 16 '23 at 09:11
  • 1
    Works for me. Do you have anything unusual in your environment, for example is `LD_PRELOAD` set? – PFee Jan 16 '23 at 09:23
  • Is this Virtualbox 7.0.4 on MacOS Ventura?. – Mark Plotnick Jan 16 '23 at 18:42
  • @MarkPlotnick Yes. Is this the root cause? – Edward Wang Jan 16 '23 at 19:26
  • It looks like the reports [here](https://stackoverflow.com/questions/74992755/gdb-always-fails-with-segv-at-the-beginning-of-execution), [here](https://stackoverflow.com/questions/74525002/gdb-always-returns-segmentation-fault), and [here](https://forums.virtualbox.org/viewtopic.php?f=8&t=108016) have those two things in common. I haven't seen a solution yet. – Mark Plotnick Jan 17 '23 at 01:04

0 Answers0