From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22544 invoked by alias); 18 Jun 2010 14:21:39 -0000 Received: (qmail 22529 invoked by uid 22791); 18 Jun 2010 14:21:38 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_05,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 18 Jun 2010 14:21:32 +0000 Received: from wpaz37.hot.corp.google.com (wpaz37.hot.corp.google.com [172.24.198.101]) by smtp-out.google.com with ESMTP id o5IELTfm024328 for ; Fri, 18 Jun 2010 07:21:29 -0700 Received: from pwi5 (pwi5.prod.google.com [10.241.219.5]) by wpaz37.hot.corp.google.com with ESMTP id o5IEL28N016863 for ; Fri, 18 Jun 2010 07:21:28 -0700 Received: by pwi5 with SMTP id 5so570238pwi.38 for ; Fri, 18 Jun 2010 07:21:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.89.199 with SMTP id f7mr554579vcm.69.1276870887586; Fri, 18 Jun 2010 07:21:27 -0700 (PDT) Received: by 10.220.189.201 with HTTP; Fri, 18 Jun 2010 07:21:27 -0700 (PDT) In-Reply-To: <4C1B16BF.3040000@redhat.com> References: <4BFA6E82.3070704@redhat.com> <4C1B16BF.3040000@redhat.com> Date: Fri, 18 Jun 2010 14:21:00 -0000 Message-ID: Subject: Re: [python][patch] Inferior and Thread information support. From: Doug Evans To: Phil Muldoon Cc: tromey@redhat.com, gdb-patches ml Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true X-IsSubscribed: yes 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 X-SW-Source: 2010-06/txt/msg00406.txt.bz2 Hi. Just a few comments. On Thu, Jun 17, 2010 at 11:48 PM, Phil Muldoon wrote: > + > +@findex gdb.read_memory > +@defmethod Inferior read_memory address length > +Read @var{length} bytes of memory from the inferior, starting at > +@var{address}. =A0Returns a buffer object, which behaves much like an ar= ray > +or a string. =A0It can be modified and given to the @code{gdb.write_memo= ry} > +function. > +@end defmethod > + > +@findex gdb.write_memory > +@defmethod Inferior write_memory address buffer @r{[}length@r{]} > +Write the contents of @var{buffer} to the inferior, starting at > +@var{address}. =A0The @var{buffer} parameter must be a Python object > +which supports the buffer protocol, i.e., a string, an array or the > +object returned from @code{gdb.read_memory}. =A0If given, @var{length} > +determines the number of bytes from @var{buffer} to be written. > +@end defmethod > + > +@findex gdb.search_memory > +@defmethod Inferior search_memory address length pattern @r{[}size@r{]} = @r{[}max_count@r{]} > +Search a region of the inferior memory starting at @var{address} with the > +given @var{length}. =A0@var{pattern} can be a string, a byte array, a bu= ffer > +object, a number, a @code{gdb.Value} object (@pxref{Values From > +Inferior}), or a Python list or a tuple with elements in any combination > +of those types. =A0If @var{pattern} is a list or a tuple, each element > +will be extracted and concatenated together to form @var{pattern}. > + > +If @var{size} is given and is non-zero, it specifies the size in bytes > +of a Python scalar or @code{gdb.Value} in the search pattern. =A0If > +@var{size} is zero or not specified, the size is taken from the value's = type > +in the current language. =A0If @var{pattern} is a tuple or list, these > +actions apply to each element in the tuple or list. =A0This is useful > +when one wants to specify the search pattern as a mixture of types. > +Note that this means, for example, that in the case of C-like > +languages a search for an untyped 0x42 will search for @samp{(int) > +0x42} which is typically four bytes. =A0@var{max_count} is the highest > +number of matches to search for. > +@end defmethod > +@end table I think search_memory should take just the same type of parameter for the search pattern that write_memory takes: a byte array (etc.). Keep the API simple and let the caller do the conversion to a byte array (or buffer protocol). We could provide utilities to convert to/from byte arrays (then write_memory can use them too!) but Python probably has them already. Then you can punt on the `size' parameter completely. You also want to document what the result is. > +@defivar InferiorThread ptid > +ID of the thread, as assigned by the operating system. =A0This attribute= is a > +tuple containing three integers. =A0The first is the Process ID (PID); t= he second > +is the Lightweight Process ID (TID), and the third is the Thread ID (TID= ). > +Either the TID or TID may be 0, which indicates that the operating system > +does not =A0use that identifier. > +@end defivar A couple of typos here: TID is duplicated. > +# Test max-count with size, with different parameter position > + > +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, lengt= h, \[0x61, 0x61\], 1, 1)" \ > + =A0"${one_pattern_found}" "size =3D 1, max_count =3D 1" > + > +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, lengt= h, \[0x61, 0x61\], 1, 2)" \ > + =A0"${two_patterns_found}" "size =3D 1, max_count =3D 2, normal orderin= g" > + > +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, lengt= h, \[0x61, 0x61\], size =3D 1, max_count =3D 2)" \ > + =A0"${two_patterns_found}" "size =3D 1, max_count =3D 2, normal orderin= g, with keywords" > + > +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, lengt= h, \[0x61, 0x61\], max_count =3D 2, size =3D 1)" \ > + =A0"${two_patterns_found}" "size =3D 1, max_count =3D 2, inverted order= ing" > + > +gdb_test "py print gdb.inferiors()\[0\].search_memory (start_addr, lengt= h, \['a', 'a'\], max_count =3D 2)" \ > + =A0"${two_patterns_found}" "max_count =3D 2, with keyword" The CLI testcase for this tests the parameter ordering in order to test the parsing of the parameters, but you don't need to do that here (we can trust python on this). Doesn't hurt though.