Skip to content

PerfectCarl/vala-stacktrace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This library displays the stacktrace when your vala application crashes (should it ever happen).

Just have Stacktrace register the handlers :

int main (string[] args) {
    // register the handler
    Stacktrace.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 ;
}

... and build your application with -X -rdynamic and required dependencies

valac -g -X -rdynamic --pkg linux --pkg gee-0.8  -o sample <your vala files>

Your application will display a complete stacktrace before it crashes :

Documentation

  • [Usage] (#usage)
  • [How does it work?] (#how-does-it-work)
  • [Samples] (#samples)
  • [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 [SIGABRT][1], [SIGSEV][2], [SIGTRAP][3] [1]: /doc/sigabrt.md [2]: /doc/sigsev.md [3]: /doc/sigtrap.md

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 and nm 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

Samples

Samples are provided for a wide variety of use cases

To run all the samples, execute

./run_samples.sh

How to build

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr ../
make

About

A class to display stacktrace within your vala application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published