[RFA 04/42] Move last_source file to buildsym_compunit

Tom Tromey
2018-05-23T04:59:07Z

This moves the global last_source_file into buildsym_compunit.

gdb/ChangeLog
2018-05-22 Tom Tromey <tom@tromey.com>

* buildsym.c (buildsym_compunit::buildsym_compunit): Add name
parameter.
(buildsym_compunit::set_last_source_file): New method.
<m_last_source_file>: New member.
(prepare_for_building): Remove "name" parameter.
(start_symtab, restart_symtab, reset_symtab_globals): Update.
(last_source_file): Remove.
(set_last_source_file, get_last_source_file): Update.
---
gdb/ChangeLog | 11 +++++++++++
gdb/buildsym.c | 44 ++++++++++++++++++++++++++------------------
2 files changed, 37 insertions(+), 18 deletions(-)

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 9e0c39a4a4..5dd6f7e343 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -105,9 +105,10 @@ struct buildsym_compunit
COMP_DIR is the directory in which the compilation unit was compiled
(or NULL if not known). */

- buildsym_compunit (struct objfile *objfile_, const char *comp_dir_,
- enum language language_)
+ buildsym_compunit (struct objfile *objfile_, const char *name,
+ const char *comp_dir_, enum language language_)
: objfile (objfile_),
+ m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)),
language (language_)
{
@@ -128,6 +129,12 @@ struct buildsym_compunit
}
}

+ void set_last_source_file (const char *name)
+ {
+ char *new_name = name == NULL ? NULL : xstrdup (name);
+ m_last_source_file.reset (new_name);
+ }
+
/* The objfile we're reading debug info from. */
struct objfile *objfile;

@@ -140,6 +147,12 @@ struct buildsym_compunit
/* The subfile of the main source file. */
struct subfile *main_subfile = nullptr;

+ /* Name of source file whose symbol data we are now processing. This
+ comes from a symbol of type N_SO for stabs. For Dwarf it comes
+ from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
+
+ gdb::unique_xmalloc_ptr<char> m_last_source_file;
+
/* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
gdb::unique_xmalloc_ptr<char> comp_dir;

@@ -1005,9 +1018,8 @@ get_macro_table (void)
buildsym_init. */

static void
-prepare_for_building (const char *name, CORE_ADDR start_addr)
+prepare_for_building (CORE_ADDR start_addr)
{
- set_last_source_file (name);
last_source_start_addr = start_addr;

local_symbols = NULL;
@@ -1044,9 +1056,9 @@ struct compunit_symtab *
start_symtab (struct objfile *objfile, const char *name, const char *comp_dir,
CORE_ADDR start_addr, enum language language)
{
- prepare_for_building (name, start_addr);
+ prepare_for_building (start_addr);

- buildsym_compunit = new struct buildsym_compunit (objfile, comp_dir,
+ buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
language);

/* Allocate the compunit symtab now. The caller needs it to allocate
@@ -1081,10 +1093,11 @@ void
restart_symtab (struct compunit_symtab *cust,
const char *name, CORE_ADDR start_addr)
{
- prepare_for_building (name, start_addr);
+ prepare_for_building (start_addr);

buildsym_compunit
= new struct buildsym_compunit (COMPUNIT_OBJFILE (cust),
+ name,
COMPUNIT_DIRNAME (cust),
compunit_language (cust));
buildsym_compunit->compunit_symtab = cust;
@@ -1172,8 +1185,6 @@ watch_main_source_file_lossage (void)
static void
reset_symtab_globals (void)
{
- set_last_source_file (NULL);
-
local_symbols = NULL;
local_using_directives = NULL;
file_symbols = NULL;
@@ -1706,19 +1717,14 @@ merge_symbol_lists (struct pending **srclist, struct pending **targetlist)
}
\f

-/* Name of source file whose symbol data we are now processing. This
- comes from a symbol of type N_SO for stabs. For Dwarf it comes
- from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
-
-static char *last_source_file;
-
/* See buildsym.h. */

void
set_last_source_file (const char *name)
{
- xfree (last_source_file);
- last_source_file = name == NULL ? NULL : xstrdup (name);
+ gdb_assert (buildsym_compunit != nullptr || name == nullptr);
+ if (buildsym_compunit != nullptr)
+ buildsym_compunit->set_last_source_file (name);
}

/* See buildsym.h. */
@@ -1726,7 +1732,9 @@ set_last_source_file (const char *name)
const char *
get_last_source_file (void)
{
- return last_source_file;
+ if (buildsym_compunit == nullptr)
+ return nullptr;
+ return buildsym_compunit->m_last_source_file.get ();
}

\f
--
2.13.6