Fix end of CU calculation in cooked_indexer::index_dies
authorTom Tromey <tom@tromey.com>
Thu, 9 Jun 2022 13:21:24 +0000 (07:21 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 25 Jun 2022 16:58:16 +0000 (10:58 -0600)
cooked_indexer::index_dies incorrect computes the end of the current
CU in the .debug_info.  This isn't readily testable without writing
intentionally corrupt DWARF, but it's apparent through observation: it
is currently based on 'info_ptr', which does not always point to the
start of the CU.  This patch fixes the expression.  Tested on x86-64
Fedora 34.

gdb/dwarf2/read.c

index e22e09b4e2b4e1fdeb4b825610f3c7c102d5e110..80bb2929435285986872855a7c13b9010f7cd9ac 100644 (file)
@@ -18283,7 +18283,9 @@ cooked_indexer::index_dies (cutu_reader *reader,
                            const cooked_index_entry *parent_entry,
                            bool fully)
 {
-  const gdb_byte *end_ptr = info_ptr + reader->cu->header.get_length ();
+  const gdb_byte *end_ptr = (reader->buffer
+                            + to_underlying (reader->cu->header.sect_off)
+                            + reader->cu->header.get_length ());
 
   while (info_ptr < end_ptr)
     {