From: Ben Pfaff Date: Wed, 18 Aug 2004 00:10:57 +0000 (+0000) Subject: Make debug.h non-idempotent, like . X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c956c0c2175fc09a8e8d6d3f8effd49abcf7aae1;p=pintos-anon Make debug.h non-idempotent, like . Add backtrace() function. --- diff --git a/src/lib/debug.c b/src/lib/debug.c index 577ab67..fafbc8c 100644 --- a/src/lib/debug.c +++ b/src/lib/debug.c @@ -15,5 +15,20 @@ panic (const char *format, ...) printk ("\n"); va_end (args); + backtrace (); + for (;;); } + +void +backtrace (void) +{ + void **frame; + + printk ("Call stack:"); + for (frame = __builtin_frame_address (0); + frame != NULL && frame[0] != NULL; + frame = frame[0]) + printk (" %p", frame[1]); + printk (".\n"); +} diff --git a/src/lib/debug.h b/src/lib/debug.h index 1382473..4f3cb5b 100644 --- a/src/lib/debug.h +++ b/src/lib/debug.h @@ -1,6 +1,28 @@ #ifndef HEADER_DEBUG_H #define HEADER_DEBUG_H 1 +#if __GNUC__ > 1 +#define ATTRIBUTE(X) __attribute__ (X) +#else +#define ATTRIBUTE(X) +#endif + +#define UNUSED ATTRIBUTE ((unused)) +#define NO_RETURN ATTRIBUTE ((noreturn)) +#define PRINTF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (printf, FMT, FIRST))) +#define SCANF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (scanf, FMT, FIRST))) + +void panic (const char *, ...) + __attribute__ ((format (printf, 1, 2), noreturn)); +void backtrace (void); + +#endif /* debug.h */ + +/* This is outside the header guard so that debug.h may be + included multiple times with different settings of NDEBUG. */ +#undef ASSERT +#undef NOT_REACHED + #ifndef NDEBUG #define ASSERT(CONDITION) \ if (CONDITION) { \ @@ -14,19 +36,3 @@ #define ASSERT(CONDITION) ((void) 0) #define NOT_REACHED() for (;;) #endif - -void panic (const char *, ...) - __attribute__ ((format (printf, 1, 2), noreturn)); - -#if __GNUC__ > 1 -#define ATTRIBUTE(X) __attribute__ (X) -#else -#define ATTRIBUTE(X) -#endif - -#define UNUSED ATTRIBUTE ((unused)) -#define NO_RETURN ATTRIBUTE ((noreturn)) -#define PRINTF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (printf, FMT, FIRST))) -#define SCANF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (scanf, FMT, FIRST))) - -#endif /* debug.h */