All Projects → septag → stackwalkerc

septag / stackwalkerc

Licence: BSD-2-Clause License
Windows single header stack walker in C (DbgHelp.DLL)

Programming Languages

c
50402 projects - #5 most used programming language
C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to stackwalkerc

Backtrace
Makes Python tracebacks human friendly
Stars: ✭ 80 (+207.69%)
Mutual labels:  stacktrace
Stacktrace
C++ library for storing and printing backtraces.
Stars: ✭ 250 (+861.54%)
Mutual labels:  stacktrace
ngx-flamegraph
Flame graph for stack trace visualization written in Angular
Stars: ✭ 54 (+107.69%)
Mutual labels:  stacktrace
Pasta Sourcemaps
Pretty (and) Accurate Stack Trace Analysis is an extension to the JavaScript source map format that allows for accurate function name decoding.
Stars: ✭ 112 (+330.77%)
Mutual labels:  stacktrace
Blocked At
Detects node eventloop block and reports where it started
Stars: ✭ 219 (+742.31%)
Mutual labels:  stacktrace
stacktrace
Atom package to navigate stacktraces.
Stars: ✭ 35 (+34.62%)
Mutual labels:  stacktrace
Panic Overlay
Displays JS errors in browsers. Shows sources. Use with any framework. 💥✨
Stars: ✭ 50 (+92.31%)
Mutual labels:  stacktrace
CrashLogger
A dll injected into process to dump stack when crashing.
Stars: ✭ 19 (-26.92%)
Mutual labels:  stackwalker
Fracker
PHP function tracker
Stars: ✭ 234 (+800%)
Mutual labels:  stacktrace
py better exchook
nice Python exception hook replacement
Stars: ✭ 35 (+34.62%)
Mutual labels:  stacktrace
Debugengine
Delphi debug framework
Stars: ✭ 133 (+411.54%)
Mutual labels:  stacktrace
Ololog
A better console.log for the log-driven debugging junkies
Stars: ✭ 141 (+442.31%)
Mutual labels:  stacktrace
gostackparse
Package gostackparse parses goroutines stack traces as produced by panic() or debug.Stack() at ~300 MiB/s.
Stars: ✭ 88 (+238.46%)
Mutual labels:  stacktrace
Errors
Drop-in replacement for the standard library errors package and github.com/pkg/errors
Stars: ✭ 88 (+238.46%)
Mutual labels:  stacktrace
asmCrashReport
🐞 Installs signal handlers to capture stack traces for MinGW 32 and macOS builds.
Stars: ✭ 39 (+50%)
Mutual labels:  stacktrace
Memstrack
A memory allocation tracer combined with stack trace.
Stars: ✭ 60 (+130.77%)
Mutual labels:  stacktrace
errors
errors with paired message and caller stack frame
Stars: ✭ 19 (-26.92%)
Mutual labels:  stacktrace
stacktrace compat
get_stacktrace() compatibility in Erlang/OTP 21+
Stars: ✭ 18 (-30.77%)
Mutual labels:  stacktrace
rebucket
ReBucket – A Method for Clustering Duplicate Crash Reports based on Call Stack Similarity
Stars: ✭ 21 (-19.23%)
Mutual labels:  stacktrace
xUnwind
🔥 xUnwind is a collection of Android native stack unwinding solutions.
Stars: ✭ 127 (+388.46%)
Mutual labels:  stacktrace

stackwalkerc - Windows single header stack walker in C (DbgHelp.DLL)

Features

  • Can be used in C or C++ code
  • Super simple API
  • Single header library makes integration into projects easy and fast
  • Overridable memory allocations and assertion
  • Zero heap allocations in callstack function (sw_show_callstack)
  • No extra header inclusions except lightweight stdbool.h and stdint.h for delclarations
  • Reporting of loaded modules and symbol search paths of the executable
  • Callstack reporting of other threads and processes
  • Callstack reporting in system exceptions
  • Does not depend on DbgHelp.DLL to be included with the executable, this library dynamically loads the DbgHelp.dll from common system paths
  • Fast code-path for current thread callstack captures
  • Manual callstack resolving for lazy symbol resolves

Usage

This is a single header library, so all you need is include the file in your source and you are good to go:

// SW_IMPL includes implementation as well, you can skip this if you only want the declarations
#define SW_IMPL
#include "stackwalker.h"

Optionally, you can override some base functionality like function visibility, assertion and malloc, before including stackwalkerc.h:

#define SW_API_DECL static  // declars everything as static so only visible to current translation unit
#define SW_ASSERT(e)  MyAssert(e)       // override assert
#define SW_MALLOC(size)  MyMalloc(size) // override default stdc malloc
#define SW_FREE(ptr) MyFree(ptr)        //  override default stdc free
#define SW_IMPL
#include "stackwalker.h"

The API usage is super simple. There is more functionality like listing symbol search paths and loaded modules, for more detailed example, check out example.cpp for details.

static void callstack_entry(const sw_callstack_entry* entry, void* userptr)
{
    printf("\t%s(%d): %s\n", entry->line_filename, entry->line, entry->und_name);
}

static void error_msg(const char* filename, uint32_t gle, uint64_t addr, void* userptr)
{
    printf("error: %s, ErrorCode: %u\n", filename, gle);
}

int main(int argc, char* argv[]) 
{
    sw_callbacks callbacks = {
        .callstack_entry = callstack_entry,
        .error_msg = error_msg
    };
    sw_context* stackwalk = sw_create_context_capture(SW_OPTIONS_ALL, callbacks, NULL);
    if (!stackwalk) {
        puts("ERROR: stackwalk init");
        return -1;
    }
    sw_show_callstack(stackwalk, NULL); // Second parameter NULL means that stackwalker should resolve for current thread
    sw_destroy_context(g_stackwalk);
    return 0;
}

To build the example, just make sure you have the right compiler flags (build debug symbols) and also link with Version.lib. The main API will be loaded dyamically from dbghelp.dll in common system paths (see sw__init_internal to see the search paths for the DLL file):

MSVC:

cd example
cl /Od /Zi Version.lib example.cpp

Clang (win):

cd example 
clang -g -O0 -lVersion example.cpp -o example.exe

Acknowledgments

Almost all of the Windows API usage for StackWalk are taken from StackWalker project by Jochen Kalmbach. For detailed information on how to use the API, read the Kalmbach's article on CodeProject.
This is actually a much more simplified (and improved imo) and straight-to-the-point version of StackWalker library.
This project only supports msvc2015+/clang(windows) compilers, if you prefer C++ API or want support for older Visual studio versions, check out Kalmbach's StackWalker library mentioned above.

License (BSD 2-clause)

Copyright 2021 Sepehr Taghdisian. All rights reserved.

https://github.com/septag/stackwalker.c

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.

   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].