Wrong dwarf in nested proc for "var FOO: integer absolute FOO_IN_OUTER"
Original Reporter info from Mantis: Martin @martin_frb
-
Reporter name: Martin Friebe
Original Reporter info from Mantis: Martin @martin_frb
- Reporter name: Martin Friebe
Description:
See code below and https://forum.lazarus.freepascal.org/index.php/topic,49795.msg362072/topicseen.html#new
In a nested procedure, have a variable that is absolute to a variable in the outer proc.
var
ProcedureBVariable : integer absolute ProcedureAVariable;
A normal local var has dwarf info like:
DW_AT_location, DW_FORM_block1 => DW_OP_breg5, SLEB(-4)
(The offset "-4" varies for the location on the stackframe)
For the "absolute" var, fpc copies the dwarf info. But the nested procedure has its own stackframe. So the copy points to the wrong location.
Steps to reproduce:
program Project1;
{$APPTYPE CONSOLE}
procedure ProcedureA();
var
ProcedureAVariable : integer = 5;
procedure ProcedureB();
var
{ absolute clause on nested variable }
ProcedureBVariable : integer absolute ProcedureAVariable;
begin
writeln(ProcedureBVariable);
writeln; // set break here - hover over ProcedureBVariable now
end;
begin
ProcedureB();
end;
begin
ProcedureA(); { output is correct. The compiler handles "absolute" correctly. }
writeln('Press enter/return to end this program');
readln;
end.
Additional information:
I have not tested this, but if memory serves:
Lets say the "parentFp" passed to the nested is at -4
and the variable is at -8 on the outer frame
DW_AT_location, DW_FORM_block1 =>
DW_OP_breg5,
SLEB(-4)
deref
SLEB(-8)
With this it may be possible to also include all "visible outer var" as locals.
In the example ProcedureAVariable could be added as local var to ProcedureB.
Currently a debugger must recognize parentFp, follow it and find local vars from the outer proc.
However, a debugger has no means to know which of them are declared before or after the nested proc. This causes visibility issue https://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Nested_Procedures_.2F_Function
Mantis conversion info:
- Mantis ID: 37069
- OS: win 10
- OS Build: 10
- Platform: 64bit Intel
- Version: 3.3.1