From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 01/10] change gdb to refcount bfd everywhere
Date: Thu, 19 Jul 2012 14:18:00 -0000 [thread overview]
Message-ID: <20120719141750.GB23801@host2.jankratochvil.net> (raw)
In-Reply-To: <87vchk3lxs.fsf@fleche.redhat.com>
On Wed, 18 Jul 2012 21:31:59 +0200, Tom Tromey wrote:
> --- /dev/null
> +++ b/gdb/gdb_bfd.c
> @@ -0,0 +1,90 @@
[...]
> +/* Add reference to ABFD. Returns ABFD. */
> +
> +struct bfd *
> +gdb_bfd_ref (struct bfd *abfd)
[...]
> +/* Unreference and possibly close ABFD. */
> +
> +void
> +gdb_bfd_unref (struct bfd *abfd)
[...]
> --- /dev/null
> +++ b/gdb/gdb_bfd.h
> @@ -0,0 +1,35 @@
[...]
> +/* Acquire a new reference to ABFD. Returns ABFD for convenience.
> + It is fine for ABFD to be NULL; in this case the function does
> + nothing and returns NULL. */
> +
> +struct bfd *gdb_bfd_ref (struct bfd *abfd);
> +
> +/* Release a reference to ABFD. If this is the last reference, ABFD
> + will be freed. If ABFD is NULL, this function does nothing. */
> +
> +void gdb_bfd_unref (struct bfd *abfd);
The comments are present in both and neither is a reference, they are already
out of sync.
> diff --git a/gdb/jit.c b/gdb/jit.c
> index 568d17b..6a1425c 100644
> --- a/gdb/jit.c
> +++ b/gdb/jit.c
> @@ -861,6 +862,7 @@ jit_bfd_try_read_symtab (struct jit_code_entry *code_entry,
> puts_unfiltered (_("Error opening JITed symbol file, ignoring it.\n"));
> return;
> }
> + nbfd = gdb_bfd_ref (nbfd);
I personally disagree about the returned value from gdb_bfd_ref being useful,
it makes the code more magic IMO (plus it is not much compatible with the
narrow GNU Coding Standard code formatting). But when it is already this way
then this gdb_bfd_ref wrapped should have been around
bfd_open_from_target_memory above as gdb_bfd_ref can handle NULL parameter.
> @@ -193,9 +194,9 @@ allocate_objfile (bfd *abfd, int flags)
>
> /* Update the per-objfile information that comes from the bfd, ensuring
> that any data that is reference is saved in the per-objfile data
> - region. */
> + region. Note that we steal a reference to ABFD. */
>
> - objfile->obfd = gdb_bfd_ref (abfd);
> + objfile->obfd = abfd;
Caller could gdb_bfd_unref its reference but YMMV.
> @@ -794,10 +795,10 @@ add_vmap (LdInfo *ldi)
> {
> warning (_("\"%s\": not in executable format: %s."),
> objname, bfd_errmsg (bfd_get_error ()));
> - bfd_close (abfd);
> + gdb_bfd_unref (abfd);
> return NULL;
> }
> - obj = allocate_objfile (vp->bfd, 0);
> + obj = allocate_objfile (gdb_bfd_ref (vp->bfd), 0);
This code is a bit magic due to it. map_vmap is missing gdb_bfd_ref despite
it creates new reference etc.
This all pain would not exist with C++.
> @@ -2519,14 +2512,10 @@ reread_symbols (void)
> to close the descriptor but BFD lacks a way of closing the
> BFD without closing the descriptor. */
> obfd_filename = bfd_get_filename (objfile->obfd);
> - if (!bfd_close (objfile->obfd))
> - error (_("Can't close BFD for %s: %s"), objfile->name,
> - bfd_errmsg (bfd_get_error ()));
> + gdb_bfd_unref (objfile->obfd);
> objfile->obfd = bfd_open_maybe_remote (obfd_filename);
> if (objfile->obfd == NULL)
> error (_("Can't open %s to read symbols."), objfile->name);
> - else
> - objfile->obfd = gdb_bfd_ref (objfile->obfd);
Why isn't gdb_bfd_ref missing here?
> /* bfd_openr sets cacheable to true, which is what we want. */
> if (!bfd_check_format (objfile->obfd, bfd_object))
> error (_("Can't read symbols from %s: %s."), objfile->name,
Thanks,
Jan
next prev parent reply other threads:[~2012-07-19 14:18 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-18 19:32 Tom Tromey
2012-07-19 14:18 ` Jan Kratochvil [this message]
2012-07-19 20:58 ` Tom Tromey
2012-07-20 16:37 ` Tom Tromey
2012-07-23 8:54 ` Jan Kratochvil
2012-07-23 9:06 ` Jan Kratochvil
2012-07-23 15:23 ` Tom Tromey
2012-07-23 15:25 ` Tom Tromey
2012-07-24 13:17 ` Jan Kratochvil
2012-07-24 19:52 ` Tom Tromey
2012-07-24 20:27 ` Eli Zaretskii
2012-07-25 14:25 ` Tom Tromey
2012-07-25 14:29 ` Jan Kratochvil
2012-07-25 14:52 ` Tom Tromey
2012-07-25 14:55 ` Jan Kratochvil
2012-07-25 15:44 ` Tom Tromey
2012-07-25 15:37 ` Eli Zaretskii
2012-07-25 11:57 ` Jan Kratochvil
2012-07-23 14:52 ` Tom Tromey
2012-07-23 18:54 ` Tom Tromey
2012-07-23 19:02 ` Jan Kratochvil
2012-07-23 19:08 ` Tom Tromey
2012-07-20 16:37 ` Tom Tromey
2012-07-20 18:11 ` Jan Kratochvil
2012-07-22 19:00 ` Jan Kratochvil
2012-07-23 14:49 ` Tom Tromey
2012-07-23 15:01 ` Tom Tromey
2012-07-23 15:03 ` Tom Tromey
2012-07-20 16:31 ` Tom Tromey
2012-07-20 18:10 ` Jan Kratochvil
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=20120719141750.GB23801@host2.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@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