Merge pull request #4393 from donaldsharp/debug_all

Debug all
This commit is contained in:
Renato Westphal 2019-05-29 23:55:50 -03:00 committed by GitHub
commit 4eb4afa3b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 7 deletions

View File

@ -18,29 +18,46 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <zebra.h> #include <zebra.h>
#include "typesafe.h"
#include "debug.h" #include "debug.h"
#include "command.h" #include "command.h"
static const struct debug_callbacks *callbacks; static struct debug_cb_list_head cb_head;
DECLARE_LIST(debug_cb_list, struct debug_callbacks, item)
/* All code in this section should be reentrant and MT-safe */ /* All code in this section should be reentrant and MT-safe */
DEFUN_NOSH(debug_all, debug_all_cmd, "[no] debug all", DEFUN_NOSH(debug_all, debug_all_cmd, "[no] debug all",
NO_STR DEBUG_STR "Toggle all debugging output\n") NO_STR DEBUG_STR "Toggle all debugging output\n")
{ {
struct debug_callbacks *cb;
bool set = !strmatch(argv[0]->text, "no"); bool set = !strmatch(argv[0]->text, "no");
uint32_t mode = DEBUG_NODE2MODE(vty->node); uint32_t mode = DEBUG_NODE2MODE(vty->node);
if (callbacks->debug_set_all) frr_each (debug_cb_list, &cb_head, cb)
callbacks->debug_set_all(mode, set); cb->debug_set_all(mode, set);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
void debug_init(const struct debug_callbacks *cb) void debug_init(struct debug_callbacks *cb)
{
static bool inited = false;
if (!inited) {
inited = true;
debug_cb_list_init(&cb_head);
}
debug_cb_list_add_head(&cb_head, cb);
}
void debug_init_cli(void)
{ {
callbacks = cb;
install_element(ENABLE_NODE, &debug_all_cmd); install_element(ENABLE_NODE, &debug_all_cmd);
install_element(CONFIG_NODE, &debug_all_cmd); install_element(CONFIG_NODE, &debug_all_cmd);
} }

View File

@ -84,6 +84,7 @@ struct debug {
const char *desc; const char *desc;
}; };
PREDECL_LIST(debug_cb_list)
/* /*
* Callback set for debugging code. * Callback set for debugging code.
* *
@ -92,6 +93,11 @@ struct debug {
* mode set. * mode set.
*/ */
struct debug_callbacks { struct debug_callbacks {
/*
* Linked list of Callbacks to call
*/
struct debug_cb_list_item item;
/* /*
* flags * flags
* flags to set on debug flag fields * flags to set on debug flag fields
@ -233,7 +239,13 @@ struct debug_callbacks {
* *
* MT-Safe * MT-Safe
*/ */
void debug_init(const struct debug_callbacks *cb); void debug_init(struct debug_callbacks *cb);
/*
* Turn on the cli to turn on/off debugs.
* Should only be called by libfrr
*/
void debug_init_cli(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -39,6 +39,7 @@
#include "db.h" #include "db.h"
#include "northbound_cli.h" #include "northbound_cli.h"
#include "northbound_db.h" #include "northbound_db.h"
#include "debug.h"
DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm)) DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm))
DEFINE_KOOH(frr_early_fini, (), ()) DEFINE_KOOH(frr_early_fini, (), ())
@ -654,6 +655,9 @@ struct thread_master *frr_init(void)
lib_error_init(); lib_error_init();
yang_init(); yang_init();
debug_init_cli();
nb_init(master, di->yang_modules, di->n_yang_modules); nb_init(master, di->yang_modules, di->n_yang_modules);
if (nb_db_init() != NB_OK) if (nb_db_init() != NB_OK)
flog_warn(EC_LIB_NB_DATABASE, flog_warn(EC_LIB_NB_DATABASE,

View File

@ -1722,8 +1722,8 @@ void nb_cli_init(struct thread_master *tm)
/* Initialize the shared candidate configuration. */ /* Initialize the shared candidate configuration. */
vty_shared_candidate_config = nb_config_new(NULL); vty_shared_candidate_config = nb_config_new(NULL);
/* Install debug commands */
debug_init(&nb_dbg_cbs); debug_init(&nb_dbg_cbs);
install_node(&nb_debug_node, nb_debug_config_write); install_node(&nb_debug_node, nb_debug_config_write);
install_element(ENABLE_NODE, &debug_nb_cmd); install_element(ENABLE_NODE, &debug_nb_cmd);
install_element(CONFIG_NODE, &debug_nb_cmd); install_element(CONFIG_NODE, &debug_nb_cmd);