gdb_test "python astr = gdb.inferiors()\[0\].read_memory (addr, 5); print(astr)" \
"<memory at $hex>" \
"read str contents"
+gdb_test "python print(astr\[0\])" "b'h'"
gdb_py_test_silent_cmd "python a = bytes('a', 'ascii')" "" 0
gdb_py_test_silent_cmd "python astr\[1\] = a" "change str" 0
gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, astr)" \
gdb_test "print str" " = \"hallo, testsuite\"" \
"ensure str was changed in the inferior"
+# Add a new inferior here, so we can test that operations work on the
+# correct inferior.
+set num [add_inferior]
+
# Test memory search.
set hex_number {0x[0-9a-fA-F][0-9a-fA-F]*}
gdb_test_no_output "py start_addr = search_buf.address"
gdb_test_no_output "py length = search_buf.type.sizeof"
+ # Switch to the new inferior before testing.
+ gdb_test "inferior $num" "Switching to inferior $num.*" \
+ "switch to inferior $num"
+
gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, length, 'aaa'))" \
"${one_pattern_found}" "find string pattern"
"${one_pattern_found}" "pattern found at end of range"
}
+# While still in the new inferior, test reading and writing memory
+# again.
+gdb_test "python astr = gdb.inferiors()\[0\].read_memory (addr, 5); print(astr)" \
+ "<memory at $hex>" \
+ "read str while other inferior selected"
+gdb_test "python print(astr\[1\])" "b'a'" \
+ "print a character from the string"
+gdb_py_test_silent_cmd "python astr\[1\] = b'X'" "change str again" 0
+gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, astr)" \
+ "write str while other inferior selected" 1
+
+gdb_test "inferior 1" "Switching to inferior 1.*" "switch back to inferior 1"
+
+gdb_test "print str" " = \"hXllo, testsuite\"" \
+ "ensure str was changed while other inferior selected"
+
+gdb_test_no_output "remove-inferiors $num" "remove-inferiors $num"
+
# Import struct to pack the following patterns.
gdb_test_no_output "py from struct import *"