0

I have some code, that I'm currently porting from OS X to Linux (console tool).

Somewhere in this code, I get a segmentation fault. The problem is, that if I run the program without GDB, I clearly see the segmentation fault, and the program is killed. But when I'm running GDB it just halts, and GDB never returns to the prompt. So I'm not really able to examine what's going on.

C++ is the code. Compiled with the -g option in g++.

Btw. Pretty new to GDB, so excuse me if this is obvious.

Any ideas? Thanks in advance.

Trenskow

4
  • What happens if you press Ctrl-C whilst it's "hanging"? That should return control to GDB. Commented Jan 16, 2011 at 22:42
  • Sorry if this seems like a silly suggestion, but did you actually quit gdb (usually with 'quit')? It halts so that you can inspect the state of the stack whenever the segmentation fault actually occurred, to figure out what caused it. Commented Jan 16, 2011 at 22:43
  • You might try running your program under valgrind -- it will often pick up errors before gdb notices them (at the cost of running the program 10x slower than normal, of course) Commented Jan 17, 2011 at 0:33
  • CTRL+C doesn't do anything. It just hangs after the segmentation fault. No GDB prompt, no bash prompt. No nothing. The only way to get out of it, is to open another console window, and kill gdb, which gets me back to bash. Commented Jan 17, 2011 at 16:28

3 Answers 3

3

gdb will suspend your program when the seg fault signal is received

type where to see the stack trace and start inspecting what's going on from there.

Also consider enabling core dumps, that way you can load the core dump in GDB and investigate what is going on

you can then load the core dump like this

> gdb your_program the_core_dump

Sign up to request clarification or add additional context in comments.

Comments

0

The behaviour you describe is not typical - I suspect the stack may have been trashed.

Try sending various signals directly via the 'kill' command.

Might be worth you running a test program in gdb with an abort() in it so that you can learn what the expected behaviour is for gdb.

Comments

0

I've seen this before when my stack was too large. Try moving stack variables onto the heap (make them globals), recompile, and see if you still get the error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.