From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 61473 invoked by alias); 19 Feb 2019 02:46:31 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 61200 invoked by uid 89); 19 Feb 2019 02:46:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:3005 X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 19 Feb 2019 02:46:09 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id x1J2k2xl008076 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 18 Feb 2019 21:46:07 -0500 Received: by simark.ca (Postfix, from userid 112) id 568F71E652; Mon, 18 Feb 2019 21:46:02 -0500 (EST) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id A41CA1E16B; Mon, 18 Feb 2019 21:46:01 -0500 (EST) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 19 Feb 2019 02:46:00 -0000 From: Simon Marchi To: Kevin Buettner Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 3/4] Add tests for gdb.Value(bufobj, type) constructor In-Reply-To: <20190218080745.7f2554e5@f29-4.lan> References: <20190218075816.6f67f3d9@f29-4.lan> <20190218080745.7f2554e5@f29-4.lan> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.6 X-IsSubscribed: yes X-SW-Source: 2019-02/txt/msg00298.txt.bz2 On 2019-02-18 10:07, Kevin Buettner wrote: > 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" > +} Just a nit: I would suggest testing the code path when the second argument does not have the right type (is not a gdb.Type). Simon