views:

81

answers:

2

Hi Everyone,

I am writing a program that runs some unit tests on code that that been written by my colleagues. I am using the Google C++ testing framework. I run a function that spawns 3 threads, and then runs for 30 seconds. After it runs, the program exits with status 0. This is not the expected behavior, obviously. I know it doesn't make it any farther, because I put a cout statement in the next immediate line.

My question is, what is the best way to go about debugging this with gdb? It is difficult because the program doesn't segfault or anything like that, it just exits. Is there a way to hook an exit call, and then get a long backtrace?

Thank you for your help.

Edit:

cSystemCfg* pSystemCfg = new cSystemCfg();
std::cout << "Before runThing" << std::endl;
pSomething->runThing(&acq, pHwIf, pSystemCfg, pIf);
//Exits here, never gets to the next line
std::cout << "After runThing" << std::endl;
+2  A: 

A simple break exit command in gdb should stop the program and allow you to examine the state when the program calls exit from any thread.

This is of course assuming that the program is ending from exit being called and not for some other reason such as abort, an assertion failure, an unhandled exception, or returning from main.

Tyler McHenry
should do it ineed. Else, look up calls to exit() etc and put breakpoint on there, but I guess that's the whole point of gdb's break exit, no?
stijn
I just tried this, and it still allows threads to exit. I tried reverse-step and it says: "Target multi-thread does not support this command."
xxpor
If it doesn't break on `exit` when you say `break exit`, then `exit` is not what is causing your program to exit. Try breaking on `abort`, or `catch throw` to stop on thrown exceptions, or investigate if your program is receiving a signal that is causing it to terminate.
Tyler McHenry
+3  A: 

Besides break exit, there are a couple other places you might need to set breakpoints. Take a look at this question and answers.

SCFrench
Thanks for that link; it helped a lot. It turns out my program is executing everything, its just after that function call nothing is being printed to the screen.
xxpor