]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: replace fprint_frame_id
authorAndrew Burgess <andrew.burgess@embecosm.com>
Sat, 8 May 2021 14:43:56 +0000 (15:43 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Sun, 9 May 2021 15:50:15 +0000 (16:50 +0100)
Replace fprint_frame_id with a member function frame_id::to_string
that returns a std::string.  Convert all of the previous users of
fprint_frame_id to use the new member function.  This means that
instead of writing things like this:

  fprintf_unfiltered (file, " id=");
  fprint_frame_id (file, s->id.id);

We can write this:

  fprintf_unfiltered (file, " id=%s", s->id.id.to_string ().c_str ());

There should be no user visible changes after this commit.

gdb/ChangeLog:

* dummy-frame.c (fprint_dummy_frames): Convert use of
fprint_frame_id to use frame_id::to_string.
* frame.c (fprint_field): Delete.
(fprint_frame_id): Moved to...
(frame_id::to_string): ...this, rewritten to return a string.
(fprint_frame): Convert use of fprint_frame_id to use
frame_id::to_string.
(compute_frame_id): Likewise.
(frame_id_p): Likewise.
(frame_id_eq): Likewise.
(frame_id_inner): Likewise.
* frame.h (struct frame_id) <to_string>: New member function.
(fprint_frame_id): Delete declaration.
* guile/scm-frame.c (frscm_print_frame_smob): Convert use of
fprint_frame_id to use frame_id::to_string.
* python/py-frame.c (frame_object_to_frame_info): Likewise.
* python/py-unwind.c (unwind_infopy_str): Likewise.
(pyuw_this_id): Likewise.

gdb/ChangeLog
gdb/dummy-frame.c
gdb/frame.c
gdb/frame.h
gdb/guile/scm-frame.c
gdb/python/py-frame.c
gdb/python/py-unwind.c

index 75e344ff7073d3f843beeee0ff72587b9bdb459a..23710bc7bad2d9c42a803037f0e466c74dd2f8c3 100644 (file)
@@ -1,3 +1,24 @@
+2021-05-09  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * dummy-frame.c (fprint_dummy_frames): Convert use of
+       fprint_frame_id to use frame_id::to_string.
+       * frame.c (fprint_field): Delete.
+       (fprint_frame_id): Moved to...
+       (frame_id::to_string): ...this, rewritten to return a string.
+       (fprint_frame): Convert use of fprint_frame_id to use
+       frame_id::to_string.
+       (compute_frame_id): Likewise.
+       (frame_id_p): Likewise.
+       (frame_id_eq): Likewise.
+       (frame_id_inner): Likewise.
+       * frame.h (struct frame_id) <to_string>: New member function.
+       (fprint_frame_id): Delete declaration.
+       * guile/scm-frame.c (frscm_print_frame_smob): Convert use of
+       fprint_frame_id to use frame_id::to_string.
+       * python/py-frame.c (frame_object_to_frame_info): Likewise.
+       * python/py-unwind.c (unwind_infopy_str): Likewise.
+       (pyuw_this_id): Likewise.
+
 2021-05-08  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * nat/linux-waitpid.c (status_to_str): Return std::string.
index 6bbcbba48bfcaddf316cb15b94ab503934ee1a66..155dec377f34435a4cf1cbedac3636a20889daab 100644 (file)
@@ -408,8 +408,7 @@ fprint_dummy_frames (struct ui_file *file)
     {
       gdb_print_host_address (s, file);
       fprintf_unfiltered (file, ":");
-      fprintf_unfiltered (file, " id=");
-      fprint_frame_id (file, s->id.id);
+      fprintf_unfiltered (file, " id=%s", s->id.id.to_string ().c_str ());
       fprintf_unfiltered (file, ", ptid=%s",
                          target_pid_to_str (s->id.thread->ptid).c_str ());
       fprintf_unfiltered (file, "\n");
index 2032abb2738d72d28f61d0d845d392a611cee451..cd10f3f0770b593e1b7ba8e0f4a8a08e7f705c07 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;
 }
index 597a45967ed25198813cee4b04827ce4e6aab445..da52522ad2aafe16308c922dc59d288e696ce2f9 100644 (file)
@@ -169,6 +169,9 @@ struct frame_id
      Caller of inlined function will have it zero, each more inner called frame
      will have it increasingly one, two etc.  Similarly for TAILCALL_FRAME.  */
   int artificial_depth;
+
+  /* Return a string representation of this frame id.  */
+  std::string to_string () const;
 };
 
 /* Save and restore the currently selected frame.  */
