Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tom de Vries <tdevries@suse.de>, gdb-patches@sourceware.org
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>
Subject: Re: [PATCH][gdb] Fix gdb.arch/amd64-tailcall-*.exp with -fPIE/-pie
Date: Fri, 09 Aug 2019 17:38:00 -0000	[thread overview]
Message-ID: <cfc49467-972f-1558-6906-8737360273c0@redhat.com> (raw)
In-Reply-To: <38825791-ad92-3f7e-d3ae-2ac123dd6422@suse.de>

On 8/9/19 4:03 PM, Tom de Vries wrote:

>  
> +/* Given an unrelocated address ADDR belonging to the text section of OBJFILE,
> +   return the relocated address.  */
> +
> +static CORE_ADDR
> +relocate_text_addr (CORE_ADDR addr, struct objfile *objfile)
> +{
> +  CORE_ADDR baseaddr
> +    = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
> +  struct gdbarch *gdbarch = get_objfile_arch (objfile);
> +  addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr + baseaddr);
> +  return addr;

I'd write:

 return gdbarch_adjust_dwarf2_addr (gdbarch, addr + baseaddr);

> +}
> +
>  /* Find PC to be unwound from THIS_FRAME.  THIS_FRAME must be a part of
>     CACHE.  */
>  
> @@ -240,14 +255,25 @@ pretend_pc (struct frame_info *this_frame, struct tailcall_cache *cache)
>    gdb_assert (next_levels >= 0);
>  
>    if (next_levels < chain->callees)
> -    return chain->call_site[chain->length - next_levels - 1]->pc;
> +    {
> +      struct call_site *call_site
> +	= chain->call_site[chain->length - next_levels - 1];
> +      struct objfile *objfile = call_site->per_cu->dwarf2_per_objfile->objfile;
> +      return relocate_text_addr (call_site->pc, objfile);
> +    }
>    next_levels -= chain->callees;
>  
>    /* Otherwise CHAIN->CALLEES are already covered by CHAIN->CALLERS.  */
>    if (chain->callees != chain->length)
>      {
>        if (next_levels < chain->callers)
> -	return chain->call_site[chain->callers - next_levels - 1]->pc;
> +	{
> +	  struct call_site *call_site
> +	    = chain->call_site[chain->callers - next_levels - 1];
> +	  struct objfile *objfile
> +	    = call_site->per_cu->dwarf2_per_objfile->objfile;
> +	  return relocate_text_addr (call_site->pc, objfile);
> +	}

That seems fine, but it seems you could have factored out more, like:

static CORE_ADDR
call_site_relocated_pc (struct call_site *call_site)
{
  struct objfile *objfile
    = call_site->per_cu->dwarf2_per_objfile->objfile;
  CORE_ADDR baseaddr
    = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
  struct gdbarch *gdbarch = get_objfile_arch (objfile);
  return gdbarch_adjust_dwarf2_addr (gdbarch, call_size->pc + baseaddr);
}

Then the other hunks would look like:

  struct call_site *call_site
    = chain->call_site[chain->length - next_levels - 1];
  return call_site_relocated_pc (call_site);

...

  struct call_site *call_site
    = chain->call_site[chain->callers - next_levels - 1];
  return call_site_relocated_pc (call_site);

call_site_relocated_pc could even be a method of struct call_site, I guess,
so you'd write:

  return call_site->relocated_pc ();

Any reason you didn't do something like that?

Thanks,
Pedro Alves


  parent reply	other threads:[~2019-08-09 17:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-09 10:48 Tom de Vries
     [not found] ` <57ada901-a8d8-b632-f7d8-e42283314b5a@redhat.com>
     [not found]   ` <38825791-ad92-3f7e-d3ae-2ac123dd6422@suse.de>
2019-08-09 17:38     ` Pedro Alves [this message]
2019-08-10  5:44       ` Tom de Vries
2019-08-16 18:34         ` 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=cfc49467-972f-1558-6906-8737360273c0@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=tdevries@suse.de \
    /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