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 :
- [Usage] (#usage)
- [How does it work?] (#how-does-it-work)
- [Samples] (#samples)
- [Changelog] (#changelog)
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
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 are provided for a wide variety of use cases
To run all the samples, execute
./run_samples.sh
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr ../
make