potential patch for gdb bug c++/20020 - updated

Message ID CAOhs8xJN5+z3NBqHnf3KXRcdO=7efZqdA4xueoeAdV2fDJLDJg@mail.gmail.com
State New, archived
Headers

Commit Message

Bob Steagall Dec. 7, 2018, 12:57 p.m. UTC
  Description:

This patch, against released version 8.2, fixes the
problem reported in gdb bug c++/20020, using the
approach described in comment 1 of that report.

Changelog entry:

2018-12-06  Bob Steagall   <bob.steagall.cpp@gmail.com>

        * cp-valprint.c: Fixes bug c++/20020.
  

Comments

Andrew Burgess Dec. 7, 2018, 3:49 p.m. UTC | #1
* Bob Steagall <bob.steagall.cpp@gmail.com> [2018-12-07 07:57:28 -0500]:

> Description:
> 
> This patch, against released version 8.2, fixes the
> problem reported in gdb bug c++/20020, using the
> approach described in comment 1 of that report.

As Tom said, it would be great to have a proper reproducer for this in
the testsuite.

I had a little go digging through all the various linked bugs, but I
wasn't able to come up with anything that could trigger this issue.

Would you be able to identify exactly which error is being thrown that
causes cp_print_value_fields to have 'v == NULL' condition?

If you run gdb under gdb, then in this code:

                  TRY
                    {
                      v = value_static_field (type, i); // <--- Break on this line
                    }

                  CATCH (ex, RETURN_MASK_ERROR)
                    {
                      fprintf_filtered (stream,
                                        _("<error reading variable: %s>"),
                                        ex.message);
                    }
                  END_CATCH

Break on the marked line, and do:

  (gdb) catch throw
  (gdb) continue

With luck this should allow you to figure out exactly which error is
landing GDB in the CATCH block.

Another data point that will be useful would be a dump of all the
DWARF related to the static field that is causing the problem.

If you could dig this information out then we should be able to put
together a reproducer.

Thanks,
Andrew


> 
> Changelog entry:
> 
> 2018-12-06  Bob Steagall   <bob.steagall.cpp@gmail.com>
> 
>         * cp-valprint.c: Fixes bug c++/20020.

> --- gdb/cp-valprint.c	2018-09-05 03:27:13.000000000 -0400
> +++ gdb/cp-valprint.c.new	2018-12-07 07:41:00.657110092 -0500
> @@ -329,9 +329,10 @@ cp_print_value_fields (struct type *type
>  		    }
>  		  END_CATCH
>  
> -		  cp_print_static_field (TYPE_FIELD_TYPE (type, i),
> -					 v, stream, recurse + 1,
> -					 options);
> +                  if (v != NULL)
> +                      cp_print_static_field (TYPE_FIELD_TYPE (type, i),
> +                                             v, stream, recurse + 1,
> +                                             options);
>  		}
>  	      else if (i == vptr_fieldno && type == vptr_basetype)
>  		{
  

Patch

--- gdb/cp-valprint.c	2018-09-05 03:27:13.000000000 -0400
+++ gdb/cp-valprint.c.new	2018-12-07 07:41:00.657110092 -0500
@@ -329,9 +329,10 @@  cp_print_value_fields (struct type *type
 		    }
 		  END_CATCH
 
-		  cp_print_static_field (TYPE_FIELD_TYPE (type, i),
-					 v, stream, recurse + 1,
-					 options);
+                  if (v != NULL)
+                      cp_print_static_field (TYPE_FIELD_TYPE (type, i),
+                                             v, stream, recurse + 1,
+                                             options);
 		}
 	      else if (i == vptr_fieldno && type == vptr_basetype)
 		{