The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Functions to help with debugging. More...
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/hash.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/syserror.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/wait.h>
Go to the source code of this file.
Macros | |
#define | TALLOC_REPORT_MAX_DEPTH 20 |
Functions | |
static int | _disable_null_tracking (UNUSED bool *p) |
bool | _fr_assert_fail (char const *file, int line, char const *expr, char const *msg,...) |
A soft assertion which triggers the fault handler in debug builds. More... | |
void | _fr_assert_fatal (char const *file, int line, char const *expr, char const *msg,...) |
A fatal assertion which triggers the fault handler in debug builds or exits. More... | |
NEVER_RETURNS void | _fr_exit (char const *file, int line, int status, bool now) |
Exit possibly printing a message about why we're exiting. More... | |
static void | _fr_talloc_fault (char const *reason) |
Callback executed on fatal talloc error. More... | |
static void | _fr_talloc_fault_simple (char const *reason) |
Callback executed on fatal talloc error. More... | |
static void | _fr_talloc_log (char const *msg) |
Wrapper to pass talloc log output to our fr_fault_log function. More... | |
static int | _panic_on_free (UNUSED char *foo) |
void | backtrace_print (UNUSED fr_fring_t *fring, UNUSED void *obj) |
fr_bt_marker_t * | fr_backtrace_attach (UNUSED fr_fring_t **fring, UNUSED TALLOC_CTX *obj) |
void | fr_debug_break (bool always) |
Break in debugger (if were running under a debugger) More... | |
void | fr_debug_state_store (void) |
Should be run before using setuid or setgid to get useful results. More... | |
char const * | fr_debug_state_to_msg (fr_debug_state_t state) |
Return current value of debug_state. More... | |
void | fr_disable_null_tracking_on_free (TALLOC_CTX *ctx) |
Disable the null tracking context when a talloc chunk is freed. More... | |
NEVER_RETURNS void | fr_fault (int sig) |
Prints a simple backtrace (if execinfo is available) and calls panic_action if set. More... | |
void | fr_fault_backtrace (void) |
Split out so it can be sprinkled throughout the server and called via a debugger. More... | |
static int | fr_fault_check_permissions (void) |
Check to see if panic_action file is world writable. More... | |
void | fr_fault_log (char const *msg,...) |
Log output to the fr_fault_log_fd. More... | |
void | fr_fault_log_hex (uint8_t const *data, size_t data_len) |
Print data as a hex block. More... | |
void | fr_fault_set_cb (fr_fault_cb_t func) |
Set a callback to be called before fr_fault() More... | |
void | fr_fault_set_log_fd (int fd) |
Set a file descriptor to log memory reports to. More... | |
int | fr_fault_setup (TALLOC_CTX *ctx, char const *cmd, char const *program) |
Registers signal handlers to execute panic_action on fatal signal. More... | |
int | fr_get_debug_state (void) |
int | fr_get_lsan_state (void) |
static int | fr_get_pr_dumpable_flag (void) |
Get the processes dumpable flag. More... | |
static uint32_t | fr_hash_struct (void const *ptr, size_t size, size_t offset) |
int | fr_log_talloc_report (TALLOC_CTX const *ctx) |
Generate a talloc memory report for a context and print to stderr/stdout. More... | |
void | fr_panic_on_free (TALLOC_CTX *ctx) |
Insert memory into the context of another talloc memory chunk which causes a panic when freed. More... | |
int | fr_reset_dumpable (void) |
Reset dumpable state to previously configured value. More... | |
int | fr_set_dumpable (bool allow_core_dumps) |
Enable or disable core dumps. More... | |
int | fr_set_dumpable_init (void) |
Get the current maximum for core files. More... | |
static int | fr_set_pr_dumpable_flag (UNUSED bool dumpable) |
Set the dumpable flag, also controls whether processes can PATTACH. More... | |
void | fr_sign_struct (void *ptr, size_t size, size_t offset) |
void | fr_talloc_fault_setup (void) |
Register talloc fault handlers. More... | |
void | fr_verify_struct (void const *ptr, size_t size, size_t offset) |
void | fr_verify_struct_member (void const *ptr, size_t len, uint32_t *signature) |
Variables | |
static bool | dump_core |
Whether we should drop a core on fatal signals. More... | |
fr_debug_state_t | fr_debug_state = DEBUGGER_STATE_UNKNOWN |
Whether we're attached to by a debugger. More... | |
static int | fr_fault_log_fd = STDERR_FILENO |
Where to write debug output. More... | |
static char | panic_action [512] |
The command to execute when panicking. More... | |
static fr_fault_cb_t | panic_cb = NULL |
Callback to execute whilst panicking, before the panic_action. More... | |
static TALLOC_CTX * | talloc_autofree_ctx |
Functions to help with debugging.
Definition in file debug.c.
#define TALLOC_REPORT_MAX_DEPTH 20 |
bool _fr_assert_fail | ( | char const * | file, |
int | line, | ||
char const * | expr, | ||
char const * | msg, | ||
... | |||
) |
A soft assertion which triggers the fault handler in debug builds.
[in] | file | the assertion failed in. |
[in] | line | of the assertion in the file. |
[in] | expr | that was evaluated. |
[in] | msg | Message to print (may be NULL). |
[in] | ... | Arguments for msg string. |
Definition at line 1449 of file debug.c.
void _fr_assert_fatal | ( | char const * | file, |
int | line, | ||
char const * | expr, | ||
char const * | msg, | ||
... | |||
) |
A fatal assertion which triggers the fault handler in debug builds or exits.
[in] | file | the assertion failed in. |
[in] | line | of the assertion in the file. |
[in] | expr | that was evaluated. |
[in] | msg | Message to print (may be NULL). |
[in] | ... | Arguments for msg string. |
Definition at line 1485 of file debug.c.
NEVER_RETURNS void _fr_exit | ( | char const * | file, |
int | line, | ||
int | status, | ||
bool | now | ||
) |
Exit possibly printing a message about why we're exiting.
[in] | file | where fr_exit() was called. |
[in] | line | where fr_exit() was called. |
[in] | status | we're exiting with. |
[in] | now | Exit immediately. |
Definition at line 1517 of file debug.c.
|
static |
Callback executed on fatal talloc error.
Translates a talloc abort into a fr_fault call. Mostly to work around issues with some debuggers not being able to attach after a SIGABRT has been raised.
reason | string provided by talloc. |
Definition at line 1126 of file debug.c.
|
static |
|
static |
|
static |
void backtrace_print | ( | UNUSED fr_fring_t * | fring, |
UNUSED void * | obj | ||
) |
fr_bt_marker_t* fr_backtrace_attach | ( | UNUSED fr_fring_t ** | fring, |
UNUSED TALLOC_CTX * | obj | ||
) |
void fr_debug_break | ( | bool | always | ) |
Break in debugger (if were running under a debugger)
If the server is running under a debugger this will raise a SIGTRAP which will pause the running process.
If the server is not running under debugger then this will do nothing.
Definition at line 570 of file debug.c.
void fr_debug_state_store | ( | void | ) |
char const* fr_debug_state_to_msg | ( | fr_debug_state_t | state | ) |
void fr_disable_null_tracking_on_free | ( | TALLOC_CTX * | ctx | ) |
NEVER_RETURNS void fr_fault | ( | int | sig | ) |
void fr_fault_backtrace | ( | void | ) |
|
static |
void fr_fault_log | ( | char const * | msg, |
... | |||
) |
Log output to the fr_fault_log_fd.
We used to support a user defined callback, which was set to a radlog function. Unfortunately, when logging to syslog, syslog would alloc memory which would result in a deadlock if fr_fault was triggered from within a allocation call.
Now we just write directly to the FD.
Definition at line 1401 of file debug.c.
void fr_fault_set_cb | ( | fr_fault_cb_t | func | ) |
Set a callback to be called before fr_fault()
func | to execute. If callback returns < 0 fr_fault will exit before running panic_action code. |
Definition at line 1387 of file debug.c.
void fr_fault_set_log_fd | ( | int | fd | ) |
int fr_fault_setup | ( | TALLOC_CTX * | ctx, |
char const * | cmd, | ||
char const * | program | ||
) |
Registers signal handlers to execute panic_action on fatal signal.
May be called multiple time to change the panic_action/program.
[in] | ctx | to allocate autofreeable resources in. |
[in] | cmd | to execute on fault. If present p will be substituted for the parent PID before the command is executed, and e will be substituted for the currently running program. |
program | Name of program currently executing (argv[0]). |
Definition at line 1242 of file debug.c.
int fr_get_debug_state | ( | void | ) |
int fr_get_lsan_state | ( | void | ) |
|
static |
int fr_log_talloc_report | ( | TALLOC_CTX const * | ctx | ) |
void fr_panic_on_free | ( | TALLOC_CTX * | ctx | ) |
int fr_reset_dumpable | ( | void | ) |
int fr_set_dumpable | ( | bool | allow_core_dumps | ) |
int fr_set_dumpable_init | ( | void | ) |
void fr_talloc_fault_setup | ( | void | ) |
|
static |
fr_debug_state_t fr_debug_state = DEBUGGER_STATE_UNKNOWN |
|
static |
|
static |
|
static |