View Issue Details

IDProjectCategoryView StatusLast Update
0037069FPCCompilerpublic2020-05-14 02:45
ReporterMartin Friebe Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platform64bit IntelOSwin 10 
Product Version3.3.1 
Summary0037069: Wrong dwarf in nested proc for "var FOO: integer absolute FOO_IN_OUTER"
DescriptionSee 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 Reproduceprogram 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 InformationI 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

TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2020-05-14 02:45 Martin Friebe New Issue