Debug::FaultAutoBT - Automatic Backtrace Extractor on SIGSEGV, SIGBUS, etc.


Debug-FaultAutoBT documentation  | view source Contained in the Debug-FaultAutoBT distribution.

Index


NAME

Top

Debug::FaultAutoBT - Automatic Backtrace Extractor on SIGSEGV, SIGBUS, etc.

SYNOPSIS

Top

  use Debug::FaultAutoBT;

  use File::Spec::Functions;
  my $tmp_dir = File::Spec::Functions::tmpdir;

  my $trace = Debug::FaultAutoBT->new(
      dir            => "$tmp_dir",
      #verbose        => 1,
      #exec_path      => '/home/stas/perl/bin/perl',
      #core_path_base => catfile($tmp_dir, "mycore"),
      #command_path   => catfile($tmp_dir, "my-gdb-command"),
      #debugger       => "gdb",
  );

  # enable the sighandler
  $trace->ready();

  # or simply:
  Debug::FaultAutoBT->new(dir => "$tmp_dir")->ready;




DESCRIPTION

Top

When a signal, that normally causes a coredump, is delivered This module attempts to automatically extract a backtrace, rather than letting the core file be dumped. This has the following benefits:

Currently the following signals are trapped:

     SIGQUIT
     SIGILL
     SIGTRAP
     SIGABRT
     SIGEMT
     SIGFPE
     SIGBUS
     SIGSEGV
     SIGSYS

(If you know of other signals that should be trapped let me know. thanks.)

METHODS

Top

new()

  my $trace = Debug::FaultAutoBT->new(
      dir            => "$tmp_dir",
      verbose        => 1,
      exec_path      => '/home/stas/perl/bin/perl',
      core_path_base => catfile($tmp_dir, "mycore"),
      command_path   => catfile($tmp_dir, "my-gdb-command"),
      debugger       => "gdb",
  );

Attributes:

dir

a writable by the process directory.

This is a required attribute.

verbose

Whether to be silent (0) or verbose (1).

This is an optional attribute. The default is 0.

Currently it's always a non-verbose, with just a few traces printed out. Will work in the future.

exec_path

gdb needs to know the path to the executable in order to attach to the process (though gdb 5.2 and higher needs only pid to do that). This module is trying to automatically figure out the executable path, using several methods in the following order:

  $^X, /proc/self/exe, $Config{perlpath}

If all these methods fail the module will die(), unless you explicitly set the exec_path attribute. Notice I named it exec_path because the executable doesn't have to be perl, when Perl is embedded, which is the case with mod_perl, which sets $^X to the path to the Apache httpd server.

core_path_base

The base path of the core file. e.g. if core_path_base is set to /tmp/mycore and the pid of the process that has segfaulted is 12345, the generated core is written to the file /tmp/mycore12345.

This is an optional attribute.

By default core_path_base is a concatenation of the dir attribute and the string core..

command_path

The path to the file with debugger commands. If this attribute is set the file should already include the commands. Notice that the commands should include 'quit' as the last command, so the debugger will quit.

This is an optional attribute.

By default command_path is a concatenation of the dir attribute and the string gdb-command, which is getting populated with the following commands:

  bt
  quit

debugger

Curently not used. In the future could be used to specify which debugger to use (when more than one debugger is supported). For the future compatibility gdb is going to be the default.

ready()

  $trace->ready();

This method sets the SIGSEGV sighandler. Only after this method is called the extract of the trace will be attempted on the event of SegFault.

Notice that it sets the handler to be called only once. If another segfault happens during the processing of the handler, the SIGSEGV handler that was previously set will get invoked. If none was previously set the default SIGSEGV handler will attempt to dump the core file if the environment is configured to allow one (via shell's limit command and possibly other system-dependent manipulations).

BUGS

Top

EXPORT

Top

None.

TODO

Top

* the code is not thread-safe (so it's not running under mod_perl 2.0 with worker mpm :(. The question is how to pass data to the SIGSEGV signal handler, without using static variables.

* clean the backtrace from extra frames added by this module

* how do we pass the test suite if we exit(2)? currently used fork() to workaround it, but it's not very portable.

* how do we clean-up the autogenerated gdb-command file if we exit(2)?

* support other debuggers than gdb. Need your input/patches.

Currently this module works only on systems with gdb installed.

I'm not sure how portable is my C code, but should probable work on any POSIX-complient system.

If you know how to make the code more portable, or support other debuggers on other OSes please send patches.

ACKNOWLEDGEMENTS

Top

The idea has been borrowed from the GNOME's gnome-crash project, which is used to automatically extract a backtrace when reporting a bug.

Parts of the C non-blocking-read implementation were borrowed from Matt Sergeant's PPerl project.

AUTHOR

Top

Stas Bekman <stas@stason.org>

SEE ALSO

Top

perl(3), Debug::DumpCore(3).


Debug-FaultAutoBT documentation  | view source Contained in the Debug-FaultAutoBT distribution.