Backtrace

Differences between revisions 1 and 12 (spanning 11 versions)
Revision 1 as of 2006-05-01 19:18:28
Size: 643
Editor: ottawa-hs-64-26-167-206
Comment:
Revision 12 as of 2006-05-25 21:18:37
Size: 2018
Editor: ottawa-hs-209-217-123-229
Comment: Cleanup attaching to a process
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
A backtrace shows a listing of which program functions are still active. Since functions are nested when they are called, the program must record where it left one function, to jump into an inner one. It does this on the stack, which we dump for the backtrace,

By getting a backtrace at the point of a bug, a developer may be able to isolate where that bug is, because it will narrow down to the function, or even the line, that caused the erroneous behaviour.

= Generation =
Line 3: Line 9:
 1. Make sure the GNU Debugger is installed. {{{
sudo apt-get install gdb
}}}
Line 4: Line 13:
gdb <program> gdb <program> 2>&1 | tee gdb-<program>.txt
Line 6: Line 15:
(gdb) set pagination 0
Line 10: Line 20:
(gdb) thread apply all bt }}} (gdb) backtrace
(gdb) thread apply all backtrace
}}}
 1. Attach the complete output from GDB, contained in gdb-<program>.txt, in your bug report.
Line 12: Line 25:
 1. If the output gets very long, you might want to use: {{{
(gdb) set logging file backtrace.txt
(gdb) set logging on
}}} beforehand.
= Already running programs =
Line 17: Line 27:
 1. Include the complete output from GDB in your bug report. You can ask GDB to attach to a program that's already running. This is useful for debugging things that start up, but crash when you perform a particular task.

 1. Make sure the GNU Debugger is installed. {{{
sudo apt-get install gdb
}}}

 1. Find the process ID of <program>: {{{
pidof <program>
}}}

 1. Start `gdb`: {{{
gdb | tee gdb-<program>.txt
(gdb) handle SIG33 pass nostop noprint
(gdb) set pagination 0
(gdb) attach <PID>
}}}

 1. Continue the <program>: {{{
(gdb) continue
}}}

 1. The program will continue running. Perform any actions necessary to reproduce the crash

 1. Retrieve a backtrace of the crash: {{{
(gdb) backtrace
(gdb) thread apply all backtrace
}}}

 1. Attach the complete output from GDB, contained in gdb-<program>.txt, in your bug report.

A backtrace shows a listing of which program functions are still active. Since functions are nested when they are called, the program must record where it left one function, to jump into an inner one. It does this on the stack, which we dump for the backtrace,

By getting a backtrace at the point of a bug, a developer may be able to isolate where that bug is, because it will narrow down to the function, or even the line, that caused the erroneous behaviour.

Generation

Please ensure you have packages with debug symbols installed. You can do this by following the instructions at DebuggingProgramCrash.

  1. Make sure the GNU Debugger is installed.

    sudo apt-get install gdb
  2. Start the program under control of gdb:

    gdb <program> 2>&1 | tee gdb-<program>.txt
    (gdb) handle SIG33 pass nostop noprint
    (gdb) set pagination 0
    (gdb) run <arguments, if any>
  3. The program will start. Perform any actions necessary to reproduce the crash
  4. Retrieve a backtrace of the crash:

    (gdb) backtrace
    (gdb) thread apply all backtrace
  5. Attach the complete output from GDB, contained in gdb-<program>.txt, in your bug report.

Already running programs

You can ask GDB to attach to a program that's already running. This is useful for debugging things that start up, but crash when you perform a particular task.

  1. Make sure the GNU Debugger is installed.

    sudo apt-get install gdb
  2. Find the process ID of <program>:

    pidof <program>
  3. Start gdb:

    gdb | tee gdb-<program>.txt
    (gdb) handle SIG33 pass nostop noprint
    (gdb) set pagination 0
    (gdb) attach <PID>
  4. Continue the <program>:

    (gdb) continue
  5. The program will continue running. Perform any actions necessary to reproduce the crash
  6. Retrieve a backtrace of the crash:

    (gdb) backtrace
    (gdb) thread apply all backtrace
  7. Attach the complete output from GDB, contained in gdb-<program>.txt, in your bug report.

Backtrace (last edited 2022-12-20 22:15:16 by sergiodj)