From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31452 invoked by alias); 10 Nov 2009 11:53:41 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 31433 invoked by uid 22791); 10 Nov 2009 11:53:39 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org X-Loopcount0: from 12.110.134.31 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [python] Pretty-printers and addressprint Date: Tue, 10 Nov 2009 11:53:00 -0000 Message-ID: In-Reply-To: <8ac60eac0911100006yc31e2acmba7bf9fde33ddfa@mail.gmail.com> References: <20091110021158.C3C2576D70@ppluzhnikov.mtv.corp.google.com> <58596C4646708B4BB990C44839973330013A61DE@usplmvpbe001.ent.rt.verigy.net> <8ac60eac0911100006yc31e2acmba7bf9fde33ddfa@mail.gmail.com> From: "Paul Koning" To: "Paul Pluzhnikov" , "Elmenthaler, Jens" Cc: , , X-SW-Source: 2009-q4/txt/msg00050.txt.bz2 > On Mon, Nov 9, 2009 at 11:25 PM, Elmenthaler, Jens > wrote: >=20 > > The gdb.Value class has a string() method, you could try this in your > to_string method: > > =A0 =A0 =A0 =A0return self.val['whybother']['contents'].string() >=20 > That doesn't quite do what I want, but this almost does: >=20 > return '"' + self.val['whybother']['contents'].string() + '"' Try instead=20 return repr (self.val...) rather than manually supplying the quotes. That will do the right thing ev= en if the contents has things like quotes in it. =20 > However, consider a modification of the original test: >=20 > - string x =3D make_string ("this is x"); > + string x =3D make_string ("this is x\201\202\203\204"); > ...=20 > But this value can't be converted to a python string in ASCII charset: > the modified printer produces this: >=20 > $4 =3D Traceback (most recent call last): > File "../../../src/gdb/testsuite/gdb.python/py-prettyprint.py", > line 27, in to_string > return self.val['whybother']['contents'].string() > UnicodeDecodeError: 'ascii' codec can't decode byte 0x81 in position > 9: ordinal not in range(128) >=20 > Unfortunately I frequently deal with non-ascii strings, and the > problem just wouldn't go away :-( My test (without gdb, I don't have that installed yet) is inconclusive but = I think using repr() will cure that too. paul