【问题标题】:Line by line c - c++ code debugging in Linux ubuntu [closed]逐行 c - Linux ubuntu 中的 c++ 代码调试 [关闭]
【发布时间】:2013-08-16 10:38:11
【问题描述】:

我在 ubuntu 中使用 gedit 进行编码并在终端中运行程序。在使用 Turboc 或 netbeans 在 Windows 中工作时,我们可以逐行调试代码。我们如何在 ubuntu 终端中做到这一点?或任何其他选择?

【问题讨论】:

  • 这个问题似乎跑题了,因为它是关于 ubuntu 的。
  • 你可以使用 VS 代码。我在这里为它制作了教程:medium.com/@dcrystalj/…

标签: c++ c debugging


【解决方案1】:

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

要使用它,请确保使用 -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'

【讨论】:

    【解决方案2】:

    gdb(Gnu 调试器)是最佳选择

    apt-get 安装 gdb

    ma​​n 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  
    

    ma​​n gdb 将提供更多信息

    所有有用的gdb命令和一个简单cpp程序的例子都给出Here

    GDB Documentation

    【讨论】:

      【解决方案3】:

      您可以为此使用 gdb。

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

      sudo apt-get install gdb
      

      然后您可以按如下方式调试选择的可执行文件

      gdb <executable name>
      

      您将获得完整的交互式调试会话。

      【讨论】:

        【解决方案4】:

        您可以使用提供代码管理、突出显示和调试功能的 IDE(http://en.wikipedia.org/wiki/Integrated_development_environment)。您可以尝试其中任何一种。

        或者您可以选择直接从命令行使用gdb(https://www.gnu.org/software/gdb/)。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-12-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多