aboutsummaryrefslogtreecommitdiff
path: root/gdb/printcmd.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-05-05 10:24:54 -0600
committerTom Tromey <tom@tromey.com>2018-06-07 06:38:18 -0600
commitc7110220be62590222e35525dda499902ee49a89 (patch)
tree34756b1adffc595768d9c9d9e3c8197aefed0af5 /gdb/printcmd.c
parent2a9b2c1abe29e1063240604d2464b8de9a46011f (diff)
downloadfsf-binutils-gdb-c7110220be62590222e35525dda499902ee49a89.zip
fsf-binutils-gdb-c7110220be62590222e35525dda499902ee49a89.tar.gz
fsf-binutils-gdb-c7110220be62590222e35525dda499902ee49a89.tar.bz2
Change build_address_symbolic to return std::string
This changes two out parameters of build_address_symbolic to be std::string, and updates the callers. This allows removing some cleanups. This patch also moves the declaration of build_address_symbolic out of defs.h. I think that many things in defs.h should be elsewhere instead. In this case, I moved the declaration to valprint.h, becuase there is no "printcmd.h" -- but perhaps it would be better to introduce that instead. Tested by the buildbot. gdb/ChangeLog 2018-06-07 Tom Tromey <tom@tromey.com> * valprint.h (build_address_symbolic): Declare. * printcmd.c (print_address_symbolic): Update. (build_address_symbolic): Change "name" and "filename" to std::string. * disasm.c (gdb_pretty_print_disassembler::pretty_print_insn): Update. * defs.h (build_address_symbolic): Remove declaration.
Diffstat (limited to 'gdb/printcmd.c')
-rw-r--r--gdb/printcmd.c37
1 files changed, 12 insertions, 25 deletions
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index d0037ae..696285e 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -520,63 +520,50 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr,
struct ui_file *stream,
int do_demangle, const char *leadin)
{
- char *name = NULL;
- char *filename = NULL;
+ std::string name, filename;
int unmapped = 0;
int offset = 0;
int line = 0;
- /* Throw away both name and filename. */
- struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name);
- make_cleanup (free_current_contents, &filename);
-
if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset,
&filename, &line, &unmapped))
- {
- do_cleanups (cleanup_chain);
- return 0;
- }
+ return 0;
fputs_filtered (leadin, stream);
if (unmapped)
fputs_filtered ("<*", stream);
else
fputs_filtered ("<", stream);
- fputs_filtered (name, stream);
+ fputs_filtered (name.c_str (), stream);
if (offset != 0)
fprintf_filtered (stream, "+%u", (unsigned int) offset);
/* Append source filename and line number if desired. Give specific
line # of this addr, if we have it; else line # of the nearest symbol. */
- if (print_symbol_filename && filename != NULL)
+ if (print_symbol_filename && !filename.empty ())
{
if (line != -1)
- fprintf_filtered (stream, " at %s:%d", filename, line);
+ fprintf_filtered (stream, " at %s:%d", filename.c_str (), line);
else
- fprintf_filtered (stream, " in %s", filename);
+ fprintf_filtered (stream, " in %s", filename.c_str ());
}
if (unmapped)
fputs_filtered ("*>", stream);
else
fputs_filtered (">", stream);
- do_cleanups (cleanup_chain);
return 1;
}
-/* Given an address ADDR return all the elements needed to print the
- address in a symbolic form. NAME can be mangled or not depending
- on DO_DEMANGLE (and also on the asm_demangle global variable,
- manipulated via ''set print asm-demangle''). Return 0 in case of
- success, when all the info in the OUT paramters is valid. Return 1
- otherwise. */
+/* See valprint.h. */
+
int
build_address_symbolic (struct gdbarch *gdbarch,
CORE_ADDR addr, /* IN */
int do_demangle, /* IN */
- char **name, /* OUT */
+ std::string *name, /* OUT */
int *offset, /* OUT */
- char **filename, /* OUT */
+ std::string *filename, /* OUT */
int *line, /* OUT */
int *unmapped) /* OUT */
{
@@ -678,7 +665,7 @@ build_address_symbolic (struct gdbarch *gdbarch,
*offset = addr - name_location;
- *name = xstrdup (name_temp);
+ *name = name_temp;
if (print_symbol_filename)
{
@@ -688,7 +675,7 @@ build_address_symbolic (struct gdbarch *gdbarch,
if (sal.symtab)
{
- *filename = xstrdup (symtab_to_filename_for_display (sal.symtab));
+ *filename = symtab_to_filename_for_display (sal.symtab);
*line = sal.line;
}
}