Recent

Author Topic: FpDebug Enum question  (Read 1039 times)

440bx

  • Hero Member
  • *****
  • Posts: 5188
FpDebug Enum question
« on: April 26, 2024, 04:55:34 am »
Lazarus v3.99 (trunk)

In the attachment, the value of the variable "HighValues" is shown in both, decimal and hex.  Great feature!.

The Enum variable is supposedly displayed in "Hex", I expected the value to be $FFFFFFFF not -$1 which is basically a decimal value (an interpretation of the hex value $FFFFFFFF). 

Another thing I may not be understanding correctly is, when the "Name" radio button is selected then only the variable name is displayed, its value is no longer displayed.  I don't see how just seeing the variable name without an associated value is useful.  Am I missing something there ?

I may be missing something again but, in the snapshot, the presence of the "=" sign seems of little use.

Code used:
Code: Pascal  [Select][+][-]
  1. {$APPTYPE CONSOLE}
  2.  
  3. {$define USE_ABSOLUTE}
  4.  
  5. program _Enumerations;
  6.  
  7. type
  8.   TENUM = (e1, e2, e3);
  9.  
  10. var
  11.   {$ifndef USE_ABSOLUTE}
  12.     Enum       : TENUM = TENUM(-1);       { it won't accept this }
  13.   {$endif}
  14.  
  15.   {$ifdef USE_ABSOLUTE}
  16.     HighValues : DWORD = DWORD(-1);
  17.     Enum       : TENUM absolute HighValues;
  18.   {$endif}
  19.  
  20.  
  21.   Enum2      : TENUM;
  22.  
  23. begin
  24.   Enum2 := TENUM(-1);     { but it accepts this    }
  25.  
  26.   {$ifdef USE_ABSOLUTE}
  27.     inc(HighValues);      { needs to be referenced }
  28.   {$endif}
  29.  
  30.   readln;
  31. 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: 11050
  • Debugger - SynEdit - and more
    • wiki
Re: FpDebug Enum question
« Reply #1 on: April 26, 2024, 11:44:20 am »
The Enum variable is supposedly displayed in "Hex", I expected the value to be $FFFFFFFF not -$1 which is basically a decimal value (an interpretation of the hex value $FFFFFFFF). 
There is a checkbox (at the end of the radio row) "Unsigned".

I couldn't find docs, but looking through compiler sources it seems that enum are treated as signed.
For numbers there is signedness=auto, which does 2 things: check the type of the variable, and if it is signed, then decide based on dec vs hex.
I didn't add an "auto" for enum, as I considered it less important. So you have to explicitly change it for hex.

I did consider having the full auto/signed/unsigned choice if you switch to the "enum tab" => but then again, I considered it low value, and adding confusion by having another meaning of the "unsigned CHECKBOX" being greyed.
It can currently already be greyed for 2 reason (well one implemented, one planed)
- You select enum and bool, and they have different settings
- You edit settings for several watches at the same time (planed) // You can already edit defaults for locals and watches at the same time

Quote

Another thing I may not be understanding correctly is, when the "Name" radio button is selected then only the variable name is displayed, its value is no longer displayed.  I don't see how just seeing the variable name without an associated value is useful.  Am I missing something there ?
I think it is useful in many cases.
Usually if I look at "Form1.align" and it says clClient => that is all I need. I don't need to know the ordinal value of  alClient.

I did just check, and it is however broken => if the value is out of range (and has no name) then it ought to still give a number. (using the default format), something like TAlign(123). That it currently gives empty => bug.
--- EDIT: fixed

That also leaves the question, if in case of "both" it should then say  "TAlign(123) = $7B" or just "$7B". I think the first.

A short off topic: Such out of range values only should happen as a result of bugs in code. Otherwise the resulting behaviour is undefined (and can change with new versions of fpc). You setting it explicitly to -1 should never be coded... Currently at least "case of {all enum} else" may not enter that "else" block).

And lastly there is a difference between watching an enum-variable and an enum-identifier.

If you watch "e1" => then just name indeed makes no sense. => But  I did not add a separate setting for enum-ident in the watch properties => so the option is still shown. And because it is shown there, it is shown everywhere. In the global presets you can give different presets for "enum identifier".


I also still have to check some details when using this with boolean. That is, if the debug info provides enough info...

There is
- bytebool, longbool...
- boolean8, boolean32...

And one of those only has True=1 and False=0 and all others are not true, nor false.
The other has True= anything but 0.


Quote
I may be missing something again but, in the snapshot, the presence of the "=" sign seems of little use.
Its just a separator between the 2 forms of the value.
How else to separate them?

Note this is also used in other places, e.g. when you have colors displayed as name: clRed = $.......




Just got the idea that "set of enum" may need a "bitmap" mode. Instead of displaying the list of enum (name or number), show the bitmap as hex or bin.
« Last Edit: April 26, 2024, 11:55:57 am by Martin_fr »

440bx

  • Hero Member
  • *****
  • Posts: 5188
Re: FpDebug Enum question
« Reply #2 on: April 26, 2024, 02:03:56 pm »
Thank you Martin.  That helps understanding how it all hangs together.

Its just a separator between the 2 forms of the value.
How else to separate them?
That makes sense but, the "=" sign also seems to sometimes be there when there is only one value.  In that case, I don't see what it separates, e.g, the Enum in the screenshot above.
(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: 11050
  • Debugger - SynEdit - and more
    • wiki
Re: FpDebug Enum question
« Reply #3 on: April 26, 2024, 05:49:40 pm »
That makes sense but, the "=" sign also seems to sometimes be there when there is only one value.  In that case, I don't see what it separates, e.g, the Enum in the screenshot above.

That was because (due to the bug I mentioned), the first part wasn't printed as there was no name. It will now print
TEnum(-1) = -$1

Which is a bit of duplication... But, then not completely => the first bit tells you that it is an unnamed enum (out of range). The 2nd is the hex value, because you want a hex value. They could be combined. But given that this should be rare (enums should not be out of range, unless the code being debugger has a bug which makes it so...)

440bx

  • Hero Member
  • *****
  • Posts: 5188
Re: FpDebug Enum question
« Reply #4 on: April 26, 2024, 06:09:52 pm »
Makes sense now.

Thanks Martin. 
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018