X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=blobdiff_plain;f=stacktrace.h;h=a3b035096e796f13809eb4eedcfeada7bc84c9ba;hp=01d31d2f33c2e72fcc54ce8d120baed359fead08;hb=100760a2b7e7175343e076d852aa35d5eedff23f;hpb=8f379cb70822bfd5498da9997ad4f7c3b37a18ed diff --git a/stacktrace.h b/stacktrace.h index 01d31d2..a3b0350 100644 --- a/stacktrace.h +++ b/stacktrace.h @@ -9,10 +9,13 @@ #include #include -/** Print a demangled stack backtrace of the caller function to FILE* out. */ -static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames = 63) +/** + * @brief Print a demangled stack backtrace of the caller function to file + * descriptor fd. + */ +static inline void print_stacktrace(int fd = STDERR_FILENO, unsigned int max_frames = 63) { - fprintf(out, "stack trace:\n"); + dprintf(fd, "stack trace:\n"); // storage array for stack trace address data void* addrlist[max_frames+1]; @@ -21,7 +24,7 @@ static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames int addrlen = backtrace(addrlist, sizeof(addrlist) / sizeof(void*)); if (addrlen == 0) { - fprintf(out, " \n"); + dprintf(fd, " \n"); return; } @@ -65,17 +68,17 @@ static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames funcname, &funcnamesize, &status); if (status == 0) { funcname = ret; // use possibly realloc()-ed string - fprintf(out, " %s : %s+%s\n", + dprintf(fd, " %s : %s+%s\n", symbollist[i], funcname, begin_offset); } else { // demangling failed. Output function name as a C function with // no arguments. - fprintf(out, " %s : %s()+%s\n", + dprintf(fd, " %s : %s()+%s\n", symbollist[i], begin_name, begin_offset); } } else { // couldn't parse the line? print the whole line. - fprintf(out, " %s\n", symbollist[i]); + dprintf(fd, " %s\n", symbollist[i]); } } @@ -83,4 +86,9 @@ static inline void print_stacktrace(FILE *out = stderr, unsigned int max_frames free(symbollist); } +static inline void print_stacktrace(FILE *out, unsigned int max_frames = 63) +{ + print_stacktrace(fileno(out), max_frames); +} + #endif // __STACKTRACE_H__