Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 1/5] [gdb/symtab] Bail out of create_addrmap_from_gdb_index on error
Date: Thu, 21 Aug 2025 15:31:10 +0200	[thread overview]
Message-ID: <20250821133114.24091-2-tdevries@suse.de> (raw)
In-Reply-To: <20250821133114.24091-1-tdevries@suse.de>

Currently, in create_addrmap_from_gdb_index, when finding an incorrect entry
in the address table of a .gdb_index section:
- a (by default silent) complaint is made,
- the entry is skipped, and
- the rest of the entries is processed.

This is the use-what-you-can approach, which make sense in general.

But in the case that the .gdb_index section is incorrect while the other debug
info is correct, this approach prevents gdb from building a correct cooked
index (assuming there's no bug in gdb that would cause an incorrect index to
be generated).

Instead, bail out of create_addrmap_from_gdb_index on finding errors in the
address table.

I wonder about the following potential drawback of this approach: in the case
that the .gdb_index section is incorrect because the debug info is incorrect,
this approach rejects the .gdb_index section and spents time rebuilding a
likewise incorrect index.  But I'm not sure if this is a real problem.
Perhaps gdb will refuse to generate such an index, in which case this is a
non-issue.

Tested on aarch64-linux.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
---
 gdb/dwarf2/read-gdb-index.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c
index fc7b654be1a..7db2834f4d3 100644
--- a/gdb/dwarf2/read-gdb-index.c
+++ b/gdb/dwarf2/read-gdb-index.c
@@ -1395,9 +1395,10 @@ create_signatured_type_table_from_gdb_index
   per_bfd->signatured_types = std::move (sig_types_hash);
 }
 
-/* Read the address map data from the mapped GDB index.  */
+/* Read the address map data from the mapped GDB index.  Return true if no
+   errors were found, otherwise return false.  */
 
-static void
+static bool
 create_addrmap_from_gdb_index (dwarf2_per_objfile *per_objfile,
 			       mapped_gdb_index *index)
 {
@@ -1423,14 +1424,14 @@ create_addrmap_from_gdb_index (dwarf2_per_objfile *per_objfile,
 	{
 	  complaint (_(".gdb_index address table has invalid range (%s - %s)"),
 		     hex_string (lo), hex_string (hi));
-	  continue;
+	  return false;
 	}
 
       if (cu_index >= index->units.size ())
 	{
 	  complaint (_(".gdb_index address table has invalid CU number %u"),
 		     (unsigned) cu_index);
-	  continue;
+	  return false;
 	}
 
       mutable_map.set_empty (lo, hi - 1, index->units[cu_index]);
@@ -1438,6 +1439,8 @@ create_addrmap_from_gdb_index (dwarf2_per_objfile *per_objfile,
 
   index->index_addrmap
     = new (&per_bfd->obstack) addrmap_fixed (&per_bfd->obstack, &mutable_map);
+
+  return true;
 }
 
 /* Sets the name and language of the main function from the shortcut table.  */
@@ -1559,7 +1562,8 @@ dwarf2_read_gdb_index
 
   finalize_all_units (per_bfd);
 
-  create_addrmap_from_gdb_index (per_objfile, map.get ());
+  if (!create_addrmap_from_gdb_index (per_objfile, map.get ()))
+    return false;
 
   set_main_name_from_gdb_index (per_objfile, map.get ());
 
-- 
2.43.0


  reply	other threads:[~2025-08-21 13:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21 13:31 [PATCH v2 0/5] [gdb/symtab] Handle invalid .gdb_index better Tom de Vries
2025-08-21 13:31 ` Tom de Vries [this message]
2025-08-21 13:31 ` [PATCH v2 2/5] [gdb] Make addrmap_mutable::insert_empty return bool Tom de Vries
2025-08-22 14:54   ` Simon Marchi
2025-08-22 18:51   ` Tom Tromey
2025-08-23  4:20     ` Tom de Vries
2025-08-23 17:53       ` Simon Marchi
2025-08-29  0:20         ` Tom Tromey
2025-08-29  8:28           ` Tom de Vries
2025-08-21 13:31 ` [PATCH v2 3/5] [gdb/symtab] Detect overlapping ranges in create_addrmap_from_gdb_index Tom de Vries
2025-08-22 14:57   ` Simon Marchi
2025-08-21 13:31 ` [PATCH v2 4/5] [gdb/symtab] Improve invalid range check " Tom de Vries
2025-08-22 14:56   ` Tom de Vries
2025-08-22 15:17   ` Simon Marchi
2025-08-22 18:53   ` Tom Tromey
2025-08-23  4:33     ` Tom de Vries
2025-08-21 13:31 ` [PATCH v2 5/5] [gdb/symtab] Turn complaints in create_addrmap_from_gdb_index into warnings Tom de Vries

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=20250821133114.24091-2-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /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