2013-08-16 21 views
40

Ben ubuntu gedit kullanarak ve terminalde çalışan programı kodlama yapıyorum. Pencerelerde Turboc veya netbeans kullanarak çalışırken kod satırını hata ayıklayabiliriz. Ubuntu terminalinde bunu nasıl yapabiliriz? ya da başka bir seçenek?Satır tarafından satır c - C++ kod hata ayıklama Linux ubuntu

+5

gdb'yi kullanabilirsiniz –

+0

Bu soru, şunun gibi görünüyor: pic ubuntu hakkında çünkü. – devnull

cevap

47

gdb (Gnu ayıklayıcı) 'dir iyi seçim

apt-get gdb yüklemek

adam 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 

adam gdb fazla bilgiye

verecek

Tüm yararlı gdb komutları ve basit cpp programı ile örnek

GDB Documentation

9

Bunun için gdb'yi kullanabilirsiniz.

Henüz yüklü değilse gdb'yi yükleyin.

gdb <executable name> 

Sen tam etkileşimli hata ayıklama oturumu almak şöyle

sudo apt-get install gdb 

Sonra seçim yürütülebilir hata.

20

GDB'yi (Gnu DeBugger) c/C++ için en iyi araç olarak buluyorum. Gcc yüklüyse muhtemelen sisteminize zaten yüklenmiştir. Eğer yarayacak bazı temel komutlardır

gcc -g myprog.c -o myprog 

Sonra Burada

gdb ./myprog 

ayıklayıcıyı başlatmak:

, kullanmak emin olun -g bayrağıyla programınızı derlemek için

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' 
İlgili konular