Difference between revisions of "Creating a Backtrace with GDB"

From Free Pascal wiki
Jump to navigationJump to search
(Mostly finished writing, Understanding a backtrace still todo)
Line 72: Line 72:
 
  #2  0x081274bd in TBUTTONCONTROL__CLICK (this=0x403d8bd8) at buttoncontrol.inc:57
 
  #2  0x081274bd in TBUTTONCONTROL__CLICK (this=0x403d8bd8) at buttoncontrol.inc:57
 
  #3  0x08129171 in TCUSTOMBUTTON__CLICK (this=0x403d8bd8) at buttons.inc:186
 
  #3  0x08129171 in TCUSTOMBUTTON__CLICK (this=0x403d8bd8) at buttons.inc:186
  #4  0x08129198 in TCUSTOMBUTTON__WMDEFAULTCLICKED (MESSAGE={MSG = 1031, WPARAM = 136821192, LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087, LPARAMLO = 59548, LPARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416}, this=0x403d8bd8) at buttons.inc:198
+
  #4  0x08129198 in TCUSTOMBUTTON__WMDEFAULTCLICKED (MESSAGE={MSG = 1031, WPARAM =  
 +
        136821192, LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560,  
 +
        WPARAMHI = 2087, LPARAMLO = 59548, LPARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416},  
 +
        this=0x403d8bd8) at buttons.inc:198
 
  #5  0x0805bbf7 in SYSTEM_TOBJECT_$__DISPATCH$formal ()
 
  #5  0x0805bbf7 in SYSTEM_TOBJECT_$__DISPATCH$formal ()
  #6  0x080ec6e0 in TCONTROL__WNDPROC (THEMESSAGE={MSG = 1031, WPARAM = 136821192, LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087, LPARAMLO = 59548,  PARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416}, this=0x403d8bd8) at control.inc:1447  
+
  #6  0x080ec6e0 in TCONTROL__WNDPROC (THEMESSAGE={MSG = 1031, WPARAM = 136821192,  
  #7  0x080e4ed9 in TWINCONTROL__WNDPROC (MESSAGE={MSG = 1031, WPARAM = 136821192, LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087, LPARAMLO = 59548,  PARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416}, this=0x403d8bd8) at wincontrol.inc:2154
+
        LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087,  
 +
        LPARAMLO = 59548,  PARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416},  
 +
        this=0x403d8bd8) at control.inc:1447  
 +
  #7  0x080e4ed9 in TWINCONTROL__WNDPROC (MESSAGE={MSG = 1031, WPARAM = 136821192,  
 +
        LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087,  
 +
        LPARAMLO = 59548,  PARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416},  
 +
        this=0x403d8bd8) at wincontrol.inc:2154
 
  #8  0x08161955 in DELIVERMESSAGE (TARGET=0x403d8bd8, AMESSAGE=void) at gtkproc.inc:3242
 
  #8  0x08161955 in DELIVERMESSAGE (TARGET=0x403d8bd8, AMESSAGE=void) at gtkproc.inc:3242
 
  #9  0x0818897c in GTKWSBUTTON_CLICKED (AWIDGET=0x8285380, AINFO=0x40453794) at gtkwsbuttons.pp:112
 
  #9  0x0818897c in GTKWSBUTTON_CLICKED (AWIDGET=0x8285380, AINFO=0x40453794) at gtkwsbuttons.pp:112
 +
... { Truncated for simplicity}
 
  (gdb) _
 
  (gdb) _
 +
''Note: If the backtrace it too long you will be prompted to press enter for the next page of the backtrace until it is complete''
 +
 
