![]() |
The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Debugging function definitions and structures. More...
#include <freeradius-devel/build.h>#include <freeradius-devel/missing.h>#include <freeradius-devel/util/fring.h>
Include dependency graph for debug.h:Go to the source code of this file.
Macros | |
| #define | FR_FAULT_LOG(_fmt, ...) fr_fault_log(_fmt "\n", ## __VA_ARGS__) |
| #define | FR_FAULT_LOG_HEX(_data, _data_len) fr_fault_log_hex(_data, _data_len) |
| #define | MEM(x) do { if (!(x)) { fr_cond_assert_msg(0 && (x), "OUT OF MEMORY"); _fr_exit(__FILE__, __LINE__, EXIT_FAILURE, true); } } while (0) |
Typedefs | |
| typedef int(* | fr_fault_cb_t) (int signum) |
| Optional callback passed to fr_fault_setup. | |
Enumerations | |
| enum | fr_debug_state_t { DEBUGGER_STATE_UNKNOWN_NO_PTRACE = -3 , DEBUGGER_STATE_UNKNOWN_NO_PTRACE_CAP = -2 , DEBUGGER_STATE_UNKNOWN = -1 , DEBUGGER_STATE_NOT_ATTACHED = 0 , DEBUGGER_STATE_ATTACHED = 1 } |
Functions | |
| void | fr_debug_break (bool always) |
| Break in debugger (if were running under a debugger) | |
| void | fr_debug_state_store (void) |
| Should be run before using setuid or setgid to get useful results. | |
| char const * | fr_debug_state_to_msg (fr_debug_state_t state) |
| Return current value of debug_state. | |
| void | fr_disable_null_tracking_on_free (TALLOC_CTX *ctx) |
| Disable the null tracking context when a talloc chunk is freed. | |
| void | fr_fault (int sig) |
| Prints a simple backtrace (if execinfo is available) and calls panic_action if set. | |
| void | fr_fault_log (char const *msg,...)) |
| Log output to the fr_fault_log_fd. | |
| void | fr_fault_log_hex (uint8_t const *data, size_t data_len) |
| Print data as a hex block. | |
| void | fr_fault_set_cb (fr_fault_cb_t func) |
| Set a callback to be called before fr_fault() | |
| void | fr_fault_set_log_fd (int fd) |
| Set a file descriptor to log memory reports to. | |
| int | fr_fault_setup (TALLOC_CTX *ctx, char const *cmd, char const *program) |
| Registers signal handlers to execute panic_action on fatal signal. | |
| int | fr_get_debug_state (void) |
| int | fr_get_lsan_state (void) |
| int | fr_log_talloc_report (TALLOC_CTX const *ctx) |
| Generate a talloc memory report for a context and print to stderr/stdout. | |
| void | fr_panic_on_free (TALLOC_CTX *ctx) |
| Insert memory into the context of another talloc memory chunk which causes a panic when freed. | |
| int | fr_reset_dumpable (void) |
| Reset dumpable state to previously configured value. | |
| int | fr_set_dumpable (bool allow_core_dumps) |
| Enable or disable core dumps. | |
| int | fr_set_dumpable_init (void) |
| Get the current maximum for core files. | |
| void | fr_talloc_fault_setup (void) |
| Register talloc fault handlers. | |
Variables | |
| fr_debug_state_t | fr_debug_state |
| Whether we're attached to by a debugger. | |
| int | fr_fault_log_fd |
| Where to write debug output. | |
Assertion and exit macros | |
| #define | fr_assert(_x) if (unlikely(!((bool)(_x)))) _fr_assert_fail(__FILE__, __LINE__, #_x, NULL) |
| Calls panic_action ifndef NDEBUG, else logs error. | |
| #define | fr_assert_fail(_msg, ...) _fr_assert_fail(__FILE__, __LINE__, "false", _msg, ## __VA_ARGS__) |
| Calls panic_action ifndef NDEBUG, else logs error. | |
| #define | fr_assert_msg(_x, _msg, ...) if (unlikely(!((bool)(_x)))) _fr_assert_fail(__FILE__, __LINE__, #_x, _msg, ## __VA_ARGS__) |
| Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code 134. | |
| #define | fr_cond_assert(_x) likely((bool)((_x) ? true : (_fr_assert_fail(__FILE__, __LINE__, #_x, NULL) && false))) |
| Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x. | |
| #define | fr_cond_assert_msg(_x, _fmt, ...) likely((bool)((_x) ? true : (_fr_assert_fail(__FILE__, __LINE__, #_x, _fmt, ## __VA_ARGS__) && false))) |
| Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x. | |
| #define | fr_exit(_x) _fr_exit(__FILE__, __LINE__, (_x), false) |
| Exit, producing a log message in debug builds. | |
| #define | fr_exit_now(_x) _fr_exit(__FILE__, __LINE__, (_x), true) |
| Exit without calling atexit() handlers, producing a log message in debug builds. | |
| #define | fr_fatal_assert(_x) if (unlikely(!((bool)(_x)))) _fr_assert_fatal(__FILE__, __LINE__, #_x, NULL) |
| Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code 134. | |
| #define | fr_fatal_assert_fail(_msg, ...) _fr_assert_fatal(__FILE__, __LINE__, "false", _msg, ## __VA_ARGS__) |
| Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code 134. | |
| #define | fr_fatal_assert_msg(_x, _fmt, ...) if (unlikely(!((bool)(_x)))) _fr_assert_fatal(__FILE__, __LINE__, #_x, _fmt, ## __VA_ARGS__) |
| Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code 134. | |
Assertion support functions | |
| 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. | |
| NEVER_RETURNS 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. | |
| NEVER_RETURNS void | _fr_exit (char const *file, int line, int status, bool now) |
| Exit possibly printing a message about why we're exiting. | |
Debugging function definitions and structures.
Definition in file debug.h.
| #define fr_assert | ( | _x | ) | if (unlikely(!((bool)(_x)))) _fr_assert_fail(__FILE__, __LINE__, #_x, NULL) |
| #define fr_assert_fail | ( | _msg, | |
| ... | |||
| ) | _fr_assert_fail(__FILE__, __LINE__, "false", _msg, ## __VA_ARGS__) |
| #define fr_assert_msg | ( | _x, | |
| _msg, | |||
| ... | |||
| ) | if (unlikely(!((bool)(_x)))) _fr_assert_fail(__FILE__, __LINE__, #_x, _msg, ## __VA_ARGS__) |
| #define fr_cond_assert | ( | _x | ) | likely((bool)((_x) ? true : (_fr_assert_fail(__FILE__, __LINE__, #_x, NULL) && false))) |
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Should be wrapped in a condition, and if false, should cause function to return an error code. This allows control to return to the caller if a precondition is not satisfied and we're not debugging.
Example:
if (!fr_cond_assert(request)) return -1
| [in] | _x | expression to test (should evaluate to true) |
| #define fr_cond_assert_msg | ( | _x, | |
| _fmt, | |||
| ... | |||
| ) | likely((bool)((_x) ? true : (_fr_assert_fail(__FILE__, __LINE__, #_x, _fmt, ## __VA_ARGS__) && false))) |
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Should be wrapped in a condition, and if false, should cause function to return an error code. This allows control to return to the caller if a precondition is not satisfied and we're not debugging.
Example:
if (!fr_cond_assert_msg(request, "Bad stuff happened: %s", fr_syserror(errno)))) return -1
| [in] | _x | expression to test (should evaluate to true) |
| [in] | _fmt | of message to log. |
| [in] | ... | fmt arguments. |
| #define fr_fatal_assert | ( | _x | ) | if (unlikely(!((bool)(_x)))) _fr_assert_fatal(__FILE__, __LINE__, #_x, NULL) |
| #define fr_fatal_assert_fail | ( | _msg, | |
| ... | |||
| ) | _fr_assert_fatal(__FILE__, __LINE__, "false", _msg, ## __VA_ARGS__) |
| #define fr_fatal_assert_msg | ( | _x, | |
| _fmt, | |||
| ... | |||
| ) | if (unlikely(!((bool)(_x)))) _fr_assert_fatal(__FILE__, __LINE__, #_x, _fmt, ## __VA_ARGS__) |
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code 134.
Should be wrapped in a condition, and if false, should cause function to return an error code. This allows control to return to the caller if a precondition is not satisfied and we're not debugging.
Example:
fr_fatal_assert(<extremely_unlikely_and_fatal_condition>);
| [in] | _x | expression to test (should evaluate to true) |
| [in] | _fmt | of message to log. |
| [in] | ... | fmt arguments. |
| #define FR_FAULT_LOG | ( | _fmt, | |
| ... | |||
| ) | fr_fault_log(_fmt "\n", ## __VA_ARGS__) |
| #define FR_FAULT_LOG_HEX | ( | _data, | |
| _data_len | |||
| ) | fr_fault_log_hex(_data, _data_len) |
| #define MEM | ( | x | ) | do { if (!(x)) { fr_cond_assert_msg(0 && (x), "OUT OF MEMORY"); _fr_exit(__FILE__, __LINE__, EXIT_FAILURE, true); } } while (0) |
| typedef int(* fr_fault_cb_t) (int signum) |
| enum fr_debug_state_t |
| Enumerator | |
|---|---|
| DEBUGGER_STATE_UNKNOWN_NO_PTRACE | We don't have ptrace so can't check. |
| DEBUGGER_STATE_UNKNOWN_NO_PTRACE_CAP | CAP_SYS_PTRACE not set for the process. |
| DEBUGGER_STATE_UNKNOWN | Unknown, likely fr_get_debug_state() not called yet. |
| DEBUGGER_STATE_NOT_ATTACHED | We can attach, so a debugger must not be. |
| DEBUGGER_STATE_ATTACHED | We can't attach, it's likely a debugger is already tracing. |
| 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 1246 of file debug.c.
Here is the call graph for this function:| NEVER_RETURNS 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 1282 of file debug.c.
Here is the call graph for this function:| 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 1314 of file debug.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 540 of file debug.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 | ) |
| void fr_fault | ( | int | sig | ) |
| 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 1198 of file debug.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 1184 of file debug.c.
Here is the caller graph for this function:| 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 1055 of file debug.c.
Here is the call graph for this function:
Here is the caller graph for this function:| int fr_get_debug_state | ( | void | ) |
| int fr_get_lsan_state | ( | void | ) |
| 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 | ) |
|
extern |
1.9.8