Skip to content

I-hate-farms/ivy

Repository files navigation

Introduction

This library displays your vala stacktraces (on crashes, critical warnings and on invocation).

Just have Ivy register the handlers :

int main (string[] args) {
    // register the handler
    Ivy.register_handlers () ;
	  
    stdout.printf("  This program will crash !\n" ) ;
    // The next call will crash because it uses a null reference
    this_will_crash () ;
    return 0 ;
}

Command line

Invoke valac with -X -rdynamic and add the ivy package:

valac -g -X -rdynamic --pkg ivy --pkg <dependencies...> -o sample <your vala files>

cmake

Update your CMakeLists.txt file and add -rdynamic and ivy as a regular vala package :

ADD_DEFINITIONS(-rdynamic)
...
pkg_check_modules (DEPS REQUIRED <your packages> ivy)
...
vala_precompile (
   ...
  PACKAGES
    ...
    ivy
)

Your application will display a complete stacktrace before a crash :

Installation

# Install the spores repository if needed
curl -sL  http://i-hate-farms.github.io/spores/install | sudo bash -  
# Install the package
sudo apt-get install libivy-dev

Documentation

  • [Usage] (#usage)
  • [How does it work?] (#how-does-it-work)
  • [Samples] (#samples)
  • Valadoc
  • [Changelog] (#changelog)

Usage

The library format the stacktrace using colors default_highlight_color and default_error_background hiding the system libraries (libc, etc) for which there are usually no information available (that feature can be enabled via hide_installed_libraries`.

The library has two use cases:

  • crash interception: when a vala application crashes it emits a signal depending on the nature of error. Those signals are intercepted and before the application exits, the application stacktrace is displayed
  • tracing a call graph: a Stacktrace can be instantiated and displayed at any point in your code.

The following signals are intercepted:

Signal Likely reason Note
SIGABRT Failed critical assert
SIGSEV Using a null reference
SIGTRAP Uncaught error Try adding a throw in your code to handle this error properly

How does it work?

The library registers handlers for the SIGABRT, SIGSEV and SIGTRAP signals.

It processes the stacktrace symbols provided by Linux.Backtrace.symbols and retreive the file name, line number and function name using the symbols and calling addr2line multiple times.

Note: it means that your application will spawn synchronuous external processes.

This library is Apache licensed and has the following vala dependencies:

  • linux
  • gee-0.8
  • posix

Samples

Samples are provided for a wide variety of use cases:

To compile and run all the samples, execute

./run_samples.sh

How to build

./hen build