From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17743 invoked by alias); 31 Jan 2012 18:26:56 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 17572 invoked by uid 22791); 31 Jan 2012 18:26:53 -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: Tue, 31 Jan 2012 18:26:00 -0000 In-Reply-To: (Vladimir's message of "Wed, 25 Jan 2012 13:18:21 +0000 (UTC)") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2012-q1/txt/msg00004.txt.bz2 >>>>> "Vladimir" == Vladimir writes: Vladimir> I have a couple of question related to Python pretty Vladimir> printers. I tried to search for the answer on the web but had Vladimir> no luck. Vladimir> (gdb) print *a Vladimir> Could not find operator*. Vladimir> How can I implement a printer for the second case? gdb is giving an error here before it computes a value to print. I forget if operator* is supposed to be working now or not. I think some operators still aren't really working in gdb; but often they will fail anyway because they were not compiled into your program. You can work around this a little by having the base printer also print the pointed-to value. This is what the libstdc++ iterator printers do (for now). There is a bug open about the missing operators problem: http://sourceware.org/bugzilla/show_bug.cgi?id=12937 Vladimir> 2) Another question is about how to call from pretty printer a Vladimir> function from my currently debugged process. For example, I Vladimir> have an unsigned int variable which contains a hash of a Vladimir> string and there is a function that can map the hash to the Vladimir> original string. To make the unsigned int value a bit more Vladimir> descriptive I want to call the function and print Vladimir> corresponding string. Actually I managed to make such call but Vladimir> the result looks ugly: Vladimir> def to_string(self): Vladimir> crc = self.val Vladimir> s = gdb.execute('call hash_to_string(%d)' % crc, to_string=True) Vladimir> return ('crc = 0x%08X : \'%s\'' % (crc, s))) Vladimir> (gdb) print crc Vladimir> $1 = crc = 0x0024A837 : '$2 = "qerrrr" Vladimir> ' Vladimir> Is there any way to obtain the result of the function call as Vladimir> gdb.Value? Yes, it can be done. What you have to do is get the address of the function as a value. There's no super way to do this right now: http://sourceware.org/bugzilla/show_bug.cgi?id=12027 Once you have that you can call the Value, this is explained in the docs: A `gdb.Value' that represents a function can be executed via inferior function call. Any arguments provided to the call must match the function's prototype, and must be provided in the order specified by that prototype. For example, `some_val' is a `gdb.Value' instance representing a function that takes two integers as arguments. To execute this function, call it like so: result = some_val (10,20) However, you usually don't want to call functions when pretty-printing. For one thing, this means core-file debugging won't work. It is better, when possible, to do everything in Python instead. Tom