From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6331 invoked by alias); 22 Feb 2012 21:38:52 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 6320 invoked by uid 22791); 22 Feb 2012 21:38:52 -0000 X-SWARE-Spam-Status: No, hits=-7.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org From: Tom Tromey To: Vladimir Cc: archer@sourceware.org Subject: Re: pretty printing of smart pointers and making function calls References: Date: Wed, 22 Feb 2012 21:38:00 -0000 In-Reply-To: (Vladimir's message of "Wed, 8 Feb 2012 16:35:39 +0000 (UTC)") Message-ID: <87obsqo8fb.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.93 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2012-q1/txt/msg00008.txt.bz2 >>>>> "Vladimir" == Vladimir writes: Sorry about the long delay here. I managed to forget about this thread somehow :( Tom> You can work around this a little by having the base printer also print Tom> the pointed-to value. This is what the libstdc++ iterator printers do Tom> (for now). Vladimir> I'm not sure I understand you correctly. Do you mean that if Vladimir> the user asks for a value of variable a and pretty printer Vladimir> knows that it's a pointer then along with pointer address it Vladimir> should print the value the pointer points too? Anyway some Vladimir> reference to document or example would be useful here. E.g., the libstdc++ printers for iterators print the referred-to object as well. Here's a simple one: class StdSlistIteratorPrinter: "Print __gnu_cxx::slist::iterator" def __init__(self, typename, val): self.val = val def to_string(self): nodetype = find_type(self.val.type, '_Node') nodetype = nodetype.strip_typedefs().pointer() return self.val['_M_node'].cast(nodetype).dereference()['_M_data'] This looks into the iterator representation, finds the pointer to the iterated-over data, and prints that. This is a hack, but often a useful one. Vladimir> But you are right that this doesn't work with core-file. Is Vladimir> there any way to check in Python whether I debug alive process Vladimir> or see its dead body? Nothing direct but as a workaround you can often find this stuff using gdb.execute(..., to_string=True) and then parsing the result. The output here might change between releases, though, so it is generally better to get a real Python API. Tom