[vte] lib: debug: Hexdump incoming and outgoing buffers
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] lib: debug: Hexdump incoming and outgoing buffers
- Date: Wed, 11 Jul 2018 19:22:30 +0000 (UTC)
commit 0cb4e79077b2f40ea0ace71c9c18163d40cd9f84
Author: Christian Persch <chpe src gnome org>
Date: Wed Jul 11 21:21:15 2018 +0200
lib: debug: Hexdump incoming and outgoing buffers
Add hexdump of incoming (pre- and post-conversion) and outgoing
buffers.
src/debug.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++
src/debug.h | 6 +++++-
src/vte.cc | 21 ++++++++++++---------
3 files changed, 61 insertions(+), 10 deletions(-)
---
diff --git a/src/debug.cc b/src/debug.cc
index 03f8fd08..5d88833b 100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -121,3 +121,47 @@ _vte_debug_sequence_to_string(const char *str,
return NULL;
#endif /* VTE_DEBUG */
}
+
+#ifdef VTE_DEBUG
+static bool
+hexdump_line(GString* str,
+ size_t ofs,
+ uint8_t const* buf,
+ size_t len)
+{
+ g_string_append_printf(str, "%08x ", (unsigned int)ofs);
+ for (unsigned int i = 0; i < 16; ++i) {
+ if (i < len)
+ g_string_append_printf(str, "%02x ", buf[i]);
+ else
+ g_string_append(str, " ");
+ if (i == 7)
+ g_string_append_c(str, ' ');
+ }
+
+ g_string_append(str, " |");
+ for (unsigned int i = 0; i < 16; ++i) {
+ g_string_append_c(str, i < len ? (g_ascii_isprint(buf[i]) ? buf[i] : '.') : ' ');
+ }
+ g_string_append(str, "|\n");
+ return len >= 16;
+}
+#endif /* VTE_DEBUG */
+
+void
+_vte_debug_hexdump(char const* str,
+ uint8_t const* buf,
+ size_t len)
+{
+#ifdef VTE_DEBUG
+ GString* s = g_string_new(str);
+ g_string_append_printf(s, " len = 0x%x = %u\n", (unsigned int)len, (unsigned int)len);
+
+ size_t ofs = 0;
+ while (hexdump_line(s, ofs, buf + ofs, len - ofs))
+ ofs += 16;
+
+ g_printerr("%s", s->str);
+ g_string_free(s, true);
+#endif /* VTE_DEBUG */
+}
diff --git a/src/debug.h b/src/debug.h
index d9eb6011..41c3665d 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -22,7 +22,7 @@
#define vte_debug_h_included
#include <config.h>
-
+#include <stdint.h>
#include <glib.h>
#ifndef VTE_COMPILATION
@@ -70,6 +70,10 @@ void _vte_debug_init(void);
const char *_vte_debug_sequence_to_string(const char *str,
gssize length);
+void _vte_debug_hexdump(char const* str,
+ uint8_t const* buf,
+ size_t len);
+
extern guint _vte_debug_flags;
static inline gboolean _vte_debug_on(guint flags) G_GNUC_CONST G_GNUC_UNUSED;
diff --git a/src/vte.cc b/src/vte.cc
index 8b441f80..7546f473 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -3432,6 +3432,11 @@ VteTerminalPrivate::convert_incoming() noexcept
auto inbuf = (char*)buf->data;
size_t inbytes = buf->len;
+ _VTE_DEBUG_IF(VTE_DEBUG_IO) {
+ _vte_debug_hexdump("Incoming buffer before conversion to UTF-8",
+ (uint8_t const*)inbuf, inbytes);
+ }
+
auto unibuf = _vte_byte_array_new();
_vte_byte_array_set_minimum_size(unibuf, VTE_UTF8_BPC * inbytes);
auto outbuf = (char*)unibuf->data;
@@ -3569,6 +3574,10 @@ VteTerminalPrivate::process_incoming()
g_assert_nonnull(chunk.get());
+ _VTE_DEBUG_IF(VTE_DEBUG_IO) {
+ _vte_debug_hexdump("Incoming buffer", chunk->data, chunk->len);
+ }
+
bytes_processed += chunk->len;
auto const* ip = chunk->data;
@@ -4062,15 +4071,9 @@ VteTerminalPrivate::pty_io_write(GIOChannel *channel,
_vte_byte_array_length(m_outgoing));
if (count != -1) {
_VTE_DEBUG_IF (VTE_DEBUG_IO) {
- gssize i;
- for (i = 0; i < count; i++) {
- g_printerr("Wrote %c%c\n",
- ((guint8)m_outgoing->data[i]) >= 32 ?
- ' ' : '^',
- ((guint8)m_outgoing->data[i]) >= 32 ?
- m_outgoing->data[i] :
- ((guint8)m_outgoing->data[i]) + 64);
- }
+ _vte_debug_hexdump("Outgoing buffer written",
+ (uint8_t const*)m_outgoing->data,
+ count);
}
_vte_byte_array_consume(m_outgoing, count);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]