public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: "Elmenthaler, Jens" <jens.elmenthaler@verigy.com>
To: "Paul Pluzhnikov" <ppluzhnikov@google.com>, <gdb@sourceware.org>,
	<archer@sourceware.org>
Cc: <dje@google.com>
Subject: RE: [python] Pretty-printers and addressprint
Date: Tue, 10 Nov 2009 07:25:00 -0000	[thread overview]
Message-ID: <58596C4646708B4BB990C44839973330013A61DE@usplmvpbe001.ent.rt.verigy.net> (raw)
In-Reply-To: <20091110021158.C3C2576D70@ppluzhnikov.mtv.corp.google.com>

Hi Paul,

The gdb.Value class has a string() method, you could try this in your to_string method:
	return self.val['whybother']['contents'].string()

Greetings, Jens.

-----Original Message-----
From: gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] On Behalf Of Paul Pluzhnikov
Sent: Dienstag, 10. November 2009 03:12
To: gdb@sourceware.org; archer@sourceware.org
Cc: dje@google.com; ppluzhnikov@google.com
Subject: [python] Pretty-printers and addressprint

Greetings,

Consider the gdb.python/py-prettyprint.exp test case.
It has:

typedef struct string_repr
{
  struct whybother
  {
    const char *contents;
  } whybother;
} string;

and a prettyprinter for it:

# Test returning a Value from a printer.
class string_print:
    def __init__(self, val):
        self.val = val

    def to_string(self):
        return self.val['whybother']['contents']


Which currently produces:

$4 = 0x4007e0 "this is x"^M


The issue I am having is there is no apparent way to get rid of the
address from python side (address is not printed when the printer
returns a python string instead of a value), whereas if the
printer really wants to print the address, it can trivally add
it back by returning appropriate python string.

Printing addresses inside of a container seems to be especially
"not wanted".

Should the decision to print addresses be deferred to the
pretty-printer? Is the patch below reasonable?

Thanks,
--
Paul Pluzhnikov

2009-11-09  Paul Pluzhnikov  <ppluzhnikov@google.com>

	* gdb/python/py-prettyprint.c (print_string_repr): Don't
	print value address.



--- gdb/python/py-prettyprint.c#1    2009-11-09 17:58:39.000000000 -0800
+++ gdb/python/py-prettyprint.c     2009-11-09 16:51:16.862840000 -0800
@@ -209,7 +209,12 @@ print_string_repr (PyObject *printer, co
       Py_DECREF (py_str);
     }
   else if (replacement)
-    common_val_print (replacement, stream, recurse, options, language);
+    {
+      struct value_print_options opts = *options;
+
+      opts.addressprint = 0;
+      common_val_print (replacement, stream, recurse, &opts, language);
+    }
   else
     gdbpy_print_stack ();
 }

  reply	other threads:[~2009-11-10  7:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-10  2:12 Paul Pluzhnikov
2009-11-10  7:25 ` Elmenthaler, Jens [this message]
2009-11-10  8:06   ` Paul Pluzhnikov
2009-11-10  8:37     ` Phil Muldoon
2009-11-10 11:53     ` Paul Koning
2009-11-10 15:45       ` Paul Pluzhnikov
2009-11-10 15:53         ` Paul Koning
2009-11-10 16:53         ` Tom Tromey
2009-11-10 17:03           ` Paul Pluzhnikov
2009-11-10 20:49             ` Tom Tromey
2009-11-10 15:12 ` Tom Tromey

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=58596C4646708B4BB990C44839973330013A61DE@usplmvpbe001.ent.rt.verigy.net \
    --to=jens.elmenthaler@verigy.com \
    --cc=archer@sourceware.org \
    --cc=dje@google.com \
    --cc=gdb@sourceware.org \
    --cc=ppluzhnikov@google.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).