* 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.
This commit is contained in:
Pedro Alves 2008-11-19 14:45:09 +00:00
parent c91e322a29
commit 6e5abd65ae
3 changed files with 84 additions and 19 deletions

View File

@ -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> 2008-11-18 Paul Pluzhnikov <ppluzhnikov@google.com>
* maint.c (maintenance_translate_address): Fix a buglet. * maint.c (maintenance_translate_address): Fix a buglet.

View File

@ -5847,6 +5847,28 @@ remote_send (char **buf,
error (_("Remote failure reply: %s"), *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 /* Display a null-terminated packet on stdout, for debugging, using C
string notation. */ string notation. */
@ -5919,11 +5941,15 @@ putpkt_binary (char *buf, int cnt)
if (remote_debug) if (remote_debug)
{ {
struct cleanup *old_chain;
char *str;
*p = '\0'; *p = '\0';
fprintf_unfiltered (gdb_stdlog, "Sending packet: "); str = escape_buffer (buf2, p - buf2);
fputstrn_unfiltered (buf2, p - buf2, 0, gdb_stdlog); old_chain = make_cleanup (xfree, str);
fprintf_unfiltered (gdb_stdlog, "..."); fprintf_unfiltered (gdb_stdlog, "Sending packet: %s...", str);
gdb_flush (gdb_stdlog); gdb_flush (gdb_stdlog);
do_cleanups (old_chain);
} }
if (serial_write (remote_desc, buf2, p - buf2)) if (serial_write (remote_desc, buf2, p - buf2))
perror_with_name (_("putpkt: write failed")); perror_with_name (_("putpkt: write failed"));
@ -5997,9 +6023,15 @@ putpkt_binary (char *buf, int cnt)
{ {
if (remote_debug) if (remote_debug)
{ {
fprintf_unfiltered (gdb_stdlog, " Notification received: "); struct cleanup *old_chain;
fputstrn_unfiltered (rs->buf, val, 0, gdb_stdlog); char *str;
fprintf_unfiltered (gdb_stdlog, "\n");
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); handle_notification (rs->buf, val);
/* We're in sync now, rewait for the ack. */ /* We're in sync now, rewait for the ack. */
@ -6163,11 +6195,16 @@ read_frame (char **buf_p,
if (remote_debug) if (remote_debug)
{ {
fprintf_filtered (gdb_stdlog, struct cleanup *old_chain;
"Bad checksum, sentsum=0x%x, csum=0x%x, buf=", char *str;
pktcsum, csum);
fputstrn_filtered (buf, bc, 0, gdb_stdlog); str = escape_buffer (buf, bc);
fputs_filtered ("\n", gdb_stdlog); 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 /* Number of characters in buffer ignoring trailing
NULL. */ NULL. */
@ -6340,9 +6377,13 @@ getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever,
{ {
if (remote_debug) if (remote_debug)
{ {
fprintf_unfiltered (gdb_stdlog, "Packet received: "); struct cleanup *old_chain;
fputstrn_unfiltered (*buf, val, 0, gdb_stdlog); char *str;
fprintf_unfiltered (gdb_stdlog, "\n");
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. */ /* 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) if (remote_debug)
{ {
fprintf_unfiltered (gdb_stdlog, " Notification received: "); struct cleanup *old_chain;
fputstrn_unfiltered (*buf, val, 0, gdb_stdlog); char *str;
fprintf_unfiltered (gdb_stdlog, "\n");
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); handle_notification (*buf, val);

View File

@ -2286,13 +2286,22 @@ vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args)
{ {
struct timeval tm; struct timeval tm;
char *timestamp; char *timestamp;
int len, need_nl;
gettimeofday (&tm, NULL); 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); make_cleanup (xfree, timestamp);
fputs_unfiltered (timestamp, stream); fputs_unfiltered (timestamp, stream);
} }
fputs_unfiltered (linebuffer, stream); else
fputs_unfiltered (linebuffer, stream);
do_cleanups (old_cleanups); do_cleanups (old_cleanups);
} }