* [PATCH 1/2] Remove casts from dwarf2/index-write.c
2020-02-25 13:09 [PATCH 0/2] Specialize partial_symtab for DWARF include files Tom Tromey
2020-02-25 13:09 ` [PATCH 2/2] " Tom Tromey
@ 2020-02-25 13:09 ` Tom Tromey
2020-02-26 16:27 ` Simon Marchi
1 sibling, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2020-02-25 13:09 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
dwarf2/index-write.c casts pointers to "dwarf2_psymtab *", but as far
as I can tell, it does not actually use any DWARF-specific fields of
the psymtab. So, this patch changes this code to use partial_symtab
instead. This removes nearly every cast, leaving just the unavoidable
one from addrmap iteration.
gdb/ChangeLog
2020-02-25 Tom Tromey <tom@tromey.com>
* dwarf2/index-write.c (psym_index_map): Change type.
(add_address_entry_worker, write_one_signatured_type)
(recursively_count_psymbols, recursively_write_psymbols)
(class debug_names, psyms_seen_size, write_gdbindex)
(write_debug_names): Use partial_symtab, not dwarf2_psymtab.
---
gdb/ChangeLog | 8 ++++++++
gdb/dwarf2/index-write.c | 26 +++++++++++++-------------
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 2cbf2ebd202..4b711d0d29a 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -399,7 +399,7 @@ write_hash_table (mapped_symtab *symtab, data_buf &output, data_buf &cpool)
}
}
-typedef std::unordered_map<dwarf2_psymtab *, unsigned int> psym_index_map;
+typedef std::unordered_map<partial_symtab *, unsigned int> psym_index_map;
/* Helper struct for building the address table. */
struct addrmap_index_data
@@ -439,7 +439,7 @@ static int
add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj)
{
struct addrmap_index_data *data = (struct addrmap_index_data *) datap;
- dwarf2_psymtab *pst = (dwarf2_psymtab *) obj;
+ partial_symtab *pst = (partial_symtab *) obj;
if (data->previous_valid)
add_address_entry (data->objfile, data->addr_vec,
@@ -582,7 +582,7 @@ write_one_signatured_type (void **slot, void *d)
struct signatured_type_index_data *info
= (struct signatured_type_index_data *) d;
struct signatured_type *entry = (struct signatured_type *) *slot;
- dwarf2_psymtab *psymtab = entry->per_cu.v.psymtab;
+ partial_symtab *psymtab = entry->per_cu.v.psymtab;
write_psymbols (info->symtab,
info->psyms_seen,
@@ -612,12 +612,12 @@ write_one_signatured_type (void **slot, void *d)
if they appeared in this psymtab. */
static void
-recursively_count_psymbols (dwarf2_psymtab *psymtab,
+recursively_count_psymbols (partial_symtab *psymtab,
size_t &psyms_seen)
{
for (int i = 0; i < psymtab->number_of_dependencies; ++i)
if (psymtab->dependencies[i]->user != NULL)
- recursively_count_psymbols ((dwarf2_psymtab *) psymtab->dependencies[i],
+ recursively_count_psymbols (psymtab->dependencies[i],
psyms_seen);
psyms_seen += psymtab->n_global_syms;
@@ -629,7 +629,7 @@ recursively_count_psymbols (dwarf2_psymtab *psymtab,
static void
recursively_write_psymbols (struct objfile *objfile,
- dwarf2_psymtab *psymtab,
+ partial_symtab *psymtab,
struct mapped_symtab *symtab,
std::unordered_set<partial_symbol *> &psyms_seen,
offset_type cu_index)
@@ -639,7 +639,7 @@ recursively_write_psymbols (struct objfile *objfile,
for (i = 0; i < psymtab->number_of_dependencies; ++i)
if (psymtab->dependencies[i]->user != NULL)
recursively_write_psymbols (objfile,
- (dwarf2_psymtab *) psymtab->dependencies[i],
+ psymtab->dependencies[i],
symtab, psyms_seen, cu_index);
write_psymbols (symtab,
@@ -869,14 +869,14 @@ public:
as if they appeared in this psymtab. */
void recursively_write_psymbols
(struct objfile *objfile,
- dwarf2_psymtab *psymtab,
+ partial_symtab *psymtab,
std::unordered_set<partial_symbol *> &psyms_seen,
int cu_index)
{
for (int i = 0; i < psymtab->number_of_dependencies; ++i)
if (psymtab->dependencies[i]->user != NULL)
recursively_write_psymbols
- (objfile, (dwarf2_psymtab *) psymtab->dependencies[i], psyms_seen, cu_index);
+ (objfile, psymtab->dependencies[i], psyms_seen, cu_index);
write_psymbols (psyms_seen,
(objfile->partial_symtabs->global_psymbols.data ()
@@ -1234,7 +1234,7 @@ private:
write_one_signatured_type (struct signatured_type *entry,
struct signatured_type_index_data *info)
{
- dwarf2_psymtab *psymtab = entry->per_cu.v.psymtab;
+ partial_symtab *psymtab = entry->per_cu.v.psymtab;
write_psymbols (info->psyms_seen,
(info->objfile->partial_symtabs->global_psymbols.data ()
@@ -1320,7 +1320,7 @@ psyms_seen_size (struct dwarf2_per_objfile *dwarf2_per_objfile)
size_t psyms_count = 0;
for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
- dwarf2_psymtab *psymtab = per_cu->v.psymtab;
+ partial_symtab *psymtab = per_cu->v.psymtab;
if (psymtab != NULL && psymtab->user == NULL)
recursively_count_psymbols (psymtab, psyms_count);
@@ -1423,7 +1423,7 @@ write_gdbindex (struct dwarf2_per_objfile *dwarf2_per_objfile, FILE *out_file,
{
struct dwarf2_per_cu_data *per_cu
= dwarf2_per_objfile->all_comp_units[i];
- dwarf2_psymtab *psymtab = per_cu->v.psymtab;
+ partial_symtab *psymtab = per_cu->v.psymtab;
/* CU of a shared file from 'dwz -m' may be unused by this main file.
It may be referenced from a local scope but in such case it does not
@@ -1508,7 +1508,7 @@ write_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
for (int i = 0; i < dwarf2_per_objfile->all_comp_units.size (); ++i)
{
const dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->all_comp_units[i];
- dwarf2_psymtab *psymtab = per_cu->v.psymtab;
+ partial_symtab *psymtab = per_cu->v.psymtab;
/* CU of a shared file from 'dwz -m' may be unused by this main
file. It may be referenced from a local scope but in such
--
2.17.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] Specialize partial_symtab for DWARF include files
2020-02-25 13:09 [PATCH 0/2] Specialize partial_symtab for DWARF include files Tom Tromey
@ 2020-02-25 13:09 ` Tom Tromey
2020-02-26 16:34 ` Simon Marchi
2020-02-25 13:09 ` [PATCH 1/2] Remove casts from dwarf2/index-write.c Tom Tromey
1 sibling, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2020-02-25 13:09 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
Include files are represented by a partial symtab, but don't expand to
anything. From dwarf2_psymtab::expand_psymtab:
if (per_cu == NULL)
{
/* It's an include file, no symbols to read for it.
Everything is in the parent symtab. */
readin = true;
return;
}
This patch introduces a new specialization of partial_symtab to handle
this case. In addition to being slightly smaller, I believe an
include file is the only situation where a DWARF psymtab can result in
a null compunit_symtab. This adds an assert to that effect as well.
This change will simplify one of the psymtab sharing patches.
gdb/ChangeLog
2020-02-25 Tom Tromey <tom@tromey.com>
* dwarf2/read.c (struct dwarf2_include_psymtab): New.
(dwarf2_create_include_psymtab): Use dwarf2_include_psymtab.
(dwarf2_psymtab::expand_psymtab, dwarf2_psymtab::readin_p)
(dwarf2_psymtab::get_compunit_symtab): Remove null checks for
per_cu_data.
---
gdb/ChangeLog | 8 +++++++
gdb/dwarf2/read.c | 61 ++++++++++++++++++++++++++++++++---------------
2 files changed, 50 insertions(+), 19 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8c40ddb727a..d22a53deb25 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -5894,6 +5894,45 @@ read_abbrev_offset (struct dwarf2_per_objfile *dwarf2_per_objfile,
return (sect_offset) read_offset (abfd, info_ptr, offset_size);
}
+/* A partial symtab that is used only for include files. */
+struct dwarf2_include_psymtab : public partial_symtab
+{
+ dwarf2_include_psymtab (const char *filename, struct objfile *objfile)
+ : partial_symtab (filename, objfile)
+ {
+ }
+
+ void read_symtab (struct objfile *objfile) override
+ {
+ expand_psymtab (objfile);
+ }
+
+ void expand_psymtab (struct objfile *objfile) override
+ {
+ if (m_readin)
+ return;
+ /* It's an include file, no symbols to read for it.
+ Everything is in the parent symtab. */
+ read_dependencies (objfile);
+ m_readin = true;
+ }
+
+ bool readin_p () const override
+ {
+ return m_readin;
+ }
+
+ struct compunit_symtab *get_compunit_symtab () const
+ override
+ {
+ return nullptr;
+ }
+
+private:
+
+ bool m_readin = false;
+};
+
/* Allocate a new partial symtab for file named NAME and mark this new
partial symtab as being an include of PST. */
@@ -5901,7 +5940,7 @@ static void
dwarf2_create_include_psymtab (const char *name, dwarf2_psymtab *pst,
struct objfile *objfile)
{
- dwarf2_psymtab *subpst = new dwarf2_psymtab (name, objfile);
+ dwarf2_include_psymtab *subpst = new dwarf2_include_psymtab (name, objfile);
if (!IS_ABSOLUTE_PATH (subpst->filename))
{
@@ -5912,11 +5951,6 @@ dwarf2_create_include_psymtab (const char *name, dwarf2_psymtab *pst,
subpst->dependencies = objfile->partial_symtabs->allocate_dependencies (1);
subpst->dependencies[0] = pst;
subpst->number_of_dependencies = 1;
-
- /* No private part is necessary for include psymtabs. This property
- can be used to differentiate between such include psymtabs and
- the regular ones. */
- subpst->per_cu_data = nullptr;
}
/* Read the Line Number Program data and extract the list of files
@@ -8827,24 +8861,13 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
void
dwarf2_psymtab::expand_psymtab (struct objfile *objfile)
{
- struct dwarf2_per_cu_data *per_cu;
-
if (readin)
return;
read_dependencies (objfile);
- per_cu = per_cu_data;
-
- if (per_cu == NULL)
- {
- /* It's an include file, no symbols to read for it.
- Everything is in the parent symtab. */
- readin = true;
- return;
- }
-
- dw2_do_instantiate_symtab (per_cu, false);
+ dw2_do_instantiate_symtab (per_cu_data, false);
+ gdb_assert (get_compunit_symtab () != nullptr);
}
/* Trivial hash function for die_info: the hash value of a DIE
--
2.17.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 0/2] Specialize partial_symtab for DWARF include files
@ 2020-02-25 13:09 Tom Tromey
2020-02-25 13:09 ` [PATCH 2/2] " Tom Tromey
2020-02-25 13:09 ` [PATCH 1/2] Remove casts from dwarf2/index-write.c Tom Tromey
0 siblings, 2 replies; 6+ messages in thread
From: Tom Tromey @ 2020-02-25 13:09 UTC (permalink / raw)
To: gdb-patches
This started as just a patch to Specialize partial_symtab for DWARF
include files, but then I noticed a bunch of casts in index-write.c
that would no longer be correct; and so it turned into a 2-patch
series.
This is the patch I was talking about in another thread. I think it
will let us remove the optional<> from the psymtab sharing series.
Tested by the buildbot.
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] Remove casts from dwarf2/index-write.c
2020-02-25 13:09 ` [PATCH 1/2] Remove casts from dwarf2/index-write.c Tom Tromey
@ 2020-02-26 16:27 ` Simon Marchi
0 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2020-02-26 16:27 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 2020-02-25 8:09 a.m., Tom Tromey wrote:
> dwarf2/index-write.c casts pointers to "dwarf2_psymtab *", but as far
> as I can tell, it does not actually use any DWARF-specific fields of
> the psymtab. So, this patch changes this code to use partial_symtab
> instead. This removes nearly every cast, leaving just the unavoidable
> one from addrmap iteration.
Thanks, that LGTM.
Simon
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] Specialize partial_symtab for DWARF include files
2020-02-25 13:09 ` [PATCH 2/2] " Tom Tromey
@ 2020-02-26 16:34 ` Simon Marchi
2020-02-26 23:28 ` Tom Tromey
0 siblings, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2020-02-26 16:34 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 2020-02-25 8:09 a.m., Tom Tromey wrote:
> Include files are represented by a partial symtab, but don't expand to
> anything. From dwarf2_psymtab::expand_psymtab:
>
> if (per_cu == NULL)
> {
> /* It's an include file, no symbols to read for it.
> Everything is in the parent symtab. */
> readin = true;
> return;
> }
>
> This patch introduces a new specialization of partial_symtab to handle
> this case. In addition to being slightly smaller, I believe an
> include file is the only situation where a DWARF psymtab can result in
> a null compunit_symtab. This adds an assert to that effect as well.
> This change will simplify one of the psymtab sharing patches.
>
> gdb/ChangeLog
> 2020-02-25 Tom Tromey <tom@tromey.com>
>
> * dwarf2/read.c (struct dwarf2_include_psymtab): New.
> (dwarf2_create_include_psymtab): Use dwarf2_include_psymtab.
> (dwarf2_psymtab::expand_psymtab, dwarf2_psymtab::readin_p)
> (dwarf2_psymtab::get_compunit_symtab): Remove null checks for
> per_cu_data.
Hi Tom,
From what I understand, this is fine, thanks.
> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index 8c40ddb727a..d22a53deb25 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -5894,6 +5894,45 @@ read_abbrev_offset (struct dwarf2_per_objfile *dwarf2_per_objfile,
> return (sect_offset) read_offset (abfd, info_ptr, offset_size);
> }
>
> +/* A partial symtab that is used only for include files. */
> +struct dwarf2_include_psymtab : public partial_symtab
> +{
> + dwarf2_include_psymtab (const char *filename, struct objfile *objfile)
> + : partial_symtab (filename, objfile)
> + {
> + }
> +
> + void read_symtab (struct objfile *objfile) override
> + {
> + expand_psymtab (objfile);
> + }
> +
> + void expand_psymtab (struct objfile *objfile) override
> + {
> + if (m_readin)
> + return;
> + /* It's an include file, no symbols to read for it.
> + Everything is in the parent symtab. */
> + read_dependencies (objfile);
> + m_readin = true;
> + }
> +
> + bool readin_p () const override
> + {
> + return m_readin;
> + }
> +
> + struct compunit_symtab *get_compunit_symtab () const
> + override
The override can be on the previous line.
Simon
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] Specialize partial_symtab for DWARF include files
2020-02-26 16:34 ` Simon Marchi
@ 2020-02-26 23:28 ` Tom Tromey
0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2020-02-26 23:28 UTC (permalink / raw)
To: Simon Marchi; +Cc: Tom Tromey, gdb-patches
>> + struct compunit_symtab *get_compunit_symtab () const
>> + override
Simon> The override can be on the previous line.
Thanks. I checked it in with that change.
Tom
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-02-26 23:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-25 13:09 [PATCH 0/2] Specialize partial_symtab for DWARF include files Tom Tromey
2020-02-25 13:09 ` [PATCH 2/2] " Tom Tromey
2020-02-26 16:34 ` Simon Marchi
2020-02-26 23:28 ` Tom Tromey
2020-02-25 13:09 ` [PATCH 1/2] Remove casts from dwarf2/index-write.c Tom Tromey
2020-02-26 16:27 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).