Re: [PATCH] [gdb/testsuite] Fix gdb.python/py-finish-breakpoint-tailcall.exp with gcc 16

Andrew Burgess <[email protected]> Fri, 31 Jul 2026 14:49:29 +0100
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
Tom de Vries <[email protected]> writes:

> On openSUSE Leap 16.0, with gcc 15.3.0, for test-case
> gdb.python/py-finish-breakpoint-tailcall.exp I get:
> ...
> (gdb) python MyFinishBreakpoint(frame)
> Temporary breakpoint 2 at 0x40102a: file py-finish-breakpoint-tailcall.c, \
>   line 43.
> (gdb) PASS: $exp: parent_frame=true: create finish breakpoint
> ...
>
> And on openSUSE Tumbleweed, with gcc 16.1.1 I get instead:
> ...
> (gdb) python MyFinishBreakpoint(frame)
> Temporary breakpoint 2 at 0x40102a: file py-finish-breakpoint-tailcall.c, \
>    line 44.
> (gdb) FAIL: $exp: parent_frame=true: create finish breakpoint
> ...
>
> The only difference is in the line numbers, 43 and 44, both in main:
> ...
>     39	int
>     40	main (void)
>     41	{
>     42	  int result = tailcall_function (42);
>     43	  result -= global_var;  /* Temporary breakpoint here.  */
>     44	  return result;
>     45	}
> ...
>
> The executable is compiled with O2, and the code for main is different.
>
> With gcc 15, we have:
> ...
> 0000000000401020 <main>:
>   401020:       bf 2a 00 00 00          mov    $0x2a,%edi
>   401025:       e8 26 01 00 00          call   401150 <tailcall_function>
>   40102a:       8b 15 e0 2f 00 00       mov    0x2fe0(%rip),%edx
>   401030:       29 d0                   sub    %edx,%eax
>   401032:       c3                      ret
> ...
> and the line number associated with 0x40102a, the first instruction after the
> call is 43:
> ...
> File name                        Line number  Starting address    View    Stmt
> py-finish-breakpoint-tailcall.c           43          0x40102a               x
> ...
>
> With gcc 16, the mov and sub have been merged:
> ...
> 0000000000401020 <main>:
>   401020:       bf 2a 00 00 00          mov    $0x2a,%edi
>   401025:       e8 26 01 00 00          call   401150 <tailcall_function>
>   40102a:       2b 05 e0 2f 00 00       sub    0x2fe0(%rip),%eax
>   401030:       c3                      ret
> ...
> and the line number info is different:
> ...
> File name                        Line number  Starting address    View    Stmt
> py-finish-breakpoint-tailcall.c           43          0x40102a               x
> py-finish-breakpoint-tailcall.c           44          0x40102a       1       x
> py-finish-breakpoint-tailcall.c           43          0x40102a       2
> ...
> and gdb picks 44 in this case.
>
> Fix this by merging lines 43 and 44 in the test-case:
> ...
> -  result -= global_var;  /* Temporary breakpoint here.  */
> -  return result;
> +  return result - global_var;  /* Temporary breakpoint here.  */
> ...
>
> Tested on x86_64-linux.
>
> I've also verified that reverting the fix in commit e6bdfed6f5d ("gdb: fix
> frame_unwind_caller_WHAT functions for inline and tail calls"), the commit
> that introduced the test-case still makes the test-case fail.

Thanks for taking the time to do this.  This fix LGTM.

Approved-By: Andrew Burgess <[email protected]>

Thanks,
Andrew


>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33989
> ---
>  gdb/testsuite/gdb.python/py-finish-breakpoint-tailcall.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/gdb/testsuite/gdb.python/py-finish-breakpoint-tailcall.c b/gdb/testsuite/gdb.python/py-finish-breakpoint-tailcall.c
> index d129d7e41b4..844ac1d2ea6 100644
> --- a/gdb/testsuite/gdb.python/py-finish-breakpoint-tailcall.c
> +++ b/gdb/testsuite/gdb.python/py-finish-breakpoint-tailcall.c
> @@ -40,6 +40,5 @@ int
>  main (void)
>  {
>    int result = tailcall_function (42);
> -  result -= global_var;			/* Temporary breakpoint here.  */
> -  return result;
> +  return result - global_var;			/* Temporary breakpoint here.  */
>  }
>
> base-commit: 6d1be0b90e837e4c82eaaf6f9e8c7da7227902e1
> -- 
> 2.51.0