我在ubuntu中使用gedit编码并在终端中运行程序.使用Turboc或netbeans在Windows中工作时,我们可以逐行调试代码.我们怎么能在ubuntu终端上做到这一点?或任何其他选择?
Gan*_*har 55
gdb(Gnu调试器)是最佳选择
apt-get install 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
Run Code Online (Sandbox Code Playgroud)
man gdb会提供更多信息
所有有用的gdb命令,并用简单的CPP程序为例,给出这里
Ale*_*136 23
我发现GDB(Gnu DeBugger)是c/c ++的最佳工具.如果您安装了gcc,它可能已安装在您的系统上.
要使用它,请确保使用-g标志编译程序:
gcc -g myprog.c -o myprog
Run Code Online (Sandbox Code Playgroud)
然后启动调试器
gdb ./myprog
Run Code Online (Sandbox Code Playgroud)
以下是一些基本命令:
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'
Run Code Online (Sandbox Code Playgroud)
您可以使用gdb.
如果尚未安装gdb,请安装它.
sudo apt-get install gdb
Run Code Online (Sandbox Code Playgroud)
然后,您可以按如下方式调试所选的可执行文件
gdb <executable name>
Run Code Online (Sandbox Code Playgroud)
您将获得完整的交互式调试会话.
您可以使用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/).