[fpc-devel] Wrong debug info when using clang backend
Martin Frb
lazarus at mfriebe.de
Wed Dec 6 17:37:10 CET 2023
Not suer if the issue is within Fpc or clang...
Should this be reported against Fpc?
- Fedora 33
- Fpc 3.3.1 from Sept 26th
- make all OPT=" " OPTNEW=" -Clv11.0 " FPCMAKEOPT=" -Clv11.0 " LLVM=1
- clang --version
clang version 11.0.0 (Fedora 11.0.0-3.fc33)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Program at the end of this mail was compiled with -O-
Assembler for nested procedure Bar
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:8 begin
00000000004012D0 897424F8 mov [rsp-$08],esi
00000000004012D4 895424F0 mov [rsp-$10],edx
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:9 a := 1;
00000000004012D8 C74424F801000000 mov [rsp-$08],$00000001
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:10 b := 1;
00000000004012E0 C74424F001000000 mov [rsp-$10],$00000001
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:11 c:=2;
00000000004012E8 C74424E402000000 mov [rsp-$1C],$00000002
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:12 d:=2;
00000000004012F0 C74424E002000000 mov [rsp-$20],$00000002
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:13 d:=2;
00000000004012F8 C74424E002000000 mov [rsp-$20],$00000002
/home/m/laz/projects/clang1/clang_nested_proc_1.lpr:14 end;
0000000000401300 C3 ret
Variables d and c are encoded using a location list
<2><9c>: Abbrev Number: 3 (DW_TAG_variable)
<9d> DW_AT_location : 0x24 (location list)
<a1> DW_AT_name : (indirect string, offset: 0xab): D
<a5> DW_AT_decl_file : 1
<a6> DW_AT_decl_line : 7
<a7> DW_AT_type : <0xdb>
<2><ab>: Abbrev Number: 3 (DW_TAG_variable)
<ac> DW_AT_location : 0x48 (location list)
<b0> DW_AT_name : (indirect string, offset: 0xad): C
<b4> DW_AT_decl_file : 1
<b5> DW_AT_decl_line : 7
<b6> DW_AT_type : <0xdb>
Contents of the .debug_loc section:
Offset Begin End Expression
00000000 00000000004012c3 00000000004012c5 (DW_OP_breg7 (rsp): 0)
00000014 <End of list>
00000024 0000000000401300 0000000000401301 (DW_OP_breg7 (rsp): -32)
00000038 <End of list>
00000048 0000000000401300 0000000000401301 (DW_OP_breg7 (rsp): -28)
0000005c <End of list>
Both location lists specify the variable is only available from
0000000000401300 0000000000401301
- That covers exactly the asm "ret" statement.
- Yet the variables are stored on the frame ([rsp-$1C] / [rsp-$20]) =>
so they are available before.
program clang_nested_proc_1;
{$mode objfpc}
procedure Foo;
procedure Bar(a, b: integer);
var
c,d: integer;
begin
a := 1;
b := 1;
c:=2;
d:=2;
d:=2;
end;
begin
Bar(1,2);
end;
begin
Foo;
end.
line info confirms the addresses from the asm.
Contents of the .debug_line section:
CU: clang_nested_proc_1.lpr:
File name Line number Starting address
View Stmt
clang_nested_proc_1.lpr 15 0x4012b0 x
clang_nested_proc_1.lpr 16 0x4012b4 x
clang_nested_proc_1.lpr 17 0x4012c3 x
clang_nested_proc_1.lpr 8 0x4012d0 x
clang_nested_proc_1.lpr 8 0x4012d0 1 x
clang_nested_proc_1.lpr 9 0x4012d8 x
clang_nested_proc_1.lpr 10 0x4012e0 x
clang_nested_proc_1.lpr 11 0x4012e8 x
clang_nested_proc_1.lpr 12 0x4012f0 x
clang_nested_proc_1.lpr 13 0x4012f8 x
clang_nested_proc_1.lpr 14 0x401300 x
clang_nested_proc_1.lpr 19 0x401310 x
clang_nested_proc_1.lpr 19 0x401311 x
clang_nested_proc_1.lpr 20 0x401316 x
clang_nested_proc_1.lpr 21 0x40131b x
clang_nested_proc_1.lpr 21 0x401322 x
More information about the fpc-devel
mailing list