[RFA,13/15] Add psymtab_storage::allocate_dependencies
Commit Message
This adds a new method to psymtab_storage to allocate storage for
psymtab dependencies, then changes the symbol readers to use it. This
has the effect of moving the storage to the psymtab storage obstack.
2018-05-10 Tom Tromey <tom@tromey.com>
* xcoffread.c (xcoff_end_psymtab): Use allocate_dependencies.
* psymtab.h (psymtab_storage::allocate_dependencies): New method.
* mdebugread.c (parse_partial_symbols): Use
allocate_dependencies.
* dwarf2read.c (dwarf2_create_include_psymtab): Use
allocate_dependencies.
(process_psymtab_comp_unit_reader)
(build_type_psymtab_dependencies): Likewise.
* dbxread.c (dbx_end_psymtab): Use allocate_dependencies.
---
gdb/ChangeLog | 12 ++++++++++++
gdb/dbxread.c | 9 ++-------
gdb/dwarf2read.c | 10 ++++------
gdb/mdebugread.c | 5 +----
gdb/psymtab.h | 6 ++++++
gdb/xcoffread.c | 11 +++--------
6 files changed, 28 insertions(+), 25 deletions(-)
Comments
On 2018-05-10 06:23 PM, Tom Tromey wrote:
> diff --git a/gdb/dbxread.c b/gdb/dbxread.c
> index c3741fda8a..e1aed48ff7 100644
> --- a/gdb/dbxread.c
> +++ b/gdb/dbxread.c
> @@ -2092,13 +2092,8 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
>
> pst->number_of_dependencies = number_dependencies;
> if (number_dependencies)
> - {
> - pst->dependencies = XOBNEWVEC (&objfile->objfile_obstack,
> - struct partial_symtab *,
> - number_dependencies);
> - memcpy (pst->dependencies, dependency_list,
> - number_dependencies * sizeof (struct partial_symtab *));
> - }
> + pst->dependencies
> + = objfile->partial_symtabs->allocate_dependencies (number_dependencies);
There is a memcpy that disappears here, probably not intended? Same in xcoffread.
Otherwise, LGTM.
Simon
>>>>> "Simon" == Simon Marchi <simon.marchi@ericsson.com> writes:
Simon> On 2018-05-10 06:23 PM, Tom Tromey wrote:
>> diff --git a/gdb/dbxread.c b/gdb/dbxread.c
>> index c3741fda8a..e1aed48ff7 100644
>> --- a/gdb/dbxread.c
>> +++ b/gdb/dbxread.c
>> @@ -2092,13 +2092,8 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
>>
pst-> number_of_dependencies = number_dependencies;
>> if (number_dependencies)
>> - {
>> - pst->dependencies = XOBNEWVEC (&objfile->objfile_obstack,
>> - struct partial_symtab *,
>> - number_dependencies);
>> - memcpy (pst->dependencies, dependency_list,
>> - number_dependencies * sizeof (struct partial_symtab *));
>> - }
>> + pst->dependencies
>> + = objfile->partial_symtabs->allocate_dependencies (number_dependencies);
Simon> There is a memcpy that disappears here, probably not intended? Same in xcoffread.
Thanks, I fixed this. There was also a spot in dbxread.c where there
should have been another change to call allocate_dependencies; I fixed
this as well.
Tom
@@ -2092,13 +2092,8 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
pst->number_of_dependencies = number_dependencies;
if (number_dependencies)
- {
- pst->dependencies = XOBNEWVEC (&objfile->objfile_obstack,
- struct partial_symtab *,
- number_dependencies);
- memcpy (pst->dependencies, dependency_list,
- number_dependencies * sizeof (struct partial_symtab *));
- }
+ pst->dependencies
+ = objfile->partial_symtabs->allocate_dependencies (number_dependencies);
else
pst->dependencies = 0;
@@ -6512,8 +6512,7 @@ dwarf2_create_include_psymtab (const char *name, struct partial_symtab *pst,
subpst->dirname = pst->dirname;
}
- subpst->dependencies
- = XOBNEW (&objfile->objfile_obstack, struct partial_symtab *);
+ subpst->dependencies = objfile->partial_symtabs->allocate_dependencies (1);
subpst->dependencies[0] = pst;
subpst->number_of_dependencies = 1;
@@ -7989,8 +7988,8 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
/* Fill in 'dependencies' here; we fill in 'users' in a
post-pass. */
pst->number_of_dependencies = len;
- pst->dependencies =
- XOBNEWVEC (&objfile->objfile_obstack, struct partial_symtab *, len);
+ pst->dependencies
+ = objfile->partial_symtabs->allocate_dependencies (len);
for (i = 0;
VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
i, iter);
@@ -8248,8 +8247,7 @@ build_type_psymtab_dependencies (void **slot, void *info)
gdb_assert (IS_TYPE_UNIT_GROUP (per_cu));
pst->number_of_dependencies = len;
- pst->dependencies =
- XOBNEWVEC (&objfile->objfile_obstack, struct partial_symtab *, len);
+ pst->dependencies = objfile->partial_symtabs->allocate_dependencies (len);
for (i = 0;
VEC_iterate (sig_type_ptr, tu_group->tus, i, iter);
++i)
@@ -3752,10 +3752,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
source files or a reverse .h -> .c dependency for header files. */
pst->number_of_dependencies = 0;
pst->dependencies =
- ((struct partial_symtab **)
- obstack_alloc (&objfile->objfile_obstack,
- ((fh->crfd - 1)
- * sizeof (struct partial_symtab *))));
+ objfile->partial_symtabs->allocate_dependencies (fh->crfd - 1);
for (s_idx = 1; s_idx < fh->crfd; s_idx++)
{
RFDT rh;
@@ -20,6 +20,7 @@
#ifndef PSYMTAB_H
#define PSYMTAB_H
+#include "gdb_obstack.h"
#include "symfile.h"
/* A bcache for partial symbols. */
@@ -60,6 +61,11 @@ public:
return m_obstack;
}
+ struct partial_symtab **allocate_dependencies (int number)
+ {
+ return OBSTACK_CALLOC (obstack (), number, struct partial_symtab *);
+ }
+
/* Each objfile points to a linked list of partial symtabs derived from
this file, one partial symtab structure for each compilation unit
@@ -2079,13 +2079,8 @@ xcoff_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
pst->number_of_dependencies = number_dependencies;
if (number_dependencies)
- {
- pst->dependencies = XOBNEWVEC (&objfile->objfile_obstack,
- struct partial_symtab *,
- number_dependencies);
- memcpy (pst->dependencies, dependency_list,
- number_dependencies * sizeof (struct partial_symtab *));
- }
+ pst->dependencies
+ = objfile->partial_symtabs->allocate_dependencies (number_dependencies);
else
pst->dependencies = 0;
@@ -2102,7 +2097,7 @@ xcoff_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
/* We could save slight bits of space by only making one of these,
shared by the entire set of include files. FIXME-someday. */
subpst->dependencies =
- XOBNEW (&objfile->objfile_obstack, struct partial_symtab *);
+ objfile->partial_symtabs->allocate_dependencies (1);
subpst->dependencies[0] = pst;
subpst->number_of_dependencies = 1;