public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/5] Add CodeView enum cv_leaf_type
@ 2024-06-29 22:06 Mark Harmstone
  2024-06-29 22:06 ` [PATCH 2/5] Add CodeView enum cv_sym_type Mark Harmstone
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Mark Harmstone @ 2024-06-29 22:06 UTC (permalink / raw)
  To: gcc-patches; +Cc: Mark Harmstone

Make everything more gdb-friendly by using an enum for type constants
rather than #defines.

    gcc/
            * dwarf2codeview.cc (enum cv_leaf_type): Define.
            (struct codeview_subtype): Use enum cv_leaf_type.
            (struct codeview_custom_type): Use enum cv_leaf_type.
            (write_lf_fieldlist): Add default to switch.
            (write_custom_types): Add default to switch.
            * dwarf2codeview.h (LF_MODIFIER, LF_POINTER): Undefine.
            (LF_PROCEDURE, LF_ARGLIST, LF_FIELDLIST, LF_BITFIELD): Likewise.
            (LF_INDEX, LF_ENUMERATE, LF_ARRAY, LF_CLASS): Likewise.
            (LF_STRUCTURE, LF_UNION, LF_ENUM, LF_MEMBER, LF_CHAR): Likewise.
            (LF_SHORT, LF_USHORT, LF_LONG, LF_ULONG, LF_QUADWORD): Likewise.
            (LF_UQUADWORD): Likewise.
---
 gcc/dwarf2codeview.cc | 37 +++++++++++++++++++++++++++++++++++--
 gcc/dwarf2codeview.h  | 23 -----------------------
 2 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index e8ed3713480..5155aa70139 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -70,6 +70,33 @@ along with GCC; see the file COPYING3.  If not see
 
 #define HASH_SIZE 16
 
+/* This is enum LEAF_ENUM_e in Microsoft's cvinfo.h.  */
+
+enum cv_leaf_type {
+  LF_MODIFIER = 0x1001,
+  LF_POINTER = 0x1002,
+  LF_PROCEDURE = 0x1008,
+  LF_ARGLIST = 0x1201,
+  LF_FIELDLIST = 0x1203,
+  LF_BITFIELD = 0x1205,
+  LF_INDEX = 0x1404,
+  LF_ENUMERATE = 0x1502,
+  LF_ARRAY = 0x1503,
+  LF_CLASS = 0x1504,
+  LF_STRUCTURE = 0x1505,
+  LF_UNION = 0x1506,
+  LF_ENUM = 0x1507,
+  LF_MEMBER = 0x150d,
+  LF_FUNC_ID = 0x1601,
+  LF_CHAR = 0x8000,
+  LF_SHORT = 0x8001,
+  LF_USHORT = 0x8002,
+  LF_LONG = 0x8003,
+  LF_ULONG = 0x8004,
+  LF_QUADWORD = 0x8009,
+  LF_UQUADWORD = 0x800a
+};
+
 struct codeview_string
 {
   codeview_string *next;
@@ -185,7 +212,7 @@ struct codeview_integer
 struct codeview_subtype
 {
   struct codeview_subtype *next;
-  uint16_t kind;
+  enum cv_leaf_type kind;
 
   union
   {
@@ -212,7 +239,7 @@ struct codeview_custom_type
 {
   struct codeview_custom_type *next;
   uint32_t num;
-  uint16_t kind;
+  enum cv_leaf_type kind;
 
   union
   {
@@ -1336,6 +1363,9 @@ write_lf_fieldlist (codeview_custom_type *t)
 	  putc ('\n', asm_out_file);
 
 	  break;
+
+	default:
+	  break;
 	}
 
       t->lf_fieldlist.subtypes = next;
@@ -1790,6 +1820,9 @@ write_custom_types (void)
 	case LF_ARGLIST:
 	  write_lf_arglist (custom_types);
 	  break;
+
+	default:
+	  break;
 	}
 
       free (custom_types);
diff --git a/gcc/dwarf2codeview.h b/gcc/dwarf2codeview.h
index e6ad517bf28..8fd3632e524 100644
--- a/gcc/dwarf2codeview.h
+++ b/gcc/dwarf2codeview.h
@@ -60,29 +60,6 @@ along with GCC; see the file COPYING3.  If not see
 #define MOD_const		0x1
 #define MOD_volatile		0x2
 
-/* Constants for type definitions.  */
-#define LF_MODIFIER		0x1001
-#define LF_POINTER		0x1002
-#define LF_PROCEDURE		0x1008
-#define LF_ARGLIST		0x1201
-#define LF_FIELDLIST		0x1203
-#define LF_BITFIELD		0x1205
-#define LF_INDEX		0x1404
-#define LF_ENUMERATE		0x1502
-#define LF_ARRAY		0x1503
-#define LF_CLASS		0x1504
-#define LF_STRUCTURE		0x1505
-#define LF_UNION		0x1506
-#define LF_ENUM			0x1507
-#define LF_MEMBER		0x150d
-#define LF_CHAR			0x8000
-#define LF_SHORT		0x8001
-#define LF_USHORT		0x8002
-#define LF_LONG			0x8003
-#define LF_ULONG		0x8004
-#define LF_QUADWORD		0x8009
-#define LF_UQUADWORD		0x800a
-
 #define CV_ACCESS_PRIVATE	1
 #define CV_ACCESS_PROTECTED	2
 #define CV_ACCESS_PUBLIC	3
-- 
2.44.2


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

* [PATCH 2/5] Add CodeView enum cv_sym_type
  2024-06-29 22:06 [PATCH 1/5] Add CodeView enum cv_leaf_type Mark Harmstone
@ 2024-06-29 22:06 ` Mark Harmstone
  2024-06-29 22:06 ` [PATCH 3/5] Avoid magic numbers when writing CodeView padding Mark Harmstone
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Mark Harmstone @ 2024-06-29 22:06 UTC (permalink / raw)
  To: gcc-patches; +Cc: Mark Harmstone

Make everything more gdb-friendly by using an enum for symbol constants
rather than #defines.

    gcc/
            * dwarf2codeview.cc (S_LDATA32, S_GDATA32, S_COMPILE3): Undefine.
            (enum cv_sym_type): Define.
            (struct codeview_symbol): Use enum cv_sym_type.
            (write_codeview_symbols): Add default to switch.
---
 gcc/dwarf2codeview.cc | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index 5155aa70139..921d5f41e5a 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -46,10 +46,6 @@ along with GCC; see the file COPYING3.  If not see
 
 #define CHKSUM_TYPE_MD5		1
 
-#define S_LDATA32		0x110c
-#define S_GDATA32		0x110d
-#define S_COMPILE3		0x113c
-
 #define CV_CFL_80386		0x03
 #define CV_CFL_X64		0xD0
 
@@ -70,6 +66,14 @@ along with GCC; see the file COPYING3.  If not see
 
 #define HASH_SIZE 16
 
+/* This is enum SYM_ENUM_e in Microsoft's cvinfo.h.  */
+
+enum cv_sym_type {
+  S_LDATA32 = 0x110c,
+  S_GDATA32 = 0x110d,
+  S_COMPILE3 = 0x113c
+};
+
 /* This is enum LEAF_ENUM_e in Microsoft's cvinfo.h.  */
 
 enum cv_leaf_type {
@@ -168,7 +172,7 @@ struct codeview_function
 struct codeview_symbol
 {
   codeview_symbol *next;
-  uint16_t kind;
+  enum cv_sym_type kind;
 
   union
   {
@@ -983,6 +987,8 @@ write_codeview_symbols (void)
 	case S_GDATA32:
 	  write_data_symbol (sym);
 	  break;
+	default:
+	  break;
 	}
 
       free (sym);
-- 
2.44.2


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

* [PATCH 3/5] Avoid magic numbers when writing CodeView padding
  2024-06-29 22:06 [PATCH 1/5] Add CodeView enum cv_leaf_type Mark Harmstone
  2024-06-29 22:06 ` [PATCH 2/5] Add CodeView enum cv_sym_type Mark Harmstone
@ 2024-06-29 22:06 ` Mark Harmstone
  2024-06-29 22:06 ` [PATCH 4/5] Make sure CodeView symbols are aligned Mark Harmstone
  2024-06-29 22:06 ` [PATCH 5/5] Document return value in write_cv_integer Mark Harmstone
  3 siblings, 0 replies; 5+ messages in thread
From: Mark Harmstone @ 2024-06-29 22:06 UTC (permalink / raw)
  To: gcc-patches; +Cc: Mark Harmstone

Adds names for the padding magic numbers to enum cv_leaf_type.

    gcc/
            * dwarf2codeview.cc (enum cv_leaf_type): Add padding constants.
            (write_cv_padding): Use names for padding constants.
---
 gcc/dwarf2codeview.cc | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index 921d5f41e5a..71049ccf878 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -77,6 +77,9 @@ enum cv_sym_type {
 /* This is enum LEAF_ENUM_e in Microsoft's cvinfo.h.  */
 
 enum cv_leaf_type {
+  LF_PAD1 = 0xf1,
+  LF_PAD2 = 0xf2,
+  LF_PAD3 = 0xf3,
   LF_MODIFIER = 0x1001,
   LF_POINTER = 0x1002,
   LF_PROCEDURE = 0x1008,
@@ -1037,7 +1040,7 @@ write_lf_pointer (codeview_custom_type *t)
 
 /* All CodeView type definitions have to be aligned to a four-byte boundary,
    so write some padding bytes if necessary.  These have to be specific values:
-   f3, f2, f1.  */
+   LF_PAD3, LF_PAD2, LF_PAD1.  */
 
 static void
 write_cv_padding (size_t padding)
@@ -1048,19 +1051,19 @@ write_cv_padding (size_t padding)
   if (padding == 3)
     {
       fputs (integer_asm_op (1, false), asm_out_file);
-      fprint_whex (asm_out_file, 0xf3);
+      fprint_whex (asm_out_file, LF_PAD3);
       putc ('\n', asm_out_file);
     }
 
   if (padding >= 2)
     {
       fputs (integer_asm_op (1, false), asm_out_file);
-      fprint_whex (asm_out_file, 0xf2);
+      fprint_whex (asm_out_file, LF_PAD2);
       putc ('\n', asm_out_file);
     }
 
   fputs (integer_asm_op (1, false), asm_out_file);
-  fprint_whex (asm_out_file, 0xf1);
+  fprint_whex (asm_out_file, LF_PAD1);
   putc ('\n', asm_out_file);
 }
 
-- 
2.44.2


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

* [PATCH 4/5] Make sure CodeView symbols are aligned
  2024-06-29 22:06 [PATCH 1/5] Add CodeView enum cv_leaf_type Mark Harmstone
  2024-06-29 22:06 ` [PATCH 2/5] Add CodeView enum cv_sym_type Mark Harmstone
  2024-06-29 22:06 ` [PATCH 3/5] Avoid magic numbers when writing CodeView padding Mark Harmstone
@ 2024-06-29 22:06 ` Mark Harmstone
  2024-06-29 22:06 ` [PATCH 5/5] Document return value in write_cv_integer Mark Harmstone
  3 siblings, 0 replies; 5+ messages in thread
From: Mark Harmstone @ 2024-06-29 22:06 UTC (permalink / raw)
  To: gcc-patches; +Cc: Mark Harmstone

CodeView symbols have to be multiples of four bytes; add an alignment
directive to write_data_symbol to ensure this.

Note that these can be zeroes, so we can rely on GAS to do this for us;
it's only types that need f3, f2, f1 values.

    gcc/
            * dwarf2codeview.cc (write_data_symbol): Add alignment directive.
---
 gcc/dwarf2codeview.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index 71049ccf878..5a33b439b14 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -958,6 +958,8 @@ write_data_symbol (codeview_symbol *s)
   ASM_OUTPUT_ASCII (asm_out_file, s->data_symbol.name,
 		    strlen (s->data_symbol.name) + 1);
 
+  ASM_OUTPUT_ALIGN (asm_out_file, 2);
+
   targetm.asm_out.internal_label (asm_out_file, SYMBOL_END_LABEL, label_num);
 
 end:
-- 
2.44.2


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

* [PATCH 5/5] Document return value in write_cv_integer
  2024-06-29 22:06 [PATCH 1/5] Add CodeView enum cv_leaf_type Mark Harmstone
                   ` (2 preceding siblings ...)
  2024-06-29 22:06 ` [PATCH 4/5] Make sure CodeView symbols are aligned Mark Harmstone
@ 2024-06-29 22:06 ` Mark Harmstone
  3 siblings, 0 replies; 5+ messages in thread
