From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 970923972489 for ; Wed, 2 Dec 2020 21:40:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 970923972489 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-504-Tu9l516RMDqpPqKRO3CT8A-1; Wed, 02 Dec 2020 16:40:04 -0500 X-MC-Unique: Tu9l516RMDqpPqKRO3CT8A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23039100746C; Wed, 2 Dec 2020 21:40:03 +0000 (UTC) Received: from localhost (unknown [10.33.37.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id B15F660BFA; Wed, 2 Dec 2020 21:40:02 +0000 (UTC) Date: Wed, 2 Dec 2020 21:40:01 +0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix std::any pretty printer [PR 68735] Message-ID: <20201202214001.GA3639256@redhat.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="fUYQa+Pmc3FrFX/N" Content-Disposition: inline X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Dec 2020 21:40:10 -0000 --fUYQa+Pmc3FrFX/N Content-Type: text/plain; charset=us-ascii Content-Disposition: inline This fixes errors seen on powerpc64 (big endian only) due to the printers for std::any and std::experimental::any being unable to find the manager function. libstdc++-v3/ChangeLog: PR libstdc++/65480 PR libstdc++/68735 * python/libstdcxx/v6/printers.py (function_pointer_to_name): New helper function to get the name of a function from its address. (StdExpAnyPrinter.__init__): Use it. Tested powerpc64-linux, powerpc64le-linux and x86_64-linux. Committed to trunk. --fUYQa+Pmc3FrFX/N Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit dc2b372ed1b1e9af6db45051cff95478c7616807 Author: Jonathan Wakely Date: Wed Dec 2 21:39:08 2020 libstdc++: Fix std::any pretty printer [PR 68735] This fixes errors seen on powerpc64 (big endian only) due to the printers for std::any and std::experimental::any being unable to find the manager function. libstdc++-v3/ChangeLog: PR libstdc++/65480 PR libstdc++/68735 * python/libstdcxx/v6/printers.py (function_pointer_to_name): New helper function to get the name of a function from its address. (StdExpAnyPrinter.__init__): Use it. diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 4176f739004..9c6393712a0 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -1126,6 +1126,29 @@ class SingleObjContainerPrinter(object): return self.visualizer.display_hint () return self.hint +def function_pointer_to_name(f): + "Find the name of the function referred to by the gdb.Value f, " + " which should contain a function pointer from the program." + + # Turn the function pointer into an actual address. + # This is needed to unpack ppc64 function descriptors. + f = f.dereference().address + + if sys.version_info[0] == 2: + # Older versions of GDB need to use long for Python 2, + # because int(f) on 64-bit big-endian values raises a + # gdb.error saying "Cannot convert value to int." + f = long(f) + else: + f = int(f) + + try: + # If the function can't be found older versions of GDB raise a + # RuntimeError saying "Cannot locate object file for block." + return gdb.block_for_pc(f).function.name + except: + return None + class StdExpAnyPrinter(SingleObjContainerPrinter): "Print a std::any or std::experimental::any" @@ -1138,11 +1161,11 @@ class StdExpAnyPrinter(SingleObjContainerPrinter): visualizer = None mgr = self.val['_M_manager'] if mgr != 0: - func = gdb.block_for_pc(int(mgr.cast(gdb.lookup_type('intptr_t')))) + func = function_pointer_to_name(mgr) if not func: - raise ValueError("Invalid function pointer in %s" % self.typename) + raise ValueError("Invalid function pointer in %s" % (self.typename)) rx = r"""({0}::_Manager_\w+<.*>)::_S_manage\((enum )?{0}::_Op, (const {0}|{0} const) ?\*, (union )?{0}::_Arg ?\*\)""".format(typename) - m = re.match(rx, func.function.name) + m = re.match(rx, func) if not m: raise ValueError("Unknown manager function in %s" % self.typename) --fUYQa+Pmc3FrFX/N--