From: Hui Zhu <hui_zhu@mentor.com>
To: Tom Tromey <tromey@redhat.com>
Cc: Sergio Durigan Junior <sergiodj@redhat.com>,
gdb-patches ml <gdb-patches@sourceware.org>,
Edjunior Barbosa Machado <emachado@linux.vnet.ibm.com>,
Nick Clifton <nickc@redhat.com>
Subject: Re: [PATCH] Remove gdb_bfd_stash_filename to fix crash with fix of binutils/11983
Date: Mon, 06 Jan 2014 10:50:00 -0000 [thread overview]
Message-ID: <52CA8A7F.7090907@mentor.com> (raw)
In-Reply-To: <87k3edseia.fsf@fleche.redhat.com>
On 01/06/14 16:25, Tom Tromey wrote:
>>>>>> "Hui" == Hui Zhu <hui_zhu@mentor.com> writes:
>
> Hui> Thanks. Post a new version.
>
> Thanks Hui. This is definitely the direction I think the code should
> go.
>
> Hui> --- a/gdb/symfile-mem.c
> Hui> +++ b/gdb/symfile-mem.c
> Hui> @@ -104,11 +104,7 @@ symbol_file_add_from_memory (struct bfd
> Hui> if (name == NULL)
> Hui> nbfd-> filename = "shared object read from target memory";
> Hui> else
> Hui> - {
> Hui> - nbfd->filename = name;
> Hui> - gdb_bfd_stash_filename (nbfd);
> Hui> - xfree (name);
> Hui> - }
> Hui> + nbfd->filename = name;
> Hui> cleanup = make_cleanup_bfd_unref (nbfd);
>
> In this hunk there are two things to note.
>
> First, there is an earlier assignment to filename (in the context above)
> that should use xstrdup.
>
> Second, the new assignment really ought to free the old nbfd->filename
> first.
I changed this part to:
xfree (bfd_get_filename (nbfd));
if (name == NULL)
nbfd->filename = xstrdup ("shared object read from target memory");
else
nbfd->filename = name;
>
> There are also some assignments that must be fixed that do not use
> gdb_bfd_stash_filename:
>
> solib-aix.c:solib_aix_bfd_open
> solib-darwin.c:darwin_bfd_open
I fixed them.
> solib-spu.c:spu_bfd_open
> spu-linux-nat.c:spu_bfd_open
These two functions have used xstrdup, for example:
if (sect_size > 20)
{
char *buf = alloca (sect_size - 20 + strlen (original_name) + 1);
bfd_get_section_contents (abfd, spu_name, buf, 20, sect_size - 20);
buf[sect_size - 20] = '\0';
strcat (buf, original_name);
xfree ((char *)abfd->filename);
abfd->filename = xstrdup (buf);
}
So I didn't update them.
>
> If you don't get to this soon, no worries, I will add these to your
> patch tomorrow morning and check it in.
>
> Tom
>
Thunderbird and maybe some others will see some empty lines because this patch include page identifier.
Thanks,
Hui
2014-01-06 Hui Zhu <hui@codesourcery.com>
* gdb_bfd.c (gdb_bfd_stash_filename): Removed.
(gdb_bfd_open): Removed gdb_bfd_stash_filename.
(gdb_bfd_fopen): Ditto.
(gdb_bfd_openr): Ditto.
(gdb_bfd_openw): Ditto.
(gdb_bfd_openr_iovec): Ditto.
(gdb_bfd_fdopenr): Ditto.
* gdb_bfd.h (gdb_bfd_stash_filename): Removed.
* solib-aix.c (solib_aix_bfd_open): Alloc object_bfd->filename
with xstrdup.
* solib-darwin.c (darwin_bfd_open): Alloc res->filename
with xstrdup.
* symfile-mem.c (symbol_file_add_from_memory): Removed
gdb_bfd_stash_filename.
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -57,21 +57,6 @@ struct gdb_bfd_section_data
static htab_t all_bfds;
-/* See gdb_bfd.h. */
-
-void
-gdb_bfd_stash_filename (struct bfd *abfd)
-{
- char *name = bfd_get_filename (abfd);
- char *data;
-
- data = bfd_alloc (abfd, strlen (name) + 1);
- strcpy (data, name);
-
- /* Unwarranted chumminess with BFD. */
- abfd->filename = data;
-}
-
/* An object of this type is stored in each BFD's user data. */
struct gdb_bfd_data
@@ -204,7 +189,6 @@ gdb_bfd_open (const char *name, const ch
gdb_assert (!*slot);
*slot = abfd;
- gdb_bfd_stash_filename (abfd);
gdb_bfd_ref (abfd);
return abfd;
}
@@ -490,10 +474,7 @@ gdb_bfd_fopen (const char *filename, con
bfd *result = bfd_fopen (filename, target, mode, fd);
if (result)
- {
- gdb_bfd_stash_filename (result);
- gdb_bfd_ref (result);
- }
+ gdb_bfd_ref (result);
return result;
}
@@ -506,10 +487,7 @@ gdb_bfd_openr (const char *filename, con
bfd *result = bfd_openr (filename, target);
if (result)
- {
- gdb_bfd_stash_filename (result);
- gdb_bfd_ref (result);
- }
+ gdb_bfd_ref (result);
return result;
}
@@ -522,10 +500,7 @@ gdb_bfd_openw (const char *filename, con
bfd *result = bfd_openw (filename, target);
if (result)
- {
- gdb_bfd_stash_filename (result);
- gdb_bfd_ref (result);
- }
+ gdb_bfd_ref (result);
return result;
}
@@ -553,10 +528,7 @@ gdb_bfd_openr_iovec (const char *filenam
pread_func, close_func, stat_func);
if (result)
- {
- gdb_bfd_ref (result);
- gdb_bfd_stash_filename (result);
- }
+ gdb_bfd_ref (result);
return result;
}
@@ -603,10 +575,7 @@ gdb_bfd_fdopenr (const char *filename, c
bfd *result = bfd_fdopenr (filename, target, fd);
if (result)
- {
- gdb_bfd_ref (result);
- gdb_bfd_stash_filename (result);
- }
+ gdb_bfd_ref (result);
return result;
}
--- a/gdb/gdb_bfd.h
+++ b/gdb/gdb_bfd.h
@@ -24,12 +24,6 @@
DECLARE_REGISTRY (bfd);
-/* Make a copy ABFD's filename using bfd_alloc, and reassign it to the
- BFD. This ensures that the BFD's filename has the same lifetime as
- the BFD itself. */
-
-void gdb_bfd_stash_filename (struct bfd *abfd);
-
/* Open a read-only (FOPEN_RB) BFD given arguments like bfd_fopen.
Returns NULL on error. On success, returns a new reference to the
BFD, which must be freed with gdb_bfd_unref. BFDs returned by this
@@ -79,22 +73,22 @@ int gdb_bfd_crc (struct bfd *abfd, unsig
\f
/* A wrapper for bfd_fopen that initializes the gdb-specific reference
- count and calls gdb_bfd_stash_filename. */
+ count. */
bfd *gdb_bfd_fopen (const char *, const char *, const char *, int);
/* A wrapper for bfd_openr that initializes the gdb-specific reference
- count and calls gdb_bfd_stash_filename. */
+ count. */
bfd *gdb_bfd_openr (const char *, const char *);
/* A wrapper for bfd_openw that initializes the gdb-specific reference
- count and calls gdb_bfd_stash_filename. */
+ count. */
bfd *gdb_bfd_openw (const char *, const char *);
/* A wrapper for bfd_openr_iovec that initializes the gdb-specific
- reference count and calls gdb_bfd_stash_filename. */
+ reference count. */
bfd *gdb_bfd_openr_iovec (const char *filename, const char *target,
void *(*open_func) (struct bfd *nbfd,
@@ -112,12 +106,12 @@ bfd *gdb_bfd_openr_iovec (const char *fi
struct stat *sb));
/* A wrapper for bfd_openr_next_archived_file that initializes the
- gdb-specific reference count and calls gdb_bfd_stash_filename. */
+ gdb-specific reference count. */
bfd *gdb_bfd_openr_next_archived_file (bfd *archive, bfd *previous);
/* A wrapper for bfd_fdopenr that initializes the gdb-specific
- reference count and calls gdb_bfd_stash_filename. */
+ reference count. */
bfd *gdb_bfd_fdopenr (const char *filename, const char *target, int fd);
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -728,12 +728,8 @@ solib_aix_bfd_open (char *pathname)
to allow commands listing all shared libraries to display that
synthetic name. Otherwise, we would only be displaying the name
of the archive member object. */
- {
- char *data = bfd_alloc (object_bfd, path_len + 1);
-
- strcpy (data, pathname);
- object_bfd->filename = data;
- }
+ xfree (bfd_get_filename (object_bfd));
+ object_bfd->filename = xstrdup (pathname);
gdb_bfd_unref (archive_bfd);
do_cleanups (cleanup);
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -621,12 +621,8 @@ darwin_bfd_open (char *pathname)
/* The current filename for fat-binary BFDs is a name generated
by BFD, usually a string containing the name of the architecture.
Reset its value to the actual filename. */
- {
- char *data = bfd_alloc (res, strlen (pathname) + 1);
-
- strcpy (data, pathname);
- res->filename = data;
- }
+ xfree (bfd_get_filename (res));
+ res->filename = xstrdup (pathname);
gdb_bfd_unref (abfd);
return res;
--- a/gdb/symfile-mem.c
+++ b/gdb/symfile-mem.c
@@ -101,14 +101,11 @@ symbol_file_add_from_memory (struct bfd
error (_("Failed to read a valid object file image from memory."));
gdb_bfd_ref (nbfd);
+ xfree (bfd_get_filename (nbfd));
if (name == NULL)
- nbfd->filename = "shared object read from target memory";
+ nbfd->filename = xstrdup ("shared object read from target memory");
else
- {
- nbfd->filename = name;
- gdb_bfd_stash_filename (nbfd);
- xfree (name);
- }
+ nbfd->filename = name;
cleanup = make_cleanup_bfd_unref (nbfd);
next prev parent reply other threads:[~2014-01-06 10:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-04 16:23 Hui Zhu
2014-01-05 15:06 ` Sergio Durigan Junior
2014-01-05 15:48 ` Hui Zhu
2014-01-06 8:25 ` Tom Tromey
2014-01-06 10:50 ` Hui Zhu [this message]
2014-01-06 16:14 ` Tom Tromey
2014-01-06 17:12 ` Doug Evans
2014-01-06 21:07 ` Tom Tromey
2014-01-07 12:35 ` Pedro Alves
2014-01-07 13:55 ` Pedro Alves
2014-01-07 17:41 ` Tom Tromey
2014-01-07 19:54 ` Pedro Alves
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=52CA8A7F.7090907@mentor.com \
--to=hui_zhu@mentor.com \
--cc=emachado@linux.vnet.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=nickc@redhat.com \
--cc=sergiodj@redhat.com \
--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