gdb_test_no_output "disable 2" "disable 2.I"
gdb_test "info breakpoints" "keep n.*keep n.*keep y.*keep n.*keep n.*" "before re-enable check breakpoint state"
gdb_test_no_output "enable" "re-enable all breakpoints"
-gdb_continue_to_breakpoint "bar" ".*break-always.c:$bar_location.*"
+set bp_address 0
+set test "set breakpoint on bar 2"
+gdb_test_multiple "break bar" $test {
+ -re "Breakpoint 6 at ($hex).*$gdb_prompt $" {
+ set bp_address $expect_out(1,string)
+ pass $test
+ }
+}
+
+# Save the original INSN under the breakpoint.
+gdb_test "p /x \$shadow = *(char *) $bp_address" \
+ " = $hex" \
+ "save shadow"
+# Overwrite memory where the breakpoint is planted. GDB should update
+# its memory breakpoint's shadows, to account for the new contents,
+# and still leave the breakpoint insn planted. Try twice with
+# different values, in case we happen to be writting exactly what was
+# there already.
+gdb_test "p /x *(char *) $bp_address = 0" \
+ " = 0x0" \
+ "write 0 to breakpoint's address"
+gdb_test "p /x *(char *) $bp_address" \
+ " = 0x0" \
+ "read back 0 from the breakpoint's address"
+gdb_test "p /x *(char *) $bp_address = 1" \
+ " = 0x1" \
+ "write 1 to breakpoint's address"
+gdb_test "p /x *(char *) $bp_address" \
+ " = 0x1" \
+ "read back 1 from the breakpoint's address"
+
+# Restore the original contents.
+gdb_test "p /x *(char *) $bp_address = \$shadow" ""
+
+# Run to breakpoint.
+gdb_continue_to_breakpoint "bar" ".*break-always.c:$bar_location.*"