From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id EC4E53850223; Mon, 20 Mar 2023 11:54:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC4E53850223 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679313296; bh=7+lGpWKEaEVhKbK9aop4tLjUJxcGbljU5ZsKJIyR7aQ=; h=From:To:Subject:Date:From; b=w3PbSZoPikmOGWnu7VkD4s8wWvjKw5XQhdhNX+Wmom5HaIZzfiHgRQWCaoAbwakTZ d2HoJlYKS0yGPLmj9ez5P51V3nzJzBNsqLEbhlYFJlvZkFpxKKpxc5po0weBZwgp5W QIIgI3QfXOwWGs76gwhqXabB63T+TvRpam/Nad+k= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-9300] libstdc++: Fix gdb pretty printers when dealing with std::string X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: abd85fa15043ee32483ff1daa6dee5d47c9071c4 X-Git-Newrev: 0a6e26e79798057301e5e2f56e89aec65e83161c Message-Id: <20230320115456.EC4E53850223@sourceware.org> Date: Mon, 20 Mar 2023 11:54:56 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0a6e26e79798057301e5e2f56e89aec65e83161c commit r12-9300-g0a6e26e79798057301e5e2f56e89aec65e83161c Author: François Dumont Date: Mon Sep 26 19:14:54 2022 +0200 libstdc++: Fix gdb pretty printers when dealing with std::string Since revision 33b43b0d8cd2de722d177ef823930500948a7487 std::string and other similar typedef are ambiguous from a gdb point of view because it matches both std::basic_string and std::__cxx11::basic_string symbols. For those typedef add a workaround to accept the substitution as long as the same regardless of __cxx11 namespace. Also avoid to register printers for types in std::__cxx11::__8:: namespace, there is no such symbols. libstdc++-v3/ChangeLog: * python/libstdcxx/v6/printers.py (Printer.add_version): Do not add version namespace for __cxx11 symbols. (add_one_template_type_printer): Likewise. (add_one_type_printer): Likewise. (FilteringTypePrinter._recognizer.recognize): Add a workaround for std::string & al ambiguous typedef matching both std:: and std::__cxx11:: symbols. * testsuite/libstdc++-prettyprinters/cxx17.cc: Remove obsolete \#define _GLIBCXX_USE_CXX11_ABI 0. * testsuite/libstdc++-prettyprinters/simple.cc: Likewise. Adapt test to accept std::__cxx11::list. * testsuite/libstdc++-prettyprinters/simple11.cc: Likewise. * testsuite/libstdc++-prettyprinters/whatis.cc: Likewise. * testsuite/libstdc++-prettyprinters/80276.cc: Likewise and remove xfail for c++20 and debug mode. * testsuite/libstdc++-prettyprinters/libfundts.cc: Likewise. (cherry picked from commit 4347fea9c28b6dc5997ef8b87e49867a071967ea) Diff: --- libstdc++-v3/python/libstdcxx/v6/printers.py | 21 ++++++++++++++++++--- .../testsuite/libstdc++-prettyprinters/80276.cc | 5 +---- .../testsuite/libstdc++-prettyprinters/cxx17.cc | 3 --- .../testsuite/libstdc++-prettyprinters/libfundts.cc | 7 ++----- .../testsuite/libstdc++-prettyprinters/simple.cc | 5 +---- .../testsuite/libstdc++-prettyprinters/simple11.cc | 5 +---- .../testsuite/libstdc++-prettyprinters/whatis.cc | 4 ---- 7 files changed, 23 insertions(+), 27 deletions(-) diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 7d3c61de613..593b568b3a1 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -1806,7 +1806,7 @@ class Printer(object): # Add a name using _GLIBCXX_BEGIN_NAMESPACE_VERSION. def add_version(self, base, name, function): self.add(base + name, function) - if _versioned_namespace: + if _versioned_namespace and not '__cxx11' in base: vbase = re.sub('^(std|__gnu_cxx)::', r'\g<0>%s' % _versioned_namespace, base) self.add(vbase + name, function) @@ -1975,7 +1975,7 @@ def add_one_template_type_printer(obj, name, defargs): printer = TemplateTypePrinter('std::__debug::'+name, defargs) gdb.types.register_type_printer(obj, printer) - if _versioned_namespace: + if _versioned_namespace and not '__cxx11' in name: # Add second type printer for same type in versioned namespace: ns = 'std::' + _versioned_namespace # PR 86112 Cannot use dict comprehension here: @@ -2029,6 +2029,21 @@ class FilteringTypePrinter(object): pass if self.type_obj == type_obj: return strip_inline_namespaces(self.name) + + if self.type_obj is None: + return None + + # Workaround ambiguous typedefs matching both std:: and std::__cxx11:: symbols. + ambiguous = False + for ch in ('', 'w', 'u8', 'u16', 'u32'): + if self.name == 'std::' + ch + 'string': + ambiguous = True + break + + if ambiguous: + if self.type_obj.tag.replace('__cxx11::', '') == type_obj.tag.replace('__cxx11::', ''): + return strip_inline_namespaces(self.name) + return None def instantiate(self): @@ -2038,7 +2053,7 @@ class FilteringTypePrinter(object): def add_one_type_printer(obj, match, name): printer = FilteringTypePrinter('std::' + match, 'std::' + name) gdb.types.register_type_printer(obj, printer) - if _versioned_namespace: + if _versioned_namespace and not '__cxx11' in match: ns = 'std::' + _versioned_namespace printer = FilteringTypePrinter(ns + match, ns + name) gdb.types.register_type_printer(obj, printer) diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/80276.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/80276.cc index 4abe7d384e8..d1016b58d79 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/80276.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/80276.cc @@ -18,9 +18,6 @@ // with this library; see the file COPYING3. If not see // . -// Type printers only recognize the old std::string for now. -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include @@ -46,7 +43,7 @@ main() // { dg-final { whatis-regexp-test p1 "std::unique_ptr\\*>>>" } } // { dg-final { whatis-regexp-test p2 "std::unique_ptr\\*>>\\\[\\\]>" } } // { dg-final { whatis-regexp-test p3 "std::unique_ptr\\*>>\\\[10\\\]>" } } - // { dg-final { whatis-regexp-test p4 "std::unique_ptr\\\[\\\]>>\\\[99\\\]>" { xfail { c++20 || debug_mode } } } } + // { dg-final { whatis-regexp-test p4 "std::unique_ptr\\\[\\\]>>\\\[99\\\]>" } } placeholder(&p1); // Mark SPOT placeholder(&p2); diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc index e52ffbbcc15..cf699d22e78 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx17.cc @@ -18,9 +18,6 @@ // with this library; see the file COPYING3. If not see // . -// Type printers only recognize the old std::string for now. -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/libfundts.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/libfundts.cc index e81308d4f7e..b2f464d0894 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/libfundts.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/libfundts.cc @@ -18,9 +18,6 @@ // with this library; see the file COPYING3. If not see // . -// Type printers only recognize the old std::string for now. -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include @@ -50,7 +47,7 @@ main() om = std::map{ {1, 2.}, {3, 4.}, {5, 6.} }; // { dg-final { regexp-test om {std::experimental::optional> containing std::(__debug::)?map with 3 elements = {\[1\] = 2, \[3\] = 4, \[5\] = 6}} } } optional os{ "stringy" }; -// { dg-final { note-test os {std::experimental::optional = {[contained value] = "stringy"}} { xfail { c++20 || debug_mode } } } } +// { dg-final { note-test os {std::experimental::optional = {[contained value] = "stringy"}} } } any a; // { dg-final { note-test a {std::experimental::any [no contained value]} } } @@ -61,7 +58,7 @@ main() any ap = (void*)nullptr; // { dg-final { note-test ap {std::experimental::any containing void * = {[contained value] = 0x0}} } } any as = *os; -// { dg-final { note-test as {std::experimental::any containing std::string = {[contained value] = "stringy"}} { xfail { c++20 || debug_mode } } } } +// { dg-final { note-test as {std::experimental::any containing std::string = {[contained value] = "stringy"}} } } any as2("stringiest"); // { dg-final { regexp-test as2 {std::experimental::any containing const char \* = {\[contained value\] = 0x[[:xdigit:]]+ "stringiest"}} } } any am = *om; diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc index 1f85775bff0..267fa51e647 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc @@ -20,9 +20,6 @@ // with this library; see the file COPYING3. If not see // . -// Type printers only recognize the old std::string for now. -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include @@ -64,7 +61,7 @@ main() std::list lst; lst.push_back("one"); lst.push_back("two"); -// { dg-final { regexp-test lst {std::(__debug::)?list = {\[0\] = "one", \[1\] = "two"}} } } +// { dg-final { regexp-test lst {std::(__cxx11::)?(__debug::)?list = {\[0\] = "one", \[1\] = "two"}} } } std::list::iterator lstiter0; // { dg-final { note-test lstiter0 {non-dereferenceable iterator for std::list} } } diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc index 6f21675cf41..241d1a6e6fd 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc @@ -20,9 +20,6 @@ // with this library; see the file COPYING3. If not see // . -// Type printers only recognize the old std::string for now. -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include @@ -60,7 +57,7 @@ main() std::list lst; lst.push_back("one"); lst.push_back("two"); -// { dg-final { regexp-test lst {std::(__debug::)?list = {\[0\] = "one", \[1\] = "two"}} } } +// { dg-final { regexp-test lst {std::(__cxx11::)?(__debug::)?list = {\[0\] = "one", \[1\] = "two"}} } } std::list::iterator lstiter = lst.begin(); tem = *lstiter; diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/whatis.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/whatis.cc index 046d26f0020..23b9947a5de 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/whatis.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/whatis.cc @@ -18,10 +18,6 @@ // with this library; see the file COPYING3. If not see // . -// GDB can't find global variables using the abi_tag attribute. -// https://sourceware.org/bugzilla/show_bug.cgi?id=19436 -#define _GLIBCXX_USE_CXX11_ABI 0 - #include #include #include