Recent

Author Topic: Likely bug in Lazarus v1.8.2 (and maybe other versions)  (Read 2729 times)

440bx

  • Hero Member
  • *****
  • Posts: 3946
Likely bug in Lazarus v1.8.2 (and maybe other versions)
« on: May 13, 2020, 11:07:33 pm »
Hello,

When debugging and hovering over a local nested variable that is "absolute"(d) on a variable that belongs to the containing function/procedure, the debugger does not show the correct variable value.  This is shown in the small test program:
Code: Pascal  [Select][+][-]
  1. {$APPTYPE CONSOLE}
  2.  
  3. { NOTE: this test program runs as intended under Windows ONLY                 }
  4.  
  5. program NestedAbsolute;
  6.  
  7.   type
  8.     BOOL = longbool;
  9.  
  10.   function IsDebuggerPresent()
  11.          : BOOL; stdcall; external 'kernel32.dll';
  12.     { determines if the program is being run under a debugger                 }
  13.  
  14.   procedure ProcedureA();
  15.   var
  16.     ProcedureAVariable : integer = 5;
  17.  
  18.     procedure ProcedureB();
  19.     var
  20.       { absolute clause on nested variable                                    }
  21.  
  22.       ProcedureBVariable : integer absolute ProcedureAVariable;
  23.  
  24.     begin
  25.       { hover over ProcedureBVariable in the debugger                         }
  26.  
  27.       writeln(ProcedureBVariable);    { hover on ProcedureBVariable           }
  28.                                       { it should show a value of 5           }
  29.  
  30.       if IsDebuggerPresent() then asm int 3 end;
  31.  
  32.       { execution stops here - hover over ProcedureBVariable now              }
  33.  
  34.       writeln;
  35.     end;
  36.  
  37.   begin
  38.     ProcedureB();
  39.   end;
  40.  
  41. begin
  42.   ProcedureA();  { output is correct.  The compiler handles "absolute" correctly.   }
  43.  
  44.   writeln('Press enter/return to end this program');
  45.   readln;
  46. end.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Likely bug in Lazarus v1.8.2 (and maybe other versions)
« Reply #1 on: May 14, 2020, 12:57:29 am »
Just tested. (with fpc 3.0.4)

It actually is a problem in the compiler. The generated DWARF info is incorrect.

Local variables are encoded relative to the StackBasePointer.
FPC repeats the literal dwarf info of ProcedureAVariable. But since ProcedureAVariable  is only correct when in the outer procedure, the literal copy is incorrect when in the nested procedure.


440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Likely bug in Lazarus v1.8.2 (and maybe other versions)
« Reply #2 on: May 14, 2020, 01:48:51 am »
It actually is a problem in the compiler. The generated DWARF info is incorrect.
Thank you for checking it out and, I'm pleased you found the cause.

Obviously, I don't know if the problem occurs in the trunk version.  I believe you probably have a trunk version available to test with.  Since not only the problem involves how the compiler generates DWARF information and, you obviously know a lot more about that than I do, I'll leave it at your discretion whether a bug report against the compiler should be created.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Likely bug in Lazarus v1.8.2 (and maybe other versions)
« Reply #3 on: May 14, 2020, 02:47:08 am »
https://bugs.freepascal.org/view.php?id=37069


<joking on>
But the code is procedural. That is your domain :) :) :)
<joking off>

jiaxing2

  • Full Member
  • ***
  • Posts: 164
Re: Likely bug in Lazarus v1.8.2 (and maybe other versions)
« Reply #4 on: May 14, 2020, 08:16:51 am »
https://bugs.freepascal.org/view.php?id=37069


<joking on>
But the code is procedural. That is your domain :) :) :)
<joking off>

Great joke!  >:D

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
Re: Likely bug in Lazarus v1.8.2 (and maybe other versions)
« Reply #5 on: May 14, 2020, 01:20:49 pm »
Dont know if it is the same issue but hovering on absolute variables has never worked for me, CTRL-F7 does not show the absolute'd value either.
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$APPTYPE CONSOLE}
  3. var
  4.   ProcedureAVariable: integer = 5;
  5.   { absolute clause on variable }
  6.   ProcedureBVariable: integer absolute ProcedureAVariable;
  7. begin
  8.   WriteLn(ProcedureBVariable); // Hover on ProcedureBVariable
  9.                                //   displays : ProcedureBVariable = No symbol \"PROCEDUREBVARIABLE\" in current context.
  10.   writeln('Press enter/return to end this program');
  11.   readln;
  12. end.


Lazarus trunk r. 63021 ~ 19.04.2020 (+/- some  changes) FPC 3.0.4 (the mac os one) from svn + some mods.
Windows 10 Pro x64 usualy I386 mode.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Likely bug in Lazarus v1.8.2 (and maybe other versions)
« Reply #6 on: May 14, 2020, 01:26:12 pm »
Dont know if it is the same issue but hovering on absolute variables has never worked for me, CTRL-F7 does not show the absolute'd value either.

You need to make sure that you set the debug format to DWARF. For i386 the default is Stabs.

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
Re: Likely bug in Lazarus v1.8.2 (and maybe other versions)
« Reply #7 on: May 14, 2020, 05:18:22 pm »
You need to make sure that you set the debug format to DWARF. For i386 the default is Stabs.
Your are right for my specific bit of code. Using -gw2 -godwarfsets (which I normally use but forgot for this program) effectively shows the absolute var.

I must have experienced this type of problem in situations described in the OP situation, forget it.

 

TinyPortal © 2005-2018