Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Paul Pluzhnikov <ppluzhnikov@google.com>
To: Paul Pluzhnikov <ppluzhnikov@google.com>,
	tromey@redhat.com,         gdb@sourceware.org
Subject: Re: Solibs and objfile BFD ownership
Date: Tue, 18 Aug 2009 05:56:00 -0000	[thread overview]
Message-ID: <8ac60eac0908171544r6d1eac67lcaedb388b525c5@mail.gmail.com> (raw)
In-Reply-To: <8ac60eac0908041147m17f3f337g3ea15696dc0a3170@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1445 bytes --]

On Tue, Aug 4, 2009 at 11:47 AM, Paul Pluzhnikov<ppluzhnikov@google.com> wrote:

> So committed. Thanks,

I seem to have hit a rough patch with my patches :-(

The BFD refcounting patch from 2009-08-04 causes GDB to crash when I attach
to a process with many solibs, then (while GDB is reading solib symbols)
change my mind about attaching and hit Control-C, then 'run'.

This is happening because in symbol_add_stub refcount may not be set:

   so->objfile = symbol_file_add_from_bfd (so->abfd, flags, sap, OBJF_SHARED);

---> QUIT could be executed deep inside symbol_file_add_from_bfd, and
---> bfd_userdata below is never set.

   p_refcount = xmalloc (sizeof (*p_refcount));
   *p_refcount = 2;  /* Both solib and objfile refer to this abfd.  */
   bfd_usrdata (so->abfd) = p_refcount;

Later, we re-enter symbol_add_stub, and this:

   ALL_OBJFILES (so->objfile)
     {
       if (strcmp (so->objfile->name, so->so_name) == 0)
         return;

re-connects the so with the objfile, but never sets the bfd_usrdata.

Later still (during execution of 'run'), we go through clear_solib and
objfile_purge_solibs, and the latter crashes trying to bfd_close the abfd
which has already been bfd_close()d by the former.

Here is a proposed patch. Tested on Linux/x86_64 with no new failures.

Thanks,
-- 
Paul Pluzhnikov

2009-08-17  Paul Pluzhnikov  <ppluzhnikov@google.com>

	* solib.c (set_ref_count): New function.
	(symbol_add_stub): Call it.

[-- Attachment #2: gdb-bfd-ownership-20090817.txt --]
[-- Type: text/plain, Size: 1914 bytes --]

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);
 

  reply	other threads:[~2009-08-17 22:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-28 15:40 Daniel Jacobowitz
2009-07-29 23:56 ` Paul Pluzhnikov
2009-07-30 16:16   ` Tom Tromey
2009-08-04  0:50     ` Paul Pluzhnikov
2009-08-04 14:53       ` Daniel Jacobowitz
2009-08-04 17:37         ` Paul Pluzhnikov
2009-08-04 18:40           ` Daniel Jacobowitz
2009-08-04 18:47             ` Paul Pluzhnikov
2009-08-18  5:56               ` Paul Pluzhnikov [this message]
2009-08-19 22:29                 ` Tom Tromey
2009-08-20  1:50                   ` Paul Pluzhnikov
2009-08-21 17:32                     ` Tom Tromey
2009-08-21 18:04                       ` Paul Pluzhnikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ac60eac0908171544r6d1eac67lcaedb388b525c5@mail.gmail.com \
    --to=ppluzhnikov@google.com \
    --cc=gdb@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox