Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line by line c - c++ code debugging in Linux ubuntu [closed]

Tags:

c++

c

debugging

I am coding using gedit in ubuntu and running program in terminal. While working in windows using Turboc or netbeans we can debug code line by line. How can we do it in ubuntu terminal? or any other option?

like image 302
user123 Avatar asked Aug 16 '13 10:08

user123


People also ask

How do I open GDB in Ubuntu?

1. Go to your Linux command prompt and type “gdb”. Gdb open prompt lets you know that it is ready for commands. To exit out of gdb, type quit or q.

How do I stop GDB debugging?

To exit GDB, use the quit command (abbreviated q ), or type an end-of-file character (usually C-d ). If you do not supply expression , GDB will terminate normally; otherwise it will terminate using the result of expression as the error code.


1 Answers

gdb (The Gnu debugger) is best choice

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 will give more info

All useful gdb commands and an example with simple cpp program are given Here

GDB Documentation

like image 51
Gangadhar Avatar answered Sep 22 '22 04:09

Gangadhar