From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH] gdb/tui: return std::string from tui_get_function_from_frame
Date: Thu, 22 Jan 2026 14:28:00 +0000 [thread overview]
Message-ID: <32f9ecb06cced368b9f6433e9b4f38bad2e61d86.1769092070.git.aburgess@redhat.com> (raw)
Update tui_get_function_from_frame to return a std::string rather than
a pointer into a static buffer.
The value returned from tui_get_function_from_frame is passed to
tui_location_tracker::set_location, which already stores the data in a
std::string; this just moves the string creation earlier.
I don't think there was anything particularly wrong with the old code,
but I'm not a huge fan of returning data in static buffers unless
there's a really good reason, and it doesn't feel like there's a
really good reason in this case.
The current approach in tui_get_function_from_frame is to call
print_address_symbolic, and then to pull the function name from the
result. There is an argument that this approach could be improved,
but I've not done that in this commit, nor do I plan to do that any
time soon. As such the new code should do exactly what the old code
did.
There should be no user visible changes after this commit.
---
gdb/tui/tui-location.c | 6 ++----
gdb/tui/tui-location.h | 2 +-
gdb/tui/tui-status.c | 33 ++++++++++++++++-----------------
3 files changed, 19 insertions(+), 22 deletions(-)
diff --git a/gdb/tui/tui-location.c b/gdb/tui/tui-location.c
index 9527ae50c60..003c022f1e8 100644
--- a/gdb/tui/tui-location.c
+++ b/gdb/tui/tui-location.c
@@ -29,17 +29,15 @@ tui_location_tracker tui_location;
bool
tui_location_tracker::set_location (struct gdbarch *gdbarch,
const struct symtab_and_line &sal,
- const char *procname)
+ std::string procname)
{
- gdb_assert (procname != nullptr);
-
bool location_changed_p = set_fullname (sal.symtab);
location_changed_p |= procname != m_proc_name;
location_changed_p |= sal.line != m_line_no;
location_changed_p |= sal.pc != m_addr;
location_changed_p |= gdbarch != m_gdbarch;
- m_proc_name = procname;
+ m_proc_name = std::move (procname);
m_line_no = sal.line;
m_addr = sal.pc;
m_gdbarch = gdbarch;
diff --git a/gdb/tui/tui-location.h b/gdb/tui/tui-location.h
index 6b663f1df9b..5cf29c3716b 100644
--- a/gdb/tui/tui-location.h
+++ b/gdb/tui/tui-location.h
@@ -32,7 +32,7 @@ struct tui_location_tracker
and false otherwise. */
bool set_location (struct gdbarch *gdbarch,
const struct symtab_and_line &sal,
- const char *procname);
+ std::string procname);
/* Update the current location with the with the provided argument.
Return true if any of the fields actually changed, otherwise false. */
diff --git a/gdb/tui/tui-status.c b/gdb/tui/tui-status.c
index b58bf9aa990..3d252503da0 100644
--- a/gdb/tui/tui-status.c
+++ b/gdb/tui/tui-status.c
@@ -207,10 +207,9 @@ tui_status_window::make_status_line () const
/* Get a printable name for the function at the address. The symbol
name is demangled if demangling is turned on. Returns a pointer to
a static area holding the result. */
-static char*
+static std::string
tui_get_function_from_frame (const frame_info_ptr &fi)
{
- static char name[256];
string_file stream;
print_address_symbolic (get_frame_arch (fi), get_frame_pc (fi),
@@ -219,20 +218,20 @@ tui_get_function_from_frame (const frame_info_ptr &fi)
/* Use simple heuristics to isolate the function name. The symbol
can be demangled and we can have function parameters. Remove
them because the status line is too short to display them. */
- const char *d = stream.c_str ();
- if (*d == '<')
- d++;
- strncpy (name, d, sizeof (name) - 1);
- name[sizeof (name) - 1] = 0;
+ std::string name = stream.release ();
+ if (name.front () == '<')
+ name = name.substr (1);
+
+ size_t pos = name.find('(');
+ if (pos == std::string::npos)
+ pos = name.find('>');
+ if (pos != std::string::npos)
+ name.erase (pos);
+
+ pos = name.find('+');
+ if (pos != std::string::npos)
+ name.erase (pos);
- char *p = strchr (name, '(');
- if (!p)
- p = strchr (name, '>');
- if (p)
- *p = 0;
- p = strchr (name, '+');
- if (p)
- *p = 0;
return name;
}
@@ -270,7 +269,7 @@ tui_show_frame_info (const frame_info_ptr &fi)
{
symtab_and_line sal = find_frame_sal (fi);
- const char *func_name;
+ std::string func_name;
std::optional<CORE_ADDR> tmp_pc = get_frame_pc_if_available (fi);
/* find_frame_sal does not always set PC, but we want to ensure
that it is available in the SAL. */
@@ -284,7 +283,7 @@ tui_show_frame_info (const frame_info_ptr &fi)
struct gdbarch *gdbarch = get_frame_arch (fi);
status_changed_p
- = tui_location.set_location (gdbarch, sal, func_name);
+ = tui_location.set_location (gdbarch, sal, std::move (func_name));
/* If the status information has not changed, then frame information has
not changed. If frame information has not changed, then the windows'
base-commit: 93172549b7397c526b3622e16484909028d81e41
--
2.25.4
next reply other threads:[~2026-01-22 14:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 14:28 Andrew Burgess [this message]
2026-01-22 14:30 ` Andrew Burgess
2026-01-22 19:13 ` Tom Tromey
2026-01-23 10:47 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=32f9ecb06cced368b9f6433e9b4f38bad2e61d86.1769092070.git.aburgess@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox