Skip to content

Instantly share code, notes, and snippets.

@0xc010d
Forked from nkuln/cxa_throw_replace_backtrace.c
Created December 12, 2012 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xc010d/4265781 to your computer and use it in GitHub Desktop.
Save 0xc010d/4265781 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <dlfcn.h>
#include <execinfo.h>
typedef void (*cxa_throw_type)(void *, void *, void (*) (void *));
cxa_throw_type orig_cxa_throw = 0;
void load_orig_throw_code()
{
orig_cxa_throw = (cxa_throw_type) dlsym(RTLD_NEXT, "__cxa_throw");
}
#ifdef __cplusplus
extern "C" {
#endif
void __cxa_throw (void *thrown_exception, void *pvtinfo, void (*dest)(void *)) {
printf(" ################ DETECT A THROWN !!!!! #############\n");
if (orig_cxa_throw == 0)
load_orig_throw_code();
{
static int throw_count = 0;
void *array[10];
int size;
size = backtrace(array, 10);
fprintf(stderr, "#### EXCEPTION THROWN (#%d) ####\n", ++throw_count);
backtrace_symbols_fd(array, size, 2); // 2 == stderr
}
orig_cxa_throw(thrown_exception, pvtinfo, dest);
}
#ifdef __cplusplus
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment