Recent

Author Topic: Unable To Step Into Writeln Using F7  (Read 8828 times)

Aruna

  • Hero Member
  • *****
  • Posts: 574
Unable To Step Into Writeln Using F7
« on: January 09, 2025, 12:47:17 am »
Hello Everyone, I tried:

Code: Pascal  [Select][+][-]
  1.  WriteLn(Format('%m', [1234.56])); // Output: $1,234.56 (locale-dependent)

And it works but the '$' sign is not at the beginning as expected it is at the end of the displayed output. The attached screenshot shows this. I tried to debug and step through the Writeln function to see how it does things but have so far been unable to do so. I think I need to have the debug info compiled in?

How does one go about doing this, please? And is this the expected behaviour for a format string of '%m' ?

440bx

  • Hero Member
  • *****
  • Posts: 5001
Re: Unable To Step Into Writeln Using F7
« Reply #1 on: January 09, 2025, 01:19:05 am »
The documentation for %M states that the currency sign is _appended_.  It doesn't say anything  about its position being locale dependent.

see it at https://www.freepascal.org/docs-html/rtl/sysutils/format.html

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

Thaddy

  • Hero Member
  • *****
  • Posts: 16532
  • Kallstadt seems a good place to evict Trump to.
Re: Unable To Step Into Writeln Using F7
« Reply #2 on: January 09, 2025, 02:41:45 am »
To step into things like writeln you need to build a debug version of the compiler. Writeln is not in any library but a compiler intrinsic.
Once you have done that, you can step into writeln.
But I am sure they don't want the Trumps back...

TRon

  • Hero Member
  • *****
  • Posts: 3976
Re: Unable To Step Into Writeln Using F7
« Reply #3 on: January 09, 2025, 03:26:14 am »
And it works but the '$' sign is not at the beginning as expected it is at the end of the displayed output.
Although it is being described in the help that %m appends the currency symbol, on linux it is actually locale dependent.

Did you add the clocale unit to your test example ? If you did and the currency symbol is still displayed after the numbers then you would need to change that in the system locale settings or use a custom formatstring with FormatCurr().

As an alternative you could also fiddle with FormatSettings.CurrencyFormat. For details see https://www.freepascal.org/docs-html/rtl/sysutils/negcurrformat.html (yes, I know it says negcurrformat and that it is deprecated but please don't mind that as this is the only place where it seems listed in the help).


on my system without clocale:
Code: Bash  [Select][+][-]
  1. 1,234.56$

on my system with clocale
Code: Bash  [Select][+][-]
  1. 1.234,56
« Last Edit: January 09, 2025, 03:33:31 am by TRon »
I do not have to remember anything anymore thanks to total-recall.

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Unable To Step Into Writeln Using F7
« Reply #4 on: January 09, 2025, 03:33:42 am »
The documentation for %M states that the currency sign is _appended_.  It doesn't say anything  about its position being locale dependent.
see it at https://www.freepascal.org/docs-html/rtl/sysutils/format.html
HTH.
I am on Linux that could be why. Thank you for  the doc link.

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Unable To Step Into Writeln Using F7
« Reply #5 on: January 09, 2025, 03:36:39 am »
To step into things like writeln you need to build a debug version of the compiler. Writeln is not in any library but a compiler intrinsic.
Once you have done that, you can step into writeln.
Thank you Thaddy. Are there any recommended/preffered switches/flags or other-things to add when building a debug version of the compiler?  And do we have any documentation on how to go about building a debug version of the compiler, please?

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Unable To Step Into Writeln Using F7
« Reply #6 on: January 09, 2025, 03:43:14 am »
Although it is being described in the help that %m appends the currency symbol, on linux it is actually locale dependent.
This is what I was starting to think as well. Thank you for confirming my suspicions.

Did you add the clocale unit to your test example ? If you did and the currency symbol is still displayed after the numbers then you would need to change that in the system locale settings or use a custom formatstring with FormatCurr().
As always you were right. I added clocal and now it displays where "I" like currency symbols to be as a prefix.

As an alternative you could also fiddle with FormatSettings.CurrencyFormat. For details see https://www.freepascal.org/docs-html/rtl/sysutils/negcurrformat.html (yes, I know it says negcurrformat and that it is deprecated but please don't mind that as this is the only place where it seems listed in the help).
Thank you @Tron I will go through the link.

on my system without clocale:
Code: Bash  [Select][+][-]
  1. 1,234.56$

on my system with clocale
Code: Bash  [Select][+][-]
  1. 1.234,56
Exact same scenario in my Debian. Works after adding clocale like you said. Many thanks and much obliged. @Tron what would be the best+easiest way to build a debug version of the compiler?

Thaddy

  • Hero Member
  • *****
  • Posts: 16532
  • Kallstadt seems a good place to evict Trump to.
Re: Unable To Step Into Writeln Using F7
« Reply #7 on: January 09, 2025, 07:48:23 am »
Thank you Thaddy. Are there any recommended/preffered switches/flags or other-things to add when building a debug version of the compiler?  And do we have any documentation on how to go about building a debug version of the compiler, please?
The simplest way is to use fpcupdeluxe setup+ and select both debug boxes to the top right hand side of the dialog.
In this case using fpcupdeluxe is highly recommended because it is easy to set up the debug compiler with its own path/environment. That is important because you really do not want to use the debug build for anything other than debugging compiler internals or the rtl.
« Last Edit: January 09, 2025, 03:40:36 pm by Thaddy »
But I am sure they don't want the Trumps back...

TRon

  • Hero Member
  • *****
  • Posts: 3976
