我正在Ubuntu中使用gedit编码并在终端中运行程序。 而在Windows中使用Turboc或netbeans时,我们可以逐行调试代码。 那么在Ubuntu终端中如何进行逐行调试? 或者还有其他选项吗?
我正在Ubuntu中使用gedit编码并在终端中运行程序。 而在Windows中使用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程序示例Here
我认为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'
sudo apt-get install gdb
gdb <executable name>
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/)。