ELinks 0.16.1.1
|
Error handling and debugging stuff. More...
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "elinks.h"
#include "util/error.h"
#include "util/lists.h"
#include "util/memlist.h"
#include "util/memory.h"
#include "util/snprintf.h"
Macros | |
#define | _GNU_SOURCE /* Needed for vasprintf() */ |
Functions | |
static void | er (int bell, int shall_sleep, const char *fmt, va_list params) |
void | elinks_debug (const char *fmt,...) |
void | elinks_wdebug (const char *fmt,...) |
void | elinks_error (const char *fmt,...) |
void | elinks_internal (const char *fmt,...) |
void | usrerror (const char *fmt,...) |
usrerror(format_string) is used to report user errors during a peaceful ELinks run. | |
void | elinks_assertm (int x, const char *fmt,...) |
void | force_dump (void) |
This will print some fancy message, version string and possibly do something else useful. | |
static void | done_log (void) |
void | elinks_log (char *msg, char *file, int line, const char *fmt,...) |
The LOG_* () macros can be used to log to a file, however, by default log messages are written to stderr. | |
void | do_not_optimize_here (void *p) |
This function does nothing, except making compiler not to optimize certains spots of code — this is useful when that particular optimization is buggy. |
Variables | |
char | full_static_version [1024] = "ELinks " VERSION_STRING |
This function dumps backtrace (or whatever similar it founds on the stack) nicely formatted and with symbols resolved to f. | |
int | errline |
const char * | errfile |
int | assert_failed = 0 |
Whether an assertion has failed and the failure has not yet been handled. | |
static FILE * | log_file = NULL |
Error handling and debugging stuff.
#define _GNU_SOURCE /* Needed for vasprintf() */ |
void do_not_optimize_here | ( | void * | x | ) |
This function does nothing, except making compiler not to optimize certains spots of code — this is useful when that particular optimization is buggy.
So we are just workarounding buggy compilers.
This function should be always used only in context of compiler version specific macros.
|
static |
void elinks_assertm | ( | int | x, |
const char * | fmt, | ||
... ) |
void elinks_debug | ( | const char * | fmt, |
... ) |
void elinks_error | ( | const char * | fmt, |
... ) |
void elinks_internal | ( | const char * | fmt, |
... ) |
void elinks_log | ( | char * | msg, |
char * | file, | ||
int | line, | ||
const char * | fmt, | ||
... ) |
The LOG_*
() macros can be used to log to a file, however, by default log messages are written to stderr.
Set the following environment variables to configure the log behavior:
void elinks_wdebug | ( | const char * | fmt, |
... ) |
|
static |
void force_dump | ( | void | ) |
This will print some fancy message, version string and possibly do something else useful.
Then, it will dump core.
void usrerror | ( | const char * | fmt, |
... ) |
usrerror(format_string)
is used to report user errors during a peaceful ELinks run.
It does not belong to the family above - it doesn't print code location, beep nor sleep, it just wraps around fprintf(stderr, "...\n");.
int assert_failed = 0 |
Whether an assertion has failed and the failure has not yet been handled.
To make recovery path possible (assertion failed may not mean end of the world, the execution goes on if we're outside of CONFIG_DEBUG and CONFIG_FASTMEM), assert_failed
is set to true if the last assert() failed, otherwise it's zero. Note that you must never change assert_failed value, sorry guys.
You should never test assert_failed
directly anyway. Use if_assert_failed instead, it will attempt to hint compiler to optimize out the recovery path if we're CONFIG_FASTMEM. So it should go like:
In-depth explanation: this restriction is here because in the CONFIG_FASTMEM mode, assert_failed
is initially initialized to zero and then not ever touched anymore. So if you change it to non-zero failure, your all further recovery paths will get hit (and since developers usually don't test CONFIG_FASTMEM mode extensively...). So better don't mess with it, even if you would do that with awareness of this fact. We don't want to iterate over tens of spots all over the code when we change one detail regarding CONFIG_FASTMEM operation.
This is not that actual after introduction of if_assert_failed, but it's a safe recommendation anyway, so... ;-)
const char* errfile |
int errline |
char full_static_version[1024] = "ELinks " VERSION_STRING |
This function dumps backtrace (or whatever similar it founds on the stack) nicely formatted and with symbols resolved to f.
When trouble is set, it tells it to be extremely careful and not use dynamic memory allocation functions etc (useful in SIGSEGV handler etc).
Note that this function just calls system-specific backend provided by the libc, so it is available only on some systems. CONFIG_BACKTRACE is defined if it is available on yours. This is needed for providing info about features when dumping core
|
static |