+ with_test_prefix "straddling" {
+ gdb_test_no_output "set *(int32_t*) &search_buf\[${CHUNK_SIZE}-1\] = 0xfdb97531"
+ gdb_test_no_output "py pattern = pack('${python_pack_char}I', 0xfdb97531)"
+ gdb_test_no_output "py start_addr = gdb.selected_frame ().read_var ('search_buf')"
+ gdb_test "py print (gdb.inferiors()\[0\].search_memory (start_addr, end_addr - start_addr, pattern))" \
+ "${one_pattern_found}" "find pattern straddling chunk boundary"
+ }
+}
+
+# Test Inferior is_valid. This must always be the last test in
+# this testcase as it kills the inferior.
+
+with_test_prefix "is_valid" {
+ gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get initial list" 1
+ gdb_test "python print (len(inf_list))" "1" "get inferior list length 1"
+ gdb_test "python print (inf_list\[0\].is_valid())" "True" \
+ "check inferior validity 1"
+
+ gdb_py_test_multiple "install new inferior event handler" \
+ "python" "" \
+ "my_inferior_count = 1" "" \
+ "def new_inf_handler(evt):" "" \
+ " global my_inferior_count" "" \
+ " if evt.inferior is not None:" "" \
+ " my_inferior_count = my_inferior_count + 1" "" \
+ "gdb.events.new_inferior.connect(new_inf_handler)" "" \
+ "end" ""
+ gdb_py_test_multiple "install inferior deleted event handler" \
+ "python" "" \
+ "def del_inf_handler(evt):" "" \
+ " global my_inferior_count" "" \
+ " if evt.inferior is not None:" "" \
+ " my_inferior_count = my_inferior_count - 1" "" \
+ "gdb.events.inferior_deleted.connect(del_inf_handler)" "" \
+ "end" ""
+
+ gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
+ gdb_py_test_silent_cmd "python inf_list = gdb.inferiors()" "get new list" 1
+ gdb_test "python print (len(inf_list))" "2" "get inferior list length 2"
+ gdb_test "python print (inf_list\[0\].is_valid())" "True" \
+ "check inferior validity 2"
+
+ gdb_test "python print (my_inferior_count)" "2" \
+ "test new-inferior event handler"
+
+ gdb_test "python print (inf_list\[1\].is_valid())" "True" \
+ "check inferior validity 3"
+
+ gdb_test_no_output "remove-inferiors 2" "remove-inferiors 3"
+ gdb_test "python print (inf_list\[0\].is_valid())" "True" \
+ "check inferior validity 4"
+
+ gdb_test "python print (inf_list\[1\].is_valid())" "False" \
+ "check inferior validity 5"
+
+ gdb_test "python print (my_inferior_count)" "1" \
+ "test inferior-deleted event handler"
+
+ # Test that other properties and methods handle the removed inferior
+ # correctly.
+ gdb_test "python print (inf_list\[1\].num)" \
+ "RuntimeError: Inferior no longer exists.*"
+ gdb_test "python print (inf_list\[1\].pid)" \
+ "RuntimeError: Inferior no longer exists.*"
+ gdb_test "python print (inf_list\[1\].was_attached)" \
+ "RuntimeError: Inferior no longer exists.*"
+ gdb_test "python print (inf_list\[1\].progspace)" \
+ "RuntimeError: Inferior no longer exists.*"
+ gdb_test "python print (inf_list\[1\].threads ())" \
+ "RuntimeError: Inferior no longer exists.*"
+ gdb_test "python print (inf_list\[1\].thread_from_thread_handle (1))" \
+ "RuntimeError: Inferior no longer exists.*"
+}
+
+# Test gdb.selected_inferior()
+with_test_prefix "selected_inferior" {
+ gdb_test "inferior 1" ".*" "switch to first inferior"
+ gdb_test "py print (gdb.selected_inferior().num)" "1" "first inferior selected"
+
+ gdb_test "add-inferior" "Added inferior 3 on connection .*" "create new inferior"
+ gdb_test "inferior 3" ".*" "switch to third inferior"
+ gdb_test "py print (gdb.selected_inferior().num)" "3" "third inferior selected"
+ gdb_test "inferior 1" ".*" "switch back to first inferior"
+ gdb_test_no_output "remove-inferiors 3" "remove second inferior"
+}
+
+# Test repr()/str()
+with_test_prefix "__repr__" {
+ gdb_test "add-inferior" "Added inferior 4 on connection .*" "add inferior 4"
+ gdb_py_test_silent_cmd "python infs = gdb.inferiors()" "get inferior list" 1
+ gdb_test "python print (infs\[0\])" "<gdb.Inferior num=1, pid=$decimal>"
+ gdb_test "python print (infs)" \
+ "\\\(<gdb.Inferior num=1, pid=$decimal>, <gdb.Inferior num=4, pid=$decimal>\\\)" \
+ "print all inferiors 1"
+ gdb_test_no_output "remove-inferiors 4"
+ gdb_test "python print (infs)" \
+ "\\\(<gdb.Inferior num=1, pid=$decimal>, <gdb.Inferior \\\(invalid\\\)>\\\)" \
+ "print all inferiors 2"
+}
+
+# Test architecture.
+with_test_prefix "architecture" {
+ gdb_test "inferior 1" ".*" "switch to first inferior"
+ gdb_test "python print(gdb.selected_frame().architecture() is gdb.selected_inferior().architecture())" \
+ "True" \
+ "inferior architecture matches frame architecture"