[PATCH] Fix for the gdb.base/sigstep.exp test.

Tom de Vries tdevries@suse.de
Wed Nov 10 23:17:37 GMT 2021


On 11/8/21 7:26 PM, Carl Love via Gdb-patches wrote:
> 
> 
> 
> GDB maintainers:
> 
> The gdb.base/sigstep.exp has 6 fails on the PowerPC platforms.  Th
> following patch fixes the minor differences of how the test runs on
> PowerPC versus X86.  The differences have to do with the number of
> assembly instructions generated for the two systems and where gdb stops
> at the beginning of a function.  On PowerPC, gdb stops in the prolog
> rather than at the first line of code.  
> 
> The fix adds an addtional stepi in one case and an additional step in
> the other case to get to the expected location in the code.
> 
> The patch only consists of changes to the test.  No GDB internal
> changes are made.
> 
> The patch was also tested on X86 with no regression failures. 
> 
> Please let me know if the patch is acceptable for mainline.  Thanks.
> 
>                  Carl Love
> 
> ---------------------------------------------------------------------
> 

I ran the test-case on ppc64le-linux, and got 6 FAILs as well:
...
FAIL: gdb.base/sigstep.exp: stepi to handler, nothing in handler, step
from handler: leave handler
FAIL: gdb.base/sigstep.exp: stepi to handler, nothing in handler, next
from handler: leave handler
FAIL: gdb.base/sigstep.exp: stepi to handler, nothing in handler,
continue from handler: break clear done (got interactive prompt)
FAIL: gdb.base/sigstep.exp: nexti to handler, nothing in handler, step
from handler: leave handler
FAIL: gdb.base/sigstep.exp: nexti to handler, nothing in handler, next
from handler: leave handler
FAIL: gdb.base/sigstep.exp: nexti to handler, nothing in handler,
continue from handler: break clear done (got interactive prompt)
...

The first FAIL looks like this:
...
(gdb) PASS: gdb.base/sigstep.exp: stepi to handler, nothing in handler,
step from handler: continue to signal
stepi^M
<signal handler called>^M
1: x/i $pc^M
=> 0x7ffff7f804c0 <__kernel_start_sigtramp_rt64>:       bctrl^M
(gdb) PASS: gdb.base/sigstep.exp: stepi to handler, nothing in handler,
step from handler: stepi to handler
delete breakpoints^M
Delete all breakpoints? (y or n) y^M
(gdb) info breakpoints^M
No breakpoints or watchpoints.^M
(gdb) step^M
handler (sig=1685382480) at
/suse/tdevries/gdb/src/gdb/testsuite/gdb.base/sigstep.c:32^M
32      {^M
1: x/i $pc^M
=> 0x1000081c <handler>:        lis     r2,4098^M
(gdb) FAIL: gdb.base/sigstep.exp: stepi to handler, nothing in handler,
step from handler: leave handler
...

The first difference with x86_64 though is where the first stepi gets
us.  On x86_64-linux, it's:
...
gdb) PASS: gdb.base/sigstep.exp: stepi to handler, nothing in handler,
step from handler: continue to signal
stepi^M
handler (sig=0) at
/home/vries/gdb_versions/devel/src/gdb/testsuite/gdb.base/sigstep.c:32^M
32      {^M
1: x/i $pc^M
=> 0x400657 <handler>:  push   %rbp^M
(gdb) PASS: gdb.base/sigstep.exp: stepi to handler, nothing in handler,
step from handler: stepi to handler
...
while on ppc it gets us "<signal handler called>".

> This patch fixes the test for a few differences in how the test runs on
> PPC.  The firs fix adds a gdb_test_multiple to check for PPC.  The assembly
> sequence on PPC reqires two stepi commands to get into the handler where as
> it only takes one stepi on x86.

The description here does not tell us why two stepi commands are
required, while its obvious if you show it.  I'd include the relevant
part of the gdb log in the commit message to clarify why you're making
the change.

Anyway, using this change all 6 FAILs disappear.

> 
> The second change in proc advance is due to gdb stopping int the prolog of
> the function on PPC.  Specificially it stops at the opening brace for the
> function not with the first line of code.  The patch adds an extra step for
> PPC to get gdb to the expected location.

Do you really need this bit?  If so, can you show why?

> ---
>  gdb/testsuite/gdb.base/sigstep.exp | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/testsuite/gdb.base/sigstep.exp b/gdb/testsuite/gdb.base/sigstep.exp
> index ea254af5297..dca9d39d1b6 100644
> --- a/gdb/testsuite/gdb.base/sigstep.exp
> +++ b/gdb/testsuite/gdb.base/sigstep.exp
> @@ -93,7 +93,17 @@ proc advance { enter_cmd in_handler_prefix in_handler exit_cmd } {
>  	    gdb_test "handle SIGVTALRM print pass stop"
>  	    gdb_test "continue" "Program received signal.*" "continue to signal"
>  	}
> -	gdb_test "$enter_cmd" ".*handler .*" "$enter_cmd to handler"
> +
> +	set test_cmd ".*handler .*"

The second parameter of gdb_test is a regexp, not a command.

> +	gdb_test_multiple "$enter_cmd" "$enter_cmd to handler" {
> +	    -re "handler .*sig=.*" {

Both regexps are missing a -wrap, otherwise you're not consuming the prompt.

> +		pass "$test_cmd"

The name of the test is "$enter_cmd to handler", and it's available as
$gdb_test_name.

> +	    }
> +	    -re ".*signal handler called.*" {
> +	    #ppc is at branch instruction, need one more stepi to get to handler
> +	    gdb_test "$enter_cmd" ".*handler .*" "$enter_cmd to handler ppc"
> +	    }
> +	}

[ Missing indentation. ]

I guess it's easier to reuse the first regexp using exp_continue rather
than using another gdb_test.  If not, you can also assign the regexp to
a variable, and use that one twice.

So, this is what I got:
...
diff --git a/gdb/testsuite/gdb.base/sigstep.exp
b/gdb/testsuite/gdb.base/sigstep.exp
index ea254af5297..176918b67d6 100644
--- a/gdb/testsuite/gdb.base/sigstep.exp
+++ b/gdb/testsuite/gdb.base/sigstep.exp
@@ -79,6 +79,7 @@ validate_backtrace
 proc advance { enter_cmd in_handler_prefix in_handler exit_cmd } {
     global gdb_prompt inferior_exited_re
     global clear_done other_handler_location
+    global decimal

     set prefix "$enter_cmd to handler, $in_handler_prefix in handler,
$exit_cmd from handler"

@@ -93,7 +94,16 @@ proc advance { enter_cmd in_handler_prefix in_handler
exit_cmd } {
            gdb_test "handle SIGVTALRM print pass stop"
            gdb_test "continue" "Program received signal.*" "continue to
signal"
        }
-       gdb_test "$enter_cmd" ".*handler .*" "$enter_cmd to handler"
+
+       gdb_test_multiple "$enter_cmd" "$enter_cmd to handler" {
+           -re -wrap "\r\n<signal handler called>.*" {
+               send_gdb "$enter_cmd\n"
+               exp_continue
+           }
+           -re -wrap "\r\n(Breakpoint $decimal, )?handler \\(sig=.*" {
+               pass $gdb_test_name
+           }
+       }

        delete_breakpoints

...

Thanks,
- Tom


More information about the Gdb-patches mailing list