Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Gary Benson <gbenson@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 5/9] Rearrange symfile_bfd_open
Date: Wed, 01 Apr 2015 12:13:00 -0000	[thread overview]
Message-ID: <551BE0D9.9000902@redhat.com> (raw)
In-Reply-To: <1426870087-32654-6-git-send-email-gbenson@redhat.com>

On 03/20/2015 04:48 PM, Gary Benson wrote:
> symfile_bfd_open handles what were remote files as a special case.
> Now that remote files are replaced with target the reverse is true
> and the BFD opening, format checking and error printing code is
> essentially duplicated.  This commit rearranges symfile_bfd_open
> to treat local files as a special case, removing the duplication.

Where were they already done?  Can you add a comment?

> 
> gdb/ChangeLog:
> 
> 	* symfile.c (symfile_bfd_open): Reorder to remove duplicated
> 	checks and error messages.
> ---
>  gdb/ChangeLog |    5 ++++
>  gdb/symfile.c |   69 ++++++++++++++++++++++++--------------------------------
>  2 files changed, 35 insertions(+), 39 deletions(-)
> 
> diff --git a/gdb/symfile.c b/gdb/symfile.c
> index 0d8dae7..0c35ffa 100644
> --- a/gdb/symfile.c
> +++ b/gdb/symfile.c
> @@ -1718,60 +1718,51 @@ set_initial_language (void)
>     absolute).  In case of trouble, error() is called.  */
>  
>  bfd *
> -symfile_bfd_open (const char *cname)
> +symfile_bfd_open (const char *name)
>  {
>    bfd *sym_bfd;
> -  int desc;
> -  char *name, *absolute_name;
> -  struct cleanup *back_to;
> +  int desc = -1;
> +  struct cleanup *back_to = make_cleanup (null_cleanup, 0);
>  
> -  if (is_target_filename (cname))
> +  if (!is_target_filename (name))
>      {
> -      sym_bfd = gdb_bfd_open (cname, gnutarget, -1);
> -      if (!sym_bfd)
> -	error (_("`%s': can't open to read symbols: %s."), cname,
> -	       bfd_errmsg (bfd_get_error ()));
> -
> -      if (!bfd_check_format (sym_bfd, bfd_object))
> -	{
> -	  make_cleanup_bfd_unref (sym_bfd);
> -	  error (_("`%s': can't read symbols: %s."), cname,
> -		 bfd_errmsg (bfd_get_error ()));
> -	}
> +      char *expanded_name, *absolute_name;
>  
> -      return sym_bfd;
> -    }
> -
> -  name = tilde_expand (cname);	/* Returns 1st new malloc'd copy.  */
> +      expanded_name = tilde_expand (name); /* Returns 1st new malloc'd copy.  */
>  
> -  /* Look down path for it, allocate 2nd new malloc'd copy.  */
> -  desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, name,
> -		O_RDONLY | O_BINARY, &absolute_name);
> +      /* Look down path for it, allocate 2nd new malloc'd copy.  */
> +      desc = openp (getenv ("PATH"),
> +		    OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
> +		    expanded_name, O_RDONLY | O_BINARY, &absolute_name);
>  #if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__)
> -  if (desc < 0)
> -    {
> -      char *exename = alloca (strlen (name) + 5);
> +      if (desc < 0)
> +	{
> +	  char *exename = alloca (strlen (expanded_name) + 5);
>  
> -      strcat (strcpy (exename, name), ".exe");
> -      desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
> -		    exename, O_RDONLY | O_BINARY, &absolute_name);
> -    }
> +	  strcat (strcpy (exename, expanded_name), ".exe");
> +	  desc = openp (getenv ("PATH"),
> +			OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
> +			exename, O_RDONLY | O_BINARY, &absolute_name);
> +	}
>  #endif
> -  if (desc < 0)
> -    {
> -      make_cleanup (xfree, name);
> -      perror_with_name (name);
> -    }
> +      if (desc < 0)
> +	{
> +	  make_cleanup (xfree, expanded_name);
> +	  perror_with_name (expanded_name);
> +	}
>  
> -  xfree (name);
> -  name = absolute_name;
> -  back_to = make_cleanup (xfree, name);
> +      xfree (expanded_name);
> +      make_cleanup (xfree, absolute_name);
> +      name = absolute_name;
> +    }
>  
>    sym_bfd = gdb_bfd_open (name, gnutarget, desc);
>    if (!sym_bfd)
>      error (_("`%s': can't open to read symbols: %s."), name,
>  	   bfd_errmsg (bfd_get_error ()));
> -  bfd_set_cacheable (sym_bfd, 1);
> +
> +  if (!gdb_bfd_has_target_filename (sym_bfd))
> +    bfd_set_cacheable (sym_bfd, 1);
>  
>    if (!bfd_check_format (sym_bfd, bfd_object))
>      {
> 


Thanks,
Pedro Alves


  reply	other threads:[~2015-04-01 12:13 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-20 16:48 [PATCH 0/9] New default sysroot "target:" Gary Benson
2015-03-20 16:48 ` [PATCH 6/9] Strip "target:" prefix in solib_find if accessing local files Gary Benson
2015-04-01 12:14   ` Pedro Alves
2015-03-20 16:48 ` [PATCH 1/9] Introduce target_fileio_fstat Gary Benson
2015-04-01 12:11   ` Pedro Alves
2015-03-20 16:48 ` [PATCH 4/9] Convert "remote:" sysroots to "target:" and remove "remote:" Gary Benson
2015-04-01 12:13   ` Pedro Alves
2015-04-01 13:48     ` Gary Benson
2015-03-20 16:57 ` [PATCH 8/9] Make the default sysroot be "target:" Gary Benson
2015-04-01 12:15   ` Pedro Alves
2015-04-01 14:12     ` Gary Benson
2015-04-01 14:18       ` Pedro Alves
2015-03-20 16:57 ` [PATCH 9/9] Document "target:" sysroot changes Gary Benson
2015-03-20 17:51   ` Eli Zaretskii
2015-04-01 12:15   ` Pedro Alves
2015-03-20 17:18 ` [PATCH 7/9] Update exec_file_attach to cope with "target:" filenames Gary Benson
2015-04-01 12:14   ` Pedro Alves
2015-04-01 13:55     ` Gary Benson
2015-04-01 14:16       ` Pedro Alves
2015-04-01 15:59         ` Gary Benson
2015-03-20 17:32 ` [PATCH 2/9] Introduce target_filesystem_is_local Gary Benson
2015-04-01 12:11   ` Pedro Alves
2015-03-20 17:46 ` [PATCH 5/9] Rearrange symfile_bfd_open Gary Benson
2015-04-01 12:13   ` Pedro Alves [this message]
2015-04-01 15:50     ` Gary Benson
2015-04-01 16:03       ` Pedro Alves
2015-03-20 17:47 ` [PATCH 3/9] Make gdb_bfd_open able to open BFDs using target fileio Gary Benson
2015-04-01 12:13   ` Pedro Alves
2015-04-01 12:17 ` [PATCH 0/9] New default sysroot "target:" Pedro Alves
2015-04-02 13:00   ` Gary Benson
2015-04-01 12:22 ` [PING][PATCH " Gary Benson

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=551BE0D9.9000902@redhat.com \
    --to=palves@redhat.com \
    --cc=gbenson@redhat.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