Recent

Author Topic: static REGLOC <error reading variable> - debug error?  (Read 3266 times)

Birger52

  • Sr. Member
  • ****
  • Posts: 270
static REGLOC <error reading variable> - debug error?
« on: August 12, 2020, 02:12:28 pm »
I'm getting the error in the attached image.

A settings editor, for 4 apps working together, communicating via SimpleIPC.
A procedure shows the editor-form - reads data as they are, and compares after editing - and distributes messages as required to the apps.

Code: Pascal  [Select][+][-]
  1. procedure EditSettings(aSender:TForm;aP:Tpoint;aCl:TSimpleIPCClient);
  2. var
  3.   setForm : TSettingsForm;
  4.   sSet, nSet : TSetSet; // sSet is settings before they are changed - used to determine what needs to be updated
  5.  
  6.   procedure SendIPCMsg(aMsg, IPCId:string);
  7.   begin  // Sends msgs using aCl - the IPC Client of the app that activated the editor
  8.   ...
  9.   end;
  10.  
  11. begin
  12.   SetForm := TSettingsForm.Create(aSender);
  13.   aP.X := aP.X - SetForm.Width;
  14.   SetForm.Left := aP.X;
  15.   SetForm.Top := aP.Y;
  16.   SetForm.ShowModal;
  17.   sSet := TSetSet.Create;
  18.   sSet.ReadSet;
  19.   nSet := SetForm.edtSet;
  20.   nSet.WriteSet;
  21.   if nSet.BoolChrs <> sSet.BoolChrs then begin // Alert Apps that use boolChrs
  22.     // ... Send IPC to other apps
  23.   end;
  24.   if nSet.ToMetric <> sSet.ToMetric then
  25.     // ... Send IPC to other apps
  26.   if (nSet.StoreTiming <> sSet.StoreTiming) or (nSet.PlayTimerInterval <> sSet.PlayTimerInterval) then
  27.      // ... Send IPC to other apps
  28.   if (nSet.PlayAuto <> sSet.PlayAuto) or (nSet.PlayAutoInterval <> sSet.PlayAutoInterval) then
  29.     // ... Send IPC to other apps
  30.   if (nSet.HistoryRec <> sSet.HistoryRec) and (nSet.HistoryAnt <> sSet.HistoryAnt) then
  31.      // ... Send IPC to other apps
  32. {
  33.   if (nSet.IgnoreCards <> sSet.IgnoreCards) and (nSet.IgnoreModels <> sSet.IgnoreModels) then
  34.     saveSet := true;
  35.   Ignore Cards and Ignore models used solely by DBupdater - and is not yet implemented.
  36. }
  37.   SetForm.Free; // also frees nSet
  38.   sSet.Free;
  39. end;
  40.  

It compiles fine - but does not produce expected results.
f.eks. sSet.PlayAuto (boolean) is 240 - sSet.PlayAutoInterval (int) is -MaxInt is what it looks like.
In contrast nSet have the correct values (default as assigned in object, edited or read from registry).

