Jump to content
Dave Novo

Delphi 11.2 Linker eliminating symbols

Recommended Posts

Hello All.

 

If I create the following simple console application

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.Classes,
  System.SysUtils,
  System.IOUtils;

var
  combinedPath:string;
  curPath:string;
begin
  try
    combinedPath := TPath.Combine(ParamStr(0),'..\..\..\');
    curPath:=TPath.GetFullPath(combinedPath);

    var f:=TFileStream.Create(curPath+'file.txt',fmCreate);
    f.free;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

everything works fine. I hover the mouse over the string variables and it pulls up the values, and I can view them in the watch list. However, if I make this slight change to use the new Delphi language features

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.Classes,
  System.SysUtils,
  System.IOUtils;

begin
  try
    var combinedPath := TPath.Combine(ParamStr(0),'..\..\..\');
    var curPath:=TPath.GetFullPath(combinedPath);

    var f:=TFileStream.Create(curPath+'file.txt',fmCreate);
    f.free;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

then when I hover the mouse over combinedPath, or curPath, nothing happens. If I enter them into the watch list I get

image.png.97b1dd8739a4c64917641840d54e39c1.png

 

Is there any way around this behavior. I like this new language feature, but if I cannot debug my variables then it is not very helpful.

Share this post


Link to post

Is this still the case when you declare the type as well?

    var combinedPath: string := TPath.Combine(ParamStr(0),'..\..\..\');
    var curPath:string :=TPath.GetFullPath(combinedPath);

 

Share this post


Link to post

The problem within the global begin/end block is special - usually, inline variables are shown in the debugger but with the limitation that the compiler does not emit so-called live-range data for them which the debugger can use to know the locations they are valid for.

For example having two nested variables of the same name causes issues with properly inspecting them because the debugger always shows the value of the first (which causes wrong data to be shown) which also has been reported multiple times.

Edited by Stefan Glienke

Share this post


Link to post
On 1/26/2023 at 12:08 PM, Stefan Glienke said:

No, just pray the issue gets fixed in your lifetime

Now I finally have an excuse to live a long and healthy life 🙂

  • Like 1
  • Haha 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×