public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mjw@redhat.com>
To: elfutils-devel@lists.fedorahosted.org
Subject: Re: [PATCH] libdw: Search for the last matching address with dwarf_getsrc_die.
Date: Sat, 27 Dec 2014 16:49:46 +0100	[thread overview]
Message-ID: <20141227154946.GK8656@blokker.redhat.com> (raw)
In-Reply-To: 549DCF2E.1080002@redhat.com

[-- Attachment #1: Type: text/plain, Size: 2074 bytes --]

On Fri, Dec 26, 2014 at 02:12:14PM -0700, Josh Stone wrote:
> >    /* The lines are sorted by address, so we can use binary search.  */
> > -  size_t l = 0, u = nlines;
> > +  size_t l = 0, u = nlines - 1;
> >    while (l < u)
> 
> What if nlines == 0?

I wanted to say that cannot happen. If nlines == 0 then cu->lines would
be NULL. But looking at the code there is a theoretical possibility
that isn't the case. It seems unlikely to happen in practice, but we
should guard against it indeed.

> > +      size_t idx = u - (u -l) / 2;
> 
> [nit] missing a space: "(u - l)"

Fixed.
 
> > +  /* This is guaranteed for us by libdw read_srclines.  */
> >    if (nlines > 0)
> >      assert (lines->info[nlines - 1].end_sequence);
> 
> In case your answer above was that nlines is never 0, then this "if" is
> redundant.

I moved the if up before the while loop.

> > +  /* The last line which is less than or equal to addr is what we want,
> > +     except with an end_sequence which can only be strictly equal.  */
> > +  Dwarf_Line *line = &lines->info[l];
> > +  if (line->addr == addr || (! line->end_sequence && line->addr < addr))
> > +    return &lines->info[l];
> 
> BTW, it seems like the end ought to be exclusive, i.e. [start,end).  I
> only wrote my commit this way because some existing tests depended on
> end-inclusive behavior, and I forgot to argue it. :)  Thoughts?

I think you are right and those tests, addrscopes and funcscopes, are
wrong. They use dwfl_module_getsrc to find the line associated with start
and end of the scope. But for the end they use the value of the high_pc
attribute. The high_pc attributes indicates the first address beyond
the current scope of the associated DIE. So the tests should use
highpc - 1 as end of scope.

I created a patch to change dwfl_module_getsrc to not match against
a line with end_sequence set, changed the tests to use highpc -1.
And adjusted this patch for dwarf_getsrc_die. to match the new
behavior. Do those changes look correct to you?

Thanks,

Mark

             reply	other threads:[~2014-12-27 15:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-27 15:49 Mark Wielaard [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-01-16  8:09 Mark Wielaard
2015-01-15 19:54 Josh Stone
2015-01-12 21:25 Mark Wielaard
2014-12-26 21:12 Josh Stone
2014-12-24 12:27 Mark Wielaard

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=20141227154946.GK8656@blokker.redhat.com \
    --to=mjw@redhat.com \
    --cc=elfutils-devel@lists.fedorahosted.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).