Recent

Author Topic: How to step in within debugger into standard library files (fpjson)?  (Read 455 times)

YVK

  • Newbie
  • Posts: 2
Hi all,

I am trying to read valid json5 file
Code: Javascript  [Select][+][-]
  1. {
  2.         interface : {
  3.                 netaddr : [192,168,8,10],
  4.                 netmask : [255,255,255,0],
  5.                 gateway : [192,168,8,1],
  6.                 macaddr : 0x1c8025000001
  7.         },
  8.         segment : [
  9.                 {
  10.                         slot: 1,
  11.                         device: 'EGH.001',
  12.                         version: 0x0001,
  13.                         config: {
  14.                                 protocol: 'IENA',
  15.                                 netdst: {
  16.                                         netaddr: [232,0,8,111],
  17.                                         port: 5546
  18.                                                 }
  19.                                         }
  20.                 },
  21.  
  22.                 {
  23.                         slot: 2,
  24.                         device: 'ADC.001',
  25.                         version: 0x0001,
  26.                         config: {
  27.                                 period: 200,
  28.                                 channels: 1,
  29.                                 samples: 104,
  30.                                 stream: 102
  31.                                         }
  32.                 },
  33.  
  34.                 {
  35.                         slot: 3,
  36.                         device: 'ADC.001',
  37.                         version: 0x0001,
  38.                         config: {
  39.                                 period: 200,
  40.                                 channels: 1,
  41.                                 samples: 103,
  42.                                 stream: 103
  43.                                         }
  44.                 },
  45.  
  46.                 {
  47.                         slot: 4,
  48.                         device: 'ADC.001',
  49.                         version: 0x0001,
  50.                         config: {
  51.                                 period: 200,
  52.                                 channels: 1,
  53.                                 samples: 98,
  54.                                 stream: 104
  55.                                         }
  56.                 }
  57.         ],
  58.         schedule : [
  59.                 0x01, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  60.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  61.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  62.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  63.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  64.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  65.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  66.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  67.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  68.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  69.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  70.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  71.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  72.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  73.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  74.                 0x00, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04, 0x02, 0x03, 0x04,
  75.         ]
  76. }
  77.  

using Lazarus 2.0.10 on Win 10 with this project compiled in debug mode:

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   Forms, Unit1
  11.   { you can add units after this };
  12.  
  13. {$R *.res}
  14.  
  15. begin
  16.   RequireDerivedFormResource:=True;
  17.   Application.Scaled:=True;
  18.   Application.Initialize;
  19.   Application.CreateForm(TForm1, Form1);
  20.   Application.Run;
  21. end.
  22.  

