From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27933 invoked by alias); 5 Aug 2014 06:23:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 27893 invoked by uid 89); 5 Aug 2014 06:23:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-qa0-f48.google.com Received: from mail-qa0-f48.google.com (HELO mail-qa0-f48.google.com) (209.85.216.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 05 Aug 2014 06:23:11 +0000 Received: by mail-qa0-f48.google.com with SMTP id m5so485374qaj.35 for ; Mon, 04 Aug 2014 23:23:09 -0700 (PDT) X-Received: by 10.224.69.136 with SMTP id z8mr2148380qai.60.1407219789101; Mon, 04 Aug 2014 23:23:09 -0700 (PDT) Received: from hydrogen (naesten-pt.tunnel.tserv4.nyc4.ipv6.he.net. [2001:470:1f06:57::2]) by mx.google.com with ESMTPSA id o6sm1518452qab.9.2014.08.04.23.23.07 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 04 Aug 2014 23:23:08 -0700 (PDT) Received: from naesten by hydrogen with local (Exim 4.82) (envelope-from ) id 1XEY9L-0002pr-0L; Tue, 05 Aug 2014 02:23:07 -0400 From: Samuel Bronson To: Jonathan Wakely , gdb@sourceware.org Cc: Tom Tromey , libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org, pmuldoon@redhat.com Subject: Converting function pointers to PC values in Python (was: [patch] Add libstdc++ type printers for class templates) References: <20140714142159.GF4871@redhat.com> <20140714192206.GG4871@redhat.com> <87y4vv1z0s.fsf@fleche.redhat.com> <20140714235047.GK4871@redhat.com> Date: Tue, 05 Aug 2014 06:23:00 -0000 In-Reply-To: <20140714235047.GK4871@redhat.com> (Jonathan Wakely's message of "Tue, 15 Jul 2014 00:50:47 +0100") Message-ID: <877g2nxxo5.fsf_-_@naesten.mooo.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2014-08/txt/msg00316.txt.bz2 Jonathan Wakely writes: > One part of the patch I wasn't sure about was this, where 'mgr' is a > function pointer: > > func = gdb.block_for_pc(int(mgr.cast(gdb.lookup_type('intptr_t')))) > > Is there a better way to get a pc from the function pointer? > I tried simply int(mgr) but it didn't work. Well, long() WFM; e.g. with Python 2 and gdb 7.8.50.20140706-cvs I can do: (gdb) python print(long(gdb.parse_and_eval("(void(*)())-1"))) 4294967295 The fact that int() does not work the same way may indicate a shortcoming in gdb.Value.__int__(); I'm told that in recent 2.x versions, int() is perfectly happy returning a long instead of an int. Of course, this still presumably won't work on architectures where function pointers don't point straight to the code, e.g. most PowerPC, where as I understand things it actually points at a "function descriptor", which in turn references the actual code. So it seems we're missing an API for this. -- Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!