public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Pedro Alves <palves@redhat.com>, gdb-patches@sourceware.org
Cc: Keith Seitz <keiths@redhat.com>
Subject: Re: Change inline frame breakpoint skipping logic (Re: [PATCH] Ensure captured_main has unique address)
Date: Thu, 14 Jun 2018 13:22:00 -0000	[thread overview]
Message-ID: <58a758b7-e4b4-4fee-c7cb-be5a2ab344e6@suse.de> (raw)
In-Reply-To: <aeaa9820-bd70-dd33-cb25-b84d85ad48f6@redhat.com>

On 06/12/2018 07:38 PM, Pedro Alves wrote:
> On 06/12/2018 04:06 PM, Tom de Vries wrote:
>> Hi,
>>
>> atm selftest.exp fails for me.
>>
>> One of the reasons is that after setting a breakpoint in captured_main, we
>> stop at:
>> ...
>> Breakpoint 1, captured_main_1 (context=<optimized out>) at src/gdb/main.c:492
>> ...
>> while selftest_setup expects to stop at captured_main.
>>
>> The problem is that captured_main_1 has been inlined into captured_main, and
>> captured_main has been inlined into gdb_main:
>> ...
>> $ nm ./build/gdb/gdb | egrep ' [tT] .*captured_main|gdb_main' | c++filt
>> 000000000061b950 T gdb_main(captured_main_args*)
>> ...
>>
>> The reason that we seem to be stopping at inline function captured_main_1 has
>> probably something to do with commit "Don't elide all inlined frames", 
> 
> Yes, sounds like it.  But the selftest.exp explicitly asks to stop
> at "captured_main", not "captured_main_1", so I'm thinking that
> it's gdb's behavior that might be wrong:
> 
>  (top-gdb) b captured_main
>  Breakpoint 3 at 0x792f99: file src/gdb/main.c, line 492.
>  (top-gdb) r
>  Starting program: build/gdb/gdb 
>  
>  Breakpoint 3, captured_main_1 (context=<optimized out>) at /home/pedro/gdb/binutils-gdb/src/gdb/main.c:492
>  492       lim_at_start = (char *) sbrk (0);
>  (top-gdb) 
> 
> With the patch below, we instead get:
> 
>  (top-gdb) b captured_main
>  Breakpoint 6 at 0x791339: file src/gdb/main.c, line 492.
>  (top-gdb) r
>  Starting program: build/gdb/gdb 
> 
>  Breakpoint 6, captured_main (data=<optimized out>) at src/gdb/main.c:1147
>  1147      captured_main_1 (context);
>  (top-gdb) 
> 
> and:
> 
>  (top-gdb) b captured_main_1
>  Breakpoint 7 at 0x791339: file src/gdb/main.c, line 492.
>  (top-gdb) r
>  Starting program: build/gdb/gdb 
>  Breakpoint 7, captured_main_1 (context=<optimized out>) at src/gdb/main.c:492
>  492       lim_at_start = (char *) sbrk (0);
>  (top-gdb) 
> 

Agreed, that's a better solution.

> Note that both captured_main and captured_main_1 resolved to the
> same address, 0x791339.  

Right. I played around a bit with this, and set breakpoints on
captured_main and captured_main_1.

If I set a breakpoint on captured_main_1, we have captured_main unknown:
...
Breakpoint 2, captured_main_1 (context=<optimized out>)
    at /home/vries/gdb_versions/devel/src/gdb/main.c:492
492       lim_at_start = (char *) sbrk (0);
(gdb) p captured_main
No symbol "captured_main" in current context.
(gdb) p captured_main_1
$1 = {void (captured_main_args *)} 0x61b959
<gdb_main(captured_main_args*)+25>
...

But If I set a breakpoint on captured_main instead, we have
captured_main_1 unknown:
...
Breakpoint 3, captured_main (data=<optimized out>)
    at /home/vries/gdb_versions/devel/src/gdb/main.c:1147
1147      captured_main_1 (context);
(gdb) p captured_main
$2 = {void (void *)} 0x61b959 <gdb_main(captured_main_args*)+25>
(gdb) p captured_main_1
No symbol "captured_main_1" in current context.
...

And if I set a breakpoint on both, captured_main_1 seems to take
precedence (independent of the order used to set the breakpoint):
...
Breakpoint 1, captured_main_1 (context=<optimized out>)
    at /home/vries/gdb_versions/devel/src/gdb/main.c:492
492       lim_at_start = (char *) sbrk (0);
(gdb) p captured_main_1
$1 = {void (captured_main_args *)} 0x61b959
<gdb_main(captured_main_args*)+25>
(gdb) p captured_main
No symbol "captured_main" in current context.
...

I don't understand the underlying mechanisms well enough to decide
whether this is a problem or not, but I thought I just mention it.

> The gdb.base/inline-break.exp testcase
> currently does not exercise that, but the new test added by the
> patch below does.  That new test fails without the patch and passes
> with the patch.  No regressions on x86-64 GNU/Linux.  WDYT?
> 

AFAICT, the patch looks ok (just one nit below).

> +/* A static inlined function that is called by another static inlined
> +   function.  */
> +
> +static inline ATTR int
> +func_callee (int x)
> +{
> +  return x * 23;
> +}
> +
> +/* A static inlined function that calls another static inlined
> +   function.  The body of the function is a simple as possible so that
> +   both functions are inlined to the same PC address.  */
> +
> +static int

inline ATTR ?

> +func_caller (int x)
> +{
> +  return func_callee (x);
> +}
> +

Thanks,
- Tom

  reply	other threads:[~2018-06-14 13:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-12 15:06 [PATCH] Ensure captured_main has unique address Tom de Vries
2018-06-12 17:38 ` Change inline frame breakpoint skipping logic (Re: [PATCH] Ensure captured_main has unique address) Pedro Alves
2018-06-14 13:22   ` Tom de Vries [this message]
2018-06-19 16:36     ` [pushed] Change inline frame breakpoint skipping logic (fix gdb.gdb/selftest.exp) Pedro Alves
2018-06-25 21:04       ` Joel Brobecker
2018-06-26 19:02         ` Pedro Alves
2018-06-26 22:02           ` Joel Brobecker
2018-06-27 16:28             ` Pedro Alves
2018-06-28 14:48               ` Pedro Alves
2018-06-28 14:50                 ` [PATCH 2/2] "break LINENO/*ADDRESS", inline functions and "info break" output Pedro Alves
2018-06-28 17:42                   ` Joel Brobecker
2018-06-29 18:43                     ` Pedro Alves
2018-06-28 14:50                 ` [PATCH 1/2] Fix running to breakpoint set in inline function by lineno/address Pedro Alves
2018-06-28 17:32                   ` Joel Brobecker

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=58a758b7-e4b4-4fee-c7cb-be5a2ab344e6@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@redhat.com \
    --cc=palves@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).