public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gas] Emit v2 .debug_line for -gdwarf-2
@ 2023-01-31 11:42 Tom de Vries
  2023-01-31 11:55 ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2023-01-31 11:42 UTC (permalink / raw)
  To: binutils

Currently, when using -gdwarf-2, gas emits a v3 .debug_line contribution.

Fix this by emitting a v3 .debug_line contribution instead.

gas/ChangeLog:

2023-01-31  Tom de Vries  <tdevries@suse.de>

	PR 23941
	* dwarf2dbg.c (DWARF2_LINE_VERSION): Set to 2 for -gdwarf-2.
	(DWARF2_LINE_OPCODE_BASE): Handle DWARF2_LINE_VERSION == 2.
	(dwarf2_directive_loc): Bump dwarf_level when encountering
	v3 .loc options.
	(out_debug_line): Don't output v3 standard opcodes for v2.
	* testsuite/gas/i386/debug1.d: Update.
	* testsuite/gas/i386/dwarf2-line-1.d: Update.
	* testsuite/gas/i386/dwarf2-line-4.d: Update.
---
 gas/dwarf2dbg.c                        | 27 ++++++++++++++++++--------
 gas/testsuite/gas/i386/debug1.d        |  7 ++-----
 gas/testsuite/gas/i386/dwarf2-line-1.d |  7 ++-----
 gas/testsuite/gas/i386/dwarf2-line-4.d |  7 ++-----
 4 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index c7d9e8ef72f..e6c411426af 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -88,7 +88,7 @@
 
 /* This implementation outputs version 3 .debug_line information.  */
 #ifndef DWARF2_LINE_VERSION
-#define DWARF2_LINE_VERSION (dwarf_level > 3 ? dwarf_level : 3)
+#define DWARF2_LINE_VERSION dwarf_level
 #endif
 
 /* The .debug_rnglists has only been in DWARF version 5. */
@@ -119,7 +119,7 @@
    Note: If you want to change this, you'll have to update the
    "standard_opcode_lengths" table that is emitted below in
    out_debug_line().  */
-#define DWARF2_LINE_OPCODE_BASE		13
+#define DWARF2_LINE_OPCODE_BASE		(DWARF2_LINE_VERSION == 2 ? 10 : 13)
 
 #ifndef DWARF2_LINE_BASE
   /* Minimum line offset in a special line info. opcode.  This value
@@ -1328,11 +1328,15 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
 	}
       else if (strcmp (p, "prologue_end") == 0)
 	{
+	  if (dwarf_level < 3)
+	    dwarf_level = 3;
 	  current.flags |= DWARF2_FLAG_PROLOGUE_END;
 	  *input_line_pointer = c;
 	}
       else if (strcmp (p, "epilogue_begin") == 0)
 	{
+	  if (dwarf_level < 3)
+	    dwarf_level = 3;
 	  current.flags |= DWARF2_FLAG_EPILOGUE_BEGIN;
 	  *input_line_pointer = c;
 	}
@@ -1352,6 +1356,8 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
 	}
       else if (strcmp (p, "isa") == 0)
 	{
+	  if (dwarf_level < 3)
+	    dwarf_level = 3;
 	  (void) restore_line_pointer (c);
 	  value = get_absolute_expression ();
 	  if (value >= 0)
@@ -2479,12 +2485,17 @@ out_debug_line (segT line_seg)
   out_byte (0);			/* DW_LNS_set_basic_block */
   out_byte (0);			/* DW_LNS_const_add_pc */
   out_byte (1);			/* DW_LNS_fixed_advance_pc */
-  out_byte (0);			/* DW_LNS_set_prologue_end */
-  out_byte (0);			/* DW_LNS_set_epilogue_begin */
-  out_byte (1);			/* DW_LNS_set_isa */
-  /* We have emitted 12 opcode lengths, so make that this
-     matches up to the opcode base value we have been using.  */
-  gas_assert (DWARF2_LINE_OPCODE_BASE == 13);
+  if (DWARF2_LINE_VERSION >= 3)
+    {
+      out_byte (0);			/* DW_LNS_set_prologue_end */
+      out_byte (0);			/* DW_LNS_set_epilogue_begin */
+      out_byte (1);			/* DW_LNS_set_isa */
+      /* We have emitted 12 opcode lengths, so make that this
+	 matches up to the opcode base value we have been using.  */
+      gas_assert (DWARF2_LINE_OPCODE_BASE == 13);
+    }
+  else
+    gas_assert (DWARF2_LINE_OPCODE_BASE == 10);
 
   out_dir_and_file_list (line_seg, sizeof_offset);
 
