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, obviou开发者_StackOverflowsly. 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;
Besides break exit
, there are a couple other places you might need to set breakpoints. Take a look at this question and answers.
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.
精彩评论