]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/testsuite/gdb.python/py-frame.exp
* configure.ac: Move comment to remove extra space in last argument
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-frame.exp
index 86fe660b3125ee9d5189986fe07d146dc21e7a9d..6c296b9e609bb1175c26eab9457f1ddfd6c6af38 100644 (file)
@@ -20,6 +20,8 @@ if $tracelevel then {
     strace $tracelevel
 }
 
+load_lib gdb-python.exp
+
 set testfile "py-frame"
 set srcfile ${testfile}.c
 set binfile ${objdir}/${subdir}/${testfile}
@@ -28,17 +30,6 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debu
     return -1
 }
 
-# Run a command in GDB, and report a failure if a Python exception is thrown.
-# If report_pass is true, report a pass if no exception is thrown.
-proc gdb_py_test_silent_cmd {cmd name report_pass} {
-  global gdb_prompt
-
-  gdb_test_multiple $cmd $name {
-      -re "Traceback.*$gdb_prompt $"  { fail $name }
-      -re "$gdb_prompt $"            { if $report_pass { pass $name } }
-  }
-}
-
 # Start with a fresh gdb.
 
 gdb_exit
@@ -46,13 +37,8 @@ gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
 gdb_load ${binfile}
 
-gdb_test_multiple "python print 'hello, world!'" "verify python support" {
-    -re "not supported.*$gdb_prompt $" {
-      unsupported "python support is disabled"
-      return -1
-    }
-    -re "$gdb_prompt $"        {}
-}
+# Skip all tests if Python scripting is not enabled.
+if { [skip_python_tests] } { continue }
 
 # The following tests require execution.
 
@@ -61,9 +47,33 @@ if ![runto_main] then {
     return 0
 }
 
+gdb_breakpoint [gdb_get_line_number "Block break here."]
+gdb_continue_to_breakpoint "Block break here."
+gdb_py_test_silent_cmd "python bf1 = gdb.selected_frame ()" "get frame" 0
+
+# First test that read_var is unaffected by PR 11036 changes.
+gdb_test "python print bf1.read_var(\"i\")" "\"stuff\"" "test i"
+gdb_test "python print bf1.read_var(\"f\")" "\"foo\"" "test f"
+gdb_test "python print bf1.read_var(\"b\")" "\"bar\"" "test b"
+
+# Test the read_var function in another block other than the current
+# block (in this case, the super block). Test thar read_var is reading
+# the correct variables of i and f but they are the correct value and type.
+gdb_py_test_silent_cmd "python sb = bf1.block().superblock" "get superblock" 0
+gdb_test "python print bf1.read_var(\"i\", sb)" "1.1.*" "test i = 1.1"
+gdb_test "python print bf1.read_var(\"i\", sb).type" "double" "test double i"
+gdb_test "python print bf1.read_var(\"f\", sb)" "2.2.*" "test f = 2.2"
+gdb_test "python print bf1.read_var(\"f\", sb).type" "double" "test double f"
+
+# And again test another outerblock, this time testing "i" is the
+# correct value and type.
+gdb_py_test_silent_cmd "python sb = sb.superblock" "get superblock" 0
+gdb_test "python print bf1.read_var(\"i\", sb)" "99" "test i = 99"
+gdb_test "python print bf1.read_var(\"i\", sb).type" "int" "test int i"
+
 gdb_breakpoint "f2"
 gdb_continue_to_breakpoint "breakpoint at f2"
-gdb_test "up" "" ""
+gdb_test "up" ".*" ""
 
 gdb_py_test_silent_cmd "python f1 = gdb.selected_frame ()" "get second frame" 0
 gdb_py_test_silent_cmd "python f0 = f1.newer ()" "get first frame" 0
@@ -81,7 +91,7 @@ gdb_test "python print 'result =', f0.pc ()" " = \[0-9\]+" "test Frame.pc"
 gdb_test "python print 'result =', f0.older () == f1" " = True" "test Frame.older"
 gdb_test "python print 'result =', f1.newer () == f0" " = True" "test Frame.newer"
 gdb_test "python print 'result =', f0.read_var ('variable_which_surely_doesnt_exist')" \
-  "ValueError: variable 'variable_which_surely_doesnt_exist' not found.*Error while executing Python code." \
+  "ValueError: Variable 'variable_which_surely_doesnt_exist' not found.*Error while executing Python code." \
   "test Frame.read_var - error"
 gdb_test "python print 'result =', f0.read_var ('a')" " = 1" "test Frame.read_var - success"