[PATCH v3 7/7] adapt btrace testcases for arm target

Luis Machado luis.machado@linaro.org
Tue Apr 6 13:09:22 GMT 2021


On 4/4/21 4:30 PM, Zied Guermazi wrote:
> hi Luis
> 
> thanks for your review comments. Here is the status of the updates. The 
> changes will be published in next version of the patch set.
> 
> /Zied
> 
> On 01.04.21 15:34, Luis Machado wrote:
>> On 3/30/21 11:52 PM, Zied Guermazi wrote:
>>> diff --git a/gdb/testsuite/gdb.btrace/buffer-size.exp 
>>> b/gdb/testsuite/gdb.btrace/buffer-size.exp
>>> index ea4e36c1593..77d7b77852a 100644
>>> --- a/gdb/testsuite/gdb.btrace/buffer-size.exp
>>> +++ b/gdb/testsuite/gdb.btrace/buffer-size.exp
>>> @@ -32,10 +32,17 @@ if ![runto_main] {
>>>       return -1
>>>   }
>>>   -gdb_test_no_output "set record btrace bts buffer-size 1"
>>> -gdb_test_no_output "set record btrace pt buffer-size 1"
>>> -gdb_test "show record btrace bts buffer-size" "The record/replay bts 
>>> buffer size is 1\.\r"
>>> -gdb_test "show record btrace pt buffer-size" "The record/replay pt 
>>> buffer size is 1\.\r"
>>> +if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
>>> +    gdb_test_no_output "set record btrace bts buffer-size 1"
>>> +    gdb_test_no_output "set record btrace pt buffer-size 1"
>>> +    gdb_test "show record btrace bts buffer-size" "The record/replay 
>>> bts buffer size is 1\.\r"
>>> +    gdb_test "show record btrace pt buffer-size" "The record/replay 
>>> pt buffer size is 1\.\r"
>>> +}
>>> +
>>> +if {[istarget "arm*-*-*"]|| [istarget "aarch64*-*-*"]} {
>>> +    gdb_test_no_output "set record btrace etm buffer-size 1"
>>> +    gdb_test "show record btrace etm buffer-size" "The record/replay 
>>> etm buffer size is 1\.\r"
>>> +}
>>
>> To avoid duplication of code, I think we could simplify this by 
>> checking for the architecture and then creating a list of the btrace 
>> formats we're dealing with. Something like:
>>
>> set btrace_type ""
>> if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
>>     set btrace_type { "bts" "pt" }
>> } elseif {[istarget "arm*-*-*"]|| [istarget "aarch64*-*-*"]} {
>>     set btrace_type { "etm" }
>>
>> Then have a for loop over btrace_type entries and write the tests only 
>> once...
>>
>> foreach_with_prefix format $btrace_format {
>>     gdb_test_no_output "set record btrace $format buffer-size 1"
>>     gdb_test "show record btrace $format buffer-size" "The 
>> record/replay $format buffer size is 1\.\r"
>> }
>>
> [Zied] done. thanks for the hint.
>> I'd apply this to any other cases where it is possible. That way we 
>> avoid duplicated code with hardcoded content on them, which tends to 
>> be hard to maintain and update.
> [Zied] I did not find other tests with specific btrace format

There seems to be other cases in the patch.

>>
>>>     gdb_test_no_output "record btrace"
>>>   gdb_test "info record" [multi_line \
>>> diff --git a/gdb/testsuite/gdb.btrace/delta.exp 
>>> b/gdb/testsuite/gdb.btrace/delta.exp
>>> index 9f6d741c013..2c8bada2065 100644
>>> --- a/gdb/testsuite/gdb.btrace/delta.exp
>>> +++ b/gdb/testsuite/gdb.btrace/delta.exp
>>> @@ -58,8 +58,18 @@ proc check_trace {} {
>>>       "Recording format: .*" \
>>>       "Recorded 1 instructions in 1 functions \\\(0 gaps\\\) for .*" \
>>>       ]
>>> +  if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
>>>       gdb_test "record instruction-history /f 1" \
>>>         "1\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tmov *\\\$0x0,%eax\r"
>>> +  }
>>> +  if { [istarget "arm*-*-*"] } {
>>> +    gdb_test "record instruction-history /f 1" \
>>> +      "1\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tmovs\tr3, #0\r"
>>> +  }
>>> +  if { [istarget "aarch64*-*-*"]} {
>>> +    gdb_test "record instruction-history /f 1" \
>>> +      "1\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tmov\tw0, #0x0.*\r"
>>> +  }
>>>     gdb_test "record function-call-history /c 1" "1\tmain"

Here, for example. You could avoid duplicating the gdb_test invocation 
and, instead, set the expected pattern for each architecture. That way 
you only need to modify the expected pattern, leaving the gdb_test 
invocation intact.

>>>   }
>>>   diff --git a/gdb/testsuite/gdb.btrace/instruction_history.exp 
>>> b/gdb/testsuite/gdb.btrace/instruction_history.exp
>>> index 403085c083f..76fcadb9ac2 100644
>>> --- a/gdb/testsuite/gdb.btrace/instruction_history.exp
>>> +++ b/gdb/testsuite/gdb.btrace/instruction_history.exp
>>> @@ -21,8 +21,14 @@ if { [skip_btrace_tests] } {
>>>       unsupported "target does not support record-btrace"
>>>       return -1
>>>   }
>>> +if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
>>> +  standard_testfile instruction_history.c x86-instruction_history.S
>>> +} elseif { [istarget "arm*-*-*"] } {
>>> +  standard_testfile instruction_history.c arm-instruction_history.S
>>> +} elseif { [istarget "aarch64*-*-*"]} {
>>> +  standard_testfile instruction_history.c aarch64-instruction_history.S
>>
>> Same here. I'd use the conditional blocks to set the prefix for the 
>> source file, then call standard_testfile only once.

As I mentioned before... You could set the prefix depending on the 
architecture (x86/arm/aarch64) and only invoke standard_testfile once.

>>
>>> +}
>>>   -standard_testfile .c .S
>>>   if [prepare_for_testing "failed to prepare" $testfile "$srcfile 
>>> $srcfile2" {debug}] {
>>>       return -1
>>>   }
>>> @@ -68,39 +74,128 @@ if { $traced != 11 } {
>>>   }
>>>     # test that we see the expected instructions
>>> -gdb_test "record instruction-history 3,7" [multi_line \
>>> +if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
>>> +  gdb_test "record instruction-history 3,7" [multi_line \
>>>       "3\t   0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>" \
>>>       "4\t   0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax" \
>>>       "5\t   0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>" \
>>>       "6\t   0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
>>>       "7\t   0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>\r" \
>>>       ]
>>> +}
>>> +if { [istarget "arm*-*-*"] } {
>>> +  gdb_test "record instruction-history 3,7" [multi_line \
>>> +    "3\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tbeq\t0x\[0-9a-f\]+ <L2>" \
>>> +    "4\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tsubs\tr0, r0, #1" \
>>> +    "5\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tb\t0x\[0-9a-f\]+ <L1>" \
>>> +    "6\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tcmp\tr0, #0" \
>>> +    "7\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tbeq\t0x\[0-9a-f\]+ <L2>\r" \
>>> +    ]
>>> +}
>>> +if { [istarget "aarch64*-*-*"]} {
>>> +  gdb_test "record instruction-history 3,7" [multi_line \
>>> +    "3\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tb\.eq\t0x\[0-9a-f\]+ 
>>> <L2>.*" \
>>> +    "4\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tsubs\tx0, x0, #0x1.*" \
>>> +    "5\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tb\t0x\[0-9a-f\]+ <L1>.*" \
>>> +    "6\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tcmp\tx0, #0x0.*" \
>>> +    "7\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tb\.eq\t0x\[0-9a-f\]+ 
>>> <L2>.*\r" \
>>> +    ]
>>> +}

Here as well. Basically, anywhere where you have to differentiate 
between x86/arm/aarch64, if possible, try to set patterns and invoke the 
commands only once using the pattern contained in a variable set 
conditionally.

>>>   -gdb_test "record instruction-history /f 3,+5" [multi_line \
>>> +if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
>>> +  gdb_test "record instruction-history /f 3,+5" [multi_line \
>>>       "3\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>" \
>>>       "4\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec    %eax" \
>>>       "5\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>" \
>>>       "6\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
>>>       "7\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>\r" \
>>>       ]
>>> +}
>>> +if { [istarget "arm*-*-*"] } {
>>> +  gdb_test "record instruction-history /f 3,+5" [multi_line \
>>> +    "3\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tbeq\t0x\[0-9a-f\]+ <L2>" \
>>> +    "4\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tsubs\tr0, r0, #1" \
>>> +    "5\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tb\t0x\[0-9a-f\]+ <L1>" \
>>> +    "6\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp\tr0, #0" \
>>> +    "7\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tbeq\t0x\[0-9a-f\]+ <L2>\r" \
>>> +    ]
>>> +}
>>> +if { [istarget "aarch64*-*-*"]} {
>>> +  gdb_test "record instruction-history /f 3,+5" [multi_line \
>>> +    "3\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tb\.eq\t0x\[0-9a-f\]+ <L2>.*" \
>>> +    "4\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tsubs\tx0, x0, #0x1.*" \
>>> +    "5\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tb\t0x\[0-9a-f\]+ <L1>.*" \
>>> +    "6\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp\tx0, #0x0.*" \
>>> +    "7\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tb\.eq\t0x\[0-9a-f\]+ 
>>> <L2>.*\r" \
>>> +    ]
>>> +}
>>>   -gdb_test "record instruction-history /p 7,-5" [multi_line \
>>> +if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
>>> +  gdb_test "record instruction-history /p 7,-5" [multi_line \
>>>       "3\t   0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>" \
>>>       "4\t   0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax" \
>>>       "5\t   0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>" \
>>>       "6\t   0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
>>>       "7\t   0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>\r" \
>>>       ]
>>> +}
>>> +if { [istarget "arm*-*-*"] } {
>>> +  gdb_test "record instruction-history /p 7,-5" [multi_line \
>>> +    "3\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tbeq\t0x\[0-9a-f\]+ <L2>" \
>>> +    "4\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tsubs\tr0, r0, #1" \
>>> +    "5\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tb\t0x\[0-9a-f\]+ <L1>" \
>>> +    "6\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tcmp\tr0, #0" \
>>> +    "7\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tbeq\t0x\[0-9a-f\]+ <L2>\r" \
>>> +    ]
>>> +}
>>> +if { [istarget "aarch64*-*-*"]} {
>>> +  gdb_test "record instruction-history /p 7,-5" [multi_line \
>>> +    "3\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tb\.eq\t0x\[0-9a-f\]+ 
>>> <L2>.*" \
>>> +    "4\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tsubs\tx0, x0, #0x1.*" \
>>> +    "5\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tb\t0x\[0-9a-f\]+ <L1>.*" \
>>> +    "6\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tcmp\tx0, #0x0.*" \
>>> +    "7\t   0x\[0-9a-f\]+ <L1\\+\[0-9\]+>:\tb\.eq\t0x\[0-9a-f\]+ 
>>> <L2>.*\r" \
>>> +    ]
>>> +}
>>>   -gdb_test "record instruction-history /pf 3,7" [multi_line \
>>> +
>>> +if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
>>> +  gdb_test "record instruction-history /pf 3,7" [multi_line \
>>>       "3\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>" \
>>>       "4\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec    %eax" \
>>>       "5\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>" \
>>>       "6\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax" \
>>>       "7\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>\r" \
>>>       ]
>>> +}
>>> +if { [istarget "arm*-*-*"] } {
>>> +  gdb_test "record instruction-history /pf 3,7" [multi_line \
>>> +    "3\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tbeq\t0x\[0-9a-f\]+ <L2>" \
>>> +    "4\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tsubs\tr0, r0, #1" \
>>> +    "5\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tb\t0x\[0-9a-f\]+ <L1>" \
>>> +    "6\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp\tr0, #0" \
>>> +    "7\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tbeq\t0x\[0-9a-f\]+ <L2>\r" \
>>> +    ]
>>> +}
>>> +if { [istarget "aarch64*-*-*"]} {
>>> +  gdb_test "record instruction-history /pf 3,7" [multi_line \
>>> +    "3\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tb\\.eq\t0x\[0-9a-f\]+ 
>>> <L2>.*" \
>>> +    "4\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tsubs\tx0, x0, #0x1.*" \
>>> +    "5\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tb\t0x\[0-9a-f\]+ <L1>.*" \
>>> +    "6\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp\tx0, #0x0.*" \
>>> +    "7\t   0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tb\\.eq\t0x\[0-9a-f\]+ 
>>> <L2>.*\r" \
>>> +    ]
>>> +}
>>>   -gdb_test "record instruction-history 3,3" "3\t 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>:\tje     0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
>>> +if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
>>> +  gdb_test "record instruction-history 3,3" "3\t 0x\[0-9a-f\]+ 
>>> <loop\\+\[0-9\]+>:\tje     0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
>>> +}
>>> +if { [istarget "arm*-*-*"] } {
>>> +  gdb_test "record instruction-history 3,3" "3\t 0x\[0-9a-f\]+ 
>>> <L1\\+\[0-9\]+>:\tbeq\t0x\[0-9a-f\]+ <L2>\r"
>>> +}
>>> +if { [istarget "aarch64*-*-*"]} {
>>> +  gdb_test "record instruction-history 3,3" "3\t 0x\[0-9a-f\]+ 
>>> <L1\\+\[0-9\]+>:\tb\.eq\t0x\[0-9a-f\]+ <L2>  // b\.none\r"
>>> +}
>>>     # the following tests are checking the iterators
>>>   # to avoid lots of regexps, we just check the number of lines that
>>> diff --git a/gdb/testsuite/gdb.btrace/non-stop.exp 
>>> b/gdb/testsuite/gdb.btrace/non-stop.exp
>>> index 40cced7a8bb..58459de5359 100644
>>> --- a/gdb/testsuite/gdb.btrace/non-stop.exp
>>> +++ b/gdb/testsuite/gdb.btrace/non-stop.exp
>>> @@ -31,6 +31,12 @@ save_vars { GDBFLAGS } {
>>>       clean_restart $testfile
>>>   }
>>>   +if {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
>>> +    set loop_position 2
>>> +} elseif {[istarget "arm*-*-*"] || [istarget "aarch64*-*-*"]} {
>>> +    set loop_position 3
>>> +}
>>> +
>>>   if ![runto_main] {
>>>       untested "failed to run to main"
>>>       return -1
>>> @@ -111,87 +117,99 @@ gdb_test "thread apply all info rec" ".*"
>>>   gdb_test "info threads" ".*"
>>>     with_test_prefix "navigate" {
>>> -    gdb_test "thread apply 1 record goto 2" "$loop_line"
>>> -    gdb_test "thread apply 2 record goto 4" "$loop_line"
>>> +    gdb_test "thread apply 1 record goto $loop_position" "$loop_line"
>>> +    gdb_test "thread apply 2 record goto [expr {$loop_position + 
>>> 2}]" "$loop_line"
>>>       gdb_test "thread apply 1 info record" \
>>> -        ".*Replay in progress\.  At instruction 2\." "thread 1 at 
>>> insn 2"
>>> +        ".*Replay in progress\.  At instruction $loop_position\." 
>>> "thread 1 at insn $loop_position"
>>>       gdb_test "thread apply 2 info record" \
>>> -        ".*Replay in progress\.  At instruction 4\." "thread 2 at 
>>> insn 4"
>>> +        ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 2}]\." "thread 2 at insn [expr {$loop_position + 2}]"
>>>   -    gdb_test "thread apply all record goto 5" "$loop_line"
>>> +    gdb_test "thread apply all record goto [expr {$loop_position + 
>>> 3}]" "$loop_line"
>>>       gdb_test "thread apply 1 info record" \
>>> -        ".*Replay in progress\.  At instruction 5\." "thread 1 at 
>>> insn 5"
>>> +        ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 3}]\." "thread 1 at insn [expr {$loop_position + 3}]"
>>>       gdb_test "thread apply 2 info record" \
>>> -        ".*Replay in progress\.  At instruction 5\." "thread 2 at 
>>> insn 5"
>>> +        ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 3}]\." "thread 2 at insn [expr {$loop_position + 3}]"
>>>   }
>>>     with_test_prefix "step" {
>>> +    with_test_prefix "fixture" {
>>> +    gdb_test "thread apply 1 record goto [expr {$loop_position + 
>>> 3}]" ".*"
>>> +    gdb_test "thread apply 2 record goto [expr {$loop_position + 
>>> 3}]" ".*"
>>> +    }
>>>       with_test_prefix "thread 1" {
>>>           gdb_test "thread apply 1 stepi 2" "$loop_line"
>>>           gdb_test "thread apply 1 info record" \
>>> -            ".*Replay in progress\.  At instruction 7\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 5}]\."
>>>           gdb_test "thread apply 2 info record" \
>>> -            ".*Replay in progress\.  At instruction 5\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 3}]\."
>>>       }
>>>         with_test_prefix "thread 2" {
>>>           gdb_test "thread apply 2 stepi 3" "$loop_line"
>>>           gdb_test "thread apply 1 info record" \
>>> -            ".*Replay in progress\.  At instruction 7\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 5}]\."
>>>           gdb_test "thread apply 2 info record" \
>>> -            ".*Replay in progress\.  At instruction 8\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 6}]\."
>>>       }
>>>         with_test_prefix "all" {
>>>           gdb_cont_to all "stepi 4" "$loop_line" 2
>>>           gdb_test "thread apply 1 info record" \
>>> -            ".*Replay in progress\.  At instruction 11\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 9}]\."
>>>           gdb_test "thread apply 2 info record" \
>>> -            ".*Replay in progress\.  At instruction 12\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 10}]\."
>>>       }
>>>   }
>>>     with_test_prefix "reverse-step" {
>>> +    with_test_prefix "fixture" {
>>> +        gdb_test "thread apply 1 record goto [expr {$loop_position + 
>>> 9}]" ".*"
>>> +        gdb_test "thread apply 2 record goto [expr {$loop_position + 
>>> 10}]" ".*"
>>> +    }
>>>       with_test_prefix "thread 1" {
>>>           gdb_test "thread apply 1 reverse-stepi 2" "$loop_line"
>>>           gdb_test "thread apply 1 info record" \
>>> -            ".*Replay in progress\.  At instruction 9\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 7}]\."
>>>           gdb_test "thread apply 2 info record" \
>>> -            ".*Replay in progress\.  At instruction 12\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 10}]\."
>>>       }
>>>         with_test_prefix "thread 2" {
>>>           gdb_test "thread apply 2 reverse-stepi 3" "$loop_line"
>>>           gdb_test "thread apply 1 info record" \
>>> -            ".*Replay in progress\.  At instruction 9\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 7}]\."
>>>           gdb_test "thread apply 2 info record" \
>>> -            ".*Replay in progress\.  At instruction 9\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 7}]\."
>>>       }
>>>         with_test_prefix "all" {
>>>           gdb_cont_to all "reverse-stepi 4" "$loop_line" 2
>>>           gdb_test "thread apply 1 info record" \
>>> -            ".*Replay in progress\.  At instruction 5\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 3}]\."
>>>           gdb_test "thread apply 2 info record" \
>>> -            ".*Replay in progress\.  At instruction 5\."
>>> +            ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 3}]\."
>>>       }
>>>   }
>>>     with_test_prefix "continue" {
>>> +    with_test_prefix "fixture" {
>>> +    gdb_test "thread apply 1 record goto [expr {$loop_position + 
>>> 3}]" ".*"
>>> +    gdb_test "thread apply 2 record goto [expr {$loop_position + 
>>> 3}]" ".*"
>>> +    }
>>>       with_test_prefix "thread 1" {
>>>       with_test_prefix "continue" {
>>>           gdb_cont_to_no_history 1 "continue" 1
>>>           gdb_test "thread apply 1 info record" \
>>>           ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
>>>           gdb_test "thread apply 2 info record" \
>>> -        ".*Replay in progress\.  At instruction 5\."
>>> +        ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 3}]\."
>>>       }
>>>       with_test_prefix "reverse-continue" {
>>>           gdb_cont_to_no_history 1 "reverse-continue" 1
>>>           gdb_test "thread apply 1 info record" \
>>>           ".*Replay in progress\.  At instruction 1\."
>>>           gdb_test "thread apply 2 info record" \
>>> -        ".*Replay in progress\.  At instruction 5\."
>>> +        ".*Replay in progress\.  At instruction [expr 
>>> {$loop_position + 3}]\."
>>>       }
>>>       }
>>>   diff --git a/gdb/testsuite/gdb.btrace/record_goto.exp 
>>> b/gdb/testsuite/gdb.btrace/record_goto.exp
>>> index 75d76da1c7f..a04983a4859 100644
>>> --- a/gdb/testsuite/gdb.btrace/record_goto.exp
>>> +++ b/gdb/testsuite/gdb.btrace/record_goto.exp
>>> @@ -41,6 +41,10 @@ if [info exists COMPILE] {
>>>       } else {
>>>           standard_testfile i686-record_goto.S
>>>       }
>>> +} elseif {[istarget "arm*-*-*"]} {
>>> +    standard_testfile arm-record_goto.S
>>> +} elseif {[istarget "aarch64*-*-*"]} {
>>> +    standard_testfile aarch64-record_goto.S
>>>   } else {
>>>       unsupported "target architecture not supported"
>>>       return -1
>>> @@ -50,6 +54,126 @@ if [prepare_for_testing "failed to prepare" 
>>> $testfile $srcfile $opts] {
>>>       return -1
>>>   }
>>>   +if {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
>>> +    set function_positions(0) 19
>>> +    set function_positions(1) 27
>>> +    set function_positions(2) 2
>>> +    set function_positions(end) 40
>>> +    set function_positions(3) 39
>>> +
>>> +    set sequence_begin(1) 1
>>> +    set sequence_end(1) 1
>>> +    set sequence_begin(2) 2
>>> +    set sequence_end(2) 4
>>> +    set sequence_begin(3) 5
>>> +    set sequence_end(3) 8
>>> +    set sequence_begin(4) 9
>>> +    set sequence_end(4) 9
>>> +    set sequence_begin(5) 10
>>> +    set sequence_end(5) 12
>>> +    set sequence_begin(6) 13
>>> +    set sequence_end(6) 16
>>> +    set sequence_begin(7) 17
>>> +    set sequence_end(7) 18
>>> +    set sequence_begin(8) 19
>>> +    set sequence_end(8) 19
>>> +    set sequence_begin(9) 20
>>> +    set sequence_end(9) 22
>>> +    set sequence_begin(10) 23
>>> +    set sequence_end(10) 26
>>> +    set sequence_begin(11) 27
>>> +    set sequence_end(11) 27
>>> +    set sequence_begin(12) 28
>>> +    set sequence_end(12) 30
>>> +    set sequence_begin(13) 31
>>> +    set sequence_end(13) 34
>>> +    set sequence_begin(14) 35
>>> +    set sequence_end(14) 36
>>> +    set sequence_begin(15) 37
>>> +    set sequence_end(15) 38
>>> +    set sequence_begin(16) 39
>>> +    set sequence_end(16) 40
>>> +
>>> +} elseif {[istarget "arm*-*-*"]} {
>>> +    set function_positions(0) 23
>>> +    set function_positions(1) 33
>>> +    set function_positions(2) 2
>>> +    set function_positions(end) 48
>>> +    set function_positions(3) 47
>>> +
>>> +    set sequence_begin(1) 1
>>> +    set sequence_end(1) 1
>>> +    set sequence_begin(2) 2
>>> +    set sequence_end(2) 4
>>> +    set sequence_begin(3) 5
>>> +    set sequence_end(3) 10
>>> +    set sequence_begin(4) 11
>>> +    set sequence_end(4) 11
>>> +    set sequence_begin(5) 12
>>> +    set sequence_end(5) 14
>>> +    set sequence_begin(6) 15
>>> +    set sequence_end(6) 20
>>> +    set sequence_begin(7) 21
>>> +    set sequence_end(7) 22
>>> +    set sequence_begin(8) 23
>>> +    set sequence_end(8) 23
>>> +    set sequence_begin(9) 24
>>> +    set sequence_end(9) 26
>>> +    set sequence_begin(10) 27
>>> +    set sequence_end(10) 32
>>> +    set sequence_begin(11) 33
>>> +    set sequence_end(11) 33
>>> +    set sequence_begin(12) 34
>>> +    set sequence_end(12) 36
>>> +    set sequence_begin(13) 37
>>> +    set sequence_end(13) 42
>>> +    set sequence_begin(14) 43
>>> +    set sequence_end(14) 44
>>> +    set sequence_begin(15) 45
>>> +    set sequence_end(15) 46
>>> +    set sequence_begin(16) 47
>>> +    set sequence_end(16) 48
>>> +} elseif {[istarget "aarch64*-*-*"]} {
>>> +    set function_positions(0) 16
>>> +    set function_positions(1) 22
>>> +    set function_positions(2) 2
>>> +    set function_positions(end) 36
>>> +    set function_positions(3) 35
>>> +
>>> +    set sequence_begin(1) 1
>>> +    set sequence_end(1) 1
>>> +    set sequence_begin(2) 2
>>> +    set sequence_end(2) 4
>>> +    set sequence_begin(3) 5
>>> +    set sequence_end(3) 6
>>> +    set sequence_begin(4) 7
>>> +    set sequence_end(4) 7
>>> +    set sequence_begin(5) 8
>>> +    set sequence_end(5) 10
>>> +    set sequence_begin(6) 11
>>> +    set sequence_end(6) 12
>>> +    set sequence_begin(7) 13
>>> +    set sequence_end(7) 15
>>> +    set sequence_begin(8) 16
>>> +    set sequence_end(8) 16
>>> +    set sequence_begin(9) 17
>>> +    set sequence_end(9) 19
>>> +    set sequence_begin(10) 20
>>> +    set sequence_end(10) 21
>>> +    set sequence_begin(11) 22
>>> +    set sequence_end(11) 22
>>> +    set sequence_begin(12) 23
>>> +    set sequence_end(12) 25
>>> +    set sequence_begin(13) 26
>>> +    set sequence_end(13) 27
>>> +    set sequence_begin(14) 28
>>> +    set sequence_end(14) 30
>>> +    set sequence_begin(15) 31
>>> +    set sequence_end(15) 33
>>> +    set sequence_begin(16) 34
>>> +    set sequence_end(16) 36
>>> +}
>>> +
>>>   if ![runto_main] {
>>>       untested "failed to run to main"
>>>       return -1
>>> @@ -65,43 +189,43 @@ gdb_test "next"
>>>     # start by listing all functions
>>>   gdb_test "record function-call-history /ci 1, +20" [multi_line \
>>> -  "1\tmain\tinst 1,1" \
>>> -  "2\t  fun4\tinst 2,4" \
>>> -  "3\t    fun1\tinst 5,8" \
>>> -  "4\t  fun4\tinst 9,9" \
>>> -  "5\t    fun2\tinst 10,12" \
>>> -  "6\t      fun1\tinst 13,16" \
>>> -  "7\t    fun2\tinst 17,18" \
>>> -  "8\t  fun4\tinst 19,19" \
>>> -  "9\t    fun3\tinst 20,22" \
>>> -  "10\t      fun1\tinst 23,26" \
>>> -  "11\t    fun3\tinst 27,27" \
>>> -  "12\t      fun2\tinst 28,30" \
>>> -  "13\t        fun1\tinst 31,34" \
>>> -  "14\t      fun2\tinst 35,36" \
>>> -  "15\t    fun3\tinst 37,38" \
>>> -  "16\t  fun4\tinst 39,40" \
>>> +  "1\tmain\tinst $sequence_begin(1),$sequence_end(1)" \
>>> +  "2\t  fun4\tinst $sequence_begin(2),$sequence_end(2)" \
>>> +  "3\t    fun1\tinst $sequence_begin(3),$sequence_end(3)" \
>>> +  "4\t  fun4\tinst $sequence_begin(4),$sequence_end(4)" \
>>> +  "5\t    fun2\tinst $sequence_begin(5),$sequence_end(5)" \
>>> +  "6\t      fun1\tinst $sequence_begin(6),$sequence_end(6)" \
>>> +  "7\t    fun2\tinst $sequence_begin(7),$sequence_end(7)" \
>>> +  "8\t  fun4\tinst $sequence_begin(8),$sequence_end(8)" \
>>> +  "9\t    fun3\tinst $sequence_begin(9),$sequence_end(9)" \
>>> +  "10\t      fun1\tinst $sequence_begin(10),$sequence_end(10)" \
>>> +  "11\t    fun3\tinst $sequence_begin(11),$sequence_end(11)" \
>>> +  "12\t      fun2\tinst $sequence_begin(12),$sequence_end(12)" \
>>> +  "13\t        fun1\tinst $sequence_begin(13),$sequence_end(13)" \
>>> +  "14\t      fun2\tinst $sequence_begin(14),$sequence_end(14)" \
>>> +  "15\t    fun3\tinst $sequence_begin(15),$sequence_end(15)" \
>>> +  "16\t  fun4\tinst $sequence_begin(16),$sequence_end(16)" \
>>>     ]
>>>     # let's see if we can go back in history
>>> -gdb_test "record goto 19" ".*fun4 \\(\\) at record_goto.c:43.*"
>>> +gdb_test "record goto $function_positions(0)" ".*fun4 \\(\\) at 
>>> record_goto.c:43.*"
>>>     # the function call history should start at the new location
>>>   gdb_test "record function-call-history /ci" [multi_line \
>>> -  "8\t  fun4\tinst 19,19" \
>>> -  "9\t    fun3\tinst 20,22" \
>>> -  "10\t      fun1\tinst 23,26" \
>>> -  ] "function-call-history from 19 forwards"
>>> +  "8\t  fun4\tinst $sequence_begin(8),$sequence_end(8)" \
>>> +  "9\t    fun3\tinst $sequence_begin(9),$sequence_end(9)" \
>>> +  "10\t      fun1\tinst $sequence_begin(10),$sequence_end(10)" \
>>> +  ] "function-call-history from $function_positions(0) forwards"
>>>     # the instruction history should start at the new location
>>>   gdb_test "record instruction-history" [multi_line \
>>> -  "19.*" \
>>> -  "20.*" \
>>> -  "21.*" \
>>> -  ] "instruction-history from 19 forwards"
>>> +  "$function_positions(0).*" \
>>> +  "[expr {$function_positions(0) + 1}].*" \
>>> +  "[expr {$function_positions(0) + 2}].*" \
>>> +  ] "instruction-history from $function_positions(0) forwards"
>>>     # let's go to another place in the history
>>> -gdb_test "record goto 27" ".*fun3 \\(\\) at record_goto.c:35.*"
>>> +gdb_test "record goto $function_positions(1)" ".*fun3 \\(\\) at 
>>> record_goto.c:35.*"
>>>     # check the back trace at that location
>>>   gdb_test "backtrace" [multi_line \
>>> @@ -117,26 +241,26 @@ gdb_test "up" ".*main.*at record_goto.c:49.*" 
>>> "up to main"
>>>     # the function call history should start at the new location
>>>   gdb_test "record function-call-history /ci -" [multi_line \
>>> -  "9\t    fun3\tinst 20,22" \
>>> -  "10\t      fun1\tinst 23,26" \
>>> -  "11\t    fun3\tinst 27,27" \
>>> -  ] "function-call-history from 27 backwards"
>>> +  "9\t    fun3\tinst $sequence_begin(9),$sequence_end(9)" \
>>> +  "10\t      fun1\tinst $sequence_begin(10),$sequence_end(10)" \
>>> +  "11\t    fun3\tinst $sequence_begin(11),$sequence_end(11)" \
>>> +  ] "function-call-history from $function_positions(1) backwards"
>>>     # the instruction history should start at the new location
>>>   gdb_test "record instruction-history -" [multi_line \
>>> -  "25.*" \
>>> -  "26.*" \
>>> -  "27.*" \
>>> -  ] "instruction-history from 27 backwards"
>>> +  "[expr {$function_positions(1) - 2}].*" \
>>> +  "[expr {$function_positions(1) - 1}].*" \
>>> +  "$function_positions(1).*" \
>>> +  ] "instruction-history from $function_positions(1) backwards"
>>>     # test that we can go to the begin of the trace
>>>   gdb_test "record goto begin" ".*main \\(\\) at record_goto.c:49.*"
>>>     # check that we're filling up the context correctly
>>>   gdb_test "record function-call-history /ci -" [multi_line \
>>> -  "1\tmain\tinst 1,1" \
>>> -  "2\t  fun4\tinst 2,4" \
>>> -  "3\t    fun1\tinst 5,8" \
>>> +  "1\tmain\tinst $sequence_begin(1),$sequence_end(1)" \
>>> +  "2\t  fun4\tinst $sequence_begin(2),$sequence_end(2)" \
>>> +  "3\t    fun1\tinst $sequence_begin(3),$sequence_end(3)" \
>>>     ] "function-call-history from begin backwards"
>>>     # check that we're filling up the context correctly
>>> @@ -147,52 +271,53 @@ gdb_test "record instruction-history -" 
>>> [multi_line \
>>>     ] "instruction-history from begin backwards"
>>>     # we should get the exact same history from the first instruction
>>> -gdb_test "record goto 2" ".*fun4 \\(\\) at record_goto.c:40.*"
>>> +gdb_test "record goto $function_positions(2)" ".*fun4 \\(\\) at 
>>> record_goto.c:40.*"
>>>     # check that we're filling up the context correctly
>>>   gdb_test "record function-call-history /ci -" [multi_line \
>>> -  "1\tmain\tinst 1,1" \
>>> -  "2\t  fun4\tinst 2,4" \
>>> -  "3\t    fun1\tinst 5,8\r" \
>>> -  ] "function-call-history from 2 backwards"
>>> +  "1\tmain\tinst $sequence_begin(1),$sequence_end(1)" \
>>> +  "2\t  fun4\tinst $sequence_begin(2),$sequence_end(2)" \
>>> +  "3\t    fun1\tinst $sequence_begin(3),$sequence_end(3)\r" \
>>> +  ] "function-call-history from $function_positions(2) backwards"
>>>     # check that we're filling up the context correctly
>>>   gdb_test "record instruction-history -" [multi_line \
>>>     "1.*" \
>>>     "2.*" \
>>>     "3.*" \
>>> -  ] "instruction-history from 2 backwards"
>>> +  ] "instruction-history from $function_positions(2) backwards"
>>>     # check that we can go to the end of the trace
>>>   gdb_test "record goto end" ".*main \\(\\) at record_goto.c:50.*"
>>>     # check that we're filling up the context correctly
>>>   gdb_test "record function-call-history /ci" [multi_line \
>>> -  "14\t      fun2\tinst 35,36" \
>>> -  "15\t    fun3\tinst 37,38" \
>>> -  "16\t  fun4\tinst 39,40" \
>>> +  "14\t    �� fun2\tinst $sequence_begin(14),$sequence_end(14)" \
>>> +  "15\t    fun3\tinst $sequence_begin(15),$sequence_end(15)" \
>>> +  "16\t  fun4\tinst $sequence_begin(16),$sequence_end(16)" \
>>>     ] "function-call-history from end forwards"
>>>     # check that we're filling up the context correctly
>>> +#adapt it for arm, last instruction is  at pos 48
>>>   gdb_test "record instruction-history" [multi_line \
>>> -  "38.*" \
>>> -  "39.*" \
>>> -  "40.*\r" \
>>> +  "[expr {$function_positions(end) - 2}].*" \
>>> +  "[expr {$function_positions(end) - 1}].*" \
>>> +  "$function_positions(end).*\r" \
>>>     ] "instruction-history from end forwards"
>>>     # we should get the exact same history from the second to last 
>>> instruction
>>> -gdb_test "record goto 39" ".*fun4 \\(\\) at record_goto.c:44.*"
>>> +gdb_test "record goto $function_positions(3)" ".*fun4 \\(\\) at 
>>> record_goto.c:44.*"
>>>     # check that we're filling up the context correctly
>>>   gdb_test "record function-call-history /ci" [multi_line \
>>> -  "14\t      fun2\tinst 35,36" \
>>> -  "15\t    fun3\tinst 37,38" \
>>> -  "16\t  fun4\tinst 39,40\r" \
>>> -  ] "function-call-history from 39 forwards"
>>> +  "14\t      fun2\tinst $sequence_begin(14),$sequence_end(14)" \
>>> +  "15\t    fun3\tinst $sequence_begin(15),$sequence_end(15)" \
>>> +  "16\t  fun4\tinst $sequence_begin(16),$sequence_end(16)\r" \
>>> +  ] "function-call-history from $function_positions(3) forwards"
>>>     # check that we're filling up the context correctly
>>>   gdb_test "record instruction-history" [multi_line \
>>> -  "38.*" \
>>> -  "39.*" \
>>> -  "40.*\r" \
>>> -  ] "instruction-history from 39 forwards"
>>> +  "[expr {$function_positions(3) - 1}].*" \
>>> +  "$function_positions(3).*" \
>>> +  "[expr {$function_positions(3) + 1}].*\r" \
>>> +  ] "instruction-history from $function_positions(3) forwards"
>>> diff --git a/gdb/testsuite/gdb.btrace/stepi.exp 
>>> b/gdb/testsuite/gdb.btrace/stepi.exp
>>> index bfb680bb30d..5b37d17ba0e 100644
>>> --- a/gdb/testsuite/gdb.btrace/stepi.exp
>>> +++ b/gdb/testsuite/gdb.btrace/stepi.exp
>>> @@ -39,6 +39,10 @@ if [info exists COMPILE] {
>>>       } else {
>>>           standard_testfile i686-record_goto.S
>>>       }
>>> +} elseif {[istarget "arm*-*-*"]} {
>>> +    standard_testfile arm-record_goto.S
>>> +} elseif {[istarget "aarch64*-*-*"]} {
>>> +    standard_testfile aarch64-record_goto.S
>>>   } else {
>>>       unsupported "target architecture not supported"
>>>       return -1
>>> @@ -48,6 +52,56 @@ if [prepare_for_testing "failed to prepare" 
>>> $testfile $srcfile] {
>>>       return -1
>>>   }
>>>   +if {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
>>> +    set instructions_count 40
>>> +    set instruction_position(0) 39
>>> +    set instruction_position(1) 40
>>> +    set instruction_position(2) 1
>>> +    set instruction_position(3) 1
>>> +    set instruction_position(4) 22
>>> +    set instruction_position(5) 23
>>> +    set instruction_position(6) 22
>>> +    set instruction_position(7) 27
>>> +    set instruction_position(8) 22
>>> +    set instruction_position(9) 1
>>> +    set instruction_position(10) 1
>>> +    set instruction_position(11) 1
>>> +    set instruction_position(12) 2
>>> +    set instruction_position(13) 1
>>> +} elseif {[istarget "arm*-*-*"]} {
>>> +    set instructions_count 48
>>> +    set instruction_position(0) 47
>>> +    set instruction_position(1) 48
>>> +    set instruction_position(2) 1
>>> +    set instruction_position(3) 1
>>> +    set instruction_position(4) 26
>>> +    set instruction_position(5) 27
>>> +    set instruction_position(6) 26
>>> +    set instruction_position(7) 33
>>> +    set instruction_position(8) 26
>>> +    set instruction_position(9) 1
>>> +    set instruction_position(10) 1
>>> +    set instruction_position(11) 1
>>> +    set instruction_position(12) 2
>>> +    set instruction_position(13) 1
>>> +} elseif {[istarget "aarch64*-*-*"]} {
>>> +    set instructions_count 36
>>> +    set instruction_position(0) 35
>>> +    set instruction_position(1) 36
>>> +    set instruction_position(2) 1
>>> +    set instruction_position(3) 1
>>> +    set instruction_position(4) 19
>>> +    set instruction_position(5) 20
>>> +    set instruction_position(6) 19
>>> +    set instruction_position(7) 22
>>> +    set instruction_position(8) 19
>>> +    set instruction_position(9) 1
>>> +    set instruction_position(10) 1
>>> +    set instruction_position(11) 1
>>> +    set instruction_position(12) 2
>>> +    set instruction_position(13) 1
>>> +}
>>> +
>>>   if ![runto_main] {
>>>       untested "failed to run to main"
>>>       return -1
>>> @@ -56,10 +110,11 @@ if ![runto_main] {
>>>   global gdb_prompt
>>>     proc check_replay_at { insn } {
>>> +  global instructions_count
>>>     gdb_test "info record" [multi_line \
>>>       "Active record target: record-btrace" \
>>>       ".*" \
>>> -    "Recorded 40 instructions in 16 functions \\\(0 gaps\\\) for .*" \
>>> +    "Recorded $instructions_count instructions in 16 functions \\\(0 
>>> gaps\\\) for .*" \
>>>       "Replay in progress\.  At instruction $insn\." \
>>>       ] "check replay at $insn"
>>>   }
>>> @@ -74,15 +129,14 @@ with_test_prefix "record" {
>>>   with_test_prefix "fetch" {
>>>       gdb_test "reverse-stepi" ".*fun4\.5.*" "reverse-stepi.1"
>>>       gdb_test "reverse-stepi" ".*fun4\.5.*" "reverse-stepi.2"
>>> -
>>>       # let's check where we are in the trace
>>> -    check_replay_at 39
>>> +    check_replay_at $instruction_position(0)
>>>   }
>>>     # let's step forward and check again
>>>   with_test_prefix "stepi" {
>>>       gdb_test "stepi" ".*fun4\.5.*"
>>> -    check_replay_at 40
>>> +    check_replay_at $instruction_position(1)
>>>   }
>>>     # with the next step, we stop replaying
>>> @@ -91,14 +145,17 @@ with_test_prefix "end" {
>>>       gdb_test "info record" [multi_line \
>>>         "Active record target: record-btrace" \
>>>         ".*" \
>>> -      "Recorded 40 instructions in 16 functions \\\(0 gaps\\\) for 
>>> \[^\\\r\\\n\]*" \
>>> +      "Recorded $instructions_count instructions in 16 functions 
>>> \\\(0 gaps\\\) for \[^\\\r\\\n\]*" \
>>>     ]
>>>   }
>>>   +#recover from a missing lr register in arm
>>> +gdb_test "record goto end"
>>> +
>>>   # let's try nexti
>>>   with_test_prefix "reverse-nexti.1" {
>>>       gdb_test "reverse-nexti" ".*main\.2.*"
>>> -    check_replay_at 1
>>> +    check_replay_at $instruction_position(2)
>>>   }
>>>     # we can't reverse-nexti any further
>>> @@ -106,7 +163,7 @@ with_test_prefix "reverse-nexti.2" {
>>>       gdb_test "reverse-nexti" \
>>>       "No more reverse-execution history\.\r\n.*main\.2.*" \
>>>       "reverse-nexti.2"
>>> -    check_replay_at 1
>>> +    check_replay_at $instruction_position(3)
>>>   }
>>>     # but we can step back again
>>> @@ -115,32 +172,32 @@ with_test_prefix "nexti" {
>>>       gdb_test "info record" [multi_line \
>>>         "Active record target: record-btrace" \
>>>         ".*" \
>>> -      "Recorded 40 instructions in 16 functions \\\(0 gaps\\\) for 
>>> \[^\\\r\\\n\]*" \
>>> +      "Recorded $instructions_count instructions in 16 functions 
>>> \\\(0 gaps\\\) for \[^\\\r\\\n\]*" \
>>>                      ]
>>>   }
>>>     # let's step from a goto position somewhere in the middle
>>>   with_test_prefix "goto" {
>>> -    gdb_test "record goto 22" ".*fun3\.2.*"
>>> -    with_test_prefix "goto 22" { check_replay_at 22 }
>>> +    gdb_test "record goto $instruction_position(4) " ".*fun3\.2.*"
>>> +    with_test_prefix "goto $instruction_position(4) " { 
>>> check_replay_at $instruction_position(4)  }
>>>         gdb_test "stepi" ".*fun1\.1.*" "stepi.3"
>>> -    with_test_prefix "stepi to 23" { check_replay_at 23 }
>>> +    with_test_prefix "stepi to $instruction_position(5)" { 
>>> check_replay_at $instruction_position(5) }
>>>         gdb_test "reverse-stepi" ".*fun3\.2.*" "reverse-stepi.3"
>>> -    with_test_prefix "reverse-stepi to 22" { check_replay_at 22 }
>>> +    with_test_prefix "reverse-stepi to $instruction_position(6)" { 
>>> check_replay_at $instruction_position(6) }
>>>         gdb_test "nexti" ".*fun3\.3.*"
>>> -    with_test_prefix "nexti to 27" { check_replay_at 27 }
>>> +    with_test_prefix "nexti to $instruction_position(7) " { 
>>> check_replay_at $instruction_position(7)  }
>>>         gdb_test "reverse-nexti" ".*fun3\.2.*" "reverse-nexti.3"
>>> -    with_test_prefix "reverse-nexti to 22" { check_replay_at 22 }
>>> +    with_test_prefix "reverse-nexti to $instruction_position(8)" { 
>>> check_replay_at $instruction_position(8) }
>>>   }
>>>     # let's try to step off the left end
>>>   with_test_prefix "goto begin" {
>>>       gdb_test "record goto begin" ".*main\.2.*"
>>> -    check_replay_at 1
>>> +    check_replay_at $instruction_position(9)
>>>         with_test_prefix "reverse-stepi" {
>>>       gdb_test "reverse-stepi" \
>>> @@ -149,7 +206,7 @@ with_test_prefix "goto begin" {
>>>       gdb_test "reverse-stepi" \
>>>           "No more reverse-execution history\.\r\n.*main\.2.*" \
>>>           "reverse-stepi.2"
>>> -    check_replay_at 1
>>> +    check_replay_at $instruction_position(10)
>>>       }
>>>         with_test_prefix "reverse-nexti" {
>>> @@ -159,13 +216,13 @@ with_test_prefix "goto begin" {
>>>       gdb_test "reverse-nexti" \
>>>           "No more reverse-execution history\.\r\n.*main\.2.*" \
>>>           "reverse-nexti.2"
>>> -    check_replay_at 1
>>> +    check_replay_at $instruction_position(11)
>>>       }
>>>         # we can step forward, though
>>>       with_test_prefix "stepi" {
>>>       gdb_test "stepi" ".*fun4\.1.*"
>>> -    check_replay_at 2
>>> +    check_replay_at $instruction_position(12)
>>>       }
>>>   }
>>>   @@ -178,5 +235,5 @@ with_test_prefix "reverse-stepi" {
>>>       gdb_test "reverse-stepi" \
>>>       "No more reverse-execution history\.\r\n.*main\.2.*" \
>>>       "reverse-stepi.3"
>>> -    check_replay_at 1
>>> +    check_replay_at $instruction_position(13)
>>>   }
>>> diff --git a/gdb/testsuite/gdb.btrace/tailcall-only.exp 
>>> b/gdb/testsuite/gdb.btrace/tailcall-only.exp
>>> index 510f90c9d5e..7e449ee38da 100644
>>> --- a/gdb/testsuite/gdb.btrace/tailcall-only.exp
>>> +++ b/gdb/testsuite/gdb.btrace/tailcall-only.exp
>>> @@ -43,6 +43,10 @@ if [info exists COMPILE] {
>>>       } else {
>>>           standard_testfile i686-tailcall-only.S
>>>       }
>>> +} elseif { [istarget "arm*-*-*"] } {
>>> +  standard_testfile arm-tailcall-only.S
>>> +} elseif {[istarget "aarch64*-*-*"]} {
>>> +  standard_testfile aarch64-tailcall-only.S
>>>   } else {
>>>       unsupported "target architecture not supported"
>>>       return -1
>>> @@ -62,6 +66,10 @@ gdb_test_no_output "set record 
>>> function-call-history-size 0"
>>>     # trace foo
>>>   gdb_test "step" ".*" "prepare for recording"
>>> +# make sure we get out of function epilogue
>>> +if { [istarget "arm*-*-*"] } {
>>> +  gdb_test "stepi"
>>> +}
>>>   gdb_test_no_output "record btrace"
>>>   gdb_test "stepi 4" ".*" "record branch trace"
>>>   diff --git a/gdb/testsuite/gdb.btrace/tailcall.exp 
>>> b/gdb/testsuite/gdb.btrace/tailcall.exp
>>> index 07a3ec103f4..602a9ed6fba 100644
>>> --- a/gdb/testsuite/gdb.btrace/tailcall.exp
>>> +++ b/gdb/testsuite/gdb.btrace/tailcall.exp
>>> @@ -40,6 +40,10 @@ if [info exists COMPILE] {
>>>       } else {
>>>           standard_testfile i686-tailcall.S
>>>       }
>>> +} elseif { [istarget "arm*-*-*"] } {
>>> +  standard_testfile arm-tailcall.S
>>> +} elseif { [istarget "aarch64*-*-*"] } {
>>> +  standard_testfile aarch64-tailcall.S
>>>   } else {
>>>       unsupported "target architecture not supported"
>>>       return -1
>>> @@ -48,6 +52,20 @@ if [info exists COMPILE] {
>>>   if [prepare_for_testing "failed to prepare" $testfile $srcfile 
>>> $opts] {
>>>       return -1
>>>   }
>>> +
>>> +if {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
>>> +    set bar_return_line 24
>>> +    set bar_return_position 4
>>> +    set main_return_line 38
>>> +} elseif {[istarget "arm*-*-*"]} {
>>> +    set bar_return_line 24
>>> +    set bar_return_position 5
>>> +    set main_return_line 41
>>> +    } elseif {[istarget "aarch64*-*-*"]} {
>>> +    set bar_return_line 23
>>> +    set bar_return_position 6
>>> +    set main_return_line 40
>>> +}
>>
>> There may be better ways to fetch this information without hardcoding 
>> it, through regular expressions and $expect_out. See, for example, 
>> gdb.base/step-over-syscall.exp and how it uses $expect_out to extract 
>> some bits of information.
>>
>> You could extract this information first and then store it in these 
>> variables. If the sources change, then we won't need to update the 
>> test again.
>>
>> If it is hardcoded, every time the source changes you need to update 
>> the test.
>>
> [Zied] I will appreciate extracting this information from the elf file. 
> Problem is that according to the architecture, the last line number 
> before the function returns can change slightly. Can you please explain 
> further how to use $expect_out to get the line number.

Extracting from the ELF file is not a good approach. Instead, you should 
first run the test, stopping at each of these places of interest (bar 
return, main return etc) and record the line number and position in some 
way. Using regular expressions you can extract the line number the 
program stopped at, for example. Then you do another run and actually 
test the btrace functionality.

If it is not possible to determine some of these fields dynamically, 
then using the conditional blocks is an acceptable approach.

But you should be aware that different compiler versions may generate 
different code. So this particular test will only work for this 
particular .S file.

>>>   if ![runto_main] {
>>>       untested "failed to run to main"
>>>       return -1
>>> @@ -58,7 +76,17 @@ gdb_test_no_output "set record 
>>> function-call-history-size 0"
>>>     # trace the call to foo
>>>   gdb_test_no_output "record btrace"
>>> -gdb_test "next 2"
>>> +
>>> +# make sure we get out of function epilogue
>>> +if {[istarget "i?86-*-*"] || [istarget "x86_64-*-*"]} {
>>> +    gdb_test "next 2"
>>> +} elseif {[istarget "arm*-*-*"]} {
>>> +  gdb_test "next 2"
>>> +  gdb_test "stepi"
>>> +} elseif {[istarget "aarch64*-*-*"]} {
>>> +  gdb_test "next"
>>> +  gdb_test "stepi"
>>> +}

The above will make the test complicated to follow, because it does 
something different for different architectures.

If the program is not stopping at the right location, it is best to work 
with breakpoints to force it to stop there instead of playing with 
next/stepi calls.

>>>     # show the flat branch trace
>>>   gdb_test "record function-call-history 1" [multi_line \
>>> @@ -77,11 +105,11 @@ gdb_test "record function-call-history /c 1" 
>>> [multi_line \
>>>     ] "indented"
>>>     # go into bar
>>> -gdb_test "record goto 4" ".*bar \\(\\) at .*tailcall.c:24\r\n.*"
>>> +gdb_test "record goto $bar_return_position" ".*bar \\(\\) at 
>>> .*tailcall.c:$bar_return_line\r\n.*"
>>>     # check the backtrace
>>>   gdb_test "backtrace" [multi_line \
>>> -  "#0.*bar \\(\\) at tailcall.c:24" \
>>> +  "#0.*bar \\(\\) at tailcall.c:$bar_return_line" \
>>>     "#1.*foo \\(\\) at tailcall.c:29" \
>>>     "#2.*main \\(\\) at tailcall.c:37" \
>>>     "Backtrace stopped: not enough registers or memory available to 
>>> unwind further" \
>>> @@ -93,23 +121,23 @@ gdb_test "up" "#2\[^\r\n\]*main \\(\\) at 
>>> tailcall.c:37\r\n.*" "up to main"
>>>   gdb_test "down" "#1\[^\r\n\]*foo \\(\\) at tailcall.c:29\r\n.*" 
>>> "down to foo"
>>>     # test stepping into and out of tailcalls.
>>> -gdb_test "finish" "\[^\r\n\]*main \\(\\) at tailcall.c:38\r\n.*" \
>>> +gdb_test "finish" "\[^\r\n\]*main \\(\\) at 
>>> tailcall.c:$main_return_line\r\n.*" \
>>>       "finish.1"
>>> -gdb_test "reverse-step" "\[^\r\n\]*bar \\(\\) at tailcall.c:24\r\n.*" \
>>> +gdb_test "reverse-step" "\[^\r\n\]*bar \\(\\) at 
>>> tailcall.c:$bar_return_line\r\n.*" \
>>>       "reverse-step.1"
>>>   gdb_test "reverse-finish" "\[^\r\n\]*foo \\(\\) at 
>>> tailcall.c:29\r\n.*" \
>>>       "reverse-finish.1"
>>>   gdb_test "reverse-step" "\[^\r\n\]*main \\(\\) at 
>>> tailcall.c:37\r\n.*" \
>>>       "reverse-step.2"
>>> -gdb_test "next" "\[^\r\n\]*38.*" \
>>> +gdb_test "next" "\[^\r\n\]*$main_return_line.*" \
>>>       "next.1"
>>>   gdb_test "reverse-next" "\[^\r\n\]*main \\(\\) at 
>>> tailcall.c:37\r\n.*" \
>>>       "reverse-next.1"
>>>   gdb_test "step" "\[^\r\n\]*foo \\(\\) at tailcall.c:29\r\n.*" \
>>>       "step.1"
>>> -gdb_test "finish" "\[^\r\n\]*main \\(\\) at tailcall.c:38\r\n.*" \
>>> +gdb_test "finish" "\[^\r\n\]*main \\(\\) at 
>>> tailcall.c:$main_return_line\r\n.*" \
>>>       "finish.2"
>>> -gdb_test "reverse-step" "\[^\r\n\]*bar \\(\\) at tailcall.c:24\r\n.*" \
>>> +gdb_test "reverse-step" "\[^\r\n\]*bar \\(\\) at 
>>> tailcall.c:$bar_return_line\r\n.*" \
>>>       "reverse-step.3"
>>> -gdb_test "finish" "\[^\r\n\]*main \\(\\) at tailcall.c:38\r\n.*" \
>>> +gdb_test "finish" "\[^\r\n\]*main \\(\\) at 
>>> tailcall.c:$main_return_line\r\n.*" \
>>>       "finish.3"
>>> diff --git a/gdb/testsuite/gdb.btrace/instruction_history.S 
>>> b/gdb/testsuite/gdb.btrace/x86-instruction_history.S
>>> similarity index 100%
>>> rename from gdb/testsuite/gdb.btrace/instruction_history.S
>>> rename to gdb/testsuite/gdb.btrace/x86-instruction_history.S
>>> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
>>> index 60f84d22aad..b7b11deab57 100644
>>> --- a/gdb/testsuite/lib/gdb.exp
>>> +++ b/gdb/testsuite/lib/gdb.exp
>>> @@ -3232,7 +3232,7 @@ gdb_caching_proc skip_btrace_tests {
>>>       global srcdir subdir gdb_prompt inferior_exited_re
>>>         set me "skip_btrace_tests"
>>> -    if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
>>> +    if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] && 
>>> ![istarget "arm*-*-*"] && ![istarget "aarch64*-*-*"]} {
>>>           verbose "$me:  target does not support btrace, returning 1" 2
>>>           return 1
>>>       }
>>>
>>
> 


More information about the Gdb-patches mailing list