Singlestepping to locate error, I get the attached message (static REGLOC <error reading variable>) for sSet - but nSet is just fine.
Also I get an debug message in the TSetSet object when closing reigstry key
(reg.CloseKey - \"finish\" not meaningful in outermost frame.)..?
Image attached and so is unit that defines the TSetSet object.

Anybody know what's going on?
And/or how to correct whatever it is that is wrong?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Birger52

  • Sr. Member
  • ****
  • Posts: 270
Re: static REGLOC <error reading variable> - debug error?
« Reply #1 on: August 13, 2020, 11:51:44 am »
Tried moving the comaprison and sending af messages to the form, when clicking the button that closes the editor.
It does the same thing.
One of the TSetSet objects it knows - the other it don't, and values are neither default nor the ones read from registry.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Birger52

  • Sr. Member
  • ****
  • Posts: 270
Re: static REGLOC <error reading variable> - debug error?
« Reply #2 on: August 13, 2020, 01:24:18 pm »
Downgraded to when things were last functining - Lazarus 2.08 -fpc 3.0.4.
Needed to "Clean Up and Buikd" as the FPC 3.2.0 version of TSimpleIPCServer has a "Threaded" property, that doesn't exists in 3.0.4.
Things are functioning as expected.
Don't know if this is Lazarus or FPC - but something is obviously not going according to plans.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6592
    • wiki
Re: static REGLOC <error reading variable> - debug error?
« Reply #3 on: August 13, 2020, 02:40:34 pm »
Quote
Also I get an debug message in the TSetSet object when closing reigstry key
(reg.CloseKey - \"finish\" not meaningful in outermost frame.)..?

Did that happen during a "step over" (F8)?
Or did you do "Step out" (Shift F8) ?

If they first: Do you have (Tools > Options > Debugger > prop-grid) "FixIncorrectStepOver" enabled?

There is an issue (either FPC, or GDB - could be either), which leads to gdb stepping into, when it should step over.
The IDE fixes that by issuing a "step out" (internally "step finish").
But given that something already got wrong with where a function begins, it could be that in your case the "step out" fails....

This issue can be triggered by changes in unrelated code. Maybe because code changes move addresses and their relative distance... (just wild guessing)....
So then 3.2 could just have triggered it in that code, but  3.0.4 probably can too, if other code changes.




How is TSetSet declared?

"REGLOC" is a class variable?
Or is this an old style object?


Would either sset or nset be nil at the time?

Birger52

  • Sr. Member
  • ****
  • Posts: 270
Re: static REGLOC <error reading variable> - debug error?
« Reply #4 on: August 13, 2020, 03:41:50 pm »
TSetSet is in the file settingsset.pas, attached to the first post.
It is a descendant of TObject - and holds booleans, integer and strings read from registry - with some tweaks to make sure they have default values, if they are not found in registry.

I have the "FixIncorrectStepOver" checked - actually tried to uncheck it, and it makes no difference.

REGLOC must be something in debugger (or linker/compiler) - it's no invention of mine.

None of them are nil.
Initially both variables read the values from registry (and they are there - and are correct).
And both objects seem to be getting the correct values, inside the ReadSet() of the TSetSet object (F7 Step Into).
But once the ReadSet() procedure that reads values from registry to variables in object returns, one of the variables have values that are wrong (in many ways - a boolean have value true in one and 243 in the other, an integer that is defined and in registry as value 3, suddently has a value if -11 millions)

I tried to comment out the CloseKey of TRegistry - it is called by OpenKey, so it should make no functional  difference - and it does not make any difference, except the message from the compiler doesn't show up.
(Indicating a problem in the 3.0.10 version of TRegistry?)
Values are still terribly wrong, outside the ReadSet() procedure...

The odd thing is, that it is the same class - the same code, that sometimes does right and sometimes wrong.

So looks more like the reference to the one of the variables is lost (REGLOC)...
But I have no idea....




Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6592
    • wiki
Re: static REGLOC <error reading variable> - debug error?
« Reply #5 on: August 13, 2020, 05:00:07 pm »
REGLOC must be something in debugger (or linker/compiler) - it's no invention of mine.
This is
Code: Pascal  [Select][+][-]
  1.   private const
  2.     RegLoc = '\Software\SDC\Play';

I tested with fpc 3.2 and 3.0.4 with different gdb versions. For me all of them return the error.
Unfortunately, as soon as gdb reports that error, it appears to stop reading the entire object => So you never see the other fields.

It seems even fpdebug is currently troubled by this. But fpdebug continues with the other fields.


Quote
Values are still terribly wrong, outside the ReadSet() procedure...
If your setup somehow continues to the next field, then what does it print for RegLoc?
The issue is, if gdb did still have an error on that field (but continued...), then the remaining output may still be affected by that error.


On a first glance (but I need to look at details) the debug info generated by fpc seems to be correct. If that is the case, the error is in gdb.

2.0.10 came with a different gdb version. That has been rolled back. 2.2 will have the old gdb again (though for diff reasons).
However that old gdb fails in my tests too....

If the error is in gdb, then there is little hope of it getting fixed.

Birger52

  • Sr. Member
  • ****
  • Posts: 270
Re: static REGLOC <error reading variable> - debug error?
« Reply #6 on: August 14, 2020, 11:17:12 am »
Ok.
RegLoc is mine - loacation in Registry. - was thrown off by capitals (and static and variable - my RegLoc is (defined as) a constant...  :o)

But if it for some reason doesn't know where to look for the values, it makes sense it doesn't get the correct values. But not that singlestepping finds the values.

As you may have seen (https://forum.lazarus.freepascal.org/index.php/topic,51010.0.html), I downgraded to 2.0.8 - fpc 3.0.4, and here the same code function as it should.

I'll try to go back to 2.0.10 with 3.2.0 and check values of RegLoc, after the reported error.
But it may be a while.
Can it be cause by the constant declaration?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6592
    • wiki
Re: static REGLOC <error reading variable> - debug error?
« Reply #7 on: August 14, 2020, 11:45:09 am »
Can it be cause by the constant declaration?

Probably. Though it is hard to tell if the trouble is gdb, fpc, or the fact that the dwarf spec may be to unspecific....

The constant is a member of the structure.
Now normally in debug info members have some info about where in the structures memory they are (offset to start of struct).

Only a constant is not stored in the structure. => So that field in the debug info is missing.
Dwarf3 just says "has member location". There is no "must have". Only in dwarf 5 this is clarified to be optional, but even then to be assumed zero (offset) if missing.
(Note that DW_AT_MEMBER_LOCATION is only a starting point for the fields value's address, and there can and will be further steps to calculate the address, and those steps are not bound to use the member's location)

My guess: GDB stops after not finding the location. Or it assumes it to be 0 offset, but then still can not find instructions where to read the constant. Because a constant is replicated as a literal in the debug info. So there is no memory location at all...

To me the debug info looks ok. But when implementing FpDebug from the dwarf spec, I did not foresee this case either... (So fpdebug needs fixing too).


Also you would have to test, if GDB deals with string (shortstring in this case) constants outside a structure..... I have not even checked that. (And that may depend on fpc version)

Birger52

  • Sr. Member
  • ****
  • Posts: 270
Re: static REGLOC <error reading variable> - debug error?
« Reply #8 on: August 14, 2020, 12:07:25 pm »
I'm afraid I can't follow all you are saying - but appreciate the effort.

I reinstalled 2.0.10 and fpc 3.2.0
The problem still exists - but only outside the object.
Inside the object RegLoc is what it needs to be (value assigned to constant).
But outside, it gives the error, even tho RegLoc is private and not addressed from outside.
(Actually it doesn't give any error - it appears only when holding mouse over variable, when execution paused).
And values of all other variables in object are wrong.
Values are correct when inside object (reading values from registry) - but outside they are not.
Probably as you mentioned, because "something" looses track of where they are.

And here's something odd.
Same problem exists for the other TSetSet object (The one whos values the editor-form can manipulate) but this instance initially has the correct values form registry.
(Holding mouse over variables name, reports the same REGLOC-error, but vlues are correct).

Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Birger52

  • Sr. Member
  • ****
  • Posts: 270
Re: static REGLOC <error reading variable> - debug error?
« Reply #9 on: August 14, 2020, 12:17:13 pm »
And now it gets spooky...

Changing declaration of objects contants to include type
Code: Pascal  [Select][+][-]
  1.    
  2.     RegLoc : string = '\Software\SDC\Play';
  3.     lGen : string = '\general';
  4.     lPlay : string = '\playlist';
  5.  

Removes the problem - that is, the reported inability to read RegLoc - but it does not make the object have the values read from registry, except inside the procedure that does the reading.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Birger52

  • Sr. Member
  • ****
  • Posts: 270
Re: static REGLOC <error reading variable> - debug error?
« Reply #10 on: August 14, 2020, 12:29:13 pm »
And then - before I downgrade to previous version, that functions - I tried to change the constants to variables, that are assigned values in a constructor.
It has the same effect as defining constants with type - no reported problem reading RegLoc, but unfortunately the object does not have the value read from the registry either.
Values are simply not the same outside the object, as they are inside...
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6592
    • wiki
Re: static REGLOC <error reading variable> - debug error?
« Reply #11 on: August 14, 2020, 12:57:25 pm »
And now it gets spooky...

Changing declaration of objects contants to include type
Code: Pascal  [Select][+][-]
  1.    
  2.     RegLoc : string = '\Software\SDC\Play';
  3.  
Well that makes them pre-initialized variables.

So new they will be a pointer to the memory in your application.

Quote
And then - before I downgrade to previous version, that functions - I tried to change the constants to variables, that are assigned values in a constructor.
It has the same effect as defining constants with type - no reported problem reading RegLoc, but unfortunately the object does not have the value read from the registry either.
Values are simply not the same outside the object, as they are inside...

I haven't tested this any further yet. (You do compile with all optimization disabled? -O- )

Have you "debugln" (unit LazLogger / console output, compile with -WC ) the values that the reader sets to the object?

Does it change, if you watch a single field? e.g. "nSet.IgnoreCards"
Is that strings only, or bools also?

----
You can always try FpDebug. Just install the package LazDebuggerFp and the change the debugger in Tools > Options > Debugger.




Birger52

  • Sr. Member
  • ****
  • Posts: 270
Re: static REGLOC <error reading variable> - debug error?
« Reply #12 on: August 14, 2020, 07:29:46 pm »
One more...

Turns out, in the version where things are working(2.0.8/3.0.4), values are also reported wrong by debugger/watches.
But the program must be using other values, than the ones presented when execution is paused.

Did like this.
Open the editor - this creates an object called Settings, which is a TSetSet, which reads its values from registry.
Before Closing - when clicking close button - another TSetSet is created - sSet, and read from Registry.
Same class, same code.
As nothing was changed in the editor, these two object now holds the same data.
The accompanying image shows watches - and data are obviously not the same in the two objects.
What is more, the comparisons that determines if messages are sent, are all true.

So according to values in Watch window (deubgger?) this should result in messages being sent to all other apps.
This does however not happen.
No messages are sent - SendIPCMsg() is never called.

So - even tho this LOOKS all wrong, it is actually behaving as it is supposed to (And I have tested, if I change things. If I make changes, messages are sent, as they should).

And what prompted all of this, was that in 2.0.10/3.2.0 code did NOT behave as expected.
In 2.0.8/3.0.4 it does.

Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6592
    • wiki
Re: static REGLOC <error reading variable> - debug error?
« Reply #13 on: August 14, 2020, 08:03:31 pm »
Hard to comment on, without further info....

Very important > Optimization level 0 "NONE".
And that includes, changing package options, if this code is in a package. (Because package have their own settings)

-O1  can screw up local variables.





Ideally if I could reproduce it. (Though that does not guarantee that it can be fixed, if it is a gdb problem)
 I.e. small example with only those classes, and hardcoded values.

Otherwise: Log, or "debug output" https://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session




One thing, I did note: "sSet: vptr$TOBJECT = 0"
That must be wrong. (Or the app has corrupted data).

That is the pointer to the VMT of the class. (i.e TClass-info). That simply cannot be nil.

Birger52

  • Sr. Member
  • ****
  • Posts: 270
Re: static REGLOC <error reading variable> - debug error?
« Reply #14 on: August 15, 2020, 12:15:26 pm »
Well ... optimization was -O1 and the code is not in a package

Setting it to 0 makes no functional difference (Program still behaves as expected).
Watch window seems to give up reading values, as it can't read RegLoc - image1.
But if specific object.var are requested, it does find the values - image2 (and yes - I did change setting for HistroyRec in the editor, so the difference is correct - I did check all the objects variables, even tho they are not all shown here in Watches).

This is in 2.0.8/3.0.4 - not tested in 2.0.10/3.2.0
and it is with the constant declaration
Code: Pascal  [Select][+][-]
  1.     private const
  2.       RegLoc = '\Software\SDC\myStrip';
  3.  
It may be different if changed to initiated vars or regulars vars initiated in a create constructor.


I will consider attempting to create a simpler example.
Will be a while, tho.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

 

TinyPortal © 2005-2018