where reading is plain simple:
Code: Pascal  [Select][+][-]
  1. unit uJSON;
  2.  
  3.   {$MODE objfpc}
  4.   {$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   SysUtils,
  10.   Classes,
  11.   fpjson;
  12.  
  13. function LoadFromFile(aFilename: string):TJSONData;
  14.  
  15. implementation
  16.  
  17. function LoadFromFile(aFilename: string):TJSONData;
  18. var
  19.   str: TFPJSStream;
  20. begin
  21.   result:= nil;
  22.   str := TFPJSStream.Create;
  23.   try
  24.     str.LoadFromFile(aFilename);
  25.     result := GetJSON(str);
  26.   finally
  27.     str.Free;
  28.   end;
  29. end;
  30.  
  31. initialization
  32.  
  33. finalization
  34.  
  35. end.
  36.  

and it is used on creation of the form

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     procedure FormCreate(Sender: TObject);
  16.   private
  17.  
  18.   public
  19.  
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. uses
  30.     uJSON, fpjson;
  31. { TForm1 }
  32.  
  33. procedure TForm1.FormCreate(Sender: TObject);
  34. var
  35.   f: uJSON.TFDLJSONDescr;
  36.   js: TJSONData;
  37.   sFN: string = 'C:\D\mess\eye\data\config.json';
  38. begin
  39.   js := uJSON.LoadFromFile( sFN );
  40. end;
  41.  
  42. end.
  43.  

but I've got an exception at first hexadecimal token within json.

I am suspecting it might be an option that has to be enabled for some internal object, but stepping in debugger I can step in within proximity of my files, but not into fpjson for some reason.
In other words, when I've got to GetJSON invocation next Step In (F7 in my case) works like step over (F8) and I've got immediately exception.
I see stack but would not be able to get into source from there either.

How can I enable debugging of standard library files?

Thaddy

  • Hero Member
  • *****
  • Posts: 10568
Re: How to step in within debugger into standard library files (fpjson)?
« Reply #1 on: September 29, 2020, 01:42:46 pm »
If you want to do that, you need to build FPC - or the library you want to debug - with debug information. That needs to be done from source.
The official distributions do not contain debug information for the standard libraries.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6705
  • Debugger - SynEdit - and more
    • wiki
Re: How to step in within debugger into standard library files (fpjson)?
« Reply #2 on: September 29, 2020, 03:38:26 pm »
You can either rebuild the entire FPC. There is a Makefile, so you need to use "make" (and google the details).

You can also do this by using fpcupdeluxe, and create a 2nd fpc installation with debug info, then in the IDE under Tools>Options change the path to fpc.


fpjson is afaik a package in the fpc distro.
Sometimes you can just rebuild that one package. (If you do not use other prebuild packages that depend on it)
Create a copy and an that a Lazarus package for the code, and recompile it. Temporarily remove the old package.

If that works without hickups => good. Otherwise => fcpupdeluxe

MarkMLl

  • Hero Member
  • *****
  • Posts: 1445
Re: How to step in within debugger into standard library files (fpjson)?
« Reply #3 on: September 29, 2020, 05:38:50 pm »
Martin, is there any way that one can query the about dialog(ue) etc. to get any idea how the IDE's been built?

I can see that e.g. trunk has an SVN revision etc., but some sort of indication as to whether e.g. the LCL had debug symbols would be valuable from a support POV.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6705
  • Debugger - SynEdit - and more
    • wiki
Re: How to step in within debugger into standard library files (fpjson)?
« Reply #4 on: September 29, 2020, 06:08:32 pm »
Martin, is there any way that one can query the about dialog(ue) etc. to get any idea how the IDE's been built?

I can see that e.g. trunk has an SVN revision etc., but some sort of indication as to whether e.g. the LCL had debug symbols would be valuable from a support POV.

Not that I am aware of.

If you (re)build yourself then you can check for each package in the package options. (you need to click "show options" to see the final applied opitons).
The releases are build via Makefiles, and may have extra arguments passed in.

As for the fpc parts (rtl / fpc packages), those are afaik a black box to the IDE in regards of debug info.

--
Each of them have .o files. So with the correct tools (objdump ??) in a script, it might be possible to get some info on the presence of debug info. (Though that may still be limited in usage, if optimization was turned on)
I have not looked deeper into how/if that can be done.

--
As for getting as much debug info as possible the easy way: Most Lazarus packages include $(IDEBuildOptions) (or similar). So configuring -gw - godwarfsets / -gw3 in "Tools > config build laz" should get a lot of debug info.

YVK

  • Newbie
  • Posts: 2
Re: How to step in within debugger into standard library files (fpjson)?
« Reply #5 on: September 29, 2020, 06:19:04 pm »
You can either rebuild the entire FPC. There is a Makefile, so you need to use "make" (and google the details).

You can also do this by using fpcupdeluxe, and create a 2nd fpc installation with debug info, then in the IDE under Tools>Options change the path to fpc.


fpjson is afaik a package in the fpc distro.
Sometimes you can just rebuild that one package. (If you do not use other prebuild packages that depend on it)
Create a copy and an that a Lazarus package for the code, and recompile it. Temporarily remove the old package.

If that works without hickups => good. Otherwise => fcpupdeluxe

Both options did not work.

Option1 will be overkill for me, I would like to focus on solving my task, where json is just a persistency format. It would be similar to ''if file is not accessible - reformat the C: drive!'' plus, I found in the installation there is a debug version of Lazarus on a separate shortcut, but the final result was the same: I was not be able to step in in debugger.

Option2 will be reasonable, but after reading https://wiki.lazarus.freepascal.org/fppkg
I've run and got this
Code: Text  [Select][+][-]
  1. C:\T\lazarus\fpc\3.2.0\source\packages\fcl-json>fppkg install fcl-json
  2. The FPC Package tool encountered the following error:
  3. [fcl-json] Package dependency rtl <none> is not available
  4.  

in fact I've got the same on every package I was tried to install with fppkg

for example, if I would try

fppkg install rtl-objpas

I will get the same error as well.

looking at %LOCALAPPDATA%\FreePascal\fppkg\archives\rtl-objpas-3.2.source\manifest.xml
Code: XML  [Select][+][-]
  1. <?xml version="1.0"?>
  2. <packages>
  3. <package name="rtl-objpas">
  4.  <version major="3" minor="2"/>
  5.  <oses>
  6.   <os name="linux"/>
  7.   <os name="go32v2"/>
  8.   <os name="win32"/>
  9.   <os name="os2"/>
  10.   <os name="freebsd"/>
  11.   <os name="beos"/>
  12.   <os name="netbsd"/>
  13.   <os name="amiga"/>
  14.   <os name="atari"/>
  15.   <os name="solaris"/>
  16.   <os name="netware"/>
  17.   <os name="openbsd"/>
  18.   <os name="darwin"/>
  19.   <os name="emx"/>
  20.   <os name="watcom"/>
  21.   <os name="morphos"/>
  22.   <os name="netwlibc"/>
  23.   <os name="win64"/>
  24.   <os name="wince"/>
  25.   <os name="gba"/>
  26.   <os name="nds"/>
  27.   <os name="symbian"/>
  28.   <os name="haiku"/>
  29.   <os name="iphonesim"/>
  30.   <os name="aix"/>
  31.   <os name="android"/>
  32.   <os name="nativent"/>
  33.   <os name="msdos"/>
  34.   <os name="wii"/>
  35.   <os name="aros"/>
  36.   <os name="dragonfly"/>
  37.  </oses>
  38.  <filename>rtl-objpas-3.2.source.zip</filename>
  39.  <author>FPC core team</author>
  40.  <license>LGPL with modification, </license>
  41.  <homepageurl>www.freepascal.org</homepageurl>
  42.  <email></email>
  43.  <description>Rtl-objpas, aux. Delphi compat units</description>
  44.  <dependencies>
  45.   <dependency>
  46.    <package packagename="rtl"/>
  47.   </dependency>
  48.  </dependencies>
  49. </package>
  50. </packages>
  51.  

there is clear dependency with packagename="rtl", but there is no such package within the output of
Code: Text  [Select][+][-]
  1. fppkg list


I would appreciate if someone could point me out how I can fix the fppkg?
as it seems very handy...

Anyway, at the end I've simply add all source file from the package folder lazarus\fpc\3.2.0\source\packages\fcl-json\src into my project and rebuild it in Debug mode.
And that had worked, so now I have to adopt the code to be gentle on json5 format as well.

But if I have to do the same for every package - that will be absolutely awkward.
Surely should be even simpler way

Any ideas?

Many thanks!

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6705
  • Debugger - SynEdit - and more
    • wiki
Re: How to step in within debugger into standard library files (fpjson)?
« Reply #6 on: September 29, 2020, 06:33:46 pm »
fppkg is not the same as fpcupdeluxe (though I have used neither).

fpcupdeluxe, downloads from svn (but you need no knowlegde, other than selecting the version you want.
And potentially install svn on your system....

https://wiki.lazarus.freepascal.org/fpcupdeluxe

MarkMLl

  • Hero Member
  • *****
  • Posts: 1445
Re: How to step in within debugger into standard library files (fpjson)?
« Reply #7 on: September 29, 2020, 08:22:54 pm »
Each of them have .o files. So with the correct tools (objdump ??) in a script, it might be possible to get some info on the presence of debug info. (Though that may still be limited in usage, if optimization was turned on)
I have not looked deeper into how/if that can be done.

For unix-like OSes, the file command applied to the IDE appears to be a useful starting point. Comparatively few people will be rebuilding the IDE and LCL separately, and any sort of hint would be useful when somebody comes along with "can't debug...".

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6705
  • Debugger - SynEdit - and more
    • wiki
Re: How to step in within debugger into standard library files (fpjson)?
« Reply #8 on: September 29, 2020, 08:42:01 pm »
any sort of hint would be useful when somebody comes along with "can't debug...".

Well yes, a lot of better feedback (especially when things do not work) would be nice.

Of course when stepping over/into the debugger has no idea you tried to step into code that is not debug-able.
There is no difference to using F7 to step over a line of code that indeed you do want to step over.
- F7 is valid for stepping over
- Few people want to step into stuff like fpc_ansistring_assign

Setting a breakpoint in a file that has no debug info could be detected. But only while running, when the debugger can check the exe file for the debug info.
Indeed the breakpoint will have a diff color, if it is not applicable.
Whats missing is a help item: why is the breakpoint orange, instead of red.


 

TinyPortal © 2005-2018