aboutsummaryrefslogtreecommitdiff
path: root/src/helper/log.c
diff options
context:
space:
mode:
authorJan Matyas <matyas@codasip.com>2021-05-21 08:02:29 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2021-06-04 17:43:26 +0100
commit49820b8afd150af8df3c02c717d86b8d2cdf7cad (patch)
tree6cfa248fc02c155239b8c04f5a127ee02bd95f4f /src/helper/log.c
parenta8d3f601136ccfe446041631cb46a62922f46bca (diff)
downloadriscv-openocd-49820b8afd150af8df3c02c717d86b8d2cdf7cad.zip
riscv-openocd-49820b8afd150af8df3c02c717d86b8d2cdf7cad.tar.gz
riscv-openocd-49820b8afd150af8df3c02c717d86b8d2cdf7cad.tar.bz2
gdb_server: Log both incoming and outgoing GDB packets
- Made sure that also outgoing GDB packets are logged, not only the incoming ones. - Improved the treatment of non-printable characters in the packets to make it more robust. Prior to this change: - Outgoing packets were not printed unless OpenOCD was re-compiled with _DEBUG_GDB_IO_. - Non-prinable characters were only treated in incoming 'X' packets. After this change: - Both incoming and outgoing GDB packets are logged on debug_level >= 3, so that both directions of the GDB channel are visible. - Non-printable characters are checked for in every packet so that hey do not interfere with the terminal. Change-Id: I0613e57ae5059b3279b0abcb71276cf5719a8699 Signed-off-by: Jan Matyas <matyas@codasip.com> Reviewed-on: http://openocd.zylin.com/6269 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src/helper/log.c')
-rw-r--r--src/helper/log.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/helper/log.c b/src/helper/log.c
index f5a8062..36b59fe 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -518,3 +518,16 @@ void log_socket_error(const char *socket_desc)
LOG_ERROR("Error on socket '%s': errno==%d, message: %s.", socket_desc, error_code, strerror(error_code));
#endif
}
+
+/**
+ * Find the first non-printable character in the char buffer, return a pointer to it.
+ * If no such character exists, return NULL.
+ */
+char *find_nonprint_char(char *buf, unsigned buf_len)
+{
+ for (unsigned int i = 0; i < buf_len; i++) {
+ if (!isprint(buf[i]))
+ return buf + i;
+ }
+ return NULL;
+}