1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-02 15:53:12 +02:00

Remove debug plugin (merged to core), new debug variable for each plugin (no more signals for setting debug)

This commit is contained in:
Sebastien Helleu
2008-11-02 18:54:25 +01:00
parent 640ff6b51c
commit 6e69f7f3ce
38 changed files with 561 additions and 665 deletions
+94
View File
@@ -770,6 +770,86 @@ command_command (void *data, struct t_gui_buffer *buffer,
return WEECHAT_RC_OK;
}
/*
* command_debug: control debug for core/plugins
*/
int
command_debug (void *data, struct t_gui_buffer *buffer,
int argc, char **argv, char **argv_eol)
{
struct t_config_option *ptr_option;
struct t_weechat_plugin *ptr_plugin;
/* make C compiler happy */
(void) data;
(void) argv_eol;
if ((argc == 1)
|| ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0)))
{
gui_chat_printf (NULL, "");
gui_chat_printf (NULL, "Debug:");
ptr_option = config_weechat_debug_get (PLUGIN_CORE);
gui_chat_printf (NULL, " %s: %d",
PLUGIN_CORE,
(ptr_option) ? CONFIG_INTEGER(ptr_option) : 0);
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
gui_chat_printf (NULL, " %s: %d",
ptr_plugin->name,
ptr_plugin->debug);
}
return WEECHAT_RC_OK;
}
if (string_strcasecmp (argv[1], "dump") == 0)
{
hook_signal_send ("debug_dump", WEECHAT_HOOK_SIGNAL_STRING, NULL);
}
else if (string_strcasecmp (argv[1], "buffer") == 0)
{
gui_buffer_dump_hexa (buffer);
}
else if (string_strcasecmp (argv[1], "windows") == 0)
{
debug_windows_tree ();
}
else if (argc >= 3)
{
if (strcmp (argv[2], "0") == 0)
{
/* disable debug for a plugin */
ptr_option = config_weechat_debug_get (argv[1]);
if (ptr_option)
{
config_file_option_free (ptr_option);
config_weechat_debug_set_all ();
gui_chat_printf (NULL, _("Debug disabled for \"%s\""),
argv[1]);
}
}
else
{
/* set debug level for a plugin */
if (config_weechat_debug_set (argv[1], argv[2]) != WEECHAT_CONFIG_OPTION_SET_ERROR)
{
ptr_option = config_weechat_debug_get (argv[1]);
if (ptr_option)
{
gui_chat_printf (NULL, "%s: \"%s\" => %d",
"debug", argv[1],
CONFIG_INTEGER(ptr_option));
}
}
}
}
return WEECHAT_RC_OK;
}
/*
* command_filter_display: display one filter
*/
@@ -3133,6 +3213,20 @@ command_init ()
"added if not found at beginning of command)"),
"%p|weechat %P",
&command_command, NULL);
hook_command (NULL, "debug",
N_("control debug for core/plugins"),
N_("[list | plugin level | dump | buffer | windows]"),
N_(" plugin: name of plugin (\"core\" for WeeChat core)\n"
" level: debug level for plugin (0 = disable debug)\n"
" dump: save memory dump in WeeChat log file (same "
"dump is written when WeeChat crashes)\n"
" buffer: dump buffer content with hexadecimal values "
"in log file\n"
"windows: display windows tree\n"
" text: send \"debug\" signal with \"text\" as "
"argument"),
"%p|list|dump|buffer|windows",
&command_debug, NULL);
hook_command (NULL, "filter",
N_("filter messages in buffers, to hide/show them according "
"to tags or regex"),
+161 -1
View File
@@ -35,7 +35,6 @@
#include "weechat.h"
#include "wee-config.h"
#include "wee-config-file.h"
#include "wee-hook.h"
#include "wee-log.h"
#include "wee-util.h"
@@ -55,6 +54,7 @@
struct t_config_file *weechat_config_file = NULL;
struct t_config_section *weechat_config_section_debug = NULL;
struct t_config_section *weechat_config_section_bar = NULL;
/* config, startup section */
@@ -484,6 +484,151 @@ config_weechat_reload (void *data, struct t_config_file *config_file)
return rc;
}
/*
* config_weechat_debug_get: get debug level for a plugin (or "core")
*/
struct t_config_option *
config_weechat_debug_get (const char *plugin_name)
{
return config_file_search_option (weechat_config_file,
weechat_config_section_debug,
plugin_name);
}
/*
* config_weechat_debug_set_all: set debug for "core" and all plugins, using
* values from [debug] section
*/
void
config_weechat_debug_set_all ()
{
struct t_config_option *ptr_option;
struct t_weechat_plugin *ptr_plugin;
/* set debug for core */
ptr_option = config_weechat_debug_get (PLUGIN_CORE);
weechat_debug_core = (ptr_option) ? CONFIG_INTEGER(ptr_option) : 0;
/* set debug for plugins */
for (ptr_plugin = weechat_plugins; ptr_plugin;
ptr_plugin = ptr_plugin->next_plugin)
{
ptr_option = config_weechat_debug_get (ptr_plugin->name);
ptr_plugin->debug = (ptr_option) ? CONFIG_INTEGER(ptr_option) : 0;
}
}
/*
* config_weechat_debug_change: called when a debug option is changed
*/
void
config_weechat_debug_change (void *data,
struct t_config_option *option)
{
/* make C compiler happy */
(void) data;
(void) option;
config_weechat_debug_set_all ();
}
/*
* config_weechat_debug_create_option: create option in "debug" section
*/
int
config_weechat_debug_create_option (void *data,
struct t_config_file *config_file,
struct t_config_section *section,
const char *option_name,
const char *value)
{
struct t_config_option *ptr_option;
int rc;
/* make C compiler happy */
(void) data;
rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
if (option_name)
{
ptr_option = config_file_search_option (config_file, section,
option_name);
if (ptr_option)
{
if (value && value[0])
rc = config_file_option_set (ptr_option, value, 1);
else
{
config_file_option_free (ptr_option);
rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
}
}
else
{
if (value && value[0])
{
ptr_option = config_file_new_option (
config_file, section,
option_name, "integer",
_("debug level for plugin (\"core\" for WeeChat core)"),
NULL, 0, 32, "0", value, NULL, NULL,
&config_weechat_debug_change, NULL,
NULL, NULL);
rc = (ptr_option) ?
WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR;
}
else
rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
}
}
/* set debug level for "core" and all plugins */
config_weechat_debug_set_all ();
return rc;
}
/*
* config_weechat_debug_delete_option: delete option in "debug" section
*/
int
config_weechat_debug_delete_option (void *data,
struct t_config_file *config_file,
struct t_config_section *section,
struct t_config_option *option)
{
/* make C compiler happy */
(void) data;
(void) config_file;
(void) section;
config_file_option_free (option);
config_weechat_debug_set_all ();
return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED;
}
/*
* config_weechat_debug_set: set debug level for a plugin (or "core")
*/
int
config_weechat_debug_set (const char *plugin_name, const char *value)
{
return config_weechat_debug_create_option (NULL,
weechat_config_file,
weechat_config_section_debug,
plugin_name,
value);
}
/*
* config_weechat_bar_read: read bar option in config file
*/
@@ -821,6 +966,21 @@ config_weechat_init ()
if (!weechat_config_file)
return 0;
/* debug */
ptr_section = config_file_new_section (weechat_config_file, "debug",
1, 1,
NULL, NULL, NULL, NULL,
NULL, NULL,
&config_weechat_debug_create_option, NULL,
&config_weechat_debug_delete_option, NULL);
if (!ptr_section)
{
config_file_free (weechat_config_file);
return 0;
}
weechat_config_section_debug = ptr_section;
/* startup */
ptr_section = config_file_new_section (weechat_config_file, "startup",
0, 0,
+4
View File
@@ -190,6 +190,10 @@ extern struct t_config_option *config_plugin_path;
extern struct t_config_option *config_plugin_save_config_on_unload;
extern struct t_config_option *config_weechat_debug_get (const char *plugin_name);
extern int config_weechat_debug_set (const char *plugin_name,
const char *value);
extern void config_weechat_debug_set_all ();
extern int config_weechat_init ();
extern int config_weechat_read ();
extern int config_weechat_reload ();
+1
View File
@@ -24,6 +24,7 @@ struct t_gui_window_tree;
extern void debug_dump (int crash);
extern void debug_sigsegv ();
extern void debug_windows_tree ();
extern void debug_init ();
#endif /* wee-debug.h */
+1
View File
@@ -69,6 +69,7 @@
#include "../plugins/plugin.h"
int weechat_debug_core = 0; /* debug level for core */
char *weechat_argv0 = NULL; /* WeeChat binary file name (argv[0])*/
int weechat_upgrading; /* =1 if WeeChat is upgrading */
time_t weechat_start_time; /* start time (used by /uptime cmd) */
+1
View File
@@ -98,6 +98,7 @@
/* global variables and functions */
extern int weechat_debug_core;
extern char *weechat_argv0;
extern time_t weechat_start_time;
extern int weechat_quit;