summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustus Winter <justus@gnupg.org>2016-10-01 13:25:22 +0200
committerJustus Winter <justus@gnupg.org>2016-10-01 15:51:26 +0200
commitf025f685e965ac9ee1cd35ff3636c8554d9939d2 (patch)
treedc5126b12ed850de99875272f112d0e2b0a11243
parentc81df8d61ed024b253334076041917b2c8fcf55e (diff)
kern: Improve assertions and panics.
* kern/assert.h (Assert): Add function argument. (assert): Supply function argument. * kern/debug.c (Assert): Add function argument. Unify message format. (panic): Rename to 'Panic', add location information. * kern/debug.h (panic): Rename, and add a macro version that supplies the location. * linux/dev/include/linux/kernel.h: Use the new panic macro.
-rw-r--r--kern/assert.h5
-rw-r--r--kern/debug.c18
-rw-r--r--kern/debug.h6
-rw-r--r--linux/dev/include/linux/kernel.h6
4 files changed, 21 insertions, 14 deletions
diff --git a/kern/assert.h b/kern/assert.h
index 7b66d1b1..73e2a176 100644
--- a/kern/assert.h
+++ b/kern/assert.h
@@ -36,12 +36,13 @@
#endif
#if MACH_ASSERT
-extern void Assert(const char *exp, const char *filename, int line) __attribute__ ((noreturn));
+extern void Assert(const char *exp, const char *filename, int line,
+ const char *fun) __attribute__ ((noreturn));
#define assert(ex) \
((ex) \
? (void) (0) \
- : Assert (#ex, __FILE__, __LINE__))
+ : Assert (#ex, __FILE__, __LINE__, __FUNCTION__))
#define assert_static(x) assert(x)
diff --git a/kern/debug.c b/kern/debug.c
index 0d01b84f..78c55f81 100644
--- a/kern/debug.c
+++ b/kern/debug.c
@@ -51,16 +51,16 @@ do_cnputc(char c, vm_offset_t offset)
}
void
-Assert(const char *exp, const char *file, int line)
+Assert(const char *exp, const char *file, int line, const char *fun)
{
#if NCPUS > 1
simple_lock(&Assert_print_lock);
- printf("{%d} Assertion failed: file \"%s\", line %d\n",
- cpu_number(), file, line);
+ printf("{cpu%d} %s:%d: %s: Assertion `%s' failed.",
+ cpu_number(), file, line, fun, exp);
simple_unlock(&Assert_print_lock);
#else
- printf("Assertion `%s' failed in file \"%s\", line %d\n",
- exp, file, line);
+ printf("%s:%d: %s: Assertion `%s' failed.",
+ file, line, fun, exp);
#endif
Debugger("assertion failure");
@@ -136,7 +136,7 @@ extern boolean_t reboot_on_panic;
/*VARARGS1*/
void
-panic(const char *s, ...)
+Panic(const char *file, int line, const char *fun, const char *s, ...)
{
va_list listp;
@@ -155,11 +155,11 @@ panic(const char *s, ...)
paniccpu = cpu_number();
}
simple_unlock(&panic_lock);
- printf("panic");
+ printf("panic ");
#if NCPUS > 1
- printf("(cpu %U)", paniccpu);
+ printf("{cpu%d} ", paniccpu);
#endif
- printf(": ");
+ printf("%s:%d: %s: ",file, line, fun);
va_start(listp, s);
_doprnt(s, listp, do_cnputc, 16, 0);
va_end(listp);
diff --git a/kern/debug.h b/kern/debug.h
index 6c8977b8..1a5cd07c 100644
--- a/kern/debug.h
+++ b/kern/debug.h
@@ -60,7 +60,11 @@
extern void log (int level, const char *fmt, ...);
extern void panic_init(void);
-extern void panic (const char *s, ...) __attribute__ ((noreturn));
+extern void Panic (const char *file, int line, const char *fun,
+ const char *s, ...)
+ __attribute__ ((noreturn, format (printf, 4, 5)));
+#define panic(s, ...) \
+ Panic (__FILE__, __LINE__, __FUNCTION__, s, ##__VA_ARGS__)
extern void SoftDebugger (const char *message);
extern void Debugger (const char *message) __attribute__ ((noreturn));
diff --git a/linux/dev/include/linux/kernel.h b/linux/dev/include/linux/kernel.h
index 4db76acc..9c60b413 100644
--- a/linux/dev/include/linux/kernel.h
+++ b/linux/dev/include/linux/kernel.h
@@ -32,8 +32,10 @@
# define NORET_AND noreturn,
extern void math_error(void);
-NORET_TYPE void panic(const char * fmt, ...)
- __attribute__ ((NORET_AND format (printf, 1, 2)));
+
+/* Use Mach's panic. */
+#include <kern/debug.h>
+
NORET_TYPE void do_exit(long error_code)
ATTRIB_NORET;
extern unsigned long simple_strtoul(const char *,char **,unsigned int);