summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/command.c12
-rw-r--r--src/gui/gui-buffer.c62
-rw-r--r--src/gui/gui.h1
3 files changed, 73 insertions, 2 deletions
diff --git a/src/common/command.c b/src/common/command.c
index 1db3a2774..cc19ffe04 100644
--- a/src/common/command.c
+++ b/src/common/command.c
@@ -119,10 +119,11 @@ t_weechat_command weechat_commands[] =
" file: filename (on local host)"),
"chat|send|close %n %f", 1, MAX_ARGS, 0, NULL, weechat_cmd_dcc },
{ "debug", N_("print debug messages"),
- N_("dump | windows"),
+ N_("dump | buffer | windows"),
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"),
- "dump|windows", 1, 1, 0, weechat_cmd_debug, NULL },
+ "dump|buffer|windows", 1, 1, 0, weechat_cmd_debug, NULL },
{ "help", N_("display help about commands"),
N_("[command]"),
N_("command: name of a WeeChat or IRC command"),
@@ -1899,12 +1900,15 @@ int
weechat_cmd_debug (t_irc_server *server, t_irc_channel *channel,
int argc, char **argv)
{
+ t_gui_buffer *buffer;
t_irc_server *ptr_server;
/* make C compiler happy */
(void) server;
(void) channel;
+ gui_buffer_find_context (server, channel, NULL, &buffer);
+
if (argc != 1)
{
irc_display_prefix (NULL, NULL, GUI_PREFIX_ERROR);
@@ -1918,6 +1922,10 @@ weechat_cmd_debug (t_irc_server *server, t_irc_channel *channel,
{
weechat_dump (0);
}
+ else if (ascii_strcasecmp (argv[0], "buffer") == 0)
+ {
+ gui_buffer_dump_hexa (buffer);
+ }
else if (ascii_strcasecmp (argv[0], "windows") == 0)
{
gui_printf_nolog (NULL, "\n");
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 7f0a181f5..085cae0ee 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -1410,6 +1410,68 @@ gui_buffer_scroll (t_gui_window *window, char *scroll)
}
/*
+ * gui_buffer_dump_hexa: dump content of buffer as hexa data in log file
+ */
+
+void
+gui_buffer_dump_hexa (t_gui_buffer *buffer)
+{
+ t_gui_line *ptr_line;
+ int num_line, data_pos;
+ char *data_without_colors;
+ char hexa[(16 * 3) + 1], ascii[(16 * 2) + 1];
+ int hexa_pos, ascii_pos;
+
+ weechat_log_printf ("[buffer dump hexa (addr:0x%X)]\n", buffer);
+ num_line = 1;
+ for (ptr_line = buffer->lines; ptr_line; ptr_line = ptr_line->next_line)
+ {
+ /* display line without colors */
+ data_without_colors = (ptr_line->data) ?
+ (char *)gui_color_decode ((unsigned char *)ptr_line->data, 0, 0) : NULL;
+ weechat_log_printf ("\n");
+ weechat_log_printf (" line %d: %s\n",
+ num_line,
+ (data_without_colors) ? data_without_colors : "(null)");
+ if (data_without_colors)
+ free (data_without_colors);
+
+ /* display raw data for line */
+ if (ptr_line->data)
+ {
+ weechat_log_printf ("\n");
+ weechat_log_printf (" raw data for line %d (with color codes):\n",
+ num_line);
+ data_pos = 0;
+ hexa_pos = 0;
+ ascii_pos = 0;
+ while (ptr_line->data[data_pos])
+ {
+ snprintf (hexa + hexa_pos, 4, "%02X ",
+ (unsigned char)(ptr_line->data[data_pos]));
+ hexa_pos += 3;
+ snprintf (ascii + ascii_pos, 3, "%c ",
+ ((((unsigned char)ptr_line->data[data_pos]) < 32)
+ || (((unsigned char)ptr_line->data[data_pos]) > 127)) ?
+ '.' : (unsigned char)(ptr_line->data[data_pos]));
+ ascii_pos += 2;
+ if (ascii_pos == 32)
+ {
+ weechat_log_printf (" %-48s %s\n", hexa, ascii);
+ hexa_pos = 0;
+ ascii_pos = 0;
+ }
+ data_pos++;
+ }
+ if (ascii_pos > 0)
+ weechat_log_printf (" %-48s %s\n", hexa, ascii);
+ }
+
+ num_line++;
+ }
+}
+
+/*
* gui_buffer_print_log: print buffer infos in log (usually for crash dump)
*/
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 9b311e793..744f9d7a7 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -109,6 +109,7 @@ extern void gui_buffer_search_restart (t_gui_window *);
extern void gui_buffer_search_stop (t_gui_window *);
extern int gui_buffer_search_text (t_gui_window *);
extern void gui_buffer_scroll (t_gui_window *, char *);
+extern void gui_buffer_dump_hexa (t_gui_buffer *);
extern void gui_buffer_print_log (t_gui_buffer *);
/* panel */