Recent

Author Topic: When fpDebug is debugging, Currency type data shows no decimal point  (Read 4252 times)

zhuyl

  • New member
  • *
  • Posts: 8
hello
    When fpDebug is debugging, Currency type data shows no decimal point, such as a=12.48 is displayed as 1248

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9855
  • Debugger - SynEdit - and more
    • wiki
Re: When fpDebug is debugging, Currency type data shows no decimal point
« Reply #1 on: December 16, 2021, 12:48:02 pm »
Yes, it's a known issue.

It will currently happen with any debugger, as this is actually caused by the compiler.

In order for a debugger to work, the compiler adds "debug info", which among other things, describes all variables.
FPC identifies "currency" as an integer type. (IIRC 8byte signed int).

That is also how fpc actually compiles this. Currency is stored as int, not as float. The value stored is multiplied by 1000. Allowing for precisely 3 digits after the decimal dot. Because it is not stored as fraction, there is no rounding error (which is important for currency data).

Internally FPC makes sure that the data is correctly handled and displayed.
But it does not include this info for the debugger.


Currently the only difference between the types Int64 and Currency is the name.
But, the debugger can not rely on this. Since any one can define their own type currency "type Currency = int64;" and that would then NOT be a currency....

zhuyl

  • New member
  • *
  • Posts: 8
Re: When fpDebug is debugging, Currency type data shows no decimal point
« Reply #2 on: December 16, 2021, 01:47:28 pm »
I tested the gdb debugger to show that it was correct

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9855
  • Debugger - SynEdit - and more
    • wiki
Re: When fpDebug is debugging, Currency type data shows no decimal point
« Reply #3 on: December 16, 2021, 02:25:36 pm »
Just checked. Indeed my feedback was incomplete.


Fpc provides 2 types of debug info: Stabs and Dwarf (in diff versions).

When Fpc writes Dwarf (version 2 or 3, and afaik also version 4) then it declares an int value.
With stabs it writes debug info that seems to be correct.

Unfortunately FpDebug only supports Dwarf.

Actually from a brief look at the Dwarf spec, it seems they support a proper declaration.  Yet, this needs to be still added to fpdebug. I will see when I can find time to add it, but even when added, it wont do anything until fpc follows up.

I tested fpc 3.2.3 64bit win, and it did not use this, but described it as plain int (using dwarf).
Not tested 3.3.1.


EDIT:
To fast again.

The IDE-gdb translator actually has a hardcoded check for "currency".

But that means, if you declare your own type then it will also be shown with decimal point. (still depends, on debug info version, upper/lower, .... But it can happen, I managed to make it happen)
Code: Pascal  [Select][+][-]
  1. type CURRENCY = 1..999999;
  2. var a: CURRENCY;
  3.  



Dwarf vs Stabs

This (according to what I was told) also affects how "file of ..." is displayed.

If you us "variant", then select "Dwarf 2 (with sets)" for fpdebug, as it does not display with Dwarf 3 yet.

« Last Edit: December 16, 2021, 02:36:19 pm by Martin_fr »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9855
  • Debugger - SynEdit - and more
    • wiki
Re: When fpDebug is debugging, Currency type data shows no decimal point
« Reply #4 on: December 16, 2021, 02:37:41 pm »
I'll see, if I add a check to FpDebug. If I find time. It will probably be optional, and default to off (Because it can affect other data, if currency is re-declared).

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
Re: When fpDebug is debugging, Currency type data shows no decimal point
« Reply #5 on: December 16, 2021, 06:04:22 pm »

FPC identifies "currency" as an integer type. (IIRC 8byte signed int).

That is also how fpc actually compiles this. Currency is stored as int, not as float. The value stored is multiplied by 1000. Allowing for precisely 3 digits after the decimal dot.
multiplied by 10'000
Allowing for precisely 4 digits after the decimal dot.

 

TinyPortal © 2005-2018