Fix powerpc-power8.exp test with new mnemonics
[deliverable/binutils-gdb.git] / gdb / frame.c
index fed58717c95d4dc7500917f6bbc4803eb00e1c78..d2e14c831a09a3e03333ed7b75ad8bdcc3f4cd2f 100644 (file)
@@ -373,43 +373,44 @@ show_backtrace_limit (struct ui_file *file, int from_tty,
                    value);
 }
 
+/* See frame.h.  */
 
-static void
-fprint_field (struct ui_file *file, const char *name, int p, CORE_ADDR addr)
+std::string
+frame_id::to_string () const
 {
-  if (p)
-    fprintf_unfiltered (file, "%s=%s", name, hex_string (addr));
-  else
-    fprintf_unfiltered (file, "!%s", name);
-}
+  const struct frame_id &id = *this;
 
-void
-fprint_frame_id (struct ui_file *file, struct frame_id id)
-{
-  fprintf_unfiltered (file, "{");
+  std::string res = "{";
 
   if (id.stack_status == FID_STACK_INVALID)
-    fprintf_unfiltered (file, "!stack");
+    res += "!stack";
   else if (id.stack_status == FID_STACK_UNAVAILABLE)
-    fprintf_unfiltered (file, "stack=<unavailable>");
+    res += "stack=<unavailable>";
   else if (id.stack_status == FID_STACK_SENTINEL)
-    fprintf_unfiltered (file, "stack=<sentinel>");
+    res += "stack=<sentinel>";
   else if (id.stack_status == FID_STACK_OUTER)
-    fprintf_unfiltered (file, "stack=<outer>");
+    res += "stack=<outer>";
   else
-    fprintf_unfiltered (file, "stack=%s", hex_string (id.stack_addr));
-
-  fprintf_unfiltered (file, ",");
+    res += std::string ("stack=") + hex_string (id.stack_addr);
 
-  fprint_field (file, "code", id.code_addr_p, id.code_addr);
-  fprintf_unfiltered (file, ",");
+  /* Helper function to format 'N=A' if P is true, otherwise '!N'.  */
+  auto field_to_string = [] (const char *n, bool p, CORE_ADDR a) -> std::string
+  {
+    if (p)
+      return std::string (n) + "=" + core_addr_to_string (a);
+    else
+      return std::string ("!") + std::string (n);
+  };
 
-  fprint_field (file, "special", id.special_addr_p, id.special_addr);
+  res += (std::string (",")
+         + field_to_string ("code", id.code_addr_p, id.code_addr)
+         + std::string (",")
+         + field_to_string ("special", id.special_addr_p, id.special_addr));
 
   if (id.artificial_depth)
-    fprintf_unfiltered (file, ",artificial=%d", id.artificial_depth);
-
-  fprintf_unfiltered (file, "}");
+    res += ",artificial=" + std::to_string (id.artificial_depth);
+  res += "}";
+  return res;
 }
 
 static void
@@ -492,7 +493,7 @@ fprint_frame (struct ui_file *file, struct frame_info *fi)
   else if (fi->this_id.p == frame_id_status::COMPUTING)
     fprintf_unfiltered (file, "<computing>");
   else
-    fprint_frame_id (file, fi->this_id.value);
+    fprintf_unfiltered (file, "%s", fi->this_id.value.to_string ().c_str ());
   fprintf_unfiltered (file, ",");
 
   fprintf_unfiltered (file, "func=");
@@ -592,11 +593,8 @@ compute_frame_id (struct frame_info *fi)
       fi->this_id.p = frame_id_status::COMPUTED;
 
       if (frame_debug)
-       {
-         fprintf_unfiltered (gdb_stdlog, "-> ");
-         fprint_frame_id (gdb_stdlog, fi->this_id.value);
-         fprintf_unfiltered (gdb_stdlog, " }\n");
-       }
+       fprintf_unfiltered (gdb_stdlog, "-> %s }\n",
+                           fi->this_id.value.to_string ().c_str ());
     }
   catch (const gdb_exception &ex)
     {
@@ -748,11 +746,8 @@ frame_id_p (frame_id l)
   bool p = l.stack_status != FID_STACK_INVALID;
 
   if (frame_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog, "{ frame_id_p (l=");
-      fprint_frame_id (gdb_stdlog, l);
-      fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", p);
-    }
+    fprintf_unfiltered (gdb_stdlog, "{ frame_id_p (l=%s) -> %d }\n",
+                       l.to_string ().c_str (), p);
 
   return p;
 }
@@ -796,13 +791,8 @@ frame_id_eq (frame_id l, frame_id r)
     eq = true;
 
   if (frame_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog, "{ frame_id_eq (l=");
-      fprint_frame_id (gdb_stdlog, l);
-      fprintf_unfiltered (gdb_stdlog, ",r=");
-      fprint_frame_id (gdb_stdlog, r);
-      fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", eq);
-    }
+    fprintf_unfiltered (gdb_stdlog, "{ frame_id_eq (l=%s,r=%s) -> %d }\n",
+                       l.to_string ().c_str (), r.to_string ().c_str (), eq);
 
   return eq;
 }
@@ -879,13 +869,9 @@ frame_id_inner (struct gdbarch *gdbarch, struct frame_id l, struct frame_id r)
     inner = gdbarch_inner_than (gdbarch, l.stack_addr, r.stack_addr);
 
   if (frame_debug)
