summaryrefslogtreecommitdiff
path: root/cesar/lib/src/dbg.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/lib/src/dbg.c')
-rw-r--r--cesar/lib/src/dbg.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/cesar/lib/src/dbg.c b/cesar/lib/src/dbg.c
new file mode 100644
index 0000000000..f4a932dc38
--- /dev/null
+++ b/cesar/lib/src/dbg.c
@@ -0,0 +1,71 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file lib/src/dbg.c
+ * \brief Debug functions.
+ * \ingroup lib
+ */
+#include "common/std.h"
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#if DEBUG
+
+# if CONFIG_DEBUG_FATAL_CATCH
+int dbg_fatal_try_level_;
+char dbg_fatal_text_[2048];
+# endif
+
+void
+dbg_assert_fail (const char *assertion, const char *file, uint line,
+ const char *function)
+{
+ dbg_fatal (DBG_ASSERT_FMT_ "%s", file, line, function,
+ assertion);
+}
+
+void
+dbg_assert_print_fail (const char *fmt, ...)
+{
+ va_list ap;
+ va_start (ap, fmt);
+ dbg_vfatal (fmt, ap);
+ va_end (ap);
+}
+
+#endif /* DEBUG */
+
+void
+dbg_fatal (const char *fmt, ...)
+{
+ va_list ap;
+ va_start (ap, fmt);
+ dbg_vfatal (fmt, ap);
+ va_end (ap);
+}
+
+void
+dbg_vfatal (const char *fmt, va_list ap)
+{
+#if DEBUG && CONFIG_DEBUG_FATAL_CATCH
+ if (dbg_fatal_try_level_)
+ {
+ vsnprintf (dbg_fatal_text_, sizeof (dbg_fatal_text_), fmt, ap);
+ try_throw (TRY_CODE_FATAL);
+ }
+ else
+#endif
+ {
+ vfprintf (stderr, fmt, ap);
+ fputc ('\n', stderr);
+ abort ();
+ }
+}
+