Skip to content
Myr

debug.c

This file

Path

debug.c

47 lines · 1.0 KiB · C

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than c18512f point at it.

docs: correct with the prev-with-wrap and next-with-wrap docs.Mark Stosbergbefore adoptionc18512f

lines 1–47why, one step back
1#include "debug.h"
23#include <errno.h>4#include <stdarg.h>5#include <stdio.h>6#include <stdlib.h>7#include <string.h>8#include "log.h"910#if defined(__SANITIZE_ADDRESS__) || HAS_FEATURE(address_sanitizer)11#include <sanitizer/asan_interface.h>12#define ASAN_ENABLED 113#endif1415static void16print_stack_trace(void)17{18#ifdef ASAN_ENABLED19 fputs("\nStack trace:\n", stderr);20 __sanitizer_print_stack_trace();21#endif22}2324noreturn void25fatal_error(const char *file, int line, const char *msg, int err)26{27 log_msg(LOG_CLASS_ERROR, "debug", file, line, "%s: %s", msg, strerror(err));28 print_stack_trace();29 fflush(stderr);30 abort();31}3233noreturn void34bug(const char *file, int line, const char *func, const char *fmt, ...)35{36 char buf[4096];37 va_list ap;38 va_start(ap, fmt);39 int n = vsnprintf(buf, sizeof(buf), fmt, ap);40 va_end(ap);4142 const char *msg = likely(n >= 0) ? buf : "??";43 log_msg(LOG_CLASS_ERROR, "debug", file, line, "BUG in %s(): %s", func, msg);44 print_stack_trace();45 fflush(stderr);46 abort();47}