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?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With