ToxicGLaDOS
ToxicGLaDOS

Reputation: 483

During startup program exited normally. gdb doesn't break at breakpoints

I'm receiving this gdb error on any code I try to debug any program with gdb. Here's the simplest process that reproduces the error

  1. Create a main.cpp file with this content:
int main(){
    return 0;
}
  1. Run g++ -g main.cpp
  2. Run gdb a.out
  3. Inside gdb set a break point at line 2 with break 2
  4. In gdb run the program with run

Output:

Starting program: /tmp/test/a.out 
During startup program exited normally.

This is all done with gdb on the command line. I've tried using g++ and gcc with the same result. I'm not really sure where to go from here.

EDIT: I figured out what is causing the issue, but not how to fix it. The issue seems to be something related to my SHELL variable. I'm currently using xonsh as my shell but when I set my SHELL environment variable back to /bin/bash everything works as expected. Is there anything I can do to fix this while using xonsh? Should I report this to xonsh, gdb, both or neither?

Upvotes: 3

Views: 802

Answers (1)

Employed Russian
Employed Russian

Reputation: 213877

I'm currently using xonsh as my shell but when I set my SHELL environment variable back to /bin/bash everything works as expected. Is there anything I can do to fix this while using xonsh? Should I report this to xonsh, gdb, both or neither?

This might be your xonsh startup problem, or it might be xonsh problem, or it could be that xonsh doesn't do what GDB expects it to do.

Normally, GDB forks / execs $SHELL -c "/path/to/your/exe $args" and expects the $SHELL to exec your program (this is done so shell redirection still works under GDB).

Only after that exec will GDB start setting breakpoints, etc.

If you have some xonsh init-file, which e.g. causes xonsh to exec something else, things could go bad. So I suggest trying to remove any such ~/.xonshrc or whatever it's called file, and seeing whether that fixes the problem.

If it doesn't, it could be that xonsh e.g. forks and execs your binary in a child (grandchild of GDB) instead of doing it directly, or it could be that xonsh doesn't understand the -c ... syntax.


If you don't care about redirection, you could also ask GDB to not use $SHELL at all: set startup-with-shell off. Documentation.

Upvotes: 4

Related Questions