This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[rfc] .gdb_index: Fix crash on NULL psymtab
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Sun, 9 Jun 2013 20:08:04 +0200
- Subject: [rfc] .gdb_index: Fix crash on NULL psymtab
Hi,
this patch was created by a mistake, at least Fedora runs first gdb-add-index
and only then dwz is run, in such case this bug does not reproduce.
But when one runs dwz first and then gdb-add-index current GDB may crash.
Testcase is not posted here as I have not found a small reproducer and a full
reproducer is pretty big (230KB):
http://people.redhat.com/jkratoch/unusedcu.patch
The reproducer crashes GDB although it does not produce valid result as with
dwz first and gdb-add-index second objcopy fails to complete the operation:
BFD: stkYdQ3W: Not enough room for program headers, try linking with -N
objcopy:stkYdQ3W[.note.ABI-tag]: Bad value
BFD: stkYdQ3W: Not enough room for program headers, try linking with -N
objcopy:stkYdQ3W[.gdb_index]: Bad value
BFD: stkYdQ3W: Not enough room for program headers, try linking with -N
objcopy:stkYdQ3W: Bad value
While it has currently no practical usefulness it fixes a GDB crash and IMO it
is even correct, OK to check-in, Tom? It cannot regress just maybe one could
also print an error() in such case.
Thanks,
Jan
gdb/
2013-06-09 Jan Kratochvil <jan.kratochvil@redhat.com>
* dwarf2read.c (write_psymtabs_to_index): Ignore NULL PSYMTAB.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 55b1b17..09d7f7a 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -21261,6 +21261,12 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
struct psymtab_cu_index_map *map;
void **slot;
+ /* 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
+ need to be present in .gdb_index. */
+ if (psymtab == NULL)
+ continue;
+
if (psymtab->user == NULL)
recursively_write_psymbols (objfile, psymtab, symtab, psyms_seen, i);