diff options
author | Tom Tromey <tom@tromey.com> | 2019-02-08 01:40:39 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2019-02-17 16:28:38 -0700 |
commit | 9409233b0ec8a052eacc5846ee054f224f7e7213 (patch) | |
tree | 2074b48076d95b6f37bad36ddba994e03af6bf83 /gdb/macrotab.c | |
parent | 6506371f0671dd5ca11127fee4db8d8d7fec157f (diff) | |
download | gdb-9409233b0ec8a052eacc5846ee054f224f7e7213.zip gdb-9409233b0ec8a052eacc5846ee054f224f7e7213.tar.gz gdb-9409233b0ec8a052eacc5846ee054f224f7e7213.tar.bz2 |
Change macro_source_fullname to return a std::string
While working on the previous patch, I noticed that if
macro_source_fullname returned a std::string, then the callers would
be simplified. This patch implements this idea.
gdb/ChangeLog
2019-02-17 Tom Tromey <tom@tromey.com>
* macrotab.h (macro_source_fullname): Return a std::string.
* macrotab.c (macro_include, check_for_redefinition)
(macro_undef, macro_lookup_definition, foreach_macro)
(foreach_macro_in_scope): Update.
(macro_source_fullname): Return a std::string.
* macrocmd.c (show_pp_source_pos): Update.
Diffstat (limited to 'gdb/macrotab.c')
-rw-r--r-- | gdb/macrotab.c | 63 |
1 files changed, 23 insertions, 40 deletions
diff --git a/gdb/macrotab.c b/gdb/macrotab.c index f7ce26f..fa30616 100644 --- a/gdb/macrotab.c +++ b/gdb/macrotab.c @@ -466,8 +466,6 @@ macro_include (struct macro_source_file *source, the new one? */ if (*link && line == (*link)->included_at_line) { - char *link_fullname, *source_fullname; - /* This means the compiler is emitting bogus debug info. (GCC circa March 2002 did this.) It also means that the splay tree ordering function, macro_tree_compare, will abort, @@ -476,12 +474,11 @@ macro_include (struct macro_source_file *source, First, squawk. */ - link_fullname = macro_source_fullname (*link); - source_fullname = macro_source_fullname (source); + std::string link_fullname = macro_source_fullname (*link); + std::string source_fullname = macro_source_fullname (source); complaint (_("both `%s' and `%s' allegedly #included at %s:%d"), - included, link_fullname, source_fullname, line); - xfree (source_fullname); - xfree (link_fullname); + included, link_fullname.c_str (), source_fullname.c_str (), + line); /* Now, choose a new, unoccupied line number for this #inclusion, after the alleged #inclusion line. */ @@ -725,16 +722,14 @@ check_for_redefinition (struct macro_source_file *source, int line, if (! same) { - char *source_fullname, *found_key_fullname; - - source_fullname = macro_source_fullname (source); - found_key_fullname = macro_source_fullname (found_key->start_file); + std::string source_fullname = macro_source_fullname (source); + std::string found_key_fullname + = macro_source_fullname (found_key->start_file); complaint (_("macro `%s' redefined at %s:%d; " "original definition at %s:%d"), - name, source_fullname, line, found_key_fullname, + name, source_fullname.c_str (), line, + found_key_fullname.c_str (), found_key->start_line); - xfree (found_key_fullname); - xfree (source_fullname); } return found_key; @@ -854,16 +849,13 @@ macro_undef (struct macro_source_file *source, int line, #definition. */ if (key->end_file) { - char *source_fullname, *key_fullname; - - source_fullname = macro_source_fullname (source); - key_fullname = macro_source_fullname (key->end_file); + std::string source_fullname = macro_source_fullname (source); + std::string key_fullname = macro_source_fullname (key->end_file); complaint (_("macro '%s' is #undefined twice," " at %s:%d and %s:%d"), - name, source_fullname, line, key_fullname, + name, source_fullname.c_str (), line, + key_fullname.c_str (), key->end_line); - xfree (key_fullname); - xfree (source_fullname); } /* Whether or not we've seen a prior #undefinition, wipe out @@ -923,14 +915,9 @@ macro_lookup_definition (struct macro_source_file *source, if (n) { - struct macro_definition *retval; - char *source_fullname; - - source_fullname = macro_source_fullname (source); - retval = fixup_definition (source_fullname, line, - (struct macro_definition *) n->value); - xfree (source_fullname); - return retval; + std::string source_fullname = macro_source_fullname (source); + return fixup_definition (source_fullname.c_str (), line, + (struct macro_definition *) n->value); } else return 0; @@ -974,12 +961,10 @@ foreach_macro (splay_tree_node node, void *arg) struct macro_for_each_data *datum = (struct macro_for_each_data *) arg; struct macro_key *key = (struct macro_key *) node->key; struct macro_definition *def; - char *key_fullname; - key_fullname = macro_source_fullname (key->start_file); - def = fixup_definition (key_fullname, key->start_line, + std::string key_fullname = macro_source_fullname (key->start_file); + def = fixup_definition (key_fullname.c_str (), key->start_line, (struct macro_definition *) node->value); - xfree (key_fullname); datum->fn (key->name, def, key->start_file, key->start_line); return 0; @@ -1004,12 +989,10 @@ foreach_macro_in_scope (splay_tree_node node, void *info) struct macro_for_each_data *datum = (struct macro_for_each_data *) info; struct macro_key *key = (struct macro_key *) node->key; struct macro_definition *def; - char *datum_fullname; - datum_fullname = macro_source_fullname (datum->file); - def = fixup_definition (datum_fullname, datum->line, + std::string datum_fullname = macro_source_fullname (datum->file); + def = fixup_definition (datum_fullname.c_str (), datum->line, (struct macro_definition *) node->value); - xfree (datum_fullname); /* See if this macro is defined before the passed-in line, and extends past that line. */ @@ -1083,7 +1066,7 @@ free_macro_table (struct macro_table *table) /* See macrotab.h for the comment. */ -char * +std::string macro_source_fullname (struct macro_source_file *file) { const char *comp_dir = NULL; @@ -1092,7 +1075,7 @@ macro_source_fullname (struct macro_source_file *file) comp_dir = COMPUNIT_DIRNAME (file->table->compunit_symtab); if (comp_dir == NULL || IS_ABSOLUTE_PATH (file->filename)) - return xstrdup (file->filename); + return file->filename; - return concat (comp_dir, SLASH_STRING, file->filename, (char *) NULL); + return std::string (comp_dir) + SLASH_STRING + file->filename; } |