[3/5] Rename Python variable in py-inferior.exp

Message ID 20230707-py-inf-fixes-30615-v1-3-7792ab559530@adacore.com
State New
Headers
Series Fix some Python Inferior methods |

Commit Message

Tom Tromey July 7, 2023, 3:07 p.m. UTC
  py-inferior.exp creates a Python variable named 'str'.  This clashes
with the built-in type of the same name and can be confusing when
trying to evaluate Python code when debugging the test case.  This
patch renames it.
---
 gdb/testsuite/gdb.python/py-inferior.exp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Pedro Alves July 7, 2023, 6:14 p.m. UTC | #1
On 2023-07-07 16:07, Tom Tromey via Gdb-patches wrote:
> py-inferior.exp creates a Python variable named 'str'.  This clashes
> with the built-in type of the same name and can be confusing when
> trying to evaluate Python code when debugging the test case.  This
> patch renames it.
> ---
>  gdb/testsuite/gdb.python/py-inferior.exp | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
> index a29624f4fd5..41e26878031 100644
> --- a/gdb/testsuite/gdb.python/py-inferior.exp
> +++ b/gdb/testsuite/gdb.python/py-inferior.exp
> @@ -88,13 +88,13 @@ gdb_continue_to_breakpoint "cont to Break here." ".*Break here\..*"
>  
>  gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
>    "read str address" 0
> -gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \
> +gdb_py_test_silent_cmd "python astr = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \

Shouldn't the "print(str)" after the ; be adjusted as well?  How can this pass as is?

>    "read str contents" 1
>  gdb_py_test_silent_cmd "python a = bytes('a', 'ascii')" "" 0
> -gdb_py_test_silent_cmd "python str\[1\] = a" "change str" 0
> -gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \
> +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)" \
>    "write str" 1
> -gdb_test "print (str)" " = \"hallo, testsuite\"" \
> +gdb_test "print str" " = \"hallo, testsuite\"" \
>    "ensure str was changed in the inferior"
>  
>  # Test memory search.
>
  
Tom Tromey July 11, 2023, 3:19 p.m. UTC | #2
>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

>> +gdb_py_test_silent_cmd "python astr = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \

Pedro> Shouldn't the "print(str)" after the ; be adjusted as well?  How can this pass as is?

Yes, it should be.

It passes because gdb_py_test_silent_cmd doesn't seem to check the
output beyond looking for an exception, and 'str' is a built-in type, so
this passes.

I changed it not to use gdb_test and to look for <memory ...> in v2.

Tom
  

Patch

diff --git a/gdb/testsuite/gdb.python/py-inferior.exp b/gdb/testsuite/gdb.python/py-inferior.exp
index a29624f4fd5..41e26878031 100644
--- a/gdb/testsuite/gdb.python/py-inferior.exp
+++ b/gdb/testsuite/gdb.python/py-inferior.exp
@@ -88,13 +88,13 @@  gdb_continue_to_breakpoint "cont to Break here." ".*Break here\..*"
 
 gdb_py_test_silent_cmd "python addr = gdb.selected_frame ().read_var ('str')" \
   "read str address" 0
-gdb_py_test_silent_cmd "python str = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \
+gdb_py_test_silent_cmd "python astr = gdb.inferiors()\[0\].read_memory (addr, 5); print(str)" \
   "read str contents" 1
 gdb_py_test_silent_cmd "python a = bytes('a', 'ascii')" "" 0
-gdb_py_test_silent_cmd "python str\[1\] = a" "change str" 0
-gdb_py_test_silent_cmd "python gdb.inferiors()\[0\].write_memory (addr, str)" \
+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)" \
   "write str" 1
-gdb_test "print (str)" " = \"hallo, testsuite\"" \
+gdb_test "print str" " = \"hallo, testsuite\"" \
   "ensure str was changed in the inferior"
 
 # Test memory search.