Dwarf: Wrong Line info after inlined specialization of generics (Debugger breakpoints does not work in some cases)

  • Lazarus/FPC Version: Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64
  • Operating System: Windows 10 (1809 LTSC)
  • CPU / Bitness: 64

Tested with latest 2.2.0 RC1 as well.

What happens

Debugger breakpoints does not work below the line TValue.From<T>(val).
Other problem, seems to be related to FPC project, but attached example produce runtime error as well.
Same code works with Delphi 10.2 without problems.

  TGeneric<T> = class
    Items: TList<T>;
    constructor Create();
    destructor Destroy(); override;
  end;
destructor TGeneric<T>.Destroy();
var
  i: Integer;
  Val: TValue;
begin
  for i := 0 to Items.Count - 1 do
    begin

      // Not optimized, RTTI evaluation for each item, just to show that FPC can't run similar code
      Val := TValue.From<T>(Items[i]);
      // Starting from here breakpoints does not work in FPC
      if Val.Kind = tkClass then
        Val.AsObject.Free();

      if Val.Kind = tkInterface then
        // FPC can't run this code, Delphi 10.2 works
        if Supports(Val.AsInterface, ISomeBaseInterface) then
          (Val.AsInterface as ISomeInterface).SelfDestruction() // Or some another operation
        else
          raise Exception.Create('Wrong interface');

    end;
  Items.Free;
  inherited;
end;

What did you expect

  • Debugger breakpoints should work as expected;
  • Project should run without runtime error.
    This problem can be reported separately, when FPC bug tracker will work.

Steps to reproduce

Build and run attached project.
generic-interface-bug.7z

Edited by Martin