-    {
-      fprintf_unfiltered (gdb_stdlog, "{ frame_id_inner (l=");
-      fprint_frame_id (gdb_stdlog, l);
-      fprintf_unfiltered (gdb_stdlog, ",r=");
-      fprint_frame_id (gdb_stdlog, r);
-      fprintf_unfiltered (gdb_stdlog, ") -> %d }\n", inner);
-    }
+    fprintf_unfiltered (gdb_stdlog, "{ frame_id_inner (l=%s,r=%s) -> %d }\n",
+                       l.to_string ().c_str (), r.to_string ().c_str (),
+                       inner);
 
   return inner;
 }
@@ -1469,7 +1455,8 @@ deprecated_frame_register_read (frame_info *frame, int regnum,
 
 bool
 get_frame_register_bytes (frame_info *frame, int regnum,
-                         CORE_ADDR offset, int len, gdb_byte *myaddr,
+                         CORE_ADDR offset,
+                         gdb::array_view<gdb_byte> buffer,
                          int *optimizedp, int *unavailablep)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
@@ -1496,6 +1483,8 @@ get_frame_register_bytes (frame_info *frame, int regnum,
        break;  /* This register is not available on this architecture.  */
       maxsize += thissize;
     }
+
+  int len = buffer.size ();
   if (len > maxsize)
     error (_("Bad debug information detected: "
             "Attempt to read %d bytes from registers."), len);
@@ -1508,6 +1497,8 @@ get_frame_register_bytes (frame_info *frame, int regnum,
       if (curr_len > len)
        curr_len = len;
 
+      gdb_byte *myaddr = buffer.data ();
+
       if (curr_len == register_size (gdbarch, regnum))
        {
          enum lval_type lval;
@@ -1551,7 +1542,8 @@ get_frame_register_bytes (frame_info *frame, int regnum,
 
 void
 put_frame_register_bytes (struct frame_info *frame, int regnum,
-                         CORE_ADDR offset, int len, const gdb_byte *myaddr)
+                         CORE_ADDR offset,
+                         gdb::array_view<const gdb_byte> buffer)
 {
   struct gdbarch *gdbarch = get_frame_arch (frame);
 
@@ -1562,6 +1554,7 @@ put_frame_register_bytes (struct frame_info *frame, int regnum,
       regnum++;
     }
 
+  int len = buffer.size ();
   /* Copy the data.  */
   while (len > 0)
     {
@@ -1570,6 +1563,7 @@ put_frame_register_bytes (struct frame_info *frame, int regnum,
       if (curr_len > len)
        curr_len = len;
 
+      const gdb_byte *myaddr = buffer.data ();
       if (curr_len == register_size (gdbarch, regnum))
        {
          put_frame_register (frame, regnum, myaddr);
@@ -2470,9 +2464,8 @@ inside_main_func (frame_info *this_frame)
 
   /* Convert any function descriptor addresses into the actual function
      code address.  */
-  sym_addr
-    = gdbarch_convert_from_func_ptr_addr (get_frame_arch (this_frame),
-                                         sym_addr, current_top_target ());
+  sym_addr = gdbarch_convert_from_func_ptr_addr
+    (get_frame_arch (this_frame), sym_addr, current_inferior ()->top_target ());
 
   return sym_addr == get_frame_func (this_frame);
 }
@@ -2891,9 +2884,9 @@ get_frame_address_space (struct frame_info *frame)
 
 void
 get_frame_memory (struct frame_info *this_frame, CORE_ADDR addr,
-                 gdb_byte *buf, int len)
+                 gdb::array_view<gdb_byte> buffer)
 {
-  read_memory (addr, buf, len);
+  read_memory (addr, buffer.data (), buffer.size ());
 }
 
 LONGEST
@@ -2918,10 +2911,10 @@ get_frame_memory_unsigned (struct frame_info *this_frame, CORE_ADDR addr,
 
 bool
 safe_frame_unwind_memory (struct frame_info *this_frame,
-                         CORE_ADDR addr, gdb_byte *buf, int len)
+                         CORE_ADDR addr, gdb::array_view<gdb_byte> buffer)
 {
   /* NOTE: target_read_memory returns zero on success!  */
-  return target_read_memory (addr, buf, len) == 0;
+  return target_read_memory (addr, buffer.data (), buffer.size ()) == 0;
 }
 
 /* Architecture methods.  */
@@ -3172,17 +3165,18 @@ _initialize_frame ()
 
   frame_stash_create ();
 
-  gdb::observers::target_changed.attach (frame_observer_target_changed);
+  gdb::observers::target_changed.attach (frame_observer_target_changed,
+                                        "frame");
 
   add_basic_prefix_cmd ("backtrace", class_maintenance, _("\
 Set backtrace specific variables.\n\
 Configure backtrace variables such as the backtrace limit"),
-                       &set_backtrace_cmdlist, "set backtrace ",
+                       &set_backtrace_cmdlist,
                        0/*allow-unknown*/, &setlist);
   add_show_prefix_cmd ("backtrace", class_maintenance, _("\
 Show backtrace specific variables.\n\
 Show backtrace variables such as the backtrace limit."),
-                      &show_backtrace_cmdlist, "show backtrace ",
+                      &show_backtrace_cmdlist,
                       0/*allow-unknown*/, &showlist);
 
   add_setshow_uinteger_cmd ("limit", class_obscure,
This page took 0.028689 seconds and 4 git commands to generate.