From: H.J. Lu Date: Sat, 17 Oct 2020 11:24:22 +0000 (-0700) Subject: gas: Always use as_where for preprocessed assembly codes X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bd0c565edbf4ba8121fded38e389530d7fa6f963;p=binutils-gdb.git gas: Always use as_where for preprocessed assembly codes Always clear the slot 1 if it was assigned to the input file before the first .file directive has been seen. Always use as_where to generate the correct debug infor for preprocessed assembly codes. PR gas/25878 PR gas/26740 * dwarf2dbg.c (allocate_filename_to_slot): Don't reuse the slot 1 here. (dwarf2_where): Restore as_where. (dwarf2_directive_filename): Clear the slot 1 if it was assigned to the input file. * testsuite/gas/i386/dwarf5-line-2.d: New file. * testsuite/gas/i386/dwarf5-line-2.s: Likewise. * testsuite/gas/i386/dwarf5-line-3.d: Likewise. * testsuite/gas/i386/dwarf5-line-3.s: Likewise. * testsuite/gas/i386/i386.exp: Run dwarf5-line-2 and dwarf5-line-3. --- diff --git a/gas/ChangeLog b/gas/ChangeLog index a74362be587..bcc538ee2f1 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,19 @@ +2020-10-17 H.J. Lu + + PR gas/25878 + PR gas/26740 + * dwarf2dbg.c (allocate_filename_to_slot): Don't reuse the slot 1 + here. + (dwarf2_where): Restore as_where. + (dwarf2_directive_filename): Clear the slot 1 if it was assigned + to the input file. + * testsuite/gas/i386/dwarf5-line-2.d: New file. + * testsuite/gas/i386/dwarf5-line-2.s: Likewise. + * testsuite/gas/i386/dwarf5-line-3.d: Likewise. + * testsuite/gas/i386/dwarf5-line-3.s: Likewise. + * testsuite/gas/i386/i386.exp: Run dwarf5-line-2 and + dwarf5-line-3. + 2020-10-16 H.J. Lu PR gas/25878 diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c index 6943dbf9ca4..75ef7c43e39 100644 --- a/gas/dwarf2dbg.c +++ b/gas/dwarf2dbg.c @@ -790,24 +790,15 @@ allocate_filename_to_slot (const char * dirname, } fail: - /* Reuse NUM if it is 1 and was assigned to the input file before - the first .file directive was seen. */ - file = as_where_physical (&i); - file = get_basename (file); - if (num == 1 && filename_cmp (file, files[num].filename) == 0) - files[num].filename = NULL; - else - { - as_bad (_("file table slot %u is already occupied by a different file (%s%s%s vs %s%s%s)"), - num, - dir == NULL ? "" : dir, - dir == NULL ? "" : "/", - files[num].filename, - dirname == NULL ? "" : dirname, - dirname == NULL ? "" : "/", - filename); - return FALSE; - } + as_bad (_("file table slot %u is already occupied by a different file (%s%s%s vs %s%s%s)"), + num, + dir == NULL ? "" : dir, + dir == NULL ? "" : "/", + files[num].filename, + dirname == NULL ? "" : dirname, + dirname == NULL ? "" : "/", + filename); + return FALSE; } if (dirname == NULL) @@ -894,7 +885,7 @@ dwarf2_where (struct dwarf2_line_info *line) const char *filename; memset (line, 0, sizeof (*line)); - filename = as_where_physical (&line->line); + filename = as_where (&line->line); line->filenum = allocate_filenum (filename); /* FIXME: We should check the return value from allocate_filenum. */ line->column = 0; @@ -1088,6 +1079,20 @@ dwarf2_directive_filename (void) return NULL; } + if (files_in_use == 2) + { + /* Clear the slot 1 if it was assigned to the input file before + the first .file directive was seen. */ + unsigned int lineno; + const char *file = as_where (&lineno); + file = get_basename (file); + if (filename_cmp (file, files[1].filename) == 0) + { + files[1].filename = NULL; + files_in_use = 0; + } + } + if (! allocate_filename_to_slot (dirname, filename, (unsigned int) num, with_md5)) return NULL; diff --git a/gas/testsuite/gas/i386/dwarf5-line-2.d b/gas/testsuite/gas/i386/dwarf5-line-2.d new file mode 100644 index 00000000000..302a2d8fcc4 --- /dev/null +++ b/gas/testsuite/gas/i386/dwarf5-line-2.d @@ -0,0 +1,49 @@ +#as: -gdwarf-5 +#readelf: -wl +#name: DWARF5 .debug_line 2 + +Raw dump of debug contents of section \.z?debug_line: + + Offset: 0x0 + Length: .* + DWARF Version: 5 + Address size \(bytes\): .* + Segment selector \(bytes\): 0 + Prologue Length: .* + Minimum Instruction Length: 1 + Maximum Ops per Instruction: 1 + Initial value of 'is_stmt': 1 + Line Base: -5 + Line Range: 14 + Opcode Base: 13 + + Opcodes: + Opcode 1 has 0 args + Opcode 2 has 1 arg + Opcode 3 has 1 arg + Opcode 4 has 1 arg + Opcode 5 has 1 arg + Opcode 6 has 0 args + 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.*, lines 2, columns 1\): + Entry Name + 0 \(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386 + 1 \(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386 + + The File Name Table \(offset 0x.*, lines 1, columns 3\): + Entry Dir MD5 Name + 0 0 0xbbd69fc03ce253b2dbaab2522dd519ae \(indirect line string, offset: 0x.*\): core.c + + Line Number Statements: + \[0x.*\] Extended opcode 2: set Address to 0x0 + \[0x.*\] Special opcode 8: advance Address by 0 to 0x0 and Line by 3 to 4 + \[0x.*\] Advance PC by 1 to 0x1 + \[0x.*\] Extended opcode 1: End of Sequence + + diff --git a/gas/testsuite/gas/i386/dwarf5-line-2.s b/gas/testsuite/gas/i386/dwarf5-line-2.s new file mode 100644 index 00000000000..4af7d7061c9 --- /dev/null +++ b/gas/testsuite/gas/i386/dwarf5-line-2.s @@ -0,0 +1,5 @@ + .text + .global kretprobe_trampoline +kretprobe_trampoline: + ret + .file 0 "core.c" md5 0xbbd69fc03ce253b2dbaab2522dd519ae diff --git a/gas/testsuite/gas/i386/dwarf5-line-3.d b/gas/testsuite/gas/i386/dwarf5-line-3.d new file mode 100644 index 00000000000..6f4ebf04718 --- /dev/null +++ b/gas/testsuite/gas/i386/dwarf5-line-3.d @@ -0,0 +1,49 @@ +#as: -g -gdwarf-5 +#readelf: -wl +#name: DWARF5 .debug_line 2 + +Raw dump of debug contents of section \.z?debug_line: + + Offset: 0x0 + Length: .* + DWARF Version: 5 + Address size \(bytes\): .* + Segment selector \(bytes\): 0 + Prologue Length: .* + Minimum Instruction Length: 1 + Maximum Ops per Instruction: 1 + Initial value of 'is_stmt': 1 + Line Base: -5 + Line Range: 14 + Opcode Base: 13 + + Opcodes: + Opcode 1 has 0 args + Opcode 2 has 1 arg + Opcode 3 has 1 arg + Opcode 4 has 1 arg + Opcode 5 has 1 arg + Opcode 6 has 0 args + 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.*, lines 1, columns 1\): + Entry Name + 0 \(indirect line string, offset: 0x.*\): .* + + The File Name Table \(offset 0x.*, lines 2, columns 2\): + Entry Dir Name + 0 0 \(indirect line string, offset: 0x.*\): dwarf5-line-2.S + 1 0 \(indirect line string, offset: 0x.*\): dwarf5-line-2.S + + Line Number Statements: + \[0x.*\] Extended opcode 2: set Address to 0x0 + \[0x.*\] Special opcode 7: advance Address by 0 to 0x0 and Line by 2 to 3 + \[0x.*\] Advance PC by 1 to 0x1 + \[0x.*\] Extended opcode 1: End of Sequence + + diff --git a/gas/testsuite/gas/i386/dwarf5-line-3.s b/gas/testsuite/gas/i386/dwarf5-line-3.s new file mode 100644 index 00000000000..52e259d1033 --- /dev/null +++ b/gas/testsuite/gas/i386/dwarf5-line-3.s @@ -0,0 +1,10 @@ +# 1 "foo.S" +# 1 "" +# 1 "" +# 31 "" +# 1 "/usr/include/stdc-predef.h" 1 3 4 +# 32 "" 2 +# 1 "dwarf5-line-2.S" + .text +lbasename: + .nop diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp index 683474969d3..d8bae38e54f 100644 --- a/gas/testsuite/gas/i386/i386.exp +++ b/gas/testsuite/gas/i386/i386.exp @@ -615,6 +615,8 @@ if [gas_32_check] then { run_dump_test "dwarf2-line-3" run_dump_test "dwarf2-line-4" run_dump_test "dwarf5-line-1" + run_dump_test "dwarf5-line-2" + run_dump_test "dwarf5-line-3" run_dump_test "dw2-compress-2" run_dump_test "dw2-compressed-2"