static int func3() { void *tracebuf[16]; int i, nframes; int error = 0; const char *fname; isc_result_t result; unsigned long offset; result = isc_backtrace_gettrace(tracebuf, 16, &nframes); if (result != ISC_R_SUCCESS) { printf("isc_backtrace_gettrace failed: %s\n", isc_result_totext(result)); return (1); } if (nframes < 4) error++; for (i = 0; i < 4 && i < nframes; i++) { fname = NULL; result = isc_backtrace_getsymbol(tracebuf[i], &fname, &offset); if (result != ISC_R_SUCCESS) { error++; continue; } if (strcmp(fname, expected_symbols[i]) != 0) error++; } if (error) { printf("Unexpected result:\n"); printf(" # of frames: %d (expected: at least 4)\n", nframes); printf(" symbols:\n"); for (i = 0; i < nframes; i++) { fname = NULL; result = isc_backtrace_getsymbol(tracebuf[i], &fname, &offset); if (result == ISC_R_SUCCESS) printf(" [%d] %s\n", i, fname); else { printf(" [%d] %p getsymbol failed: %s\n", i, tracebuf[i], isc_result_totext(result)); } } } return (error); }
static void default_callback(const char *file, int line, isc_assertiontype_t type, const char *cond) { void *tracebuf[BACKTRACE_MAXFRAME]; int i, nframes; const char *logsuffix = "."; const char *fname; isc_result_t result; result = isc_backtrace_gettrace(tracebuf, BACKTRACE_MAXFRAME, &nframes); if (result == ISC_R_SUCCESS && nframes > 0) logsuffix = ", back trace"; fprintf(stderr, "%s:%d: %s(%s) failed%s\n", file, line, isc_assertion_typetotext(type), cond, logsuffix); if (result == ISC_R_SUCCESS) { for (i = 0; i < nframes; i++) { unsigned long offset; fname = NULL; result = isc_backtrace_getsymbol(tracebuf[i], &fname, &offset); if (result == ISC_R_SUCCESS) { fprintf(stderr, "#%d %p in %s()+0x%lx\n", i, tracebuf[i], fname, offset); } else { fprintf(stderr, "#%d %p in ??\n", i, tracebuf[i]); } } } fflush(stderr); }
static void assertion_failed(const char *file, int line, isc_assertiontype_t type, const char *cond) { void *tracebuf[BACKTRACE_MAXFRAME]; int i, nframes; isc_result_t result; const char *logsuffix = ""; const char *fname; /* * Handle assertion failures. */ if (ns_g_lctx != NULL) { /* * Reset the assertion callback in case it is the log * routines causing the assertion. */ isc_assertion_setcallback(NULL); result = isc_backtrace_gettrace(tracebuf, BACKTRACE_MAXFRAME, &nframes); if (result == ISC_R_SUCCESS && nframes > 0) logsuffix = ", back trace"; isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL, "%s:%d: %s(%s) failed%s", file, line, isc_assertion_typetotext(type), cond, logsuffix); if (result == ISC_R_SUCCESS) { for (i = 0; i < nframes; i++) { unsigned long offset; fname = NULL; result = isc_backtrace_getsymbol(tracebuf[i], &fname, &offset); if (result == ISC_R_SUCCESS) { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL, "#%d %p in %s()+0x%lx", i, tracebuf[i], fname, offset); } else { isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL, "#%d %p in ??", i, tracebuf[i]); } } } isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, ISC_LOG_CRITICAL, "exiting (due to assertion failure)"); } else { fprintf(stderr, "%s:%d: %s(%s) failed\n", file, line, isc_assertion_typetotext(type), cond); fflush(stderr); } if (ns_g_coreok) abort(); exit(1); }