Skip to content

mensinda/tracer

Repository files navigation

Tracer

A C / C++ *nix / Windows Stack trace generator.

Full Doxygen documentation: https://mensinda.github.io/tracer/html/index.html

Build Status

OS Status
Linux Build Status
Windows Build status

About the C wrapper

Tracer is written in C++11, but has an integrated C wrapper. All (supported) C++ class objects can be acquired with tr_get<ClassName> functions and must be destroyed with tr_free<ClassName> functions.

All (supported) methodes can then be called with tr_<ClassName>__<functionName>.

The doxygen generated documentation can be found here: https://mensinda.github.io/tracer/html/tracer_8h.html

Usage

Simple setup

This will print a stack trace using the default Printer (FancyPrinter) and the default Config (TracerHandler::Config)

TracerHandler::getTracer()->defaultSetup();

or in C:

tr_defaultSetup();

This will generate the following output for the segFaultTest (in test/segFaultTest):

Tracer Screenshot

More advanced setup

With this setup it is possible to customize the output and signal handler.

auto *tHandler = TracerHandler::getTracer(); // Get the singleton
auto  cfg      = tHandler->getConfig();      // Get the current config
// Edit cfg

tHandler->setConfig(cfg);                    // Update the config
auto printer = PrinterContainer::fancy();    // Generates a printer
// Edit printer config

tHandler->setup(std::move(printer));         // Sets things up. Now the signal handler is setup

or using C:

tr_TracerHandler_t *      trTH = tr_getTracerHandler();             // Get the handler
tr_TracerHandler_Config_t cfg  = tr_TracerHandler__getConfig(trTH); // get the current config

// edit cfg
tr_TracerHandler__setConfig(trTH, cfg);                             // Update the config

tr_Printer_t *systemPrinter = tr_getPrinter__system();              // Generates a printer
// Edit printer config
tr_TracerHandler__setup(trTH, systemPrinter);                       // Sets things up. Now the signal handler is setup

// Do some cleanup
tr_freePrinter(systemPrinter);
tr_freeTracerHandler(trTH);

Status

Supported Operating Systems

  • Linux
  • Windows

It currently does not work on Mac OS because of ASLR. Pull requests are welcome :D

FreeBSD is currently not tested.

Backend status

OS Backend Type Status
Windows WIN32 TB ✔️
Linux libunwind T- ✔️
glibc bactrace T- ✔️
libelf / elfutils -D ✔️
libbfd / binutils -D ✔️
addr2line fallback -D ⚠️

Types:

  • T- Stack trace generator
  • -D Debug information extractor
  • TD Both

Status:

  • ✔️ works and testet
  • ⚠️ works but not recommended
  • ❗ broken