[patch] Fix a reread_symbols regression by mmap [Re: [patch] Use mmap instead of obstack_alloc for dwarf debug sections.]

Jan Kratochvil
2009-06-23T15:03:40Z

Hi Paul,

while sure your patch is great it has a regression. Assuming a regression
reproducer needs to link GDB with -lmcheck (but did verify it).

(I do not try to advocate reread_symbols but its code is there now.)

Thanks,
Jan

This patch will fix back (tested on {x86_64,i686}-fedora-linux-gnu):

-FAIL: gdb.ada/exec_changed.exp: start second
-dwarf2read.c:10943: internal-error: munmap_section_buffer: Assertion `munmap ((void *) map_begin, map_length) == 0' failed.^M
+PASS: gdb.ada/exec_changed.exp: start second

-FAIL: gdb.base/chng-syms.exp: (timeout) running with invalidated bpt condition after executable changes
-dwarf2read.c:10943: internal-error: munmap_section_buffer: Assertion `munmap ((void *) map_begin, map_length) == 0' failed.^M
+PASS: gdb.base/chng-syms.exp: running with invalidated bpt condition after executable changes

-FAIL: gdb.base/reread.exp: run to foo() second time (timeout)
-dwarf2read.c:10943: internal-error: munmap_section_buffer: Assertion `munmap ((void *) map_begin, map_length) == 0' failed.^M
-FAIL: gdb.base/reread.exp: shell mv /home/jkratoch/hammock/20090623build-gdbcvs/fedora-11-i386/build/src/gdb/testsuite.unix.-m32/gdb.base/reread /home/jkratoch/hammock/20090623build-gdbcvs/fedora-11-i386/build/src/gdb/testsuite.unix.-m32/gdb.base/reread2 (GDB internal error)
-ERROR: Could not resync from internal error (timeout)
-[more mess]
+PASS: gdb.base/reread.exp: run to foo() second time
+PASS: gdb.base/reread.exp: second pass: breakpoint foo in first file
+PASS: gdb.base/reread.exp: second pass: run to foo()
+PASS: gdb.base/reread.exp: second pass: continue to completion
+PASS: gdb.base/reread.exp: second pass: run to foo() second time

munmap(0x9595959595959000, 10778685752873425706) = -1 EINVAL (Invalid argument)
write(1, "dwarf2read.c:10943: internal-error: munmap_section_buffer: Assertion `munmap ((void *) map_begin, map_length) == 0' failed.\nA problem internal to GDB has been detected,\nfurther debugging may prove unre"..., 209) = 209

2009-06-23 Jan Kratochvil <jan.kratochvil@redhat.com>

Fix a regression by the mmap patch from 2009-06-16.
* symfile.c (reread_symbols): Move sym_finish and clear_objfile_data
calls before deleting the OBJFILE obstack. Extend the comment.

--- gdb/symfile.c 17 Jun 2009 18:34:34 -0000 1.232
+++ gdb/symfile.c 23 Jun 2009 14:56:34 -0000
@@ -2334,7 +2334,16 @@ reread_symbols (void)

/* Nuke all the state that we will re-read. Much of the following
code which sets things to NULL really is necessary to tell
- other parts of GDB that there is nothing currently there. */
+ other parts of GDB that there is nothing currently there.
+
+ Try to keep the freeing order compatible with free_objfile. */
+
+ if (objfile->sf != NULL)
+ {
+ (*objfile->sf->sym_finish) (objfile);
+ }
+
+ clear_objfile_data (objfile);

/* FIXME: Do we have to free a whole linked list, or is this
enough? */
@@ -2371,11 +2380,6 @@ reread_symbols (void)
sizeof (objfile->msymbol_hash));
memset (&objfile->msymbol_demangled_hash, 0,
sizeof (objfile->msymbol_demangled_hash));
- clear_objfile_data (objfile);
- if (objfile->sf != NULL)
- {
- (*objfile->sf->sym_finish) (objfile);
- }

objfile->psymbol_cache = bcache_xmalloc ();
objfile->macro_cache = bcache_xmalloc ();