summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2012-01-01 18:00:22 -0500
committerTavian Barnes <tavianator@gmail.com>2012-01-01 18:10:21 -0500
commit927a195371a9817e214fb25047e60b216b0acf35 (patch)
tree1cbc94bcab901fe33dc03df16d077f4521bc000a
parentbf56062df55226e44afb574791dbbe67d3632642 (diff)
downloaddimension-927a195371a9817e214fb25047e60b216b0acf35.tar.xz
Print a backtrace on both warnings and errors.
-rw-r--r--libdimension/dimension/error.h4
-rw-r--r--libdimension/error.c15
2 files changed, 12 insertions, 7 deletions
diff --git a/libdimension/dimension/error.h b/libdimension/dimension/error.h
index 894899a..0ae349f 100644
--- a/libdimension/dimension/error.h
+++ b/libdimension/dimension/error.h
@@ -30,14 +30,14 @@
/**
* Report a warning.
- * @param[in] str A string to print explaining the warning.
+ * @param[in] str A string to print explaining the warning.
*/
#define dmnsn_warning(str) \
dmnsn_report_error(false, DMNSN_FUNC, __FILE__, __LINE__, str)
/**
* Report an error.
- * @param[in] str A string to print explaining the error.
+ * @param[in] str A string to print explaining the error.
*/
#define dmnsn_error(str) \
do { \
diff --git a/libdimension/error.c b/libdimension/error.c
index c738639..371c7cd 100644
--- a/libdimension/error.c
+++ b/libdimension/error.c
@@ -80,6 +80,7 @@ void
dmnsn_report_error(bool die, const char *func, const char *file,
unsigned int line, const char *str)
{
+ /* Save the value of errno */
int err = errno;
bool always_die;
@@ -87,8 +88,11 @@ dmnsn_report_error(bool die, const char *func, const char *file,
always_die = dmnsn_always_die;
dmnsn_local_unlock_mutex(&dmnsn_always_die_mutex);
+ /* Print the diagnostic string */
fprintf(stderr, "Dimension %s: %s, %s:%u: %s\n",
die ? "ERROR" : "WARNING", func, file, line, str);
+
+ /* Print the value of errno */
if (err != 0) {
fprintf(stderr, "Last error: %d", err);
#if DMNSN_SYS_ERRLIST
@@ -99,13 +103,17 @@ dmnsn_report_error(bool die, const char *func, const char *file,
fprintf(stderr, "\n");
}
+ /* Print a stack trace to standard error */
+ dmnsn_backtrace(stderr);
+
+ /* Call the fatal error handler if needed */
if (die || always_die) {
- /* Prevent infinite recursion if the fatal error function itself calls
- dmnsn_error() */
static __thread bool thread_exiting = false;
if (thread_exiting) {
if (die) {
+ /* Prevent infinite recursion if the fatal error function itself calls
+ dmnsn_error() (not dmnsn_warning()) */
DMNSN_LOCAL_ERROR("Error raised while in error handler, aborting.");
}
} else {
@@ -147,9 +155,6 @@ dmnsn_set_fatal_error_fn(dmnsn_fatal_error_fn *fatal)
static void
dmnsn_default_fatal_error_fn(void)
{
- /* Print a stack trace to standard error */
- dmnsn_backtrace(stderr);
-
if (dmnsn_is_main_thread()) {
exit(EXIT_FAILURE);
} else {