Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Josh Matthews <josh@joshmatthews.net>
To: gdb-patches@sourceware.org
Subject: Fix immediate Darwin crash
Date: Sun, 21 Oct 2012 06:58:00 -0000	[thread overview]
Message-ID: <CAOvJiVVwSLoCh613zjo0gUEhoSuhOPqkgxOS2AQZimw2FLVzeA@mail.gmail.com> (raw)

Attempting to debug any binary on Darwin currently triggers an
immediate segfault. This patch corrects that.

Cheers,
Josh

2012-10-21  Josh Matthews  <josh@joshmatthews.net>

        * mach-o.c (bfd_mach_o_close_and_cleanup): Clear tdata
        pointer to avoid incorrect archive data deletion.
        * archive.c (_bfd_archive_close_and_cleanup): Avoid
        accessing archive cache data when tdata is null.

diff --git a/bfd/archive.c b/bfd/archive.c
index 8e8fd2d..3771272 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -2715,7 +2715,8 @@ _bfd_archive_close_and_cleanup (bfd *abfd)
     {
       bfd *nbfd;
       bfd *next;
-      htab_t htab;
+      struct artdata *ardata;
+      htab_t htab = NULL;

       /* Close nested archives (if this bfd is a thin archive).  */
       for (nbfd = abfd->nested_archives; nbfd; nbfd = next)
@@ -2724,7 +2725,11 @@ _bfd_archive_close_and_cleanup (bfd *abfd)
          bfd_close (nbfd);
        }

-      htab = bfd_ardata (abfd)->cache;
+      ardata = bfd_ardata (abfd);
+      if (ardata)
+        {
+          htab = ardata->cache;
+        }
       if (htab)
        {
          htab_traverse_noresize (htab, archive_close_worker, NULL);
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index 0379f4f..7c44c5a 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -4863,6 +4863,10 @@ bfd_mach_o_close_and_cleanup (bfd *abfd)
           free (dsym_filename);
         }
     }
+  else if (bfd_get_format (abfd) == bfd_archive)
+    {
+      abfd->tdata.mach_o_fat_data = NULL;
+    }

   return _bfd_generic_close_and_cleanup (abfd);
 }


             reply	other threads:[~2012-10-21  6:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-21  6:58 Josh Matthews [this message]
2012-10-22  8:53 ` Tristan Gingold

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=CAOvJiVVwSLoCh613zjo0gUEhoSuhOPqkgxOS2AQZimw2FLVzeA@mail.gmail.com \
    --to=josh@joshmatthews.net \
    --cc=gdb-patches@sourceware.org \
    /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