简体   繁体   English

如何在gdb中返回主函数

[英]how to return to main function in gdb

I'm using gdb for debugging I get a segmentation fault, and then I want to set another break point in the main function and run the program from the beginning however, although I have finished the current run and it shows "THe program is not being run" 我正在使用gdb进行调试,但遇到了段错误,然后我想在main函数中设置另一个断点,然后从头开始运行程序,尽管我已经完成了当前运行,但显示“该程序不是正在运行”

when I input 'list' 当我输入“列表”时

it shows a code snippet of a libarary file it means currently I'm not in the main function 它显示了一个库文件的代码段,这意味着当前我不在主函数中

If I re-run the program, even if I set the break point at the beginning of the main() it still get segmentation fault, it means the program is running within the library file 如果我重新运行程序,即使我在main()的开头设置了断点,它仍然会出现分段错误,这意味着程序正在库文件中运行

so how to return to the main() function? 那么如何返回main()函数呢? thanks! 谢谢!

tips: I'm using libpcap.h and I have a '-lpcap' option when compiling 提示:我使用的是libpcap.h,编译时有一个'-lpcap'选项

BTW, when I use break 9 to set a breakpoint at 9, gdb runs the program to the 11-th line? 顺便说一句,当我使用break 9将断点设置为9时,gdb将程序运行到第11行吗? what is wrong with this inaccuracy? 这种不正确怎么了? thanks! 谢谢!

Simply re-issue the run command. 只需重新发出run命令。 You will lose program state, but not breakpoints which seems to match what you need. 您将丢失程序状态,但不会丢失断点,断点似乎符合您的需求。

"BTW, when I use break 9 to set a breakpoint at 9, gdb runs the program to the 11-th line" - from this, and other information you've provided, it sounds like perhaps the source code is out of sync with gdb's mapping of addresses to source lines. “顺便说一句,当我使用Break 9将断点设置为9时,gdb将程序运行到第11行”-从此以及您提供的其他信息,听起来好像源代码与gdb的地址到源代码行的映射。 Have you by any chance been editing the program? 您有没有在编辑程序? Have you recompiled it and restarted gdb? 您重新编译并重新启动gdb了吗? Have you seen any warnings similar to "executable is more recent than source"? 您是否看到过类似“可执行文件比来源更新”的警告?

If I re-run the program, even if I set the break point at the beginning of the main() it still get segmentation fault, it means the program is running within the library file 如果我重新运行程序,即使我在main()的开头设置了断点,它仍然会出现分段错误,这意味着程序正在库文件中运行

Actually it means that you either failed to set breakpoint on main function or program execution not reaches main and gets segmentation fault. 实际上,这意味着您要么无法在main函数上设置断点,要么程序执行未达到main函数并出现分段错误。 Try the following steps: 请尝试以下步骤:

  1. Rebuild program from scratch with debug info ( -g gcc option). 使用调试信息( -g gcc选项)从头开始重建程序。 Reset breakpoint and watch for any warnings from gdb. 重置断点并注意来自gdb的任何警告。
  2. If program still crashes with breakpoint set on main look at stack trace ( bt command in gdb). 如果程序仍然崩溃并在main节点上设置了断点,请查看堆栈跟踪(gdb中的bt命令)。 It is probably happening before main and you will not see main in stack trace. 它可能在main之前发生,并且您不会在堆栈跟踪中看到main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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