This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
FYI: monitor.c - fix/cleanup monitor_error()
- To: GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Subject: FYI: monitor.c - fix/cleanup monitor_error()
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Mon, 11 Oct 1999 11:33:42 +1000
- Organization: Cygnus Solutions
Hello,
The attatched should fix an un-initialized variable problem in
monitor_error(). At the same time it simplifies the monitor_error()
interface and in the process eliminate an off-by-one error with a "%*s"
fmt string.
Andrew
Thu Oct 7 17:20:01 1999 Andrew Cagney <cagney@amy.cygnus.com>
* monitor.c (monitor_printable_string): Add length argument. Don't
return final string length.
(monitor_printf_noecho, monitor_printf, monitor_expect): Update.
(monitor_error): Pass real_len to monitor_printable_string.
(monitor_error): Rewrite. Replace printf fmt string parameter with
function name and message parameters.
(monitor_read_memory_single, monitor_read_memory): Update.
Index: monitor.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/monitor.c,v
retrieving revision 1.108
diff -p -r1.108 monitor.c
*** monitor.c 1999/10/07 10:41:30 1.108
--- monitor.c 1999/10/11 01:15:46
*************** static int readchar PARAMS ((int timeout
*** 65,72 ****
static void monitor_fetch_register PARAMS ((int regno));
static void monitor_store_register PARAMS ((int regno));
! static int monitor_printable_string PARAMS ((char *newstr, char *oldstr));
! static void monitor_error PARAMS ((char *format, CORE_ADDR memaddr, int len, char *string, int final_char));
static void monitor_detach PARAMS ((char *args, int from_tty));
static void monitor_resume PARAMS ((int pid, int step, enum target_signal sig));
static void monitor_interrupt PARAMS ((int signo));
--- 65,72 ----
static void monitor_fetch_register PARAMS ((int regno));
static void monitor_store_register PARAMS ((int regno));
! static void monitor_printable_string (char *newstr, char *oldstr, int len);
! static void monitor_error (char *function, char *message, CORE_ADDR memaddr, int len, char *string, int final_char);
static void monitor_detach PARAMS ((char *args, int from_tty));
static void monitor_resume PARAMS ((int pid, int step, enum target_signal sig));
static void monitor_interrupt PARAMS ((int signo));
*************** monitor_debug (const char *fmt, ...)
*** 163,181 ****
}
! /* Convert a string into a printable representation, Return # byte in the
! new string. */
! static int
! monitor_printable_string (newstr, oldstr)
! char *newstr;
! char *oldstr;
{
- char *save = newstr;
int ch;
! while ((ch = *oldstr++) != '\0')
{
switch (ch)
{
default:
--- 163,184 ----
}
! /* Convert a string into a printable representation, Return # byte in
! the new string. When LEN is >0 it specifies the size of the
! string. Otherwize strlen(oldstr) is used. */
! static void
! monitor_printable_string (char *newstr, char *oldstr, int len)
{
int ch;
+ int i;
+
+ if (len <= 0)
+ len = strlen (oldstr);
! for (i = 0; i < len; i++)
{
+ ch = oldstr[i];
switch (ch)
{
default:
*************** monitor_printable_string (newstr, oldstr
*** 221,249 ****
}
*newstr++ = '\0';
- return newstr - save;
}
/* Print monitor errors with a string, converting the string to printable
representation. */
static void
! monitor_error (format, memaddr, len, string, final_char)
! char *format;
! CORE_ADDR memaddr;
! int len;
! char *string;
! int final_char;
{
int real_len = (len == 0 && string != (char *) 0) ? strlen (string) : len;
char *safe_string = alloca ((real_len * 4) + 1);
! char *p;
! int safe_len = monitor_printable_string (safe_string, string);
if (final_char)
! error (format, (int) memaddr, p - safe_string, safe_string, final_char);
else
! error (format, (int) memaddr, p - safe_string, safe_string);
}
/* Convert hex digit A to a number. */
--- 224,246 ----
}
*newstr++ = '\0';
}
/* Print monitor errors with a string, converting the string to printable
representation. */
static void
! monitor_error (char *function, char *message,
! CORE_ADDR memaddr, int len, char *string, int final_char)
{
int real_len = (len == 0 && string != (char *) 0) ? strlen (string) : len;
char *safe_string = alloca ((real_len * 4) + 1);
! monitor_printable_string (safe_string, string, real_len);
if (final_char)
! error ("%s (0x%s): %s: %s%c", function, paddr_nz (memaddr), message, safe_string, final_char);
else
! error ("%s (0x%s): %s: %s", function, paddr_nz (memaddr), message, safe_string);
}
/* Convert hex digit A to a number. */
*************** monitor_printf_noecho (char *pattern,...
*** 351,357 ****
if (monitor_debug_p)
{
char *safe_string = (char *) alloca ((strlen (sndbuf) * 4) + 1);
! monitor_printable_string (safe_string, sndbuf);
fprintf_unfiltered (gdb_stdlog, "sent[%s]\n", safe_string);
}
--- 348,354 ----
if (monitor_debug_p)
{
char *safe_string = (char *) alloca ((strlen (sndbuf) * 4) + 1);
! monitor_printable_string (safe_string, sndbuf, 0);
fprintf_unfiltered (gdb_stdlog, "sent[%s]\n", safe_string);
}
*************** monitor_printf (char *pattern,...)
*** 379,385 ****
if (monitor_debug_p)
{
char *safe_string = (char *) alloca ((len * 4) + 1);
! monitor_printable_string (safe_string, sndbuf);
fprintf_unfiltered (gdb_stdlog, "sent[%s]\n", safe_string);
}
--- 376,382 ----
if (monitor_debug_p)
{
char *safe_string = (char *) alloca ((len * 4) + 1);
! monitor_printable_string (safe_string, sndbuf, 0);
fprintf_unfiltered (gdb_stdlog, "sent[%s]\n", safe_string);
}
*************** monitor_expect (string, buf, buflen)
*** 533,539 ****
if (monitor_debug_p)
{
char *safe_string = (char *) alloca ((strlen (string) * 4) + 1);
! monitor_printable_string (safe_string, string);
fprintf_unfiltered (gdb_stdlog, "MON Expecting '%s'\n", safe_string);
}
--- 530,536 ----
if (monitor_debug_p)
{
char *safe_string = (char *) alloca ((strlen (string) * 4) + 1);
! monitor_printable_string (safe_string, string, 0);
fprintf_unfiltered (gdb_stdlog, "MON Expecting '%s'\n", safe_string);
}
*************** monitor_read_memory_single (memaddr, mya
*** 1817,1823 ****
if ((c == '0') && ((c = readchar (timeout)) == 'x'))
;
else
! monitor_error ("monitor_read_memory_single (0x%x): bad response from monitor: %.*s%c.",
memaddr, i, membuf, c);
}
for (i = 0; i < len * 2; i++)
--- 1814,1821 ----
if ((c == '0') && ((c = readchar (timeout)) == 'x'))
;
else
! monitor_error ("monitor_read_memory_single",
! "bad response from monitor",
memaddr, i, membuf, c);
}
for (i = 0; i < len * 2; i++)
*************** monitor_read_memory_single (memaddr, mya
*** 1832,1838 ****
if (c == ' ')
continue;
! monitor_error ("monitor_read_memory_single (0x%x): bad response from monitor: %.*s%c.",
memaddr, i, membuf, c);
}
--- 1830,1837 ----
if (c == ' ')
continue;
! monitor_error ("monitor_read_memory_single",
! "bad response from monitor",
memaddr, i, membuf, c);
}
*************** monitor_read_memory_single (memaddr, mya
*** 1862,1868 ****
val = strtoul (membuf, &p, 16);
if (val == 0 && membuf == p)
! monitor_error ("monitor_read_memory_single (0x%x): bad value from monitor: %s.",
memaddr, 0, membuf, 0);
/* supply register stores in target byte order, so swap here */
--- 1861,1868 ----
val = strtoul (membuf, &p, 16);
if (val == 0 && membuf == p)
! monitor_error ("monitor_read_memory_single",
! "bad value from monitor",
memaddr, 0, membuf, 0);
/* supply register stores in target byte order, so swap here */
*************** monitor_read_memory (memaddr, myaddr, le
*** 1937,1943 ****
resp_len = monitor_expect (current_monitor->getmem.term, buf, sizeof buf); /* get response */
if (resp_len <= 0)
! monitor_error ("monitor_read_memory (0x%x): excessive response from monitor: %.*s.",
memaddr, resp_len, buf, 0);
if (current_monitor->getmem.term_cmd)
--- 1937,1944 ----
resp_len = monitor_expect (current_monitor->getmem.term, buf, sizeof buf); /* get response */
if (resp_len <= 0)
! monitor_error ("monitor_read_memory",
! "excessive response from monitor",
memaddr, resp_len, buf, 0);
if (current_monitor->getmem.term_cmd)
*************** monitor_read_memory (memaddr, myaddr, le
*** 1968,1981 ****
&resp_strings);
if (retval < 0)
! monitor_error ("monitor_read_memory (0x%x): bad response from monitor: %.*s.",
memaddr, resp_len, buf, 0);
p += resp_strings.end[0];
#if 0
p = strstr (p, current_monitor->getmem.resp_delim);
if (!p)
! monitor_error ("monitor_read_memory (0x%x): bad response from monitor: %.*s.",
memaddr, resp_len, buf, 0);
p += strlen (current_monitor->getmem.resp_delim);
#endif
--- 1969,1984 ----
&resp_strings);
if (retval < 0)
! monitor_error ("monitor_read_memory",
! "bad response from monitor",
memaddr, resp_len, buf, 0);
p += resp_strings.end[0];
#if 0
p = strstr (p, current_monitor->getmem.resp_delim);
if (!p)
! monitor_error ("monitor_read_memory",
! "bad response from monitor",
memaddr, resp_len, buf, 0);
p += strlen (current_monitor->getmem.resp_delim);
#endif
*************** monitor_read_memory (memaddr, myaddr, le
*** 2026,2032 ****
break;
if (*p == '\000' || *p == '\n' || *p == '\r')
! monitor_error ("monitor_read_memory (0x%x): badly terminated response from monitor: %.*s",
memaddr, resp_len, buf, 0);
p++;
}
--- 2029,2036 ----
break;
if (*p == '\000' || *p == '\n' || *p == '\r')
! monitor_error ("monitor_read_memory",
! "badly terminated response from monitor",
memaddr, resp_len, buf, 0);
p++;
}
*************** monitor_read_memory (memaddr, myaddr, le
*** 2034,2040 ****
val = strtoul (p, &p1, 16);
if (val == 0 && p == p1)
! monitor_error ("monitor_read_memory (0x%x): bad value from monitor: %.*s.",
memaddr, resp_len, buf, 0);
*myaddr++ = val;
--- 2038,2045 ----
val = strtoul (p, &p1, 16);
if (val == 0 && p == p1)
! monitor_error ("monitor_read_memory",
! "bad value from monitor",
memaddr, resp_len, buf, 0);
*myaddr++ = val;