]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/testsuite/lib/gdb-python.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / lib / gdb-python.exp
index 641e4457fc694b0ddbe8dc9ac4bc989339835f1f..13a1ab517f17e91db7c53e4510d973858eebe86d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2010-2012 Free Software Foundation, Inc.
+# Copyright 2010-2021 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -27,21 +27,27 @@ proc gdb_py_test_silent_cmd { cmd name report_pass } {
     }
 }
 
-# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
-# Run a test named NAME, consisting of multiple lines of input.
-# After each input line INPUT, search for result line RESULT.
-# Succeed if all results are seen; fail otherwise.
+# Return the result of python expression EXPR.  DEFAULT is returned if
+# there's an error.  TEST is the test message to use.  It can be
+# omitted, in which case a test message is built from EXP.  This is
+# modeled after get_integer_valueof.
 
-proc gdb_py_test_multiple { name args } {
+proc get_python_valueof { exp default {test ""} } {
     global gdb_prompt
-    foreach {input result} $args {
-       if {[gdb_test_multiple $input "$name - $input" {
-           -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
-               pass "$name - $input"
-           }
-       }]} {
-           return 1
+
+    if {$test == ""} {
+       set test "get python valueof \"${exp}\""
+    }
+
+    set val ${default}
+    gdb_test_multiple "python print (\"valueof: %s\" % (${exp}))" "$test" {
+       -re "valueof: (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
+           set val $expect_out(1,string)
+           pass "$test"
+       }
+       timeout {
+           fail "$test (timeout)"
        }
     }
-    return 0
+    return ${val}
 }