diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-12-02 21:39:08 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-12-02 21:39:08 +0000 |
commit | dc2b372ed1b1e9af6db45051cff95478c7616807 (patch) | |
tree | ce0008f72deb04eb3f14f9c916dae310bebaf5d2 /libstdc++-v3 | |
parent | 2847d7d28ea79e2f93049fad16f931b6705c9fff (diff) | |
download | gcc-dc2b372ed1b1e9af6db45051cff95478c7616807.zip gcc-dc2b372ed1b1e9af6db45051cff95478c7616807.tar.gz gcc-dc2b372ed1b1e9af6db45051cff95478c7616807.tar.bz2 |
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.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/python/libstdcxx/v6/printers.py | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 4176f73..9c63937 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) |