diff mbox

[07/14] gdb/testsuite: Fix invalid watchpoint test in mi suite

Message ID 20200207150003.8383-8-shahab.vahedi@gmail.com
State New
Headers show

Commit Message

Shahab Vahedi Feb. 7, 2020, 2:59 p.m. UTC
From: Anton Kolesov <Anton.Kolesov@synopsys.com>

GDB's watchpoints are triggered only if expression value has changed, so
memory at variable address already contained assigned value - watchpoint is
not triggered. Therefore it is not reliable to check watchpoints triggering
by checking first assignment - variable might already had that assigned
value, so GDB would ignore that new assignment. This can happen in real life
when same test case is run over an over again on baremetal - stack addresses
for local variables are constant and memory is persistent across runs. So
this code:

void callee4()
{
    int A = 1;
    int B = 2;
    int C;

    C = A + B;
}

might trigger watchpoint on C at the first execution, but not on subsequent
runs - memory address of C retained value 3 from first execution. Therefore
all watchpoint tests must have an initial assignment to some value, so that
variable contain a known value, and only then create a watchpoint, so that
this watchpoint would trigger reliably.

gdb/testsuite/ChangeLog:
2016-07-15  Anton Kolesov <Anton.Kolesov@synopsys.com>
	    Shahab Vahedi <shahab@synopsys.com>

	* gdb.mi/basics.c (callee4): Initialise "C" to 0.
	* gdb.mi/mi-cli.exp: Handle the introduced initialisation.

Signed-off-by: Anton Kolesov <Anton.Kolesov@synopsys.com>
---
 gdb/testsuite/gdb.mi/basics.c   |  2 +-
 gdb/testsuite/gdb.mi/mi-cli.exp | 15 +++++++++------
 2 files changed, 10 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/gdb/testsuite/gdb.mi/basics.c b/gdb/testsuite/gdb.mi/basics.c
index 7e7a74823afa..b3000a8020d3 100644
--- a/gdb/testsuite/gdb.mi/basics.c
+++ b/gdb/testsuite/gdb.mi/basics.c
@@ -26,7 +26,7 @@  int callee4 (void)
 {
   int A=1;
   int B=2;
-  int C;
+  int C=0;
 
   C = A + B;
   return 0;
diff --git a/gdb/testsuite/gdb.mi/mi-cli.exp b/gdb/testsuite/gdb.mi/mi-cli.exp
index 214cc8a479e6..82f050a83c32 100644
--- a/gdb/testsuite/gdb.mi/mi-cli.exp
+++ b/gdb/testsuite/gdb.mi/mi-cli.exp
@@ -68,8 +68,9 @@  set line_main_return  [expr $line_main_hello + 2]
 set line_main_callme_2 [expr $line_main_return + 1]
 set line_callee4_head [gdb_get_line_number "callee4 ("]
 set line_callee4_body [expr $line_callee4_head + 2]
-set line_callee4_next [expr $line_callee4_body + 1]
-set line_callee4_next_step [expr $line_callee4_next + 3]
+set line_callee4_first_next [expr $line_callee4_body + 1]
+set line_callee4_second_next [expr $line_callee4_first_next + 1]
+set line_callee4_third_next [expr $line_callee4_second_next + 2]
 
 mi_gdb_test "-interpreter-exec console \"set args foobar\"" \
   ".*=cmd-param-changed,param=\"args\",value=\"foobar\".*\\^done" \
@@ -136,10 +137,12 @@  mi_gdb_test "500-stack-select-frame 0" \
   {500\^done} \
   "-stack-select-frame 0"
 
-mi_execute_to "interpreter-exec console step" "end-stepping-range" "callee4" "" ".*basics.c" $line_callee4_next \
+mi_execute_to "interpreter-exec console step" "end-stepping-range" "callee4" "" ".*basics.c" $line_callee4_first_next \
     "" "check *stopped from CLI command"
 
-mi_send_resuming_command "exec-step" "-exec-step to line \$line_callee4_next_step"
+mi_step_to "callee4" "" ".*basics.c" $line_callee4_second_next "step over B's initialization"
+
+mi_send_resuming_command "exec-step" "-exec-step to line $line_callee4_third_next"
 
 # Test that the new current source line is _not_ output, given we
 # executed MI's -exec-next, not CLI's 'next' command.
@@ -153,8 +156,8 @@  if {[regexp "A + B" "$output"]} {
     pass $test
 }
 
-mi_expect_stop "end-stepping-range" "callee4" "" ".*basics.c" $line_callee4_next_step \
-    "" "check *stopped from CLI command 2"
+mi_expect_stop "end-stepping-range" "callee4" "" ".*basics.c" $line_callee4_third_next \
+    "" "check *stopped from CLI command 3"
 
 # Test that CLI's "finish" command prints the function's return value
 # to both the CLI and MI streams, and that the same result variable is