[PATCHv3,1/2] gdb/amd64: Ignore zero sized fields when calling functions

Message ID a99f02ac2ff15d7c4ffffda9fc7125267a53f6fd.1520021226.git.andrew.burgess@embecosm.com
State New, archived
Headers

Commit Message

Andrew Burgess March 2, 2018, 8:09 p.m. UTC
  In some cases passing an argument to a function on amd64, or attempting
to fetch the return value, can trigger an assertion failure within GDB.
An example of a type that would trigger such an error is:

  struct foo_t
  {
    long double a;
    struct {
      struct {
        /* Empty.  */
      } es1;
    } s1;
  };

GCC does permit empty structures, so we should probably support this.

The test that exposes this bug is in the next commit along with the
RiscV support.

gdb/ChangeLog:

	* amd64-tdep.c (amd64_classify_aggregate): Ignore zero sized
	fields within aggregates.
---
 gdb/ChangeLog    | 5 +++++
 gdb/amd64-tdep.c | 5 +++--
 2 files changed, 8 insertions(+), 2 deletions(-)
  

Comments

Simon Marchi March 3, 2018, 6:29 a.m. UTC | #1
On 2018-03-02 03:09 PM, Andrew Burgess wrote:
> In some cases passing an argument to a function on amd64, or attempting
> to fetch the return value, can trigger an assertion failure within GDB.
> An example of a type that would trigger such an error is:
> 
>   struct foo_t
>   {
>     long double a;
>     struct {
>       struct {
>         /* Empty.  */
>       } es1;
>     } s1;
>   };
> 
> GCC does permit empty structures, so we should probably support this.
> 
> The test that exposes this bug is in the next commit along with the
> RiscV support.

Good job on the test :).  This patch LGTM.

Simon
  

Patch

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 6b92c9244c6..07eef5ea9f0 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -601,8 +601,9 @@  amd64_classify_aggregate (struct type *type, enum amd64_reg_class theclass[2])
 	    bitsize = TYPE_LENGTH (subtype) * 8;
 	  endpos = (TYPE_FIELD_BITPOS (type, i) + bitsize - 1) / 64;
 
-	  /* Ignore static fields.  */
-	  if (field_is_static (&TYPE_FIELD (type, i)))
+	  /* Ignore static fields, or empty fields, for example nested
+	     empty structures.*/
+	  if (field_is_static (&TYPE_FIELD (type, i)) || bitsize == 0)
 	    continue;
 
 	  gdb_assert (pos == 0 || pos == 1);