aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2008-11-19 14:45:09 +0000
committerPedro Alves <palves@redhat.com>2008-11-19 14:45:09 +0000
commit6e5abd65ae1e883e278d29249784d3bb225c6912 (patch)
tree3d2ab38cbce3d9f84b33a01a4811bf9b0e205449 /gdb
parentc91e322a293ce2af9687b5926bb45b1de83e4b13 (diff)
downloadgdb-6e5abd65ae1e883e278d29249784d3bb225c6912.zip
gdb-6e5abd65ae1e883e278d29249784d3bb225c6912.tar.gz
gdb-6e5abd65ae1e883e278d29249784d3bb225c6912.tar.bz2
* remote.c (escape_buffer): New.
(putpkt_binary, read_frame, getpkt_or_notif_sane_1): Use it. Make sure debug output printing a packet buffer goes through a single fprintf_unfiltered call. * utils.c (vfprintf_unfiltered): If outputting timestamps, end output with a newline if it wasn't going to already.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog9
-rw-r--r--gdb/remote.c81
-rw-r--r--gdb/utils.c13
3 files changed, 84 insertions, 19 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 90599b6..4b2f540 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2008-11-19 Pedro Alves <pedro@codesourcery.com>
+
+ * remote.c (escape_buffer): New.
+ (putpkt_binary, read_frame, getpkt_or_notif_sane_1): Use it. Make
+ sure debug output printing a packet buffer goes through a single
+ fprintf_unfiltered call.
+ * utils.c (vfprintf_unfiltered): If outputting timestamps, end
+ output with a newline if it wasn't going to already.
+
2008-11-18 Paul Pluzhnikov <ppluzhnikov@google.com>
* maint.c (maintenance_translate_address): Fix a buglet.
diff --git a/gdb/remote.c b/gdb/remote.c
index 5cb36b8..4580c77 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -5847,6 +5847,28 @@ remote_send (char **buf,
error (_("Remote failure reply: %s"), *buf);
}
+/* Return a pointer to an xmalloc'ed string representing an escaped
+ version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t,
+ etc. The caller is responsible for releasing the returned
+ memory. */
+
+static char *
+escape_buffer (const char *buf, int n)
+{
+ struct cleanup *old_chain;
+ struct ui_file *stb;
+ char *str;
+ long length;
+
+ stb = mem_fileopen ();
+ old_chain = make_cleanup_ui_file_delete (stb);
+
+ fputstrn_unfiltered (buf, n, 0, stb);
+ str = ui_file_xstrdup (stb, &length);
+ do_cleanups (old_chain);
+ return str;
+}
+
/* Display a null-terminated packet on stdout, for debugging, using C
string notation. */
@@ -5919,11 +5941,15 @@ putpkt_binary (char *buf, int cnt)
if (remote_debug)
{
+ struct cleanup *old_chain;
+ char *str;
+
*p = '\0';
- fprintf_unfiltered (gdb_stdlog, "Sending packet: ");
- fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog);
- fprintf_unfiltered (gdb_stdlog, "...");
+ str = escape_buffer (buf2, p - buf2);
+ old_chain = make_cleanup (xfree, str);
+ fprintf_unfiltered (gdb_stdlog, "Sending packet: %s...", str);
gdb_flush (gdb_stdlog);
+ do_cleanups (old_chain);
}
if (serial_write (remote_desc, buf2, p - buf2))
perror_with_name (_("putpkt: write failed"));
@@ -5997,9 +6023,15 @@ putpkt_binary (char *buf, int cnt)
{
if (remote_debug)
{
- fprintf_unfiltered (gdb_stdlog, " Notification received: ");
- fputstrn_unfiltered (rs->buf, val, 0, gdb_stdlog);
- fprintf_unfiltered (gdb_stdlog, "\n");
+ struct cleanup *old_chain;
+ char *str;
+
+ str = escape_buffer (rs->buf, val);
+ old_chain = make_cleanup (xfree, str);
+ fprintf_unfiltered (gdb_stdlog,
+ " Notification received: %s\n",
+ str);
+ do_cleanups (old_chain);
}
handle_notification (rs->buf, val);
/* We're in sync now, rewait for the ack. */
@@ -6163,11 +6195,16 @@ read_frame (char **buf_p,
if (remote_debug)
{
- fprintf_filtered (gdb_stdlog,
- "Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
- pktcsum, csum);
- fputstrn_filtered (buf, bc, 0, gdb_stdlog);
- fputs_filtered ("\n", gdb_stdlog);
+ struct cleanup *old_chain;
+ char *str;
+
+ str = escape_buffer (buf, bc);
+ old_chain = make_cleanup (xfree, str);
+ fprintf_unfiltered (gdb_stdlog,
+ "\
+Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
+ pktcsum, csum, str);
+ do_cleanups (old_chain);
}
/* Number of characters in buffer ignoring trailing
NULL. */
@@ -6340,9 +6377,13 @@ getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever,
{
if (remote_debug)
{
- fprintf_unfiltered (gdb_stdlog, "Packet received: ");
- fputstrn_unfiltered (*buf, val, 0, gdb_stdlog);
- fprintf_unfiltered (gdb_stdlog, "\n");
+ struct cleanup *old_chain;
+ char *str;
+
+ str = escape_buffer (*buf, val);
+ old_chain = make_cleanup (xfree, str);
+ fprintf_unfiltered (gdb_stdlog, "Packet received: %s\n", str);
+ do_cleanups (old_chain);
}
/* Skip the ack char if we're in no-ack mode. */
@@ -6359,9 +6400,15 @@ getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever,
if (remote_debug)
{
- fprintf_unfiltered (gdb_stdlog, " Notification received: ");
- fputstrn_unfiltered (*buf, val, 0, gdb_stdlog);
- fprintf_unfiltered (gdb_stdlog, "\n");
+ struct cleanup *old_chain;
+ char *str;
+
+ str = escape_buffer (*buf, val);
+ old_chain = make_cleanup (xfree, str);
+ fprintf_unfiltered (gdb_stdlog,
+ " Notification received: %s\n",
+ str);
+ do_cleanups (old_chain);
}
handle_notification (*buf, val);
diff --git a/gdb/utils.c b/gdb/utils.c
index fed2e7e..d14009f 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -2286,13 +2286,22 @@ vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args)
{
struct timeval tm;
char *timestamp;
+ int len, need_nl;
gettimeofday (&tm, NULL);
- timestamp = xstrprintf ("%ld:%ld ", (long) tm.tv_sec, (long) tm.tv_usec);
+
+ len = strlen (linebuffer);
+ need_nl = (len > 0 && linebuffer[len - 1] != '\n');
+
+ timestamp = xstrprintf ("%ld:%ld %s%s",
+ (long) tm.tv_sec, (long) tm.tv_usec,
+ linebuffer,
+ need_nl ? "\n": "");
make_cleanup (xfree, timestamp);
fputs_unfiltered (timestamp, stream);
}
- fputs_unfiltered (linebuffer, stream);
+ else
+ fputs_unfiltered (linebuffer, stream);
do_cleanups (old_cleanups);
}