From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [committed][gdb/symtab] Fix bad compile unit index complaint
Date: Thu, 21 Jul 2022 13:10:24 +0200 [thread overview]
Message-ID: <3b04b910-f020-7dba-54cd-46e23eb9657c@suse.de> (raw)
In-Reply-To: <20220714144351.GA31826@delia.home>
[-- Attachment #1: Type: text/plain, Size: 985 bytes --]
[ was: Re: [PATCH][gdb/symtab] Force usage of all_comp_units.size
(CU/TU/CUTU) ]
On 7/14/22 16:43, Tom de Vries wrote:
> Hi,
>
> I noticed this code in dw2_debug_names_iterator::next:
> ...
> case DW_IDX_compile_unit:
> /* Don't crash on bad data. */
> if (ull >= per_bfd->all_comp_units.size ())
> {
> complaint (_(".debug_names entry has bad CU index %s"
> " [in module %s]"),
> pulongest (ull),
> objfile_name (objfile));
> continue;
> }
> per_cu = per_bfd->get_cu (ull);
> break;
> ...
>
> This code used to DTRT, before we started keeping both CUs and TUs in
> all_comp_units.
>
I've dropped the all_comp_units.size (CU/TU/CUTU) part, since that
somewhat violates the One-Patch-Per-Independent=Change rule.
That also makes the patch trivial, so committed as attached.
Thanks,
- Tom
[-- Attachment #2: 0001-gdb-symtab-Fix-bad-compile-unit-index-complaint.patch --]
[-- Type: text/x-patch, Size: 3338 bytes --]
[gdb/symtab] Fix bad compile unit index complaint
I noticed this code in dw2_debug_names_iterator::next:
...
case DW_IDX_compile_unit:
/* Don't crash on bad data. */
if (ull >= per_bfd->all_comp_units.size ())
{
complaint (_(".debug_names entry has bad CU index %s"
" [in module %s]"),
pulongest (ull),
objfile_name (objfile));
continue;
}
per_cu = per_bfd->get_cu (ull);
break;
...
This code used to DTRT, before we started keeping both CUs and TUs in
all_comp_units.
Fix by using "per_bfd->all_comp_units.size () - per_bfd->tu_stats.nr_tus"
instead.
It's hard to produce a test-case for this, but let's try at least to trigger
the complaint somehow. We start out by creating an exec with .debug_types and
.debug_names:
...
$ gcc -g ~/hello.c -fdebug-types-section
$ gdb-add-index -dwarf-5 a.out
...
and verify that we don't see any complaints:
...
$ gdb -q -batch -iex "set complaints 100" ./a.out
...
We look at the CU and TU table using readelf -w and conclude that we have
nr_cus == 6 and nr_tus == 1.
Now override ull in dw2_debug_names_iterator::next for the DW_IDX_compile_unit
case to 6, and we have:
...
$ gdb -q -batch -iex "set complaints 100" ./a.out
During symbol reading: .debug_names entry has bad CU index 6 [in module a.out]
...
After this, it still crashes because this code in
dw2_debug_names_iterator::next:
...
/* Skip if already read in. */
if (m_per_objfile->symtab_set_p (per_cu))
goto again;
...
is called with per_cu == nullptr.
Fix this by skipping the entry if per_cu == nullptr.
Now revert the fix and observe that the complaint disappears, so we've
confirmed that the fix is required.
A somewhat similar issue for .gdb_index in dw2_symtab_iter_next has been filed
as PR29367.
Tested on x86_64-linux, with native and target board cc-with-debug-names.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29336
---
gdb/dwarf2/read.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index bcd01107377..42230607fe0 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -4970,15 +4970,19 @@ dw2_debug_names_iterator::next ()
switch (attr.dw_idx)
{
case DW_IDX_compile_unit:
- /* Don't crash on bad data. */
- if (ull >= per_bfd->all_comp_units.size ())
- {
- complaint (_(".debug_names entry has bad CU index %s"
- " [in module %s]"),
- pulongest (ull),
- objfile_name (objfile));
- continue;
- }
+ {
+ /* Don't crash on bad data. */
+ int nr_cus = (per_bfd->all_comp_units.size ()
+ - per_bfd->tu_stats.nr_tus);
+ if (ull >= nr_cus)
+ {
+ complaint (_(".debug_names entry has bad CU index %s"
+ " [in module %s]"),
+ pulongest (ull),
+ objfile_name (objfile));
+ continue;
+ }
+ }
per_cu = per_bfd->get_cu (ull);
break;
case DW_IDX_type_unit:
@@ -5016,6 +5020,10 @@ dw2_debug_names_iterator::next ()
}
}
+ /* Skip if we couldn't find a valid CU/TU index. */
+ if (per_cu == nullptr)
+ goto again;
+
/* Skip if already read in. */
if (m_per_objfile->symtab_set_p (per_cu))
goto again;
next prev parent reply other threads:[~2022-07-21 11:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-14 14:43 [PATCH][gdb/symtab] Force usage of all_comp_units.size (CU/TU/CUTU) Tom de Vries via Gdb-patches
2022-07-21 11:10 ` Tom de Vries via Gdb-patches [this message]
2022-07-21 11:20 ` [PATCH, v2][gdb/symtab] " Tom de Vries via Gdb-patches
2022-08-08 14:26 ` [PATCH][gdb/symtab] " Tom de Vries via Gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3b04b910-f020-7dba-54cd-46e23eb9657c@suse.de \
--to=gdb-patches@sourceware.org \
--cc=tdevries@suse.de \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox