[Bug debug/108600] Use DW_LNS_set_prologue_end

2023-01-31 Thread vries at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108600

--- Comment #4 from Tom de Vries  ---
(In reply to Tom de Vries from comment #0)
> Note that for for instance gdb test-case gdb.ada/ref_param.exp, this
> convention was broken for gcc 7.5.0 (and I don't know how much earlier), and
> my current guess is that it got fixed in gcc 11.1.0, by commit c029fcb5680
> ("Reset force_source_line in final.c").

Confirmed, see PR108615.

[Bug debug/108600] Use DW_LNS_set_prologue_end

2023-01-31 Thread vries at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108600

--- Comment #3 from Tom de Vries  ---
(In reply to Tom de Vries from comment #2)
> (In reply to Tom de Vries from comment #1)
> > Created attachment 54371 [details]
> 
> We probably don't want to emit in all cases, maybe limiting to 
> "dwarf_version >= 3", or "!dwarf_strict || dwarf_version >= 3".

Let's see about dwarf_strict.

Semantics:
...
-gstrict-dwarf

Disallow using extensions of later DWARF standard version than selected
with -gdwarf-version. On most targets using non-conflicting DWARF extensions
from later standard versions is allowed.
...

For the -gas-loc-support case (gcc emitting .locs), even when passing
-gdwarf-2, gas emits a v3 version .debug_line section (since binutils-2_32). 
And even if we'd fix that (I've filed
https://sourceware.org/bugzilla/show_bug.cgi?id=30064), the way gas works is by
bumping the dwarf version when encountering a feature that requires a higher
version, so using end_prologue in a loc directive would then end up bumping
dwarf_level to 3, bumping also the .debug_line version.

For the -gno-as-loc-support case (gcc emitting .debug_line contribution), for
-gdwarf-2 gcc indeed emits a v2 .debug_line section.  But, that makes
DW_LNS_set_prologue_end fall in the range of vendor specific extensions, and we
can't conflict with that.

Taking this all into account, I think it's better not to emit
DW_LNS_set_prologue_end for -gdwarf-2 -gno-strict-dwarf.

[Bug debug/108600] Use DW_LNS_set_prologue_end

2023-01-30 Thread vries at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108600

--- Comment #2 from Tom de Vries  ---
(In reply to Tom de Vries from comment #1)
> Created attachment 54371 [details]

We probably don't want to emit in all cases, maybe limiting to 
"dwarf_version >= 3", or "!dwarf_strict || dwarf_version >= 3".

[Bug debug/108600] Use DW_LNS_set_prologue_end

2023-01-30 Thread vries at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108600

--- Comment #1 from Tom de Vries  ---
Created attachment 54371
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54371=edit
tentative patch

Tentative patch.

For hello.c, for the -gas-loc-support case it gives us:
...
$ gcc -g ~/hello.c -S -o-
  ...
main:
.LFB0:
.file 1 "/home/vries/hello.c"
.loc 1 5 1
.cfi_startproc
pushq   %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq%rsp, %rbp
.cfi_def_cfa_register 6
.loc 1 6 3 prologue_end
movl$.LC0, %edi

...

And for the -gno-as-loc-support case:
...
$ gcc -g ~/hello.c -c -gno-as-loc-support
$ llvm-dwarfdump --debug-line hello.o
  ...
AddressLine   Column File   ISA Discriminator Flags
-- -- -- -- --- - -
0x  5  0  1   0 0  is_stmt
0x0004  6  1  1   0 0  is_stmt prologue_end
0x000e  8  3  1   0 0  is_stmt
0x0013  9 10  1   0 0  is_stmt
0x0015  9  1  1   0 0  is_stmt end_sequence
...