Skip to content

Commit 9409233

Browse files
committed
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.
1 parent 6506371 commit 9409233

File tree

4 files changed

+37
-50
lines changed

4 files changed

+37
-50
lines changed

gdb/ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2019-02-17 Tom Tromey <tom@tromey.com>
2+
3+
* macrotab.h (macro_source_fullname): Return a std::string.
4+
* macrotab.c (macro_include, check_for_redefinition)
5+
(macro_undef, macro_lookup_definition, foreach_macro)
6+
(foreach_macro_in_scope): Update.
7+
(macro_source_fullname): Return a std::string.
8+
* macrocmd.c (show_pp_source_pos): Update.
9+
110
2019-02-17 Tom Tromey <tom@tromey.com>
211

312
* macrocmd.c (show_pp_source_pos): Style the file names.

gdb/macrocmd.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,16 @@ show_pp_source_pos (struct ui_file *stream,
119119
struct macro_source_file *file,
120120
int line)
121121
{
122-
char *fullname;
123-
124-
fullname = macro_source_fullname (file);
125-
fputs_styled (fullname, file_name_style.style (), stream);
122+
std::string fullname = macro_source_fullname (file);
123+
fputs_styled (fullname.c_str (), file_name_style.style (), stream);
126124
fprintf_filtered (stream, ":%d\n", line);
127-
xfree (fullname);
128125

129126
while (file->included_by)
130127
{
131128
fullname = macro_source_fullname (file->included_by);
132129
fputs_filtered (_(" included at "), stream);
133-
fputs_styled (fullname, file_name_style.style (), stream);
130+
fputs_styled (fullname.c_str (), file_name_style.style (), stream);
134131
fprintf_filtered (stream, ":%d\n", file->included_at_line);
135-
xfree (fullname);
136132
file = file->included_by;
137133
}
138134
}

gdb/macrotab.c

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,6 @@ macro_include (struct macro_source_file *source,
466466
the new one? */
467467
if (*link && line == (*link)->included_at_line)
468468
{
469-
char *link_fullname, *source_fullname;
470-
471469
/* This means the compiler is emitting bogus debug info. (GCC
472470
circa March 2002 did this.) It also means that the splay
473471
tree ordering function, macro_tree_compare, will abort,
@@ -476,12 +474,11 @@ macro_include (struct macro_source_file *source,
476474
477475
First, squawk. */
478476

479-
link_fullname = macro_source_fullname (*link);
480-
source_fullname = macro_source_fullname (source);
477+
std::string link_fullname = macro_source_fullname (*link);
478+
std::string source_fullname = macro_source_fullname (source);
481479
complaint (_("both `%s' and `%s' allegedly #included at %s:%d"),
482-
included, link_fullname, source_fullname, line);
483-
xfree (source_fullname);
484-
xfree (link_fullname);
480+
included, link_fullname.c_str (), source_fullname.c_str (),
481+
line);
485482

486483
/* Now, choose a new, unoccupied line number for this
487484
#inclusion, after the alleged #inclusion line. */
@@ -725,16 +722,14 @@ check_for_redefinition (struct macro_source_file *source, int line,
725722

726723
if (! same)
727724
{
728-
char *source_fullname, *found_key_fullname;
729-
730-
source_fullname = macro_source_fullname (source);
731-
found_key_fullname = macro_source_fullname (found_key->start_file);
725+
std::string source_fullname = macro_source_fullname (source);
726+
std::string found_key_fullname
727+
= macro_source_fullname (found_key->start_file);
732728
complaint (_("macro `%s' redefined at %s:%d; "
733729
"original definition at %s:%d"),
734-
name, source_fullname, line, found_key_fullname,
730+
name, source_fullname.c_str (), line,
731+
found_key_fullname.c_str (),
735732
found_key->start_line);
736-
xfree (found_key_fullname);
737-
xfree (source_fullname);
738733
}
739734

740735
return found_key;
@@ -854,16 +849,13 @@ macro_undef (struct macro_source_file *source, int line,
854849
#definition. */
855850
if (key->end_file)
856851
{
857-
char *source_fullname, *key_fullname;
858-
859-
source_fullname = macro_source_fullname (source);
860-
key_fullname = macro_source_fullname (key->end_file);
852+
std::string source_fullname = macro_source_fullname (source);
853+
std::string key_fullname = macro_source_fullname (key->end_file);
861854
complaint (_("macro '%s' is #undefined twice,"
862855
" at %s:%d and %s:%d"),
863-
name, source_fullname, line, key_fullname,
856+
name, source_fullname.c_str (), line,
857+
key_fullname.c_str (),
864858
key->end_line);
865-
xfree (key_fullname);
866-
xfree (source_fullname);
867859
}
868860

869861
/* Whether or not we've seen a prior #undefinition, wipe out
@@ -923,14 +915,9 @@ macro_lookup_definition (struct macro_source_file *source,
923915

924916
if (n)
925917
{
926-
struct macro_definition *retval;
927-
char *source_fullname;
928-
929-
source_fullname = macro_source_fullname (source);
930-
retval = fixup_definition (source_fullname, line,
931-
(struct macro_definition *) n->value);
932-
xfree (source_fullname);
933-
return retval;
918+
std::string source_fullname = macro_source_fullname (source);
919+
return fixup_definition (source_fullname.c_str (), line,
920+
(struct macro_definition *) n->value);
934921
}
935922
else
936923
return 0;
@@ -974,12 +961,10 @@ foreach_macro (splay_tree_node node, void *arg)
974961
struct macro_for_each_data *datum = (struct macro_for_each_data *) arg;
975962
struct macro_key *key = (struct macro_key *) node->key;
976963
struct macro_definition *def;
977-
char *key_fullname;
978964

979-
key_fullname = macro_source_fullname (key->start_file);
980-
def = fixup_definition (key_fullname, key->start_line,
965+
std::string key_fullname = macro_source_fullname (key->start_file);
966+
def = fixup_definition (key_fullname.c_str (), key->start_line,
981967
(struct macro_definition *) node->value);
982-
xfree (key_fullname);
983968

984969
datum->fn (key->name, def, key->start_file, key->start_line);
985970
return 0;
@@ -1004,12 +989,10 @@ foreach_macro_in_scope (splay_tree_node node, void *info)
1004989
struct macro_for_each_data *datum = (struct macro_for_each_data *) info;
1005990
struct macro_key *key = (struct macro_key *) node->key;
1006991
struct macro_definition *def;
1007-
char *datum_fullname;
1008992

1009-
datum_fullname = macro_source_fullname (datum->file);
1010-
def = fixup_definition (datum_fullname, datum->line,
993+
std::string datum_fullname = macro_source_fullname (datum->file);
994+
def = fixup_definition (datum_fullname.c_str (), datum->line,
1011995
(struct macro_definition *) node->value);
1012-
xfree (datum_fullname);
1013996

1014997
/* See if this macro is defined before the passed-in line, and
1015998
extends past that line. */
@@ -1083,7 +1066,7 @@ free_macro_table (struct macro_table *table)
10831066

10841067
/* See macrotab.h for the comment. */
10851068

1086-
char *
1069+
std::string
10871070
macro_source_fullname (struct macro_source_file *file)
10881071
{
10891072
const char *comp_dir = NULL;
@@ -1092,7 +1075,7 @@ macro_source_fullname (struct macro_source_file *file)
10921075
comp_dir = COMPUNIT_DIRNAME (file->table->compunit_symtab);
10931076

10941077
if (comp_dir == NULL || IS_ABSOLUTE_PATH (file->filename))
1095-
return xstrdup (file->filename);
1078+
return file->filename;
10961079

1097-
return concat (comp_dir, SLASH_STRING, file->filename, (char *) NULL);
1080+
return std::string (comp_dir) + SLASH_STRING + file->filename;
10981081
}

gdb/macrotab.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,11 @@ void macro_for_each_in_scope (struct macro_source_file *file, int line,
351351

352352
/* Return FILE->filename with possibly prepended compilation directory name.
353353
This is raw concatenation without the "set substitute-path" and gdb_realpath
354-
applications done by symtab_to_fullname. Returned string must be freed by
355-
xfree.
354+
applications done by symtab_to_fullname.
356355
357356
THis function ignores the "set filename-display" setting. Its default
358357
setting is "relative" which is backward compatible but the former behavior
359358
of macro filenames printing was "absolute". */
360-
extern char *macro_source_fullname (struct macro_source_file *file);
359+
extern std::string macro_source_fullname (struct macro_source_file *file);
361360

362361
#endif /* MACROTAB_H */

0 commit comments

Comments
 (0)