mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
Merge branch 'fanf-backtrace-log' into 'main'
Ad-hoc backtrace logging with isc_backtrace_log() See merge request isc-projects/bind9!7743
This commit is contained in:
commit
1365edaf0c
4 changed files with 50 additions and 28 deletions
|
|
@ -101,13 +101,6 @@
|
|||
*/
|
||||
/* #include "xxdb.h" */
|
||||
|
||||
/*
|
||||
* The maximum number of stack frames to dump on assertion failure.
|
||||
*/
|
||||
#ifndef BACKTRACE_MAXFRAME
|
||||
#define BACKTRACE_MAXFRAME 128
|
||||
#endif /* ifndef BACKTRACE_MAXFRAME */
|
||||
|
||||
extern unsigned int dns_zone_mkey_hour;
|
||||
extern unsigned int dns_zone_mkey_day;
|
||||
extern unsigned int dns_zone_mkey_month;
|
||||
|
|
@ -189,9 +182,6 @@ assertion_failed(const char *file, int line, isc_assertiontype_t type,
|
|||
static void
|
||||
assertion_failed(const char *file, int line, isc_assertiontype_t type,
|
||||
const char *cond) {
|
||||
void *tracebuf[BACKTRACE_MAXFRAME];
|
||||
int nframes;
|
||||
|
||||
/*
|
||||
* Handle assertion failures.
|
||||
*/
|
||||
|
|
@ -203,24 +193,12 @@ assertion_failed(const char *file, int line, isc_assertiontype_t type,
|
|||
*/
|
||||
isc_assertion_setcallback(NULL);
|
||||
|
||||
nframes = isc_backtrace(tracebuf, BACKTRACE_MAXFRAME);
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
||||
"%s:%d: %s(%s) failed%s", file, line,
|
||||
isc_assertion_typetotext(type), cond,
|
||||
(nframes > 0) ? ", back trace" : "");
|
||||
if (nframes > 0) {
|
||||
char **strs = isc_backtrace_symbols(tracebuf, nframes);
|
||||
if (strs != NULL) {
|
||||
for (int i = 0; i < nframes; i++) {
|
||||
isc_log_write(named_g_lctx,
|
||||
NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_MAIN,
|
||||
ISC_LOG_CRITICAL, "%s",
|
||||
strs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
"%s:%d: %s(%s) failed", file, line,
|
||||
isc_assertion_typetotext(type), cond);
|
||||
isc_backtrace_log(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL);
|
||||
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
|
||||
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
|
||||
"exiting (due to assertion failure)");
|
||||
|
|
|
|||
|
|
@ -95,8 +95,8 @@ isc_assertion_typetotext(isc_assertiontype_t type) {
|
|||
static void
|
||||
default_callback(const char *file, int line, isc_assertiontype_t type,
|
||||
const char *cond) {
|
||||
void *tracebuf[BACKTRACE_MAXFRAME];
|
||||
int nframes = isc_backtrace(tracebuf, BACKTRACE_MAXFRAME);
|
||||
void *tracebuf[ISC_BACKTRACE_MAXFRAME];
|
||||
int nframes = isc_backtrace(tracebuf, ISC_BACKTRACE_MAXFRAME);
|
||||
|
||||
fprintf(stderr, "%s:%d: %s(%s) failed%s\n", file, line,
|
||||
isc_assertion_typetotext(type), cond,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#endif /* HAVE_BACKTRACE_SYMBOLS */
|
||||
|
||||
#include <isc/backtrace.h>
|
||||
#include <isc/log.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
|
|
@ -60,6 +61,26 @@ isc_backtrace_symbols_fd(void *const *buffer, int size, int fd) {
|
|||
backtrace_symbols_fd(buffer, size, fd);
|
||||
}
|
||||
|
||||
void
|
||||
isc_backtrace_log(isc_log_t *lctx, isc_logcategory_t *category,
|
||||
isc_logmodule_t *module, int level) {
|
||||
void *tracebuf[ISC_BACKTRACE_MAXFRAME];
|
||||
int nframes;
|
||||
char **strs;
|
||||
|
||||
nframes = isc_backtrace(tracebuf, ISC_BACKTRACE_MAXFRAME);
|
||||
if (nframes <= 0) {
|
||||
return;
|
||||
}
|
||||
strs = isc_backtrace_symbols(tracebuf, nframes);
|
||||
if (strs == NULL) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < nframes; i++) {
|
||||
isc_log_write(lctx, category, module, level, "%s", strs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* HAVE_BACKTRACE_SYMBOLS */
|
||||
|
||||
int
|
||||
|
|
@ -85,4 +106,13 @@ isc_backtrace_symbols_fd(void *const *buffer, int size, int fd) {
|
|||
UNUSED(fd);
|
||||
}
|
||||
|
||||
void
|
||||
isc_backtrace_log(isc_log_t *lctx, isc_logcategory_t *category,
|
||||
isc_logmodule_t *module, int level) {
|
||||
UNUSED(lctx);
|
||||
UNUSED(category);
|
||||
UNUSED(module);
|
||||
UNUSED(level);
|
||||
}
|
||||
|
||||
#endif /* HAVE_BACKTRACE_SYMBOLS */
|
||||
|
|
|
|||
|
|
@ -34,6 +34,13 @@
|
|||
***/
|
||||
#include <isc/types.h>
|
||||
|
||||
/*
|
||||
* The maximum number of stack frames to dump on assertion failure.
|
||||
*/
|
||||
#ifndef ISC_BACKTRACE_MAXFRAME
|
||||
#define ISC_BACKTRACE_MAXFRAME 128
|
||||
#endif /* ifndef ISC_BACKTRACE_MAXFRAME */
|
||||
|
||||
/***
|
||||
*** Functions
|
||||
***/
|
||||
|
|
@ -98,4 +105,11 @@ isc_backtrace_symbols_fd(void *const *buffer, int size, int fd);
|
|||
*\li See platform NOTES for backtrace_symbols_fd for caveats
|
||||
*/
|
||||
|
||||
void
|
||||
isc_backtrace_log(isc_log_t *lctx, isc_logcategory_t *category,
|
||||
isc_logmodule_t *module, int level);
|
||||
/*
|
||||
* Write a backtrace to the log.
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
|
|
|||
Loading…
Reference in a new issue