aboutsummaryrefslogtreecommitdiff
path: root/gdb/symfile.c
diff options
context:
space:
mode:
authorDoug Gilmore <Doug.Gilmore@imgtec.com>2017-06-28 02:54:22 +0100
committerMaciej W. Rozycki <macro@imgtec.com>2017-06-28 02:54:22 +0100
commit41664b45ab6387184bd0e7512fcf7a72c58744e7 (patch)
treec2c3df35f53f8a8d9ec76db7e96d066c0ef195f1 /gdb/symfile.c
parent819e1f86976dbbd13e0de004cdd3e3089e4c3fc0 (diff)
downloadgdb-41664b45ab6387184bd0e7512fcf7a72c58744e7.zip
gdb-41664b45ab6387184bd0e7512fcf7a72c58744e7.tar.gz
gdb-41664b45ab6387184bd0e7512fcf7a72c58744e7.tar.bz2
Fix PR 21337: segfault when re-reading symbols.
Fix issue exposed by commit 3e29f34. The basic issue is that section data referenced through an objfile pointer can also be referenced via the program-space data pointer, although via a separate mapping mechanism, which is set up by update_section_map. Thus once section data attached to an objfile pointer is released, the section map associated with the program-space data pointer must be marked dirty to ensure that update_section_map is called to prevent stale data being referenced. For the matter at hand this marking is being done via a call to objfiles_changed. Before commit 3e29f34 objfiles_changed could be called after all of the objfile pointers were processed in reread_symbols since section data references via the program-space data pointer would not occur in the calls of read_symbols performed by reread_symbols. With commit 3e29f34 MIPS target specific calls to find_pc_section were added to the code for DWARF information processing, which is called via read_symbols. Thus in reread_symbols the call to objfiles_changed needs to be called before calling read_symbols, otherwise stale section data can be referenced. Thanks to Luis Machado for providing text for the main comment associated with the change. gdb/ 2017-06-28 Doug Gilmore <Doug.Gilmore@imgtec.com> PR gdb/21337 * symfile.c (reread_symbols): Call objfiles_changed just before read_symbols. gdb/testsuite/ 2017-06-28 Doug Gilmore <Doug.Gilmore@imgtec.com> PR gdb/21337 * gdb.base/reread-readsym.exp: New file. * gdb.base/reread-readsym.c: New file.
Diffstat (limited to 'gdb/symfile.c')
-rw-r--r--gdb/symfile.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c
index aa53415..9cbd6e5 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2587,6 +2587,9 @@ reread_symbols (void)
/* Free the obstacks for non-reusable objfiles. */
psymbol_bcache_free (objfile->psymbol_cache);
objfile->psymbol_cache = psymbol_bcache_init ();
+
+ /* NB: after this call to obstack_free, objfiles_changed
+ will need to be called (see discussion below). */
obstack_free (&objfile->objfile_obstack, 0);
objfile->sections = NULL;
objfile->compunit_symtabs = NULL;
@@ -2639,6 +2642,23 @@ reread_symbols (void)
clear_complaints (&symfile_complaints, 1, 1);
objfile->flags &= ~OBJF_PSYMTABS_READ;
+
+ /* We are about to read new symbols and potentially also
+ DWARF information. Some targets may want to pass addresses
+ read from DWARF DIE's through an adjustment function before
+ saving them, like MIPS, which may call into
+ "find_pc_section". When called, that function will make
+ use of per-objfile program space data.
+
+ Since we discarded our section information above, we have
+ dangling pointers in the per-objfile program space data
+ structure. Force GDB to update the section mapping
+ information by letting it know the objfile has changed,
+ making the dangling pointers point to correct data
+ again. */
+
+ objfiles_changed ();
+
read_symbols (objfile, 0);
if (!objfile_has_symbols (objfile))
@@ -2671,9 +2691,6 @@ reread_symbols (void)
if (!new_objfiles.empty ())
{
- /* Notify objfiles that we've modified objfile sections. */
- objfiles_changed ();
-
clear_symtab_users (0);
/* clear_objfile_data for each objfile was called before freeing it and