简体   繁体   中英

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.

  • gdb version = 9.2
  • g++ version = 9.3.0

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?

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 fork s / exec s $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 eg 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 eg fork s and exec s 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM