Giter Site home page Giter Site logo

libsfe's Introduction

libsfe

Library for extracting stacktrace from exception.

Install (Tested only for Linux)

$ # depends on `libboost-stacktrace-dev`
$ git clone [email protected]:axolm/libsfe.git
$ cd libsfe
$ make build-release
$ sudo make install

Motivational example

basic.cpp file

#include <iostream>
#include <sfe/sfe.hpp>
#include <stdexcept>

void throw_something() {
  throw std::runtime_error("SOME ERROR");
}

int main() {
  try {
    throw_something();
  } catch (const std::exception& exc) {
    auto trace = sfe::get_current_exception_stacktrace();
    std::cerr << "Caught exception. Err: `" << exc.what() << "`, Trace:\n"
              << trace;
  }
  return 0;
}

Compiling and runing

$ g++ -g -DBOOST_STACKTRACE_DYN_LINK basic.cpp -obasic -lsfe_basic -lboost_stacktrace_backtrace

$ ./basic
Caught exception. Err: `SOME ERROR`, Trace:

# Debug info without recompiling!
$ LD_PRELOAD=/usr/local/lib/libsfe_preload.so ./basic
Caught exception. Err: `SOME ERROR`, Trace:
 0# throw_something() at /home/axolm/basic.cpp:6
 1# main at /home/axolm/basic.cpp:17
 2# 0x00007FB823D77BF7 in /lib/x86_64-linux-gnu/libc.so.6
 3# 0x0000558E89A2202A in ./basic

How does it work

  • libsfe_basic.so just returns empty stacktrace from sfe::get_current_exception_stacktrace().
  • libsfe_preload.so overrides function __cxa_allocate_exception, dumps boost::stacktrace near exception obj and in sfe::get_current_exception_stacktrace() loads it and returns.

Deps

libsfe's People

Contributors

axolm avatar

Watchers

 avatar  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.