Use enum bitfield for the calling_convention attribute of a subroutine
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Fri, 20 Dec 2019 17:23:32 +0000 (18:23 +0100)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Fri, 20 Dec 2019 18:27:29 +0000 (19:27 +0100)
This is a refactoring.  Instead of a plain unsigned value, use an enum
bitfield.

gdb/ChangeLog:
2019-12-20  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* dwarf2read.c (is_valid_DW_AT_calling_convention_for_subroutine):
New function.
(read_subroutine_type): Validate the parsed
DW_AT_calling_convention value before assigning it to a
subroutine's calling_convention attribute.
* gdbtypes.h (struct func_type) <calling_convention>: Use
an enum bitfield as its type, instead of plain unsigned.

Change-Id: Ibc6b2f71e885cbc5c3c9d49734f7125acbfd1bcd

gdb/ChangeLog
gdb/dwarf2read.c
gdb/gdbtypes.h

index c2157e44fdb9821998873ca3820820bea8bb00e4..d4b17abbdc60f26aa4d14cbf3e8a0a2b94fa3be3 100644 (file)
@@ -1,3 +1,13 @@
+2019-12-20  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       * dwarf2read.c (is_valid_DW_AT_calling_convention_for_subroutine):
+       New function.
+       (read_subroutine_type): Validate the parsed
+       DW_AT_calling_convention value before assigning it to a
+       subroutine's calling_convention attribute.
+       * gdbtypes.h (struct func_type) <calling_convention>: Use
+       an enum bitfield as its type, instead of plain unsigned.
+
 2019-12-20  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
 
        PR gdb/25054
index 6492889666f70990c91951bca08fcba179e6efe1..685d9962978ccf665d5d1f35593c7d4bc07a5155 100644 (file)
@@ -15872,6 +15872,32 @@ is_valid_DW_AT_calling_convention_for_type (ULONGEST value)
     }
 }
 
+/* Check if the given VALUE is a valid enum dwarf_calling_convention
+   constant for a subroutine, according to DWARF5 spec, Table 3.3, and
+   also according to GNU-specific values (see include/dwarf2.h).  */
+
+static bool
+is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value)
+{
+  switch (value)
+    {
+    case DW_CC_normal:
+    case DW_CC_program:
+    case DW_CC_nocall:
+      return true;
+
+    case DW_CC_GNU_renesas_sh:
+    case DW_CC_GNU_borland_fastcall_i386:
+    case DW_CC_GDB_IBM_OpenCL:
+      return true;
+
+    default:
+      complaint (_("unrecognized DW_AT_calling_convention value "
+                  "(%lu) for a subroutine"), value);
+      return false;
+    }
+}
+
 /* Called when we find the DIE that starts a structure or union scope
    (definition) to create a type for the structure or union.  Fill in
    the type's name and general properties; the members will not be
@@ -17540,8 +17566,10 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
      the subroutine die.  Otherwise set the calling convention to
      the default value DW_CC_normal.  */
   attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
-  if (attr != nullptr)
-    TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr);
+  if (attr != nullptr
+      && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr)))
+    TYPE_CALLING_CONVENTION (ftype)
+      = (enum dwarf_calling_convention) (DW_UNSND (attr));
   else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL"))
     TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL;
   else
index 12fa437b00133c6cb35b80b6dccb5d263e3449eb..167fd803ea25f65dc42cdeafcc347e7116165963 100644 (file)
@@ -1157,9 +1157,9 @@ struct func_type
     /* * The calling convention for targets supporting multiple ABIs.
        Right now this is only fetched from the Dwarf-2
        DW_AT_calling_convention attribute.  The value is one of the
-       DW_CC enum dwarf_calling_convention constants.  */
+       DW_CC constants.  */
 
-    unsigned calling_convention : 8;
+    ENUM_BITFIELD (dwarf_calling_convention) calling_convention : 8;
 
     /* * Whether this function normally returns to its caller.  It is
        set from the DW_AT_noreturn attribute if set on the
This page took 0.058979 seconds and 4 git commands to generate.