Git Product home page Git Product logo

libsegfault's Introduction

libsegfault -- get a nice stacktrace when your application crashes

What

A preloadable library that will print a stacktrace of the program when it crashes (and received SEGV), or upon receiving any other relevant signal.

Why

A lot of times the application resident memory size is so big that collecting core dumps is impractical. However being able to see the crash stacktrace is desirable. Without a stacktrace figuring our the reason of the crash might be very hard if not impossible.

How

Just link your program again libsegfault. Or use LD_PRELOAD, e.g.

% env LD_PRELOAD=/path/to/libsegfault.so ./app

Building

  • Install libunwind: pkg install libunwind
  • make && make install

Testing

After starting your program with libsegfault preloaded or linked in send the SEGV signal to the program. You should see a stacktrace printed into the stderror.

% env LD_PRELOAD=/path/to/libsegfault.so ./app
% kill -SEGV ${PID}

You should see something along the lines of:

Caught signal 11 (SEGV) in program sleep [27759]

  thread frame     IP       function
  [100689]  0: 0x800afbe0a: __sys_nanosleep()+0xa
  [100689]  1: 0x80120ebcc: _pthread_suspend_all_np()+0x10dc
  [100689]  2: 0x000400a38: <unknown>
  [100689]  3: 0x00040086f: <unknown>
  [100689]  4: 0x800620000: <unknown>

Backtrace: 0x800afbe0a 0x80120ebcc 0x400a38 0x40086f 0x800620000
Segmentation fault (core dumped)

Configuration

libsegfaults looks at the SEGFAULT_SIGNALS environment variable on startup. If that variable is not set, only SIGSEGV handler is enabled. If it's set to "all", libsegfault will intercept all the signals that usually result in a crash: SIGSEGV, SIGBUS, SIGILL, SIGABRT, SIGFPE and SIGSYS. Optionally, the variable can also be set to a custom list of space separated signals.

For example the following command will tell /libsegfault/ to intercept only SEGV and SIGILL (illegal instruction) conditions:

% env SEGFAULT_SIGNALS="SEGV ILL" LD_PRELOAD=/path/to/libsegfault.so ./app

To intercept all signals, use:

% env SEGFAULT_SIGNALS=all LD_PRELOAD=/path/to/libsegfault.so ./app

libsegfault's People

Contributors

stass avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.