From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 3DDD13A77044; Fri, 23 Apr 2021 10:37:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DDD13A77044 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/redhat/heads/gcc-8-branch)] libstdc++: Fix std::any pretty printer [PR 68735] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/vendors/redhat/heads/gcc-8-branch X-Git-Oldrev: c44d03afd63c8f537e053d00289ac3f517e1d43b X-Git-Newrev: bd5b2d17af141c8ba6c032dac00d27af5b0d82f4 Message-Id: <20210423103734.3DDD13A77044@sourceware.org> Date: Fri, 23 Apr 2021 10:37:34 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Apr 2021 10:37:34 -0000 https://gcc.gnu.org/g:bd5b2d17af141c8ba6c032dac00d27af5b0d82f4 commit bd5b2d17af141c8ba6c032dac00d27af5b0d82f4 Author: Jonathan Wakely Date: Wed Dec 2 21:39:08 2020 +0000 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. (cherry picked from commit dc2b372ed1b1e9af6db45051cff95478c7616807) Diff: --- libstdc++-v3/python/libstdcxx/v6/printers.py | 29 +++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 69d5835e0c2..a476561b32e 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -1039,6 +1039,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" @@ -1051,11 +1074,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""".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)