The information displayed here has the sequence of events up to where the error occured. [[Creating_a_Backtrace_with_GDB#Understanding a Backtrace| Understanding a Backtrace]]
 
The information displayed here has the sequence of events up to where the error occured. [[Creating_a_Backtrace_with_GDB#Understanding a Backtrace| Understanding a Backtrace]]
  
Line 87: Line 99:
  
 
''Hint: At any time while your program is running you may press Ctrl+C (from the Terminal or MS-DOS prompt) to get a "(gdb) _" prompt''
 
''Hint: At any time while your program is running you may press Ctrl+C (from the Terminal or MS-DOS prompt) to get a "(gdb) _" prompt''
 
  
 
==Getting the Backtrace out of the terminal and into an email==
 
==Getting the Backtrace out of the terminal and into an email==

Revision as of 16:56, 23 February 2005

Reasons to create a backtrace

Bug Reports

Backtraces can be very helpfull when submitting bug reports. They will no doubt increase the chances of the bug getting fixed sooner.

Help yourself find a problem

A backtrace can really take the pain out of finding a problem with your own program. Often exposing the problem immediately.

Just plain fun!!

Okay this might be a stretch, but making backtraces is just plain fun!

Seriously though, if you can think of another reason to create a backtrace add it here.

Creating a Backtrace

To create a backtrace with gdb(gnu debugger):

  1. You must have the program gdb
  2. gdb must be in the PATH enviornment variable
  3. The program you wish to debug MUST have debugging info included in the executable. If you have used "strip", "upx", compiled with "TODO what are the fpc options to strip debugging info" or some other exe shrinker/compressor this won't work!

Windows Users:

1. Open a MS-DOS prompt

2. Change to the drive you have your exe on:

C: {press enter}

3. Change to the directory containing the exe:

cd \myprograms\Project1 {press enter}

4. Run the program using gdb:

gdb Project1.exe {press enter]

Linux/BSD Users:

1. Open your favorite Terminal program

2. Change to the directory containing the exe:

cd $HOME/myprograms/project1 {press enter}

3. Run the program using gdb:

gdb project1 {press enter]


Now you should be at a prompt that looks somthing like this:

GNU gdb 6.3.50.20050217-cvs
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
(gdb) _

To run your program type:

run {press enter}

Now your program will run normally, until it crashes or causes an error.

When your program crashes instead of the usual error "Access Violation" or "Division by Zero" your program will just seem to stop, not respond and not repaint itself. This is because gdb has caught the error and is waiting for you to tell it what to do.

Switch over to your MS-DOS window or Terminal and you should have a screen somthing like this:

Program received signal SIGFPE, Arithmetic exception.
0x080733aa in TFORM1__BUTTON1CLICK (SENDER=0x403d8bd8, this=0x403d77d8) at unit1.pas:36
Current language:  auto; currently pascal
(gdb) _

To create a backtrace now type:

backtrace {press enter} or bt

You should now have a screen that looks somthing like this: (gdb) bt

#0  0x080733aa in TFORM1__BUTTON1CLICK (SENDER=0x403d8bd8, this=0x403d77d8) at unit1.pas:36
#1  0x080ecd78 in TCONTROL__CLICK (this=0x403d8bd8) at control.inc:1768
#2  0x081274bd in TBUTTONCONTROL__CLICK (this=0x403d8bd8) at buttoncontrol.inc:57
#3  0x08129171 in TCUSTOMBUTTON__CLICK (this=0x403d8bd8) at buttons.inc:186
#4  0x08129198 in TCUSTOMBUTTON__WMDEFAULTCLICKED (MESSAGE={MSG = 1031, WPARAM = 
        136821192, LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, 
        WPARAMHI = 2087, LPARAMLO = 59548, LPARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416}, 
        this=0x403d8bd8) at buttons.inc:198
#5  0x0805bbf7 in SYSTEM_TOBJECT_$__DISPATCH$formal ()
#6  0x080ec6e0 in TCONTROL__WNDPROC (THEMESSAGE={MSG = 1031, WPARAM = 136821192, 
        LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087, 
        LPARAMLO = 59548,  PARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416}, 
        this=0x403d8bd8) at control.inc:1447 
#7  0x080e4ed9 in TWINCONTROL__WNDPROC (MESSAGE={MSG = 1031, WPARAM = 136821192, 
        LPARAM = -1073747812, RESULT = 1075866658, WPARAMLO = 47560, WPARAMHI = 2087, 
        LPARAMLO = 59548,  PARAMHI = 49151, RESULTLO = 27682, RESULTHI = 16416}, 
        this=0x403d8bd8) at wincontrol.inc:2154
#8  0x08161955 in DELIVERMESSAGE (TARGET=0x403d8bd8, AMESSAGE=void) at gtkproc.inc:3242
#9  0x0818897c in GTKWSBUTTON_CLICKED (AWIDGET=0x8285380, AINFO=0x40453794) at gtkwsbuttons.pp:112
... { Truncated for simplicity}
(gdb) _

Note: If the backtrace it too long you will be prompted to press enter for the next page of the backtrace until it is complete

The information displayed here has the sequence of events up to where the error occured. Understanding a Backtrace

To exit gdb (and your program) you may now type:

quit {press enter}

Or to continue running until the next exception type:

cont {press enter}

Hint: At any time while your program is running you may press Ctrl+C (from the Terminal or MS-DOS prompt) to get a "(gdb) _" prompt

Getting the Backtrace out of the terminal and into an email

Currently we have made a backtrace and seen it in the Terminal(or MS-DOS prompt) but how do I get it into an email? There are two ways that I know of:

  1. Use the copy/paste functionality of your Terminal(or MS-DOS prompt)
  2. Redirect the output of gdb to a file like so:
gdb project1 > output.txt

Now you can open the file and copy/paste it into your email.

Caveat: The second method requires that you type blindly. So you would type "run" to start the program and "backtrace" to make a backtrace like normal but nothing would show up on the screen.

Exception: On Linux you can get around not begin able to see with the following command:

touch output.txt & tail output.txt -f & gdb project1 > output.txt

Understanding a Backtrace

TODO: Write Me :)