Giter VIP home page Giter VIP logo

c-stacktrace's Introduction

Build Status

C-stacktrace

C-stacktrace is a small header C library to print stack trace on execution if an exception occurs (such as segmentation fault). It is designed to print useful information on exceptions while the program was used or tested outside of a debugger and remove the hassle to relaunch the program and pray for it to crash again in a debugger to find the problem. With a few more features it could be extended to be a useful crash-report generator to be sent by the user to the developer. The development of such a feature is not yet seriously considered but could very well be in the near future.

Disclaimer

This library and its documentation are currently in an experimental state. It has been published fairly recently and has yet to be improved and fully tested. It is not designed to be as much portable as possible yet and has been developed and light-tested for linux-based operating systems for now. It is by far not considered to be bug free. Please feel free to report issues or requests and/or to contribute to improve it.

Installation

Just add the c-stacktrace.h header file to your project. Make sure addr2line (atos for Mac OS) is installed on the target system (the system executing the program) for nice functions printing.

Usage

#include "c-stacktrace.h" in your main.c file.

Call the init_exceptions function with argv[0] as parameter at the beginning of your main function as so :

#include "c-stacktrace.h"

int main(int argc, char* argv[])
{
	init_exceptions(argv[0]);
	//code
	exit(EXIT_SUCCESS);
}

Anywhere within this block, you can use the macro CRITICAL to generate a critical issue that will terminate the program and print your message along with the stacktrace and the exact location within a source file where the macro was called. Ex:

#include "c-stacktrace.h"

int main(int argc, char* argv[])
{
	init_exceptions(argv[0]);
	CRITICAL("There has been a critical error !");
	exit(EXIT_SUCCESS);
}

Outputs :

[0] 0x4012a4 in main at main.c:6
There has been a critical error ! (in main at main.c:6)

You can read the small demo to have a better understanding on how to use this library. As stated in the disclaimer, a better documentation will come.

Compiling

Use your compiler with the -rdynamic parameter to compile your project. If you want functions names in the stacktrace, you also obviously need to compile in debug mode, although it seems to be buggy on some configurations. It will be investigated soon.

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.