在Linux ubuntu中逐行调试c-c++代码
Line by line c - c++ code debugging in Linux ubuntu
我在ubuntu中使用gedit进行编码,并在终端中运行程序。在使用Turboc或netbeans的窗口中工作时,我们可以逐行调试代码。我们如何在ubuntu终端中做到这一点?还是其他选择?
gdb(Gnu调试器)是的最佳选择
apt-get-install gdb
man 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
man gdb将提供更多信息
这里给出了所有有用的gdb命令和一个带有简单cpp程序的示例
GDB文档
我发现GDB(Gnu DeBugger)是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'
您可以使用gdb。
如果尚未安装gdb,请安装它。
sudo apt-get install gdb
然后你可以调试选择的可执行文件如下
gdb <executable name>
您将获得一个完整的交互式调试会话。
您可以使用IDE(http://en.wikipedia.org/wiki/Integrated_development_environment)它提供代码管理、突出显示和调试功能。你可以试试这些。
QTCreator
(http://qt-project.org/wiki/Category:Tools::QtCreator)KDevelop
(http://www.kdevelop.org/)Eclipse
(http://www.eclipse.org/)
或者您可以选择使用gdb
(https://www.gnu.org/software/gdb/)直接从命令行。
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 在linux上调试巨大的C++项目
- 为什么使用__LINE_的代码在发布模式下在MSVC下编译,而不是在调试模式下
- 如何针对特定情况调试和修复此双自由内存损坏问题
- 正在VS调试器中监视映射条目
- 使用调试/崩溃报告将应用程序部署到客户端
- VC++本机单元测试,找不到调试符号
- 如何在C++生成器中禁用"使用调试.dcus"
- 使用vscode调试时,GDB意外退出
- 即使使用调试编译标志,表达式也是"optimized out"
- 调试 CUDA MMU 故障
- 小字符串优化(调试与发布模式)
- 调试和自由执行中的信号处理
- 调试编译的服务器在数据库打开时崩溃
- Visual Studio 调试优化如何工作?
- 如何配置Visual Studio Code以使用cygwin,cmake和gcc进行调试
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- 如何在大型c++项目的可视化代码中设置调试
- Qt 调试显示行号
- 如何将可变参数模板转换为多个单个模板?(C++竞争编程调试模板)