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;
return string_val;
}
-/* 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*
+/* Get a printable name for the function representing frame FI. The symbol
+ name is demangled if demangling is turned on. Returns a std::string
+ containing the function name, which could be empty. */
+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),
/* 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;
-
- char *p = strchr (name, '(');
- if (!p)
- p = strchr (name, '>');
- if (p)
- *p = 0;
- p = strchr (name, '+');
- if (p)
- *p = 0;
+ std::string name = stream.release ();
+ if (!name.empty () && name.front () == '<')
+ name = name.erase (0, 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);
+
return name;
}
{
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. */
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'