2010-05-15 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / monitor.c
index 10e588a9f2dbd0f27ccb3d278c9791ed4eaa20f0..c9df269a3d316639c96a2ba478da4087653a8ce7 100644 (file)
@@ -1,7 +1,8 @@
 /* Remote debugging interface for boot monitors, for GDB.
 
    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+   2000, 2001, 2002, 2006, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.  Written by Rob Savoye for Cygnus.
    Resurrected from the ashes by Stu Grossman.
@@ -118,7 +119,7 @@ static ptid_t monitor_ptid;
 /* Monitor specific debugging information.  Typically only useful to
    the developer of a new monitor interface. */
 
-static void monitor_debug (const char *fmt, ...) ATTR_FORMAT(printf, 1, 2);
+static void monitor_debug (const char *fmt, ...) ATTRIBUTE_PRINTF (1, 2);
 
 static int monitor_debug_p = 0;
 
@@ -132,6 +133,7 @@ monitor_debug (const char *fmt, ...)
   if (monitor_debug_p)
     {
       va_list args;
+
       va_start (args, fmt);
       vfprintf_filtered (gdb_stdlog, fmt, args);
       va_end (args);
@@ -211,12 +213,17 @@ monitor_error (char *function, char *message,
 {
   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);
+    error (_("%s (%s): %s: %s%c"),
+          function, paddress (target_gdbarch, memaddr),
+          message, safe_string, final_char);
   else
-    error (_("%s (0x%s): %s: %s"), function, paddr_nz (memaddr), message, safe_string);
+    error (_("%s (%s): %s: %s"),
+          function, paddress (target_gdbarch, memaddr),
+          message, safe_string);
 }
 
 /* Convert hex digit A to a number.  */
@@ -251,6 +258,7 @@ fromhex (int a)
 static void
 monitor_vsprintf (char *sndbuf, char *pattern, va_list args)
 {
+  int addr_bit = gdbarch_addr_bit (target_gdbarch);
   char format[10];
   char fmt;
   char *p;
@@ -279,7 +287,7 @@ monitor_vsprintf (char *sndbuf, char *pattern, va_list args)
              break;
            case 'A':
              arg_addr = va_arg (args, CORE_ADDR);
-             strcpy (sndbuf, paddr_nz (arg_addr));
+             strcpy (sndbuf, phex_nz (arg_addr, addr_bit / 8));
              break;
            case 's':
              arg_string = va_arg (args, char *);
@@ -320,6 +328,7 @@ monitor_printf_noecho (char *pattern,...)
   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);
     }
@@ -348,6 +357,7 @@ monitor_printf (char *pattern,...)
   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);
     }
@@ -431,6 +441,7 @@ readchar (int timeout)
          if (monitor_debug_p || remote_debug)
            {
              char buf[2];
+
              buf[0] = c;
              buf[1] = '\0';
              puts_debug ("read -->", buf, "<--");
@@ -588,6 +599,7 @@ monitor_expect_regexp (struct re_pattern_buffer *pat, char *buf, int buflen)
 {
   char *mybuf;
   char *p;
+
   monitor_debug ("MON Expecting regexp\n");
   if (buf)
     mybuf = buf;
@@ -700,6 +712,7 @@ monitor_open (char *args, struct monitor_ops *mon_ops, int from_tty)
 {
   char *name;
   char **p;
+  struct inferior *inf;
 
   if (mon_ops->magic != MONITOR_OPS_MAGIC)
     error (_("Magic number of monitor_ops struct wrong."));
@@ -817,7 +830,8 @@ monitor_open (char *args, struct monitor_ops *mon_ops, int from_tty)
 
   /* Make run command think we are busy...  */
   inferior_ptid = monitor_ptid;
-  add_inferior_silent (ptid_get_pid (inferior_ptid));
+  inf = current_inferior ();
+  inferior_appeared (inf, ptid_get_pid (inferior_ptid));
   add_thread_silent (inferior_ptid);
 
   /* Give monitor_wait something to read */
@@ -865,6 +879,8 @@ monitor_detach (struct target_ops *ops, char *args, int from_tty)
 char *
 monitor_supply_register (struct regcache *regcache, int regno, char *valstr)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   ULONGEST val;
   unsigned char regbuf[MAX_REGISTER_SIZE];
   char *p;
@@ -900,8 +916,7 @@ monitor_supply_register (struct regcache *regcache, int regno, char *valstr)
 
   /* supply register stores in target byte order, so swap here */
 
-  store_unsigned_integer (regbuf,
-                         register_size (get_regcache_arch (regcache), regno),
+  store_unsigned_integer (regbuf, register_size (gdbarch, regno), byte_order,
                          val);
 
   regcache_raw_supply (regcache, regno, regbuf);
@@ -951,6 +966,7 @@ parse_register_dump (struct regcache *regcache, char *buf, int len)
     {
       int regnamelen, vallen;
       char *regname, *val;
+
       /* Element 0 points to start of register name, and element 1
          points to the start of the register value.  */
       struct re_registers register_strings;
@@ -1035,6 +1051,7 @@ monitor_wait_filter (char *buf,
                     struct target_waitstatus *status)
 {
   int resp_len;
+
   do
     {
       resp_len = monitor_expect_prompt (buf, bufmax);
@@ -1197,6 +1214,7 @@ monitor_fetch_register (struct regcache *regcache, int regno)
   if (current_monitor->flags & MO_HEX_PREFIX)
     {
       int c;
+
       c = readchar (timeout);
       while (c == ' ')
        c = readchar (timeout);
@@ -1214,6 +1232,7 @@ monitor_fetch_register (struct regcache *regcache, int regno)
   for (i = 0; i < register_size (get_regcache_arch (regcache), regno) * 2; i++)
     {
       int c;
+
       c = readchar (timeout);
       while (c == ' ')
        c = readchar (timeout);
@@ -1259,6 +1278,7 @@ monitor_dump_reg_block (struct regcache *regcache, char *block_cmd)
 {
   char buf[TARGET_BUF_SIZE];
   int resp_len;
+
   monitor_printf (block_cmd);
   resp_len = monitor_expect_prompt (buf, sizeof (buf));
   parse_register_dump (regcache, buf, resp_len);
@@ -1274,6 +1294,7 @@ monitor_dump_regs (struct regcache *regcache)
 {
   char buf[TARGET_BUF_SIZE];
   int resp_len;
+
   if (current_monitor->dumpregs)
     (*(current_monitor->dumpregs)) (regcache); /* call supplied function */
   else if (current_monitor->dump_registers)    /* default version */
@@ -1314,6 +1335,7 @@ monitor_fetch_registers (struct target_ops *ops,
 static void
 monitor_store_register (struct regcache *regcache, int regno)
 {
+  int reg_size = register_size (get_regcache_arch (regcache), regno);
   const char *name;
   ULONGEST val;
   
@@ -1329,9 +1351,7 @@ monitor_store_register (struct regcache *regcache, int regno)
     }
 
   regcache_cooked_read_unsigned (regcache, regno, &val);
-  monitor_debug ("MON storeg %d %s\n", regno,
-                phex (val,
-                      register_size (get_regcache_arch (regcache), regno)));
+  monitor_debug ("MON storeg %d %s\n", regno, phex (val, reg_size));
 
   /* send the register deposit command */
 
@@ -1347,14 +1367,14 @@ monitor_store_register (struct regcache *regcache, int regno)
       monitor_debug ("EXP setreg.resp_delim\n");
       monitor_expect_regexp (&setreg_resp_delim_pattern, NULL, 0);
       if (current_monitor->flags & MO_SETREG_INTERACTIVE)
-       monitor_printf ("%s\r", paddr_nz (val));
+       monitor_printf ("%s\r", phex_nz (val, reg_size));
     }
   if (current_monitor->setreg.term)
     {
       monitor_debug ("EXP setreg.term\n");
       monitor_expect (current_monitor->setreg.term, NULL, 0);
       if (current_monitor->flags & MO_SETREG_INTERACTIVE)
-       monitor_printf ("%s\r", paddr_nz (val));
+       monitor_printf ("%s\r", phex_nz (val, reg_size));
       monitor_expect_prompt (NULL, 0);
     }
   else
@@ -1405,11 +1425,12 @@ monitor_files_info (struct target_ops *ops)
 static int
 monitor_write_memory (CORE_ADDR memaddr, char *myaddr, int len)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
   unsigned int val, hostval;
   char *cmd;
   int i;
 
-  monitor_debug ("MON write %d %s\n", len, paddr (memaddr));
+  monitor_debug ("MON write %d %s\n", len, paddress (target_gdbarch, memaddr));
 
   if (current_monitor->flags & MO_ADDR_BITS_REMOVE)
     memaddr = gdbarch_addr_bits_remove (target_gdbarch, memaddr);
@@ -1461,7 +1482,7 @@ monitor_write_memory (CORE_ADDR memaddr, char *myaddr, int len)
       cmd = current_monitor->setmem.cmdb;
     }
 
-  val = extract_unsigned_integer (myaddr, len);
+  val = extract_unsigned_integer (myaddr, len, byte_order);
 
   if (len == 4)
     {
@@ -1474,7 +1495,6 @@ monitor_write_memory (CORE_ADDR memaddr, char *myaddr, int len)
     monitor_printf_noecho (cmd, memaddr, val);
   else if (current_monitor->flags & MO_SETMEM_INTERACTIVE)
     {
-
       monitor_printf_noecho (cmd, memaddr);
 
       if (current_monitor->setmem.resp_delim)
@@ -1490,7 +1510,7 @@ monitor_write_memory (CORE_ADDR memaddr, char *myaddr, int len)
          monitor_printf ("%x\r", val);
        }
       if (current_monitor->setmem.term_cmd)
-       {                       /* Emit this to get out of the memory editing state */
+       {       /* Emit this to get out of the memory editing state */
          monitor_printf ("%s", current_monitor->setmem.term_cmd);
          /* Drop through to expecting a prompt */
        }
@@ -1509,6 +1529,7 @@ monitor_write_memory_bytes (CORE_ADDR memaddr, char *myaddr, int len)
 {
   unsigned char val;
   int written = 0;
+
   if (len == 0)
     return 0;
   /* Enter the sub mode */
@@ -1537,6 +1558,7 @@ longlongendswap (unsigned char *a)
 {
   int i, j;
   unsigned char x;
+
   i = 0;
   j = 7;
   while (i < 4)
@@ -1564,10 +1586,12 @@ longlong_hexchars (unsigned long long value,
       unsigned char *scan, *limit;     /* loop controls */
       unsigned char c, nib;
       int leadzero = 1;
+
       scan = disbuf;
       limit = scan + 8;
       {
        unsigned long long *dp;
+
        dp = (unsigned long long *) scan;
        *dp = value;
       }
@@ -1604,6 +1628,7 @@ monitor_write_memory_longlongs (CORE_ADDR memaddr, char *myaddr, int len)
   long long *llptr;
   long long value;
   int written = 0;
+
   llptr = (unsigned long long *) myaddr;
   if (len == 0)
     return 0;
@@ -1648,6 +1673,7 @@ static int
 monitor_write_memory_block (CORE_ADDR memaddr, char *myaddr, int len)
 {
   int written;
+
   written = 0;
   /* FIXME: This would be a good place to put the zero test */
 #if 1
@@ -1666,6 +1692,7 @@ monitor_write_memory_block (CORE_ADDR memaddr, char *myaddr, int len)
 static int
 monitor_read_memory_single (CORE_ADDR memaddr, char *myaddr, int len)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
   unsigned int val;
   char membuf[sizeof (int) * 2 + 1];
   char *p;
@@ -1734,6 +1761,7 @@ monitor_read_memory_single (CORE_ADDR memaddr, char *myaddr, int len)
 
   {
     int i;
+
     for (i = 0; i < len * 2; i++)
       {
        int c;
@@ -1782,7 +1810,7 @@ monitor_read_memory_single (CORE_ADDR memaddr, char *myaddr, int len)
 
   /* supply register stores in target byte order, so swap here */
 
-  store_unsigned_integer (myaddr, len, val);
+  store_unsigned_integer (myaddr, len, byte_order, val);
 
   return len;
 }
@@ -1808,7 +1836,7 @@ monitor_read_memory (CORE_ADDR memaddr, char *myaddr, int len)
     }
 
   monitor_debug ("MON read block ta(%s) ha(%lx) %d\n",
-                paddr_nz (memaddr), (long) myaddr, len);
+                paddress (target_gdbarch, memaddr), (long) myaddr, len);
 
   if (current_monitor->flags & MO_ADDR_BITS_REMOVE)
     memaddr = gdbarch_addr_bits_remove (target_gdbarch, memaddr);
@@ -1873,6 +1901,7 @@ monitor_read_memory (CORE_ADDR memaddr, char *myaddr, int len)
     {
       int retval, tmp;
       struct re_registers resp_strings;
+
       monitor_debug ("MON getmem.resp_delim %s\n", current_monitor->getmem.resp_delim);
 
       memset (&resp_strings, 0, sizeof (struct re_registers));
@@ -2027,21 +2056,22 @@ monitor_mourn_inferior (struct target_ops *ops)
 /* Tell the monitor to add a breakpoint.  */
 
 static int
-monitor_insert_breakpoint (struct bp_target_info *bp_tgt)
+monitor_insert_breakpoint (struct gdbarch *gdbarch,
+                          struct bp_target_info *bp_tgt)
 {
   CORE_ADDR addr = bp_tgt->placed_address;
   int i;
   int bplen;
 
-  monitor_debug ("MON inst bkpt %s\n", paddr (addr));
+  monitor_debug ("MON inst bkpt %s\n", paddress (gdbarch, addr));
   if (current_monitor->set_break == NULL)
     error (_("No set_break defined for this monitor"));
 
   if (current_monitor->flags & MO_ADDR_BITS_REMOVE)
-    addr = gdbarch_addr_bits_remove (current_gdbarch, addr);
+    addr = gdbarch_addr_bits_remove (gdbarch, addr);
 
   /* Determine appropriate breakpoint size for this address.  */
-  gdbarch_breakpoint_from_pc (current_gdbarch, &addr, &bplen);
+  gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
   bp_tgt->placed_address = addr;
   bp_tgt->placed_size = bplen;
 
@@ -2062,12 +2092,13 @@ monitor_insert_breakpoint (struct bp_target_info *bp_tgt)
 /* Tell the monitor to remove a breakpoint.  */
 
 static int
-monitor_remove_breakpoint (struct bp_target_info *bp_tgt)
+monitor_remove_breakpoint (struct gdbarch *gdbarch,
+                          struct bp_target_info *bp_tgt)
 {
   CORE_ADDR addr = bp_tgt->placed_address;
   int i;
 
-  monitor_debug ("MON rmbkpt %s\n", paddr (addr));
+  monitor_debug ("MON rmbkpt %s\n", paddress (gdbarch, addr));
   if (current_monitor->clr_break == NULL)
     error (_("No clr_break defined for this monitor"));
 
@@ -2088,8 +2119,8 @@ monitor_remove_breakpoint (struct bp_target_info *bp_tgt)
        }
     }
   fprintf_unfiltered (gdb_stderr,
-                     "Can't find breakpoint associated with 0x%s\n",
-                     paddr_nz (addr));
+                     "Can't find breakpoint associated with %s\n",
+                     paddress (gdbarch, addr));
   return 1;
 }
 
This page took 0.042171 seconds and 4 git commands to generate.