Re: Unable To Step Into Writeln Using F7
« Reply #8 on: January 09, 2025, 12:52:09 pm »
As always you were right.
Thank you for the confidence but please be careful. I am more wrong than I am am right  :-X

Quote
Exact same scenario in my Debian. Works after adding clocale like you said.
Do realize that the locale can be anything when the application is ran on another setup e.g. it does not have to output the same on another machine/setup/config. In case that is an actual requirement (f.i. always display dollars instead of user's locale preference) then there is need to let your code use custom formatsettings (e.g. adjusted to the programs need to always display dollars).

Quote
Many thanks and much obliged. @Tron what would be the best+easiest way to build a debug version of the compiler?
You're most welcome.

As described by Thaddy using fpcupdeluxe for a separate installation (for both FPC and Lazarus) with debug information usually would be the easiest especially in case not familiar with building the compiler from source.
I do not have to remember anything anymore thanks to total-recall.

rvk

  • Hero Member
  • *****
  • Posts: 6662
Re: Unable To Step Into Writeln Using F7
« Reply #9 on: January 09, 2025, 01:41:47 pm »
Quote
As described by Thaddy using fpcupdeluxe for a separate installation (for both FPC and Lazarus) with debug information usually would be the easiest especially in case not familiar with building the compiler from source.
And if you're not familiar with compiling the source of FPC, you probably don't have much use of 'stepping into' the writeln() procedure.

Besides... you don't want the writeln() anyway... you want the Format() function.
And for that you can put your cursor on Format(), press Alt+Up, then press Ctrl+Shift+Down.
With those keys you can jump all around the sourcecode.

Thaddy

  • Hero Member
  • *****
  • Posts: 16532
  • Kallstadt seems a good place to evict Trump to.
Re: Unable To Step Into Writeln Using F7
« Reply #10 on: January 09, 2025, 02:08:08 pm »
Besides... you don't want the writeln() anyway... you want the Format() function.
I prefer the formatting capabilities of writeln to Format and family, because it does not rely on sysutils and is just as powerful.
Except here the m option.

Ah, misinterpreted, I see what you mean, he needs to step into format, that makes sense.
« Last Edit: January 09, 2025, 02:51:18 pm by Thaddy »
But I am sure they don't want the Trumps back...

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Unable To Step Into Writeln Using F7
« Reply #11 on: January 10, 2025, 12:49:37 am »
Thank you Thaddy. Are there any recommended/preffered switches/flags or other-things to add when building a debug version of the compiler?  And do we have any documentation on how to go about building a debug version of the compiler, please?
The simplest way is to use fpcupdeluxe setup+ and select both debug boxes to the top right hand side of the dialog.
In this case using fpcupdeluxe is highly recommended because it is easy to set up the debug compiler with its own path/environment. That is important because you really do not want to use the debug build for anything other than debugging compiler internals or the rtl.
Thank you again for the guidance. I want to try and build it from the source without using fpcupdeluxe if I can. I will use fpcupdeluxe if everything else I try fails :)

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Unable To Step Into Writeln Using F7
« Reply #12 on: January 10, 2025, 12:57:36 am »
As always you were right.
Thank you for the confidence but please be careful. I am more wrong than I am am right  :-X
Thanks I will be careful :)

Do realize that the locale can be anything when the application is ran on another setup e.g. it does not have to output the same on another machine/setup/config. In case that is an actual requirement (f.i. always display dollars instead of user's locale preference) then there is need to let your code use custom formatsettings (e.g. adjusted to the programs need to always display dollars).
Thank you @TRon I am just trying to learn the available format specifiers and how to use them.

As described by Thaddy using fpcupdeluxe for a separate installation (for both FPC and Lazarus) with debug information usually would be the easiest especially in case not familiar with building the compiler from source.
I am grateful to @Thaddy for showing me the safest way to proceed forward but if I use fpcupdeluxe then I will never learn how to build the compiler from source. So I will give building from the source a try, and then failing will give fpcdeluxe a shot?

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Unable To Step Into Writeln Using F7
« Reply #13 on: January 10, 2025, 01:12:47 am »
Quote
As described by Thaddy using fpcupdeluxe for a separate installation (for both FPC and Lazarus) with debug information usually would be the easiest especially in case not familiar with building the compiler from source.
And if you're not familiar with compiling the source of FPC, you probably don't have much use of 'stepping into' the writeln() procedure.
Hello @rvk, yes I am not familiar with building the compiler from the source (yet) and yes I do have a reason for wanting to step through both writeln() and format() purely for my own understanding how things work under the hood.

Besides... you don't want the writeln() anyway... you want the Format() function.
And for that you can put your cursor on Format(), press Alt+Up, then press Ctrl+Shift+Down.
With those keys you can jump all around the sourcecode.
Thank you, I did this already and though it lets me jump around the code it is not the same thing as bein able to single-step and examine/watch how things are done.

So please help me to build from source if you do not mind doing so? I have: 
Code: Pascal  [Select][+][-]
  1. /usr/share/fpcsrc/3.2.2/
There is a Makefile in there.

I also have:
Code: Pascal  [Select][+][-]
  1.  /usr/share/fpcsrc/3.2.2/compiler
And another Makefile. Which one do I use to build and which switches/flags do I use to get a debug build? 

If the time to build is not too long I am thinking I will simply build a debug version anytime I need to understand a compiler intrinsic or RTL and revert back once done to a normal build.

Aruna

  • Hero Member
  • *****
  • Posts: 574
Re: Unable To Step Into Writeln Using F7
« Reply #14 on: January 10, 2025, 01:41:44 am »
I asked chatGPT and this was generated. Is this correct:
Code: Pascal  [Select][+][-]
  1. make clean all OPT="-g -dDEBUG"

 

TinyPortal © 2005-2018