diff mbox series

[RFC] libstdc++: Fix pretty-printing old implementations of std::unique_ptr

Message ID 20200804145123.8023-1-andresx7@gmail.com
State New
Headers show
Series [RFC] libstdc++: Fix pretty-printing old implementations of std::unique_ptr | expand

Commit Message

Andres Rodriguez Aug. 4, 2020, 2:51 p.m. UTC
On binaries compiled against gcc5 the impl_type parameter is None,
which results in an exception being raised by is_specialization_of()

These versions of std::unique_ptr have the tuple as a root element.
---

Hi,

I ran into this issue when debugging a binary built using gcc5.

I'm not very familiar with python or the gcc codebase, so this might be
the wrong way to address this problem. But a patch seemed like a good
way to start the conversation.

Thanks for taking a look.

-Andres

P.S.: This is a resend of the patch. I joined the mailing list after
sending this patch so I'm guessing the original email got stuck in a
moderation queue.


 libstdc++-v3/python/libstdcxx/v6/printers.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Andres Rodriguez Aug. 10, 2020, 1:45 p.m. UTC | #1
*ping*

On Tue, Aug 4, 2020 at 10:51 AM Andres Rodriguez <andresx7@gmail.com> wrote:
>
> On binaries compiled against gcc5 the impl_type parameter is None,
> which results in an exception being raised by is_specialization_of()
>
> These versions of std::unique_ptr have the tuple as a root element.
> ---
>
> Hi,
>
> I ran into this issue when debugging a binary built using gcc5.
>
> I'm not very familiar with python or the gcc codebase, so this might be
> the wrong way to address this problem. But a patch seemed like a good
> way to start the conversation.
>
> Thanks for taking a look.
>
> -Andres
>
> P.S.: This is a resend of the patch. I joined the mailing list after
> sending this patch so I'm guessing the original email got stuck in a
> moderation queue.
>
>
>  libstdc++-v3/python/libstdcxx/v6/printers.py | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
> index e4da8dfe5b6..3154a2a6f9d 100644
> --- a/libstdc++-v3/python/libstdcxx/v6/printers.py
> +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
> @@ -247,7 +247,9 @@ class UniquePointerPrinter:
>          self.val = val
>          impl_type = val.type.fields()[0].type.tag
>          # Check for new implementations first:
> -        if is_specialization_of(impl_type, '__uniq_ptr_data') \
> +        if impl_type is None:
> +            tuple_member = val['_M_t']
> +        elif is_specialization_of(impl_type, '__uniq_ptr_data') \
>              or is_specialization_of(impl_type, '__uniq_ptr_impl'):
>              tuple_member = val['_M_t']['_M_t']
>          elif is_specialization_of(impl_type, 'tuple'):
> --
> 2.27.0
>
Jonathan Wakely Aug. 10, 2020, 5:49 p.m. UTC | #2
On 10/08/20 09:45 -0400, Andres Rodriguez wrote:
>*ping*

As it says at https://gcc.gnu.org/lists.html all patches for libstdc++
need to be sent to the libstdc++ mailing as well as the gcc-patches
list. Otherwise I won't see them, and everybody else will ignore them.

>On Tue, Aug 4, 2020 at 10:51 AM Andres Rodriguez <andresx7@gmail.com> wrote:
>>
>> On binaries compiled against gcc5 the impl_type parameter is None,
>> which results in an exception being raised by is_specialization_of()
>>
>> These versions of std::unique_ptr have the tuple as a root element.

The unique_ptr implementation in GCC 5 should already be handled by
the second branch which handles a tuple member:

         if is_specialization_of(impl_type, '__uniq_ptr_data') \
             or is_specialization_of(impl_type, '__uniq_ptr_impl'):
             tuple_member = val['_M_t']['_M_t']
         elif is_specialization_of(impl_type, 'tuple'):
             tuple_member = val['_M_t']
         else:
             raise ValueError("Unsupported implementation for unique_ptr: %s" % impl_type)

We have a test that's supposed to verify that printing the old
unique_ptr implementation still works:
https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libstdc%2B%2B-v3/testsuite/libstdc%2B%2B-prettyprinters/compat.cc;h=f1c3b599634af2eb0a5a0889c528d9de2d21aacd;hb=HEAD

So the right fix is to work out why that branch isn't taken, and fix
it, not add a kluge.

If impl_type is None that means the .tag field is missing, which seems
to be because the _M_t member is declared using the __tuple_type
typedef, rather than std::tuple itself.

That's fixed by the attached patch.

Tested x86_64-linux, pushed to master. I'll backport it to the
branches too.
Andres Rodriguez Aug. 10, 2020, 6:20 p.m. UTC | #3
On Mon, Aug 10, 2020 at 1:49 PM Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On 10/08/20 09:45 -0400, Andres Rodriguez wrote:
> >*ping*
>
> As it says at https://gcc.gnu.org/lists.html all patches for libstdc++
> need to be sent to the libstdc++ mailing as well as the gcc-patches
> list. Otherwise I won't see them, and everybody else will ignore them.
>

Thanks for the heads up on the libstdc++ mailing list and for the
unique_ptr fix.

-Andres


> >On Tue, Aug 4, 2020 at 10:51 AM Andres Rodriguez <andresx7@gmail.com> wrote:
> >>
> >> On binaries compiled against gcc5 the impl_type parameter is None,
> >> which results in an exception being raised by is_specialization_of()
> >>
> >> These versions of std::unique_ptr have the tuple as a root element.
>
> The unique_ptr implementation in GCC 5 should already be handled by
> the second branch which handles a tuple member:
>
>          if is_specialization_of(impl_type, '__uniq_ptr_data') \
>              or is_specialization_of(impl_type, '__uniq_ptr_impl'):
>              tuple_member = val['_M_t']['_M_t']
>          elif is_specialization_of(impl_type, 'tuple'):
>              tuple_member = val['_M_t']
>          else:
>              raise ValueError("Unsupported implementation for unique_ptr: %s" % impl_type)
>
> We have a test that's supposed to verify that printing the old
> unique_ptr implementation still works:
> https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libstdc%2B%2B-v3/testsuite/libstdc%2B%2B-prettyprinters/compat.cc;h=f1c3b599634af2eb0a5a0889c528d9de2d21aacd;hb=HEAD
>
> So the right fix is to work out why that branch isn't taken, and fix
> it, not add a kluge.
>
> If impl_type is None that means the .tag field is missing, which seems
> to be because the _M_t member is declared using the __tuple_type
> typedef, rather than std::tuple itself.
>
> That's fixed by the attached patch.
>
> Tested x86_64-linux, pushed to master. I'll backport it to the
> branches too.
>
>
diff mbox series

Patch

diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py
index e4da8dfe5b6..3154a2a6f9d 100644
--- a/libstdc++-v3/python/libstdcxx/v6/printers.py
+++ b/libstdc++-v3/python/libstdcxx/v6/printers.py
@@ -247,7 +247,9 @@  class UniquePointerPrinter:
         self.val = val
         impl_type = val.type.fields()[0].type.tag
         # Check for new implementations first:
-        if is_specialization_of(impl_type, '__uniq_ptr_data') \
+        if impl_type is None:
+            tuple_member = val['_M_t']
+        elif is_specialization_of(impl_type, '__uniq_ptr_data') \
             or is_specialization_of(impl_type, '__uniq_ptr_impl'):
             tuple_member = val['_M_t']['_M_t']
         elif is_specialization_of(impl_type, 'tuple'):