gdb backtrace to file

Posted on 23rd December 2010 in KDE, Linux

flattr this!

I wanted a simple command to get a backtrace in a file from gdb. It took me years to finally discover and craft this command!

alias bt='echo 0 | gdb -batch-silent -ex "run" -ex "set logging overwrite on" -ex "set logging file gdb.bt" -ex "set logging on" -ex "set pagination off" -ex "handle SIG33 pass nostop noprint" -ex "echo backtrace:\n" -ex "backtrace full" -ex "echo \n\nregisters:\n" -ex "info registers" -ex "echo \n\ncurrent instructions:\n" -ex "x/16i \$pc" -ex "echo \n\nthreads backtrace:\n" -ex "thread apply all backtrace" -ex "set logging off" -ex "quit" --args'

bt $crashing_application

This will create gdb.bt in your current directory.

comments: 4 » tags: ,

4 Responses to “gdb backtrace to file”

  1. Nice! I quite often need the backtrace of a running process. For that I use http://bit.ly/iesz8l

  2. DDD says:

    That’s pretty nifty :) I have chucked it in my .bashrc. It’ll save me typing gdb + bt to find where I have put my NULL pointer this time… :)

  3. This is excellent :D I was looking for a way to get backtraces easier :D

  4. Michael says:

    Gentoo describe an easier way to do it [1].

    [1] http://www.gentoo.org/proj/en/qa/backtraces.xml



Pings responses to this post

Leave a Reply

Your email address will not be published. Required fields are marked *


*

Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

What is Persona?