gcc -Wall -g xxx.c -o xxx
-g mean open debug function.
When compile is done.
Execute the code
gdb ./a.out or
gdb --args executablename arg1 arg2 arg3 [2]
Type the command like below.
(gdb) b main
Breakpoint 1 at 0x804857e: file 1038.c, line 33.
(gdb) run < 2 ( feed some sample file from outside )
(gdb) s ( execute the next code )
(gdb) p ( print the variable )
Repeat to print one variable
$ break myfile.cpp:180
Breakpoint 1 at 0x46ba0e: file myfile.cpp, line 180.
$ commands 1
> print decoder.m_msg
> end
$
Reference :
- How do I use gcc, g++, and gdb?
- How do I run a program with commandline args using gdb within a bash script?
- Can gdb print a specific variable every time it breaks? [duplicate]
- GDB實用教學:自動化你的debug
0 意見:
張貼留言