Re: [PATCH v3 6/6] Use correct inferior in Inferior.read_memory et al

Pedro Alves
2023-07-14T16:57:19Z

On 2023-07-13 15:05, Tom Tromey via Gdb-patches wrote:
> --- a/gdb/testsuite/gdb.python/py-inferior.exp
> +++ b/gdb/testsuite/gdb.python/py-inferior.exp
> @@ -91,6 +91,7 @@ gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
> 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\])" .*

This one game me pause. Did you really intend to accept any output? Should the match be a bit
more strict? Otherwise, could you add a comment?

> 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)" \
> @@ -98,6 +99,10 @@ 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]*}
> @@ -115,6 +120,9 @@ with_test_prefix "string" {
> 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" ".*" "switch to inferior $num"

I wouldn't mind making this a little tighter too, since it's so easy, like match:

"Switching to inferior $num .*"

> +gdb_test "inferior 1" ".*" "switch back to inferior 1"

Ditto.

Otherwise LGTM.