diff mbox

Fix wrong assertions

Message ID 20150529141027.GA8159@host1.jankratochvil.net
State New
Headers show

Commit Message

Jan Kratochvil May 29, 2015, 2:10 p.m. UTC
On Fri, 29 May 2015 15:43:19 +0200, Yao Qi wrote:
> Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> > The terminology seems bogus there.
> >
> > "partially ambiguous" was meant the chain:
> > 	main -> a -> <???> -> d
> > An intersection of all possible chains.
> 
> Sounds like "partially ambiguous" is equivalent to "ambiguous".

Yes, probably, I am not sure how to call it all myself.


> If that is right, the assert below is too strict, isn't?

Yes, it is too strict, this is why I agree with the fix by Andreas.


>   /* See call_site_find_chain_1 why there is no way to reach the bottom callee
>      PC again.  In such case there must be two different code paths to reach
>      it, therefore some of the former determined intermediate PCs must differ
>      and the unambiguous chain gets shortened.  */
>   gdb_assert (result->callers + result->callees < result->length);
> 
> > but that doe snot matter).  Consequently its elements from the middle are
> > being removed and there remains only some few unambiguous top and
> > bottom ones.
> 
> If there is no call sites removed from the chain during the intersection,
> CALLERS + CALLEES == LENGTH, right?

Just I expected there always has to be some site removed from the chain.
I do not find obvious it does not have to.  But maybe someone else finds it
obvious.


> in function chain_candidate,
> result->length is set by the length of a chain.  If this chain is the
> shortest one, CALLERS + CALLEES == LENGTH otherwise,
> CALLERS + CALLEES < LENGTH.  Is it right?

It is right now.  But when one does not think about self-tail-calls then even
the shortest one will get one frame removed.


> If so, we need to relax the
> condition in the assert and update the comments.

Yes, attached with updated comment.


> > I did not realize that there can be self-tail-call:
> > 	main(0x100) -> a(0x200) -> d(0x400)
> > 	main(0x100) -> a(0x280) -> a(0x200) -> d(0x400)
> > which intersects to:
> > 	main(0x100) -> <???>? -> a(0x200) -> d(0x400)
> > And so if the first chain was chosen the
> > 	main(0x100) -> a(0x200) -> d(0x400)
> > then the final intersection has callers+callees==length.
> 
> What are the definitions of CALLERS, CALLEES, top and bottom? given this example?

top=CALLERS=main(0x100), therefore 1
bottom=CALLEES=d(0x400), therefore 1

top = topmost, where you can go by GDB "up" commands, also called "prev" in
struct frame_info.

bottom = bottommost, where you can go by GDB "down" commands, also called
"next" in struct frame_info.


Jan
2015-05-29  Andreas Schwab  <schwab@linux-m68k.org>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	PR symtab/18392
	* dwarf2-frame-tailcall.c (pretended_chain_levels): Correct
	assertion.
	* dwarf2loc.c (chain_candidate): Likewise.

Comments

Yao Qi May 29, 2015, 4:33 p.m. UTC | #1
Jan Kratochvil <jan.kratochvil@redhat.com> writes:

>> > I did not realize that there can be self-tail-call:
>> > 	main(0x100) -> a(0x200) -> d(0x400)
>> > 	main(0x100) -> a(0x280) -> a(0x200) -> d(0x400)
>> > which intersects to:
>> > 	main(0x100) -> <???>? -> a(0x200) -> d(0x400)
>> > And so if the first chain was chosen the
>> > 	main(0x100) -> a(0x200) -> d(0x400)
>> > then the final intersection has callers+callees==length.
>> 
>> What are the definitions of CALLERS, CALLEES, top and bottom? given
>> this example?
>
> top=CALLERS=main(0x100), therefore 1
> bottom=CALLEES=d(0x400), therefore 1
>
> top = topmost, where you can go by GDB "up" commands, also called "prev" in
> struct frame_info.
>
> bottom = bottommost, where you can go by GDB "down" commands, also called
> "next" in struct frame_info.

OK, I understand what does top/bottom mean.  Since they are numeric
values, what does these number mean?  for example, if CALLERS is 3 and
CALLEES is 2, what does the chain look like?

