File size: 1,321 Bytes
6229e10 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
static FILE *fp_trace;
int depth = 0;
static int MAX_DEPTH = 10;
extern "C" {
void __attribute__ ((constructor)) trace_begin (void) {
fp_trace = fopen("trace.out", "w");
depth = 0;
}
void __attribute__ ((destructor)) trace_end (void) {
if(fp_trace != NULL) {
fclose(fp_trace);
}
}
void __cyg_profile_func_enter (void *func, void *caller) {
if (fp_trace != NULL) {
if (depth < MAX_DEPTH) {
Dl_info info;
if (dladdr(func, &info)) {
if (info.dli_sname) {
if (!strstr(info.dli_sname, "St3")) {
fprintf (fp_trace, "%i %p %p [%s] %s\n",
depth,
func,
caller,
info.dli_fname ? info.dli_fname : "?",
info.dli_sname ? info.dli_sname : "?");
fflush(fp_trace);
}
}
}
}
depth++;
}
}
void __cyg_profile_func_exit (void *func, void *caller) {
if(fp_trace != NULL) {
//fprintf(fp_trace, "x %p %p %lu\n", func, caller, time(NULL));
depth--;
}
}
}
|