aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorKevin Buettner <kevinb@redhat.com>2019-02-16 18:07:51 -0700
committerKevin Buettner <kevinb@redhat.com>2019-02-26 10:25:40 -0700
commitbc2a507e6e90fc5766bd68d368441f5b511c2ef1 (patch)
treead9100eb29edcd89851c54f01335094d77496b9c /gdb
parentfe07eca59d0544eb6c56c3559da9ceece23cae6e (diff)
downloadgdb-bc2a507e6e90fc5766bd68d368441f5b511c2ef1.zip
gdb-bc2a507e6e90fc5766bd68d368441f5b511c2ef1.tar.gz
gdb-bc2a507e6e90fc5766bd68d368441f5b511c2ef1.tar.bz2
Add tests for gdb.Value(bufobj, type) constructor
gdb/testsuite/ChangeLog: * gdb.python/py-value.exp (test_value_from_buffer): New proc with call from main program.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.python/py-value.exp45
2 files changed, 50 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index eacb315..cb51bcb 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-02-26 Kevin Buettner <kevinb@redhat.com>
+
+ * gdb.python/py-value.exp (test_value_from_buffer): New proc with
+ call from main program.
+
2019-02-23 Joel Brobecker <brobecker@adacore.com>
* gdb.ada/mi_ref_changeable.exp: Update copyright year range.
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
index 4f04aa9..d42aff9 100644
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
@@ -510,6 +510,50 @@ proc test_float_conversion {} {
gdb_test "python print(float(gdb.Value(0)))" "0\\.0"
}
+proc test_value_from_buffer {} {
+ global gdb_prompt
+ global gdb_py_is_py3k
+
+ gdb_py_test_silent_cmd "python tp=gdb.lookup_type('int')" "look up int type" 0
+ gdb_py_test_silent_cmd "python size_a=gdb.parse_and_eval('sizeof(a)')" \
+ "find size of a" 0
+ gdb_py_test_silent_cmd "python size_a0=gdb.parse_and_eval('sizeof(a\[0\])')" \
+ "find size of element of a" 0
+ gdb_py_test_silent_cmd "python addr=gdb.parse_and_eval('&a')" \
+ "find address of a" 0
+ gdb_py_test_silent_cmd "python b=gdb.selected_inferior().read_memory(addr,size_a)" \
+ "read buffer from memory" 1
+ gdb_test "python v=gdb.Value(b,tp); print(v)" "1" \
+ "construct value from buffer"
+ gdb_test "python v=gdb.Value(b\[size_a0:\],tp); print(v)" "2" \
+ "convert 2nd elem of buffer to value"
+ gdb_test "python v=gdb.Value(b\[2*size_a0:\],tp); print(v)" "3" \
+ "convert 3rd elem of buffer to value"
+ gdb_test "python v=gdb.Value(b\[2*size_a0+1:\],tp); print(v)" \
+ "TypeError: Size of type is larger than that of buffer object\..*" \
+ "attempt to convert smaller buffer than size of type"
+ gdb_py_test_silent_cmd "python atp=tp.array(2) ; print(atp)" \
+ "make array type" 0
+ gdb_py_test_silent_cmd "python va=gdb.Value(b,atp)" \
+ "construct array value from buffer" 0
+ gdb_test "python print(va)" "\\{1, 2, 3\\}" "print array value"
+ gdb_test "python print(va\[0\])" "1" "print first array element"
+ gdb_test "python print(va\[1\])" "2" "print second array element"
+ gdb_test "python print(va\[2\])" "3" "print third array element"
+ gdb_test "python print(va\[3\])" "gdb\.error: no such vector element.*" \
+ "print out of bounds array element"
+ gdb_py_test_silent_cmd "python atpbig=tp.array(3)" "make bigger array type" 0
+ gdb_test "python vabig=gdb.Value(b,atpbig)" \
+ "ValueError: Size of type is larger than that of buffer object\..*" \
+ "attempt to construct large value with small buffer"
+ gdb_test "python v=gdb.Value(2048,tp)" \
+ "TypeError: Object must support the python buffer protocol\..*" \
+ "attempt to construct value from buffer with non-buffer object"
+ gdb_test "python v=gdb.Value(b,'int'); print(v)" \
+ "TypeError: type argument must be a gdb\.Type\..*" \
+ "attempt to construct value with string as type"
+}
+
# Build C version of executable. C++ is built later.
if { [build_inferior "${binfile}" "c"] < 0 } {
return -1
@@ -538,6 +582,7 @@ if ![runto_main] then {
}
test_value_in_inferior
+test_value_from_buffer
test_inferior_function_call
test_value_after_death