C++程序意外退出,如何使用 gdb 进行调试?

发布于 2024-09-25 12:53:56 字数 631 浏览 8 评论 0原文

我正在编写一个程序,对我的同事编写的代码运行一些单元测试。我正在使用 Google C++ 测试框架。我运行一个生成 3 个线程的函数,然后运行 ​​30 秒。运行后,程序以状态 0 退出。显然,这不是预期的行为。我知道它不会再继续下去,因为我在下一行中放置了一个 cout 语句。

我的问题是,使用 gdb 进行调试的最佳方法是什么?这很困难,因为程序没有段错误或类似的东西,它只是退出。有没有办法挂钩退出调用,然后获得长回溯?

感谢您的帮助。

编辑:

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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感情废物 2024-10-02 12:53:56

除了 break exit 之外,还有其他几个地方可能需要设置断点。查看此问题和答案

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

冬天旳寂寞 2024-10-02 12:53:56

gdb 中的一个简单的 break exit 命令应该会停止程序,并允许您在程序从任何线程调用 exit 时检查状态。

当然,这是假设程序因 exit 被调用而结束,而不是由于其他原因,例如 abort、断言失败、未处理的异常或从 main 返回。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文