Welcome to http://www.marssoft.de/
 
Wednesday, 13th November 2019 16:30:43 (GMT+1) 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

guides:gdb [2014/04/02 22:39] (current)
Line 1: Line 1:
 +====== Using the GNU Debugger GDB ======
 +
 +==== A Sample Session with GDB ====
 +
 +The following is a sample session using gdb:
 +
 +<​code>​
 +gdb /​path/​to/​program
 +GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
 +Copyright 2004 Free Software Foundation, Inc.
 +
 +(gdb) break malloc_error_break
 +Breakpoint 1 at 0x1374bc6a7e31a11
 +
 +(gdb) break SomeClass::​~SomeClass()
 +Breakpoint 2 at 0x1001a22e6:​ file ../​../​../​../​src/​code/​SomeClass.h,​ line 13.
 +Breakpoint 3 at 0x1001a2248:​ file ../​../​../​../​src/​code/​SomeClass.h,​ line 13.
 +warning: Multiple breakpoints were set.
 +Use the "​delete"​ command to delete unwanted breakpoints.
 +
 +(gdb) delete 3
 +
 +(gdb) break myLicenseManager.cxx:​330
 +Breakpoint 3 at 0xa2a9d: file ../​../​src/​code/​myLicenseManager.cxx,​ line 330.
 +
 +(gdb) run
 +Breakpoint 1, myGraphInventor::​UpdateColor (this=0x6692e00,​ aColor=@0x2e6c3cb0) at ../​../​src/​myGraphInventor.cxx:​639
 +639       ​std::​cerr << "​myGraphInventor::​UpdateColor()"​ << std::endl;
 +
 +(gdb) list
 +634                                                              myColor*&​ aColor)
 +638     {
 +639       ​std::​cerr << "​myGraphInventor::​UpdateColor()"​ << std::endl;
 +640
 +641       // switch off color coding
 +642       ​switch (mCurrentColor) {
 +
 +(gdb) run
 +Program received signal EXC_BAD_ACCESS,​ Could not access memory.
 +Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000001
 +0x00007fff8320c89c in std::​string::​find_last_of ()
 +
 +(gdb) backtrace
 +#0  0x00007fff8320c89c in std::​string::​find_last_of ()
 +#1  0x000000010059e3d9 in myFileTools::​GetPath (aFileName=@0x1) at ../​../​src/​myFileTools.cpp:​44
 +#2  0x0000000103b8e646 in QAction::​triggered ()
 +#3  0x0000000103b90814 in QAction::​activate ()
 +#4  0x0000000103f09e6f in QAbstractButtonPrivate::​click ()
 +
 +(gdb) info threads
 +  4 process 9011 thread 0x6647 ​ 0x00007fff83288642 in kevent ()
 +* 3 process 9011 thread 0x363f ​ 0x00007fffffe0026d in ?? ()
 +  2 process 9011 thread 0x3a07 ​ 0x00007fff83261d02 in __semwait_signal ()
 +  1 process 9011 local thread 0x2d03 ​ 0x00007fff8320c89c in std::​string::​find_last_of ()
 +
 +(gdb) thread 1
 +[Switching to thread 1 (process 9011 local thread 0x2d03)]
 +0x00007fff8320c89c in std::​string::​find_last_of ()
 +
 +# using the Tab key (denoted [TAB] here) to auto-complete code lines:
 +(gdb) break myTexture[TAB]
 +Display all 964 possibilities?​ (y or n) n
 +
 +(gdb) break myTextureFragmentProgram[TAB]
 +myTextureFragmentProgram.cxx
 +myTextureFragmentProgram.h
 +myTextureFragmentProgram::​Bias(float,​ float)
 +myTextureFragmentProgram::​Colorize(Color const&)
 +myTextureFragmentProgram::​Disable() const
 +myTextureFragmentProgram::​Enable() const
 +myTextureFragmentProgram::​Interpolate() const
 +myTextureFragmentProgram::​Interpolate(bool)
 +myTextureFragmentProgram::​SetSource() const
 +myTextureFragmentProgram::​SetNumber(int)
 +
 +# use single quotation marks to enclose spaces:
 +(gdb) break '​bpTextureFragmentProgram::​Enable() const'
 +Breakpoint 4 at 0x1003f5604:​ file ../​../​src/​myTextureFragmentProgram.cxx,​ line 50.
 +
 +
 +
 +(gdb) quit
 +The program is running. ​ Exit anyway? (y or n) y
 +</​code>​
 +
 +
 +==== Collection of Commands ====
 +
 +A nice collection of commonly used GDB commands can be found here: http://​www.yolinux.com/​TUTORIALS/​GDB-Commands.html
 +
 +|help|List gdb command topics.|
 +|help //​topic-classes//​|List gdb command within class.|
 +|help //​command//​|Command description.|
 +|apropos //​search-word//​|Search for commands and command topics containing //​search-word//​.|
 +|info args i args|List program command line arguments|
 +|info breakpoints|List breakpoints|
 +|info break|List breakpoint numbers.|
 +|info break //​breakpoint-number//​|List info about specific breakpoint.|
 +|info watchpoints|List breakpoints|
 +|info registers|List registers in use|
 +|info threads|List threads in use|
 +|info set|List set-able option|
 +|break //​funtion-name//​|Suspend program at specified function.|
 +|break //​line-number//​|Suspend program at specified line number.|
 +|break +//offset// break -//​offset//​|Set a breakpoint specified number of lines forward or back from the position at which execution stopped.|
 +|break //​filename:​function//​|Don'​t specify path, just the file name and function name.|
 +|break //​filename:​line-number//​|Don'​t specify path, just the file name and line number.|
 +|break *//​address//​|Suspend processing at an instruction address. Used when you do not have source.|
 +|break //​line-number//​ if //​condition//​|Where condition is an expression. i.e. <tt>x > 5</​tt>​ Suspend when boolean expression is true.|
 +|break //line// thread //​thread-number//​|Break in thread at specified line number. Use <​tt>​info threads</​tt>​ to display thread numbers.|
 +|tbreak|Temporary break. Break once only. Break is then removed. See "​break"​ above for options.|
 +|watch //​condition//​|Suspend processing when condition is met. i.e. <tt>x > 5</​tt>​|
 +|clear|Delete breakpoints as identified by command option.|
 +|clear //​function//​|Delete breakpoints as identified by command option.|
 +|clear //​line-number//​|Delete breakpoints as identified by command option.|
 +|delete d|Delete all breakpoints,​ watchpoints,​ or catchpoints.|
 +|delete //​bp-number//​|Delete the breakpoints,​ watchpoints,​ or catchpoints of the breakpoint ranges specified as arguments.|
 +|delete //​range//​|Delete the breakpoints,​ watchpoints,​ or catchpoints of the breakpoint ranges specified as arguments.|
 +|disable //​bp-number-or-range//​|Does not delete breakpoints. Just enables/​disables them.|
 +|enable //​bp-number-or-range//​|Does not delete breakpoints. Just enables/​disables them.|
 +|enable //​bp-number//​ once|Enables once|
 +|continue c|Continue executing until next break point/​watchpoint.|
 +|continue //​number//​|Continue but ignore current breakpoint //number// times. Usefull for breakpoints within a loop.|
 +|finish|Continue to end of function.|
 +|step s|Step to next line of code. Will step into a function.|
 +|step //​number-of-steps//​|Step number of steps. Will step into a function.|
 +|next n|Execute next line of code. Will not enter functions.|
 +|next //​number//​|Execute next line of code. Will **not** enter functions.|
 +|until until //​line-number//​|Continue processing until you reach a function or filename:​line-number.|
 +|stepi si nexti ni|step/​next assembly/​processor instruction.|
 +|info signals|Show information on signals.|
 +|handle //​SIGNAL-NAME//​ //​option//​|Perform the following option when signal recieved: nostop, stop, print, noprint, pass/​noignore or nopass/​ignore|
 +|where|Shows current line number and which function you are in.|
 +|backtrace bt|Show trace of where you are currently.|
 +|bt //​inner-function-nesting-depth//​|Show trace of where you are currently.|
 +|bt -//​outer-function-nesting-depth//​|Show trace of where you are currently.|
 +|backtrace full|Print values of local variables.|
 +|frame f //number// |Select frame number.|
 +|up //number// down //​number//​|Move up/down the specified number of frames in the stack.|
 +|info frame|List address, language, address of arguments/​local variables and which registers were saved in frame.|
 +|info args info locals info catch|Info arguments of selected frame, local variables and exception handlers.|
 +|list l|List source code.|
 +|list //​line-number//​|List source code.|
 +|list //​function//​|List source code.|
 +|list -|List source code.|
 +|list //​start#,​end#//​|List source code.|
 +|list //​filename:​function//​|List source code.|
 +|set listsize //​count//​|Number of lines listed when <​tt>​list command given.</​tt>​|
 +|directory dir //​directory-name//​|Add specified directory to front of source code path.|
 +|show directories|List directories in source code path.|
 +|directory|Clear sourcepath when nothing specified.|
 +|print p //​variable-name//​|Print value stored in variable.|
 +|p //​file-name::​variable-name//​|Print value stored in variable.|
 +|p '//​file-name//':://​variable-name//​|Print value stored in variable.|
 +|p *//​array-variable//​@//​length//​|Print first # values of array specified by //length//. Good for pointers to dynamicaly allocated memory.|
 +|p/x //​variable//​|Print as integer variable in hex.|
 +|p/d //​variable//​|Print variable as a signed integer.|
 +|p/u //​variable//​|Print variable as a un-signed integer.|
 +|p/o //​variable//​|Print variable as a octal.|
 +|p/t //​variable//​ x/b //address// x/b !//​variable//​|Print as integer value in binary. (1 byte/​8bits)|
 +|p/c //​variable//​|Print integer as character.|
 +|p/f //​variable//​|Print variable as floating point number.|
 +|p/a //​variable//​|Print as a hex address.|
 +|x/w //address// x/4b !//​variable//​|Print binary representation of 4 bytes (1 32 bit word) of memory pointed to by address.|
 +|set //​gdb-option//​ //​value//​|Set a GDB option|
 +|set logging on|Turn on/off logging. Default name of file is <​tt>​gdb.txt</​tt>​|
 +|set logging off|Turn on/off logging. Default name of file is <​tt>​gdb.txt</​tt>​|
 +|set logging file //​log-file//​|Turn on/off logging. Default name of file is <​tt>​gdb.txt</​tt>​|
 +|set print array on|Convient readable format for arrays turned on/off.|
 +|set print array off|Default is off.|
 +|show print array|Default is off. Convient readable format for arrays turned on/off.|
 +|set print array-indexes on|Print index of array elements.|
 +|set print array-indexes off|Default off.|
 +|show print array-indexes|Default off. Print index of array elements.|
 +|set print pretty on|Format printing of C structures.|
 +|set print pretty off|Format printing of C structures.|
 +|show print pretty|Format printing of C structures.|
 +|set print union on|Print C unions.|
 +|set print union off|Default is on.|
 +|show print union|Default is on. Print C unions.|
 +|set print demangle on|Controls printing of C++ names.|
 +|set print demangle off|Default is on.|
 +|show print demangle|Default is on. Controls printing of C++ names.|
 +|run r \\ run //​command-line-arguments//​|Start program execution from the beginning of the program.|
 +|run < //infile// > //​outfile//​|The command <​tt>​break main</​tt>​ will get you started. Also allows basic I/O redirection.|
 +|continue c|Continue execution to next break point.|
 +|kill|Stop program execution.|
 +|quit q|Exit GDB debugger.|
 +
  
guides/gdb.txt · Last modified: 2014/04/02 22:39 (external edit)