Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [review] Use enum bitfield for the calling_convention attribute of a subroutine
@ 2019-12-20 17:42 Tankut Baris Aktemur (Code Review)
  2019-12-20 17:53 ` Simon Marchi (Code Review)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tankut Baris Aktemur (Code Review) @ 2019-12-20 17:42 UTC (permalink / raw)
  To: gdb-patches

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/758
......................................................................

Use enum bitfield for the calling_convention attribute of a subroutine

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
---
M gdb/dwarf2read.c
M gdb/gdbtypes.h
2 files changed, 32 insertions(+), 4 deletions(-)



diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 6492889..685d996 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -15872,6 +15872,32 @@
     }
 }
 
+/* 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 @@
      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
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 12fa437..167fd80 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1157,9 +1157,9 @@
     /* * 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

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ibc6b2f71e885cbc5c3c9d49734f7125acbfd1bcd
Gerrit-Change-Number: 758
Gerrit-PatchSet: 1
Gerrit-Owner: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Gerrit-MessageType: newchange


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [review] Use enum bitfield for the calling_convention attribute of a subroutine
  2019-12-20 17:42 [review] Use enum bitfield for the calling_convention attribute of a subroutine Tankut Baris Aktemur (Code Review)
@ 2019-12-20 17:53 ` Simon Marchi (Code Review)
  2019-12-20 18:31 ` [pushed] " Sourceware to Gerrit sync (Code Review)
  2019-12-20 18:31 ` Sourceware to Gerrit sync (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Marchi (Code Review) @ 2019-12-20 17:53 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

Simon Marchi has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/758
......................................................................


Patch Set 1: Code-Review+2

Thanks, that LGTM.


-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ibc6b2f71e885cbc5c3c9d49734f7125acbfd1bcd
Gerrit-Change-Number: 758
Gerrit-PatchSet: 1
Gerrit-Owner: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Gerrit-Reviewer: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Reviewer: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Gerrit-Comment-Date: Fri, 20 Dec 2019 17:53:06 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pushed] Use enum bitfield for the calling_convention attribute of a subroutine
  2019-12-20 17:42 [review] Use enum bitfield for the calling_convention attribute of a subroutine Tankut Baris Aktemur (Code Review)
  2019-12-20 17:53 ` Simon Marchi (Code Review)
@ 2019-12-20 18:31 ` Sourceware to Gerrit sync (Code Review)
  2019-12-20 18:31 ` Sourceware to Gerrit sync (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-12-20 18:31 UTC (permalink / raw)
  To: Tankut Baris Aktemur, Simon Marchi, gdb-patches

The original change was created by Tankut Baris Aktemur.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/758
......................................................................

Use enum bitfield for the calling_convention attribute of a subroutine

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
---
M gdb/ChangeLog
M gdb/dwarf2read.c
M gdb/gdbtypes.h
3 files changed, 42 insertions(+), 4 deletions(-)



diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c2157e4..d4b17ab 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,15 @@
 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
 	* infcall.c (call_function_by_hand_dummy): Update the argument-
 	passing section for call-by-value parameters.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 6492889..685d996 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -15872,6 +15872,32 @@
     }
 }
 
+/* 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 @@
      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
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 12fa437..167fd80 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1157,9 +1157,9 @@
     /* * 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

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ibc6b2f71e885cbc5c3c9d49734f7125acbfd1bcd
Gerrit-Change-Number: 758
Gerrit-PatchSet: 2
Gerrit-Owner: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Gerrit-Reviewer: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Reviewer: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Gerrit-MessageType: newpatchset


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pushed] Use enum bitfield for the calling_convention attribute of a subroutine
  2019-12-20 17:42 [review] Use enum bitfield for the calling_convention attribute of a subroutine Tankut Baris Aktemur (Code Review)
  2019-12-20 17:53 ` Simon Marchi (Code Review)
  2019-12-20 18:31 ` [pushed] " Sourceware to Gerrit sync (Code Review)
@ 2019-12-20 18:31 ` Sourceware to Gerrit sync (Code Review)
  2 siblings, 0 replies; 4+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-12-20 18:31 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches; +Cc: Simon Marchi

Sourceware to Gerrit sync has submitted this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/758
......................................................................

Use enum bitfield for the calling_convention attribute of a subroutine

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
---
M gdb/ChangeLog
M gdb/dwarf2read.c
M gdb/gdbtypes.h
3 files changed, 42 insertions(+), 4 deletions(-)


diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c2157e4..d4b17ab 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,15 @@
 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
 	* infcall.c (call_function_by_hand_dummy): Update the argument-
 	passing section for call-by-value parameters.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 6492889..685d996 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -15872,6 +15872,32 @@
     }
 }
 
+/* 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 @@
      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
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 12fa437..167fd80 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1157,9 +1157,9 @@
     /* * 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

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ibc6b2f71e885cbc5c3c9d49734f7125acbfd1bcd
Gerrit-Change-Number: 758
Gerrit-PatchSet: 2
Gerrit-Owner: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Gerrit-Reviewer: Simon Marchi <simon.marchi@polymtl.ca>
Gerrit-Reviewer: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Gerrit-MessageType: merged


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-20 18:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-20 17:42 [review] Use enum bitfield for the calling_convention attribute of a subroutine Tankut Baris Aktemur (Code Review)
2019-12-20 17:53 ` Simon Marchi (Code Review)
2019-12-20 18:31 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-12-20 18:31 ` Sourceware to Gerrit sync (Code Review)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox