Index: solib.c =================================================================== RCS file: /cvs/src/src/gdb/solib.c,v retrieving revision 1.124 diff -u -p -u -r1.124 solib.c --- solib.c 10 Aug 2009 22:09:22 -0000 1.124 +++ solib.c 17 Aug 2009 22:27:07 -0000 @@ -440,26 +440,53 @@ master_so_list (void) return so_list_head; } +/* Set reference count on ABFD to COUNT. */ + +static void +set_ref_count (struct bfd *abfd, int count) +{ + int *p_refcount = (int *) xmalloc (sizeof (*p_refcount)); + *p_refcount = count; + + gdb_assert (bfd_usrdata (abfd) == NULL); + bfd_usrdata (abfd) = p_refcount; +} + static void symbol_add_stub (struct so_list *so, int flags) { struct section_addr_info *sap; - int *p_refcount; + struct objfile *objfile; /* Have we already loaded this shared object? */ - ALL_OBJFILES (so->objfile) + ALL_OBJFILES (objfile) { - if (strcmp (so->objfile->name, so->so_name) == 0) - return; + if (strcmp (objfile->name, so->so_name) == 0) + { + if (objfile != so->objfile) + { + /* This could happen when symbol_file_add_from_bfd + below is interrupted. */ + + gdb_assert (so->objfile == NULL); + gdb_assert (bfd_usrdata (so->abfd) == NULL); + + so->objfile = objfile; /* Reconnect. */ + + /* Both solib and objfile refer to this abfd. */ + set_ref_count (so->abfd, 2); + } + return; + } } sap = build_section_addr_info_from_section_table (so->sections, so->sections_end); so->objfile = symbol_file_add_from_bfd (so->abfd, flags, sap, OBJF_SHARED); - p_refcount = xmalloc (sizeof (*p_refcount)); - *p_refcount = 2; /* Both solib and objfile refer to this abfd. */ - bfd_usrdata (so->abfd) = p_refcount; + + /* Both solib and objfile refer to this abfd. */ + set_ref_count (so->abfd, 2); free_section_addr_info (sap);