To debug a C or C++ application with gdb, built in debug mode i.e -g compiling option.
gdb commands
(gdb)list 10
(gdb)list myglobalFun
14. Print the current debug code line numbers using 'frame'
(gdb)frame
15. Quit from debug console qith q or quit key word
(gdb)quit
x Command: ' x/FMT Address '
16. x command list the region of memory with specified address content in specified format.
(gdb)x/100i $sp # $sp is current stack pointer address, 100i - denotes the 100 address spaces code with disassemble code.
(gdb)x/20s 0x435281720 # 20 lines code from address with code in string format
(gdb)x/x display in hexadecimal
(gdb)x/d display in decimal format
(gdb)x/c display with charectors format
help for x u can check in gdb
(gdb) help x
Multithreading debug:
In multi threading debugging mostly thread will share code, data segment from process space only thread specific it will be having stack content, so needs to debug only stack data.
17. To list the threads info using 'info threads'
(gdb)info threads # which will list all threads with thread id
18. To check all threads stack traces ' thread apply all bt '
(gdb) thread apply all bt
19. To check particular thread stack trace first set the treat using 'thread <tread id>' listed with 'info threads' the do bt for stack trace of that thread
(gdb)thread 0x12463097 #0x12463097 thread id
(gdb) bt
debug for release/ stripped / no symbols binary using gdb
20. With gdb will do 'info file', it lists Entry point address for program. set the break point at entry point address, then do the 'disas' will list assembly code will be having main function address.
with assembly code try to under stand or match ur function names and data to under stand the flow.
more info click on link debug for release/ stripped / no symbols binary using gdb with more links in it
gdb commands
-g in compilation: will enable debug symbols into binary.
Ex: gcc -g mytest.c or gcc -g test.c -o test
g++ -g mytest.cpp or g++ -g test.cpp -o test
1. start gdb with executable and set the break point and run :
#gdb test
(gdb) b main # to set the break point at main function start
(gdb) run # program start executes
2. start gdb without process and add process with 'file'.
#gdb
(gdb) file test # start the test executable for debugging
3. Passing console arguments to process with run
(gdb) run abc 3 # abc , 3 are command line arguments for test program.
Back trace / stack frames : using bt
4. On break point / core parser gdb running out we can see current stack trace
(gdb)bt
It will list stack frames with frame id for each stack frame.
4.1 list each frame with f num
(gdb) f 4 # here 4 is 4th stack frame listed in bt
Break Points: b , break, br any of this keywords can be used to set the break points
5. Adding break point with filename with line number
(gdb) b test.c:10 # break point at line number 10
6. Adding breakpoint with function names
(gdb) break fun1 #fun1 is function in test.c
(gdb) b myclass::fun2 #fun2 is myclass member function
6.1 break with memory address
(gdb)b *(memoryAddress) # debug symbol address instead variable or function.
7. List all break points
(gdb) info break # list all break points with break point numbers in sequence.
8. Delete/Remove breakpoint using d
(gdb)d 3 #here 3 is the 3rd break point
9. traverse to next step or next break point & step in using n, c & s
(gdb) s
(gdb) n
(gdb) c
10. Print the values with p or print keyword
(gdb) print iVar #iVar is the variable
(gdb) p fVal #fVal is a variable
11. To set the values for variables using 'set'
(gdb)set iVar=20
(gdb)p iVar # iVar will print 20
12. Execute the global functions after breakpoint hit
(gdb)p myglobalFun #myglobalFun is a global function can be run here
13. Listing the source code after some line number or function content using 'list'Back trace / stack frames : using bt
4. On break point / core parser gdb running out we can see current stack trace
(gdb)bt
It will list stack frames with frame id for each stack frame.
4.1 list each frame with f num
(gdb) f 4 # here 4 is 4th stack frame listed in bt
Break Points: b , break, br any of this keywords can be used to set the break points
5. Adding break point with filename with line number
(gdb) b test.c:10 # break point at line number 10
6. Adding breakpoint with function names
(gdb) break fun1 #fun1 is function in test.c
(gdb) b myclass::fun2 #fun2 is myclass member function
6.1 break with memory address
(gdb)b *(memoryAddress) # debug symbol address instead variable or function.
7. List all break points
(gdb) info break # list all break points with break point numbers in sequence.
8. Delete/Remove breakpoint using d
(gdb)d 3 #here 3 is the 3rd break point
9. traverse to next step or next break point & step in using n, c & s
(gdb) s
(gdb) n
(gdb) c
10. Print the values with p or print keyword
(gdb) print iVar #iVar is the variable
(gdb) p fVal #fVal is a variable
11. To set the values for variables using 'set'
(gdb)set iVar=20
(gdb)p iVar # iVar will print 20
12. Execute the global functions after breakpoint hit
(gdb)p myglobalFun #myglobalFun is a global function can be run here
(gdb)list 10
(gdb)list myglobalFun
14. Print the current debug code line numbers using 'frame'
(gdb)frame
15. Quit from debug console qith q or quit key word
(gdb)quit
x Command: ' x/FMT Address '
16. x command list the region of memory with specified address content in specified format.
(gdb)x/100i $sp # $sp is current stack pointer address, 100i - denotes the 100 address spaces code with disassemble code.
(gdb)x/20s 0x435281720 # 20 lines code from address with code in string format
(gdb)x/x display in hexadecimal
(gdb)x/d display in decimal format
(gdb)x/c display with charectors format
help for x u can check in gdb
(gdb) help x
Multithreading debug:
In multi threading debugging mostly thread will share code, data segment from process space only thread specific it will be having stack content, so needs to debug only stack data.
17. To list the threads info using 'info threads'
(gdb)info threads # which will list all threads with thread id
18. To check all threads stack traces ' thread apply all bt '
(gdb) thread apply all bt
19. To check particular thread stack trace first set the treat using 'thread <tread id>' listed with 'info threads' the do bt for stack trace of that thread
(gdb)thread 0x12463097 #0x12463097 thread id
(gdb) bt
debug for release/ stripped / no symbols binary using gdb
20. With gdb will do 'info file', it lists Entry point address for program. set the break point at entry point address, then do the 'disas' will list assembly code will be having main function address.
with assembly code try to under stand or match ur function names and data to under stand the flow.
more info click on link debug for release/ stripped / no symbols binary using gdb with more links in it
No comments:
Post a Comment