From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 603D93858D38; Wed, 1 Feb 2023 00:13:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 603D93858D38 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: bfd-cvs@sourceware.org Subject: [binutils-gdb] [gas] Emit v2 .debug_line for -gdwarf-2 X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: df1d8d2e9118066e8f6ec938c89e179b7cdf7e3d X-Git-Newrev: 6cb7f6d92e4508274fab69c7acbbb961fc45dc70 Message-Id: <20230201001340.603D93858D38@sourceware.org> Date: Wed, 1 Feb 2023 00:13:40 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Feb 2023 00:13:40 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D6cb7f6d92e45= 08274fab69c7acbbb961fc45dc70 commit 6cb7f6d92e4508274fab69c7acbbb961fc45dc70 Author: Tom de Vries Date: Wed Feb 1 01:13:37 2023 +0100 [gas] Emit v2 .debug_line for -gdwarf-2 =20 Currently, when using -gdwarf-2, gas emits a v3 .debug_line contributio= n. =20 Fix this by emitting a v2 .debug_line contribution instead. =20 gas/ChangeLog: =20 2023-01-31 Tom de Vries =20 PR 23941 * dwarf2dbg.c (DWARF2_LINE_VERSION): Set to 2 for -gdwarf-2. (DWARF2_LINE_OPCODE_BASE): Handle DWARF2_LINE_VERSION =3D=3D 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. Diff: --- 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 =20 -/* 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 =20 /* 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 =3D=3D 2 ? 10 : 13) =20 #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") =3D=3D 0) { + if (dwarf_level < 3) + dwarf_level =3D 3; current.flags |=3D DWARF2_FLAG_PROLOGUE_END; *input_line_pointer =3D c; } else if (strcmp (p, "epilogue_begin") =3D=3D 0) { + if (dwarf_level < 3) + dwarf_level =3D 3; current.flags |=3D DWARF2_FLAG_EPILOGUE_BEGIN; *input_line_pointer =3D c; } @@ -1352,6 +1356,8 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED) } else if (strcmp (p, "isa") =3D=3D 0) { + if (dwarf_level < 3) + dwarf_level =3D 3; (void) restore_line_pointer (c); value =3D get_absolute_expression (); if (value >=3D 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 =3D=3D 13); + if (DWARF2_LINE_VERSION >=3D 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 =3D=3D 13); + } + else + gas_assert (DWARF2_LINE_OPCODE_BASE =3D=3D 10); =20 out_dir_and_file_list (line_seg, sizeof_offset); =20 diff --git a/gas/testsuite/gas/i386/debug1.d b/gas/testsuite/gas/i386/debug= 1.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: =20 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 =20 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 =20 The Directory Table \(offset 0x.*\): .* diff --git a/gas/testsuite/gas/i386/dwarf2-line-1.d b/gas/testsuite/gas/i38= 6/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: =20 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 =20 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 =20 The Directory Table \(offset 0x.*\): .* diff --git a/gas/testsuite/gas/i386/dwarf2-line-4.d b/gas/testsuite/gas/i38= 6/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: =20 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 =20 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 =20 The Directory Table is empty\.