[英]Debug C++ program in Linux
I have written a simple C++ program like this: 我写了一个简单的C ++程序,如下所示:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello.";
return 0;
}
Now I want to debug it. 现在我想调试它。 So what will be the command for it so my control goes to every line?
那么它的命令是什么,所以我的控制权到达每一行?
You can use gdb
for this: 您可以使用
gdb
:
$ gdb hello
This will start gdb
and prompt you for what to do next. 这将启动
gdb
并提示您下一步该做什么。 The next
command executes one line of source and stops at the next line. next
命令执行一行源并在下一行停止。
I found a basic GDB tutorial that may be helpful. 我发现了一个可能有用的基本GDB教程 。
Don't forget to compile your source code using -g option. 不要忘记使用-g选项编译源代码。 Like this:
g++ -g helloWorld.cc
This is going to create an a.out executable file. 像这样:
g++ -g helloWorld.cc
这将创建一个a.out可执行文件。 You'll be able to debug your a.out exe using gdb ./a.out
command. 您将能够使用
gdb ./a.out
命令调试a.out exe。 Another tool you may use it's ddd basically a GUI for gdb. 您可以使用它的另一个工具是ddd,基本上是gdb的GUI。
Good luck 祝好运
I always thought emacs provided a pretty user-friendly front-end to gdb... 我一直认为emacs为gdb提供了一个非常友好的前端...
Eg 例如
(That should suffice to get you started. Emacs being emacs, there are always more features...) (这应该足以让你开始.Emacs是emacs,总有更多的功能...)
If you want some user-friendly debugger, you can use Kdbg, which is basically a gdb frontend for KDE. 如果你想要一些用户友好的调试器,你可以使用Kdbg,它基本上是KDE的gdb前端。 Perhaps not so powerful as ddd, but easier to start with.
也许没有ddd那么强大,但更容易入手。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.