From 927c4e355e307698d58e6cad17f866bf5515f16e Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Sat, 8 May 2021 15:43:56 +0100 Subject: [PATCH] gdb: replace fprint_frame_id 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) : 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 | 21 +++++++++++ gdb/dummy-frame.c | 3 +- gdb/frame.c | 84 ++++++++++++++++++------------------------ gdb/frame.h | 8 ++-- gdb/guile/scm-frame.c | 11 ++---- gdb/python/py-frame.c | 6 +-- gdb/python/py-unwind.c | 10 ++--- 7 files changed, 68 insertions(+), 75 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 75e344ff707..23710bc7bad 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,24 @@ +2021-05-09 Andrew Burgess + + * 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) : 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 * nat/linux-waitpid.c (status_to_str): Return std::string. diff --git a/gdb/dummy-frame.c b/gdb/dummy-frame.c index 6bbcbba48bf..155dec377f3 100644 --- a/gdb/dummy-frame.c +++ b/gdb/dummy-frame.c @@ -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"); diff --git a/gdb/frame.c b/gdb/frame.c index 2032abb2738..cd10f3f0770 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -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="); + res += "stack="; else if (id.stack_status == FID_STACK_SENTINEL) - fprintf_unfiltered (file, "stack="); + res += "stack="; else if (id.stack_status == FID_STACK_OUTER) - fprintf_unfiltered (file, "stack="); + res += "stack="; 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, ""); 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; } diff --git a/gdb/frame.h b/gdb/frame.h index 597a45967ed..da52522ad2a 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -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). */ diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c index 9d5dfa698bc..eb32f9a2ef0 100644 --- a/gdb/guile/scm-frame.c +++ b/gdb/guile/scm-frame.c @@ -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. */ diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index 8e32ba55de4..c8eab5291ea 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -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. diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index 4b25c485b8c..c82fa3dbe97 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -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. */ -- 2.30.2