From: Mark Harmstone @ 2024-06-29 22:06 UTC (permalink / raw)
  To: gcc-patches; +Cc: Mark Harmstone

    gcc/
            * dwarf2codeview.cc (write_lf_modifier): Expand upon comment.
---
 gcc/dwarf2codeview.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index 5a33b439b14..df53d8bab9d 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -1113,7 +1113,7 @@ write_lf_modifier (codeview_custom_type *t)
 /* Write a CodeView extensible integer.  If the value is non-negative and
    < 0x8000, the value gets written directly as an uint16_t.  Otherwise, we
    output two bytes for the integer type (LF_CHAR, LF_SHORT, ...), and the
-   actual value follows.  */
+   actual value follows.  Returns the total number of bytes written.  */
 
 static size_t
 write_cv_integer (codeview_integer *i)
-- 
2.44.2


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

end of thread, other threads:[~2024-06-29 22:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-29 22:06 [PATCH 1/5] Add CodeView enum cv_leaf_type Mark Harmstone
2024-06-29 22:06 ` [PATCH 2/5] Add CodeView enum cv_sym_type Mark Harmstone
2024-06-29 22:06 ` [PATCH 3/5] Avoid magic numbers when writing CodeView padding Mark Harmstone
2024-06-29 22:06 ` [PATCH 4/5] Make sure CodeView symbols are aligned Mark Harmstone
2024-06-29 22:06 ` [PATCH 5/5] Document return value in write_cv_integer Mark Harmstone

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).