diff --git a/gas/testsuite/gas/i386/debug1.d b/gas/testsuite/gas/i386/debug1.d
index 4bed8754747..549ba66935c 100644
--- a/gas/testsuite/gas/i386/debug1.d
+++ b/gas/testsuite/gas/i386/debug1.d
@@ -6,13 +6,13 @@ Raw dump of debug contents of section \.z?debug_line:
 
   Offset:                      (0x)?0
   Length:                      .*
-  DWARF Version:               3
+  DWARF Version:               2
   Prologue Length:             .*
   Minimum Instruction Length:  1
   Initial value of 'is_stmt':  1
   Line Base:                   -5
   Line Range:                  14
-  Opcode Base:                 13
+  Opcode Base:                 10
 
  Opcodes:
   Opcode 1 has 0 args
@@ -24,9 +24,6 @@ Raw dump of debug contents of section \.z?debug_line:
   Opcode 7 has 0 args
   Opcode 8 has 0 args
   Opcode 9 has 1 arg
-  Opcode 10 has 0 args
-  Opcode 11 has 0 args
-  Opcode 12 has 1 arg
 
  The Directory Table \(offset 0x.*\):
   .*
diff --git a/gas/testsuite/gas/i386/dwarf2-line-1.d b/gas/testsuite/gas/i386/dwarf2-line-1.d
index d9baafda26d..1d9592d8c65 100644
--- a/gas/testsuite/gas/i386/dwarf2-line-1.d
+++ b/gas/testsuite/gas/i386/dwarf2-line-1.d
@@ -6,13 +6,13 @@ Raw dump of debug contents of section \.z?debug_line:
 
   Offset:                      (0x)?0
   Length:                      .*
-  DWARF Version:               3
+  DWARF Version:               2
   Prologue Length:             .*
   Minimum Instruction Length:  1
   Initial value of 'is_stmt':  1
   Line Base:                   -5
   Line Range:                  14
-  Opcode Base:                 13
+  Opcode Base:                 10
 
  Opcodes:
   Opcode 1 has 0 args
@@ -24,9 +24,6 @@ Raw dump of debug contents of section \.z?debug_line:
   Opcode 7 has 0 args
   Opcode 8 has 0 args
   Opcode 9 has 1 arg
-  Opcode 10 has 0 args
-  Opcode 11 has 0 args
-  Opcode 12 has 1 arg
 
  The Directory Table \(offset 0x.*\):
   .*
diff --git a/gas/testsuite/gas/i386/dwarf2-line-4.d b/gas/testsuite/gas/i386/dwarf2-line-4.d
index 6846ae21e9a..6b8fe5c04af 100644
--- a/gas/testsuite/gas/i386/dwarf2-line-4.d
+++ b/gas/testsuite/gas/i386/dwarf2-line-4.d
@@ -6,13 +6,13 @@ Raw dump of debug contents of section \.z?debug_line:
 
   Offset:                      (0x)?0
   Length:                      .*
-  DWARF Version:               3
+  DWARF Version:               2
   Prologue Length:             .*
   Minimum Instruction Length:  1
   Initial value of 'is_stmt':  1
   Line Base:                   -5
   Line Range:                  14
-  Opcode Base:                 13
+  Opcode Base:                 10
 
  Opcodes:
   Opcode 1 has 0 args
@@ -24,9 +24,6 @@ Raw dump of debug contents of section \.z?debug_line:
   Opcode 7 has 0 args
   Opcode 8 has 0 args
   Opcode 9 has 1 arg
-  Opcode 10 has 0 args
-  Opcode 11 has 0 args
-  Opcode 12 has 1 arg
 
  The Directory Table is empty\.
 

base-commit: 594a01c217143dce2f1f3181bcca4047b4a44107
-- 
2.35.3


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

* Re: [PATCH] [gas] Emit v2 .debug_line for -gdwarf-2
  2023-01-31 11:42 [PATCH] [gas] Emit v2 .debug_line for -gdwarf-2 Tom de Vries
@ 2023-01-31 11:55 ` Andreas Schwab
  2023-01-31 12:26   ` Tom de Vries
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2023-01-31 11:55 UTC (permalink / raw)
  To: Tom de Vries via Binutils; +Cc: Tom de Vries

On Jan 31 2023, Tom de Vries via Binutils wrote:

