[RFA,04/42] Move last_source file to buildsym_compunit
Commit Message
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(-)
Comments
On 2018-05-23 12:58 AM, Tom Tromey wrote:
> @@ -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
I think it's spelled DWARF (all caps)?
> + from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
> +
> + gdb::unique_xmalloc_ptr<char> m_last_source_file;
Nit: remove the empty line between the comment and the field.
Should this new field be private?
Otherwise, LGTM.
Simon
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:
Simon> On 2018-05-23 12:58 AM, Tom Tromey wrote:
>> @@ -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
Simon> I think it's spelled DWARF (all caps)?
Yeah, I just moved the old comment; but I've updated it now.
>> + from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
>> +
>> + gdb::unique_xmalloc_ptr<char> m_last_source_file;
Simon> Nit: remove the empty line between the comment and the field.
Done.
Simon> Should this new field be private?
All the data members are private by the end of the series, but I didn't
generally try to do that at each step along the way. This is one of
those compromises I mentioned in the cover letter -- where a bigger
reordering of the series might have yielded a prettier series, but
didn't seem worth the effort.
Tom
On 2018-07-08 12:33 PM, Tom Tromey wrote:
> All the data members are private by the end of the series, but I didn't
> generally try to do that at each step along the way. This is one of
> those compromises I mentioned in the cover letter -- where a bigger
> reordering of the series might have yielded a prettier series, but
> didn't seem worth the effort.
Ok, no problem then. You can ignore other similar comments I've already sent.
Simon
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:
Simon> On 2018-07-08 12:33 PM, Tom Tromey wrote:
>> All the data members are private by the end of the series, but I didn't
>> generally try to do that at each step along the way. This is one of
>> those compromises I mentioned in the cover letter -- where a bigger
>> reordering of the series might have yielded a prettier series, but
>> didn't seem worth the effort.
Simon> Ok, no problem then. You can ignore other similar comments I've
Simon> already sent.
I already sent one other reply but you can likewise ignore that :)
This series is a bit unwieldy. And I should probably have mentioned
earlier (before Keith went to the effort of applying it...) that it is
in my github as submit/buildsym-fixups, in case you wanted to check it
out or something.
Tom
On 2018-07-08 12:52 PM, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:
>
> Simon> On 2018-07-08 12:33 PM, Tom Tromey wrote:
>>> All the data members are private by the end of the series, but I didn't
>>> generally try to do that at each step along the way. This is one of
>>> those compromises I mentioned in the cover letter -- where a bigger
>>> reordering of the series might have yielded a prettier series, but
>>> didn't seem worth the effort.
>
> Simon> Ok, no problem then. You can ignore other similar comments I've
> Simon> already sent.
>
> I already sent one other reply but you can likewise ignore that :)
>
> This series is a bit unwieldy. And I should probably have mentioned
> earlier (before Keith went to the effort of applying it...) that it is
> in my github as submit/buildsym-fixups, in case you wanted to check it
> out or something.
It's been mostly fine so far (just one or two trivial merge conflicts), but
thanks for tip anyway. The patches are good on their own I think, so feel free
to start pushing them as soon as they are approved, so the pendant part of the
series gradually shrinks.
Simon
@@ -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)
}
-/* 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 ();
}