This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Change inline frame breakpoint skipping logic (Re: [PATCH] Ensure captured_main has unique address)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]