From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [FYI] Fix crash in machoread.c
Date: Wed, 27 Jun 2018 20:42:00 -0000 [thread overview]
Message-ID: <20180627204211.18963-1-tom@tromey.com> (raw)
"./gdb ./gdb" was crashing for me on macOS. Investigating showed that
macho_symfile_read was crashing because "symbol_table" was being freed
too soon. This was introduced by my earlier patch to change
macho_symfile_read to use a std::vector.
Tested on macOS 10.13.5 using "./gdb ./gdb". This should un-break
various already existing tests (testsuite/gdb.gdb at least), so no new
test case.
I'm checking this in as obvious.
gdb/ChangeLog
2018-06-27 Tom Tromey <tom@tromey.com>
* machoread.c (macho_symfile_read): Define "symbol_table" earlier.
---
gdb/ChangeLog | 4 ++++
gdb/machoread.c | 6 ++++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index be45bc31fa2..a125b72e420 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2018-06-27 Tom Tromey <tom@tromey.com>
+
+ * machoread.c (macho_symfile_read): Define "symbol_table" earlier.
+
2018-06-27 Simon Marchi <simon.marchi@ericsson.com>
* gdb-gdb.py.in: Format using autopep8.
diff --git a/gdb/machoread.c b/gdb/machoread.c
index 4c1d4f0bfa7..07e1cdaf4f8 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -793,6 +793,9 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
bfd *abfd = objfile->obfd;
long storage_needed;
std::vector<oso_el> oso_vector;
+ /* We have to hold on to the symbol table until the call to
+ macho_symfile_read_all_oso at the end of this function. */
+ gdb::def_vector<asymbol *> symbol_table;
/* Get symbols from the symbol table only if the file is an executable.
The symbol table of object files is not relocated and is expected to
@@ -812,8 +815,7 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{
long symcount;
- gdb::def_vector<asymbol *> symbol_table (storage_needed
- / sizeof (asymbol *));
+ symbol_table.resize (storage_needed / sizeof (asymbol *));
minimal_symbol_reader reader (objfile);
--
2.17.1
reply other threads:[~2018-06-27 20:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20180627204211.18963-1-tom@tromey.com \
--to=tom@tromey.com \
--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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).