This is the mail archive of the mailing list for the Archer project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [python] Pretty-printers and addressprint

> On Mon, Nov 9, 2009 at 11:25 PM, Elmenthaler, Jens
> <> wrote:
> > The gdb.Value class has a string() method, you could try this in your
> to_string method:
> > ? ? ? ?return self.val['whybother']['contents'].string()
> That doesn't quite do what I want, but this almost does:
>         return '"' + self.val['whybother']['contents'].string() + '"'

Try instead 
    return repr (self.val...)

rather than manually supplying the quotes.  That will do the right thing even if the contents has things like quotes in it.
> However, consider a modification of the original test:
> -  string x = make_string ("this is x");
> +  string x = make_string ("this is x\201\202\203\204");
> ... 
> But this value can't be converted to a python string in ASCII charset:
> the modified printer produces this:
>   $4 = Traceback (most recent call last):
>     File "../../../src/gdb/testsuite/gdb.python/",
> 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)
> 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]