@@ -258,11 +261,6 @@ extern bool frame_id_artificial_p (frame_id l);
 /* Returns true when L and R identify the same frame.  */
 extern bool frame_id_eq (frame_id l, frame_id r);
 
-/* Write the internal representation of a frame ID on the specified
-   stream.  */
-extern void fprint_frame_id (struct ui_file *file, struct frame_id id);
-
-
 /* Frame types.  Some are real, some are signal trampolines, and some
    are completely artificial (dummy).  */
 
index 9d5dfa698bca0ed0ec2dcb31c1971722ebd6aec9..eb32f9a2ef0057e902d022fb571c8f1e4f86f764 100644 (file)
@@ -156,14 +156,9 @@ frscm_print_frame_smob (SCM self, SCM port, scm_print_state *pstate)
 {
   frame_smob *f_smob = (frame_smob *) SCM_SMOB_DATA (self);
 
-  gdbscm_printf (port, "#<%s ", frame_smob_name);
-
-  string_file strfile;
-  fprint_frame_id (&strfile, f_smob->frame_id);
-  gdbscm_printf (port, "%s", strfile.c_str ());
-
-  scm_puts (">", port);
-
+  gdbscm_printf (port, "#<%s %s>",
+                frame_smob_name,
+                f_smob->frame_id.to_string ().c_str ());
   scm_remember_upto_here_1 (self);
 
   /* Non-zero means success.  */
index 8e32ba55de4909c25326aed7fc39c7e672a43093..c8eab5291ea471199fc405a5ba50c713196ff0d3 100644 (file)
@@ -79,10 +79,8 @@ frame_object_to_frame_info (PyObject *obj)
 static PyObject *
 frapy_str (PyObject *self)
 {
-  string_file strfile;
-
-  fprint_frame_id (&strfile, ((frame_object *) self)->frame_id);
-  return PyString_FromString (strfile.c_str ());
+  const frame_id &fid = ((frame_object *) self)->frame_id;
+  return PyString_FromString (fid.to_string ().c_str ());
 }
 
 /* Implementation of gdb.Frame.is_valid (self) -> Boolean.
index 4b25c485b8c14d164e90e150330339ef2506462f..c82fa3dbe972010a30b27a3f4fea512e57258275 100644 (file)
@@ -163,8 +163,7 @@ unwind_infopy_str (PyObject *self)
   unwind_info_object *unwind_info = (unwind_info_object *) self;
   string_file stb;
 
-  stb.puts ("Frame ID: ");
-  fprint_frame_id (&stb, unwind_info->frame_id);
+  stb.printf ("Frame ID: %s", unwind_info->frame_id.to_string ().c_str ());
   {
     const char *sep = "";
     struct value_print_options opts;
@@ -433,11 +432,8 @@ pyuw_this_id (struct frame_info *this_frame, void **cache_ptr,
 {
   *this_id = ((cached_frame_info *) *cache_ptr)->frame_id;
   if (pyuw_debug >= 1)
-    {
-      fprintf_unfiltered (gdb_stdlog, "%s: frame_id: ", __FUNCTION__);
-      fprint_frame_id (gdb_stdlog, *this_id);
-      fprintf_unfiltered (gdb_stdlog, "\n");
-    }
+    fprintf_unfiltered (gdb_stdlog, "%s: frame_id: %s\n", __FUNCTION__,
+                       this_id->to_string ().c_str ());
 }
 
 /* frame_unwind.prev_register.  */