> Fix this by emitting a v3 .debug_line contribution instead.

s/v3/v2/?

> diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
> index c7d9e8ef72f..e6c411426af 100644
> --- a/gas/dwarf2dbg.c
> +++ b/gas/dwarf2dbg.c
> @@ -88,7 +88,7 @@
>  
>  /* This implementation outputs version 3 .debug_line information.  */
>  #ifndef DWARF2_LINE_VERSION
> -#define DWARF2_LINE_VERSION (dwarf_level > 3 ? dwarf_level : 3)
> +#define DWARF2_LINE_VERSION dwarf_level

Seems like the comment is no longer accurate.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

* Re: [PATCH] [gas] Emit v2 .debug_line for -gdwarf-2
  2023-01-31 11:55 ` Andreas Schwab
@ 2023-01-31 12:26   ` Tom de Vries
  2023-01-31 13:38     ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2023-01-31 12:26 UTC (permalink / raw)
  To: Andreas Schwab, Tom de Vries via Binutils

[-- Attachment #1: Type: text/plain, Size: 1070 bytes --]

On 1/31/23 12:55, Andreas Schwab wrote:
> On Jan 31 2023, Tom de Vries via Binutils wrote:
> 
>> Fix this by emitting a v3 .debug_line contribution instead.
> 
> s/v3/v2/?
> 

Hi Andreas,

thanks for the review.

Fixed the typo.

>> diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
>> index c7d9e8ef72f..e6c411426af 100644
>> --- a/gas/dwarf2dbg.c
>> +++ b/gas/dwarf2dbg.c
>> @@ -88,7 +88,7 @@
>>   
>>   /* This implementation outputs version 3 .debug_line information.  */
>>   #ifndef DWARF2_LINE_VERSION
>> -#define DWARF2_LINE_VERSION (dwarf_level > 3 ? dwarf_level : 3)
>> +#define DWARF2_LINE_VERSION dwarf_level
> 
> Seems like the comment is no longer accurate.
> 

I've updated the comment, and I've also updated the macro definition to:
...
#define DWARF2_LINE_VERSION DWARF2_VERSION
...

In gas/config/tc-ia64.h we override DWARF2_VERSION, and using 
DWARF2_VERSION rather than dwarf_level for DWARF2_LINE_VERSION makes 
sure that we keep the same version in .debug_info and .debug_line (well, 
as long as DWARF2_LINE_VERSION isn't overridden).

Thanks,
- Tom

[-- Attachment #2: 0001-gas-Emit-v2-.debug_line-for-gdwarf-2.patch --]
[-- Type: text/x-patch, Size: 6674 bytes --]

From a96e25dbc8570125f8a37c0ca97c3cfc484b5057 Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Tue, 31 Jan 2023 12:28:12 +0100
Subject: [PATCH] [gas] Emit v2 .debug_line for -gdwarf-2

Currently, when using -gdwarf-2, gas emits a v3 .debug_line contribution.

Fix this by emitting a v2 .debug_line contribution instead.

gas/ChangeLog:

2023-01-31  Tom de Vries  <tdevries@suse.de>

	PR 23941
	* dwarf2dbg.c (DWARF2_LINE_VERSION): Set to 2 for -gdwarf-2.
	(DWARF2_LINE_OPCODE_BASE): Handle DWARF2_LINE_VERSION == 2.
	(dwarf2_directive_loc): Bump dwarf_level when encountering
	v3 .loc options.
	(out_debug_line): Don't output v3 standard opcodes for v2.
	* testsuite/gas/i386/debug1.d: Update.
	* testsuite/gas/i386/dwarf2-line-1.d: Update.
	* testsuite/gas/i386/dwarf2-line-4.d: Update.
---
 gas/dwarf2dbg.c                        | 29 ++++++++++++++++++--------
 gas/testsuite/gas/i386/debug1.d        |  7 ++-----
 gas/testsuite/gas/i386/dwarf2-line-1.d |  7 ++-----
 gas/testsuite/gas/i386/dwarf2-line-4.d |  7 ++-----
 4 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index c7d9e8ef72f..b54050c6442 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -86,9 +86,9 @@
 #define DWARF2_ARANGES_VERSION 2
 #endif
 
-/* This implementation outputs version 3 .debug_line information.  */
+/* The .debug_line version is the same as the .debug_info version.  */
 #ifndef DWARF2_LINE_VERSION
-#define DWARF2_LINE_VERSION (dwarf_level > 3 ? dwarf_level : 3)
+#define DWARF2_LINE_VERSION DWARF2_VERSION
 #endif
 
 /* The .debug_rnglists has only been in DWARF version 5. */
@@ -119,7 +119,7 @@
    Note: If you want to change this, you'll have to update the
    "standard_opcode_lengths" table that is emitted below in
    out_debug_line().  */
-#define DWARF2_LINE_OPCODE_BASE		13
+#define DWARF2_LINE_OPCODE_BASE		(DWARF2_LINE_VERSION == 2 ? 10 : 13)
 
 #ifndef DWARF2_LINE_BASE
   /* Minimum line offset in a special line info. opcode.  This value
@@ -1328,11 +1328,15 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
 	}
       else if (strcmp (p, "prologue_end") == 0)
 	{
+	  if (dwarf_level < 3)
+	    dwarf_level = 3;
 	  current.flags |= DWARF2_FLAG_PROLOGUE_END;
 	  *input_line_pointer = c;
 	}
       else if (strcmp (p, "epilogue_begin") == 0)
 	{
+	  if (dwarf_level < 3)
+	    dwarf_level = 3;
 	  current.flags |= DWARF2_FLAG_EPILOGUE_BEGIN;
 	  *input_line_pointer = c;
 	}
@@ -1352,6 +1356,8 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
 	}
       else if (strcmp (p, "isa") == 0)
 	{
+	  if (dwarf_level < 3)
+	    dwarf_level = 3;
 	  (void) restore_line_pointer (c);
 	  value = get_absolute_expression ();
 	  if (value >= 0)
@@ -2479,12 +2485,17 @@ out_debug_line (segT line_seg)
   out_byte (0);			/* DW_LNS_set_basic_block */
   out_byte (0);			/* DW_LNS_const_add_pc */
   out_byte (1);			/* DW_LNS_fixed_advance_pc */
-  out_byte (0);			/* DW_LNS_set_prologue_end */
-  out_byte (0);			/* DW_LNS_set_epilogue_begin */
-  out_byte (1);			/* DW_LNS_set_isa */
-  /* We have emitted 12 opcode lengths, so make that this
-     matches up to the opcode base value we have been using.  */
-  gas_assert (DWARF2_LINE_OPCODE_BASE == 13);
+  if (DWARF2_LINE_VERSION >= 3)
+    {
+      out_byte (0);			/* DW_LNS_set_prologue_end */
+      out_byte (0);			/* DW_LNS_set_epilogue_begin */
+      out_byte (1);			/* DW_LNS_set_isa */
+      /* We have emitted 12 opcode lengths, so make that this
+	 matches up to the opcode base value we have been using.  */
+      gas_assert (DWARF2_LINE_OPCODE_BASE == 13);
+    }
+  else
+    gas_assert (DWARF2_LINE_OPCODE_BASE == 10);
 
   out_dir_and_file_list (line_seg, sizeof_offset);
 
diff --git a/gas/testsuite/gas/i386/debug1.d b/gas/testsuite/gas/i386/debug1.d
index 4bed8754747..549ba66935c 100644
--- a/gas/testsuite/gas/i386/debug1.d
+++ b/gas/testsuite/gas/i386/debug1.d
@@ -6,13 +6,13 @@ Raw dump of debug contents of section \.z?debug_line:
 
   Offset:                      (0x)?0
   Length:                      .*
-  DWARF Version:               3
+  DWARF Version:               2
   Prologue Length:             .*
   Minimum Instruction Length:  1
   Initial value of 'is_stmt':  1
   Line Base:                   -5
   Line Range:                  14
-  Opcode Base:                 13
+  Opcode Base:                 10
 
  Opcodes:
   Opcode 1 has 0 args
@@ -24,9 +24,6 @@ Raw dump of debug contents of section \.z?debug_line:
   Opcode 7 has 0 args
   Opcode 8 has 0 args
   Opcode 9 has 1 arg
-  Opcode 10 has 0 args
-  Opcode 11 has 0 args
-  Opcode 12 has 1 arg
 
  The Directory Table \(offset 0x.*\):
   .*
diff --git a/gas/testsuite/gas/i386/dwarf2-line-1.d b/gas/testsuite/gas/i386/dwarf2-line-1.d
index d9baafda26d..1d9592d8c65 100644
--- a/gas/testsuite/gas/i386/dwarf2-line-1.d
+++ b/gas/testsuite/gas/i386/dwarf2-line-1.d
@@ -6,13 +6,13 @@ Raw dump of debug contents of section \.z?debug_line:
 
   Offset:                      (0x)?0
   Length:                      .*
-  DWARF Version:               3
+  DWARF Version:               2
   Prologue Length:             .*
   Minimum Instruction Length:  1
   Initial value of 'is_stmt':  1
   Line Base:                   -5
   Line Range:                  14
-  Opcode Base:                 13
+  Opcode Base:                 10
 
  Opcodes:
   Opcode 1 has 0 args
@@ -24,9 +24,6 @@ Raw dump of debug contents of section \.z?debug_line:
   Opcode 7 has 0 args
   Opcode 8 has 0 args
   Opcode 9 has 1 arg
-  Opcode 10 has 0 args
-  Opcode 11 has 0 args
-  Opcode 12 has 1 arg
 
  The Directory Table \(offset 0x.*\):
   .*
diff --git a/gas/testsuite/gas/i386/dwarf2-line-4.d b/gas/testsuite/gas/i386/dwarf2-line-4.d
index 6846ae21e9a..6b8fe5c04af 100644
--- a/gas/testsuite/gas/i386/dwarf2-line-4.d
+++ b/gas/testsuite/gas/i386/dwarf2-line-4.d
@@ -6,13 +6,13 @@ Raw dump of debug contents of section \.z?debug_line:
 
   Offset:                      (0x)?0
   Length:                      .*
-  DWARF Version:               3
+  DWARF Version:               2
   Prologue Length:             .*
   Minimum Instruction Length:  1
   Initial value of 'is_stmt':  1
   Line Base:                   -5
   Line Range:                  14
-  Opcode Base:                 13
+  Opcode Base:                 10
 
  Opcodes:
   Opcode 1 has 0 args
@@ -24,9 +24,6 @@ Raw dump of debug contents of section \.z?debug_line:
   Opcode 7 has 0 args
   Opcode 8 has 0 args
   Opcode 9 has 1 arg
-  Opcode 10 has 0 args
-  Opcode 11 has 0 args
-  Opcode 12 has 1 arg
 
  The Directory Table is empty\.
 

base-commit: 594a01c217143dce2f1f3181bcca4047b4a44107
-- 
2.35.3


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

* Re: [PATCH] [gas] Emit v2 .debug_line for -gdwarf-2
  2023-01-31 12:26   ` Tom de Vries
@ 2023-01-31 13:38     ` Nick Clifton
  2023-01-31 13:56       ` Tom de Vries
  0 siblings, 1 reply; 5+ messages in thread
From: Nick Clifton @ 2023-01-31 13:38 UTC (permalink / raw)
  To: Tom de Vries, Andreas Schwab, Tom de Vries via Binutils

Hi Tom,

> I've updated the comment, and I've also updated the macro definition to:
> ...
> #define DWARF2_LINE_VERSION DWARF2_VERSION

Does this mean that DWARF2_LINE_VERSION is now redundant, and
could just be replaced with DWARF2_VERSION ?

Anyway, patch approved - please apply.

Cheers
   Nick


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

* Re: [PATCH] [gas] Emit v2 .debug_line for -gdwarf-2
  2023-01-31 13:38     ` Nick Clifton
@ 2023-01-31 13:56       ` Tom de Vries
  0 siblings, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2023-01-31 13:56 UTC (permalink / raw)
  To: Nick Clifton, Andreas Schwab, Tom de Vries via Binutils

On 1/31/23 14:38, Nick Clifton wrote:
> Hi Tom,
> 
>> I've updated the comment, and I've also updated the macro definition to:
>> ...
>> #define DWARF2_LINE_VERSION DWARF2_VERSION
> 
> Does this mean that DWARF2_LINE_VERSION is now redundant, and
> could just be replaced with DWARF2_VERSION ?
> 

I suppose so, though when using DWARF2_LINE_VERSION it's immediate clear 
what it means.  With using DWARF2_VERSION when dealing .debug_lines, you 
need to know/remember/lookup that the version is the same for the two.

> Anyway, patch approved - please apply.

Thanks, I'll commit then.

- Tom

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

end of thread, other threads:[~2023-01-31 15:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 11:42 [PATCH] [gas] Emit v2 .debug_line for -gdwarf-2 Tom de Vries
2023-01-31 11:55 ` Andreas Schwab
2023-01-31 12:26   ` Tom de Vries
2023-01-31 13:38     ` Nick Clifton
2023-01-31 13:56       ` Tom de Vries

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).