2010-01-15 21 views
10

मैं अपने कार्यक्रमजीडीबी का उपयोग करके डीबग कैसे करें?

b {line number} 

का उपयोग करने में एक ब्रेकपाइंट जोड़ने के लिए कोशिश कर रहा हूँ लेकिन मैं हमेशा एक त्रुटि है कि कहते हैं हो रही है:

No symbol table is loaded. Use the "file" command. 

मुझे क्या करना चाहिए? एक पैरामीटर के रूप निष्पादन के साथ

+1

http://www.yolinux.com/TUTORIALS/GDB-Commands.html यहाँ एक अच्छा gdb कमान शीट है। जीडीबी के बारे में जानने के लिए आपको जो भी चीज चाहिए उसे आपको मिलेगा। – Phong

उत्तर

22

यहाँ है जीडीबी के लिए एक त्वरित प्रारंभ ट्यूटोरियल:

/* test.c */ 
/* Sample program to debug. */ 
#include <stdio.h> 
#include <stdlib.h> 

int 
main (int argc, char **argv) 
{ 
    if (argc != 3) 
    return 1; 
    int a = atoi (argv[1]); 
    int b = atoi (argv[2]); 
    int c = a + b; 
    printf ("%d\n", c); 
    return 0; 
} 

सह जी विकल्प के साथ mpile:

gcc -g -o test test.c 

लोड निष्पादन योग्य है, जो अब डिबगिंग प्रतीक हो, gdb में:

gdb --annotate=3 test.exe 

अब आप अपने आप को gdb प्रॉम्प्ट पर खोजना चाहिए। वहां आप gdb को कमांड जारी कर सकते हैं। आप स्थानीय चर के मूल्यों मुद्रण लाइन 11 पर एक ब्रेकपाइंट जगह है और निष्पादन से निकलने के लिए पसंद करते हैं, कहते हैं - निम्न कमांड दृश्यों आप यह कर मदद मिलेगी:

(gdb) break test.c:11 
Breakpoint 1 at 0x401329: file test.c, line 11. 
(gdb) set args 10 20 
(gdb) run 
Starting program: c:\Documents and Settings\VMathew\Desktop/test.exe 10 20 
[New thread 3824.0x8e8] 

Breakpoint 1, main (argc=3, argv=0x3d5a90) at test.c:11 
(gdb) n 
(gdb) print a 
$1 = 10 
(gdb) n 
(gdb) print b 
$2 = 20 
(gdb) n 
(gdb) print c 
$3 = 30 
(gdb) c 
Continuing. 
30 

Program exited normally. 
(gdb) 

संक्षेप में, निम्न कमांड सभी कर रहे हैं

(gdb) पर
break file:lineno - sets a breakpoint in the file at lineno. 
set args - sets the command line arguments. 
run - executes the debugged program with the given command line arguments. 
next (n) and step (s) - step program and step program until it 
         reaches a different source line, respectively. 
print - prints a local variable 
bt - print backtrace of all stack frames 
c - continue execution. 

प्रकार सहायता शीघ्र सभी वैध आदेशों की एक सूची और विवरण प्राप्त करने के लिए: यदि आप gdb का उपयोग शुरू करने की जरूरत है।

4

प्रारंभ gdb, इतना है कि यह जानता है जो कार्यक्रम आप डिबग हैं:

gdb ./myprogram 

तो फिर तुम breakpoints सेट करने के लिए सक्षम होना चाहिए। उदाहरण के लिए:

b myfile.cpp:25 
b some_function 
+4

और डीबगिंग जानकारी के साथ संकलन करना न भूलें (जीसीसी में "-g" पैरामीटर है)। – wilhelmtell

2

आप अपने निष्पादन योग्य फ़ाइल का नाम GDB बताने की आवश्यकता है, जब आप gdb या फ़ाइल आदेश का उपयोग कर चलाएँ:

$ gdb a.out 

या

(gdb) file a.out 
2

सुनिश्चित करें कि आपने संकलन करते समय -g विकल्प का उपयोग किया था।

-1

आपको अपने प्रोग्राम के संकलन समय पर -g या -ggdb विकल्प का उपयोग करने की आवश्यकता है।

जैसे, gcc -ggdb file_name.c ; gdb ./a.out

संबंधित मुद्दे