The code change in the patch looks reasonable to me, but comments change
doesn't, probably because I don't fully understand it.  I'll take a
deeper look next Monday.
Jan Kratochvil May 30, 2015, 7:44 a.m. UTC | #2
On Fri, 29 May 2015 18:33:01 +0200, Yao Qi wrote:
> OK, I understand what does top/bottom mean.  Since they are numeric
> values, what does these number mean?

CALLERS and CALLEES together with LENGTH say what data is at what indexes of
CALL_SITE:

struct call_site_chain
  {
    /* Initially CALLERS == CALLEES == LENGTH.  For partially ambiguous result
       CALLERS + CALLEES < LENGTH.  */
    int callers, callees, length;

    /* Variably sized array with LENGTH elements.  Later [0..CALLERS-1] contain
       top (GDB "prev") sites and [LENGTH-CALLEES..LENGTH-1] contain bottom
       (GDB "next") sites.  One is interested primarily in the PC field.  */
    struct call_site *call_site[1];
  };


> for example, if CALLERS is 3 and
> CALLEES is 2, what does the chain look like?

main(0x100) -> x(0x150) -> y(0x200) -> <???>? -> a(0x200) -> d(0x400)

And if LENGTH is 7 then:
	call_site[0] = main(0x100)
	call_site[1] = x(0x150)
	call_site[2] = y(0x200)
	call_site[3] = garbage
	call_site[4] = garbage
	call_site[5] = a(0x200)
	call_site[6] = d(0x400)


Thanks,
Jan
Yao Qi June 1, 2015, 11:35 a.m. UTC | #3
Jan Kratochvil <jan.kratochvil@redhat.com> writes:

> diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
> index 3aa8ddd..68d6cb4 100644
> --- a/gdb/dwarf2loc.c
> +++ b/gdb/dwarf2loc.c
> @@ -825,9 +825,9 @@ chain_candidate (struct gdbarch *gdbarch, struct call_site_chain **resultp,
>  
>    /* See call_site_find_chain_1 why there is no way to reach the bottom callee
>       PC again.  In such case there must be two different code paths to reach
> -     it, therefore some of the former determined intermediate PCs must differ
> -     and the unambiguous chain gets shortened.  */
> -  gdb_assert (result->callers + result->callees < result->length);
> +     it.  Still it may CALLERS+CALLEES==LENGTH in the case of optional
> +     tail-call calling itself.  */
> +  gdb_assert (result->callers + result->callees <= result->length);

I am not a native English speaker, but I can't parse the comment.  How
about "CALLERS + CALLEES equal to LENGTH in the case of self tail-call"?

Otherwise, the patch is OK to me.
Jan Kratochvil June 1, 2015, 12:05 p.m. UTC | #4
On Mon, 01 Jun 2015 13:35:02 +0200, Yao Qi wrote:
> I am not a native English speaker, but I can't parse the comment.  How
> about "CALLERS + CALLEES equal to LENGTH in the case of self tail-call"?

Used your comment part.


> Otherwise, the patch is OK to me.

Checked in:
	e0619de699ae6e86d8b93fa96a7668aef2e9636a


Thanks,
Jan
diff mbox

Patch

diff --git a/gdb/dwarf2-frame-tailcall.c b/gdb/dwarf2-frame-tailcall.c
index b412a5b..f964ab2 100644
--- a/gdb/dwarf2-frame-tailcall.c
+++ b/gdb/dwarf2-frame-tailcall.c
@@ -197,7 +197,7 @@  pretended_chain_levels (struct call_site_chain *chain)
     return chain->length;
 
   chain_levels = chain->callers + chain->callees;
-  gdb_assert (chain_levels < chain->length);
+  gdb_assert (chain_levels <= chain->length);
 
   return chain_levels;
 }
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 3aa8ddd..68d6cb4 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -825,9 +825,9 @@  chain_candidate (struct gdbarch *gdbarch, struct call_site_chain **resultp,
 
   /* See call_site_find_chain_1 why there is no way to reach the bottom callee
      PC again.  In such case there must be two different code paths to reach
-     it, therefore some of the former determined intermediate PCs must differ
-     and the unambiguous chain gets shortened.  */
-  gdb_assert (result->callers + result->callees < result->length);
+     it.  Still it may CALLERS+CALLEES==LENGTH in the case of optional
+     tail-call calling itself.  */
+  gdb_assert (result->callers + result->callees <= result->length);
 }
 
 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC.  All the