Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 逐行c-c++;Linux-ubuntu中的代码调试_C++_C_Debugging - Fatal编程技术网

C++ 逐行c-c++;Linux-ubuntu中的代码调试

C++ 逐行c-c++;Linux-ubuntu中的代码调试,c++,c,debugging,C++,C,Debugging,我在ubuntu中使用gedit编码,并在终端中运行程序。在windows中使用Turboc或netbeans时,我们可以逐行调试代码。我们如何在ubuntu终端上做到这一点?或任何其他选项?gdb(Gnu调试器)是最佳选择 apt获取安装gdb 曼恩gdb 1. cc -g file.c // compile your program ,this will generate a.out file with required debugging info

我在ubuntu中使用gedit编码,并在终端中运行程序。在windows中使用Turboc或netbeans时,我们可以逐行调试代码。我们如何在ubuntu终端上做到这一点?或任何其他选项?gdb(Gnu调试器)是最佳选择

apt获取安装gdb

曼恩gdb

1.    cc -g file.c             //       compile your program ,this will generate a.out file with required debugging information 

2.    gdb a.out                //        start with gdb

3.    b main                   //        to set break point at main       

4.     run                     //        run now , and it will stop at break point main 

5.     s                       //        option s is to step single line and even step into functions

6.     n                       //        option n is to execute next line and step over functions  

7.     p    variable name      //        to print the value of variable at that particular instance very helpful  
曼恩gdb将提供更多信息

给出了所有有用的gdb命令和一个简单的cpp程序示例

您可以使用IDE(),它提供代码管理、突出显示和调试功能。你可以试试这些

  • QTCreator
    ()
  • KDevelop
    ()
  • Eclipse
    ()

或者,您可以直接从命令行选择使用
gdb
()。

您可以为此使用gdb

如果尚未安装gdb,请安装它

sudo apt-get install gdb
然后,您可以调试所选的可执行文件,如下所示

gdb <executable name>
gdb
您将获得一个完整的交互式调试会话。

我发现GDB(Gnu调试器)是c/c++的最佳工具。如果您已经安装了gcc,那么它可能已经安装在您的系统上

sudo apt-get install gdb
要使用它,请确保使用
-g
标志编译程序:

gcc -g myprog.c -o myprog
然后使用启动调试器

gdb ./myprog
以下是一些基本命令,可以帮助您继续:

b lineno           - set a break point at line 'lineno'
b srcfile:lineno   - set a break point in source file 'srcfile' at line 'lineno'
r                  - run the program
s                  - step through the next line of code
c                  - continue execution up to the next breakpoint
p varname          - print the value of the variable 'varname'

这个问题似乎离题了,因为它是关于ubuntu的。你可以使用VS代码。我在这里为它制作了教程: