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.
+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.
+
2019-02-17 Tom Tromey <tom@tromey.com>
* macrocmd.c (show_pp_source_pos): Style the file names.
2019-02-17 Tom Tromey <tom@tromey.com>
* macrocmd.c (show_pp_source_pos): Style the file names.
struct macro_source_file *file,
int line)
{
struct macro_source_file *file,
int line)
{
- char *fullname;
-
- fullname = macro_source_fullname (file);
- fputs_styled (fullname, file_name_style.style (), stream);
+ std::string fullname = macro_source_fullname (file);
+ fputs_styled (fullname.c_str (), file_name_style.style (), stream);
fprintf_filtered (stream, ":%d\n", line);
fprintf_filtered (stream, ":%d\n", line);
while (file->included_by)
{
fullname = macro_source_fullname (file->included_by);
fputs_filtered (_(" included at "), stream);
while (file->included_by)
{
fullname = macro_source_fullname (file->included_by);
fputs_filtered (_(" included at "), stream);
- fputs_styled (fullname, file_name_style.style (), stream);
+ fputs_styled (fullname.c_str (), file_name_style.style (), stream);
fprintf_filtered (stream, ":%d\n", file->included_at_line);
fprintf_filtered (stream, ":%d\n", file->included_at_line);
file = file->included_by;
}
}
file = file->included_by;
}
}
the new one? */
if (*link && line == (*link)->included_at_line)
{
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,
/* 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,
- 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"),
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. */
/* Now, choose a new, unoccupied line number for this
#inclusion, after the alleged #inclusion line. */
- 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"),
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 (),
- xfree (found_key_fullname);
- xfree (source_fullname);
#definition. */
if (key->end_file)
{
#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"),
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 (),
- xfree (key_fullname);
- xfree (source_fullname);
}
/* Whether or not we've seen a prior #undefinition, wipe out
}
/* Whether or not we've seen a prior #undefinition, wipe out
- 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);
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;
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;
- 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);
(struct macro_definition *) node->value);
datum->fn (key->name, def, key->start_file, key->start_line);
return 0;
datum->fn (key->name, def, key->start_file, key->start_line);
return 0;
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;
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;
- 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);
(struct macro_definition *) node->value);
- xfree (datum_fullname);
/* See if this macro is defined before the passed-in line, and
extends past that line. */
/* See if this macro is defined before the passed-in line, and
extends past that line. */
/* See macrotab.h for the comment. */
/* See macrotab.h for the comment. */
macro_source_fullname (struct macro_source_file *file)
{
const char *comp_dir = NULL;
macro_source_fullname (struct macro_source_file *file)
{
const char *comp_dir = NULL;
comp_dir = COMPUNIT_DIRNAME (file->table->compunit_symtab);
if (comp_dir == NULL || IS_ABSOLUTE_PATH (file->filename))
comp_dir = COMPUNIT_DIRNAME (file->table->compunit_symtab);
if (comp_dir == NULL || IS_ABSOLUTE_PATH (file->filename))
- return xstrdup (file->filename);
- return concat (comp_dir, SLASH_STRING, file->filename, (char *) NULL);
+ return std::string (comp_dir) + SLASH_STRING + file->filename;
/* Return FILE->filename with possibly prepended compilation directory name.
This is raw concatenation without the "set substitute-path" and gdb_realpath
/* Return FILE->filename with possibly prepended compilation directory name.
This is raw concatenation without the "set substitute-path" and gdb_realpath
- applications done by symtab_to_fullname. Returned string must be freed by
- xfree.
+ applications done by symtab_to_fullname.
THis function ignores the "set filename-display" setting. Its default
setting is "relative" which is backward compatible but the former behavior
of macro filenames printing was "absolute". */
THis function ignores the "set filename-display" setting. Its default
setting is "relative" which is backward compatible but the former behavior
of macro filenames printing was "absolute". */
-extern char *macro_source_fullname (struct macro_source_file *file);
+extern std::string macro_source_fullname (struct macro_source_file *file);