From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/4] Add tests for gdb.Value(bufobj, type) constructor
Date: Mon, 18 Feb 2019 15:07:00 -0000 [thread overview]
Message-ID: <20190218080745.7f2554e5@f29-4.lan> (raw)
In-Reply-To: <20190218075816.6f67f3d9@f29-4.lan>
gdb/testsuite/ChangeLog:
* gdb.python/py-value.exp (test_value_from_buffer): New proc with
call from main program.
---
gdb/testsuite/gdb.python/py-value.exp | 42 +++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
index 4f04aa9417..ba7de2166e 100644
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
@@ -510,6 +510,47 @@ 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)" \
+ "TypeError: 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"
+}
+
# Build C version of executable. C++ is built later.
if { [build_inferior "${binfile}" "c"] < 0 } {
return -1
@@ -538,6 +579,7 @@ if ![runto_main] then {
}
test_value_in_inferior
+test_value_from_buffer
test_inferior_function_call
test_value_after_death
next prev parent reply other threads:[~2019-02-18 15:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190218075816.6f67f3d9@f29-4.lan>
2019-02-18 15:03 ` [PATCH 1/4] Define unique_ptr specialization for Py_buffer Kevin Buettner
2019-02-18 15:06 ` [PATCH 2/4] Define gdb.Value(bufobj, type) constructor Kevin Buettner
2019-02-18 22:46 ` Tom Tromey
2019-02-19 0:57 ` Kevin Buettner
2019-02-19 15:19 ` Tom Tromey
2019-02-19 15:28 ` Ulrich Weigand
2019-02-19 2:41 ` Simon Marchi
2019-02-18 15:07 ` Kevin Buettner [this message]
2019-02-19 2:46 ` [PATCH 3/4] Add tests for " Simon Marchi
2019-02-18 15:09 ` [PATCH 4/4] Document two argument form of gdb.Value constructor Kevin Buettner
2019-02-18 16:13 ` Eli Zaretskii
2019-02-18 17:25 ` Kevin Buettner
2019-02-18 17:45 ` Eli Zaretskii
2019-02-19 2:48 ` [PATCH 0/4] Define gdb.Value(val, type) constructor Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190218080745.7f2554e5@f29-4.lan \
--to=kevinb@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox