2010年7月14日 星期三

[GDB] Using gdb debug

compile the code

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 :

  1. How do I use gcc, g++, and gdb?
  2. How do I run a program with commandline args using gdb within a bash script?
  3. Can gdb print a specific variable every time it breaks? [duplicate]
  4. GDB實用教學:自動化你的debug
Youtube
  1. 'Become a GDB Power User' - Greg Law [ ACCU 2016 ]

Related Posts:

0 意見:

張貼留言