code-debug icon indicating copy to clipboard operation
code-debug copied to clipboard

Progress made with Lazarus/Free Pascal + Native Debug

Open carlca opened this issue 8 years ago • 30 comments

lldb --version: lldb-370.0.42 -

Hello, further to my post a couple of months ago https://github.com/WebFreak001/code-debug/issues/106 , I have tried again with Native Pascal, and have managed to get further this time.

I'm not seeing the flurry of error messages in the debug console so that's good. I am, however, still having problems accessing variables. As you can see from the screenshot below, I have, for example, a variable called Code. This is an instance of the TCodeBuffer class. The default entry in the variable list doesn't work because Lazarus/FPC does a dereferencing trick to make the true value of *Code appear as Code in the code. If however, I add a watch with the variable specified as *CODE then I get to see the variables class name displayed. It also successfully displays simple class members, such as strings, numbers and booleans.

The second screen shot shows the Xcode application working with LLDB to debug the same Lazarus/FPC application. My logic is that if Xcode can do it, then it must be theoretically possible for Native Debug to do the same thing. I'm not suggesting it's easy, just theoretically possible!

screen shot 2017-07-26 at 17 18 37

screen shot 2017-07-26 at 17 26 02

Why not just use Xcode, you may ask. Well, VSCode is a much more pleasant application to use compare to Xcode, IMO.

I know you said you don't have any FPC/Lazarus/Pascal experience but hopefully, I've been able to supply a little more useful information this time.

To recap then, can you help me uncover more of LLDB's hidden variable information?

Thanks in advance, Carl

carlca avatar Jul 26 '17 16:07 carlca

can you send me some source that is as minimal as possible to replicate the problem?

WebFreak001 avatar Jul 26 '17 18:07 WebFreak001

Hi Jan, thanks for the reply.

I’ve uploaded a sample app to https://dropfile.to/mpZpcbp access code is D51wjvO.

It’s a simple console app with a simplified but similar structure to the app I’m working on at the moment.

Try putting a breakpoint in the Pascal source file uwebfreak.pas

Cheers, Carl

On 26 Jul 2017, 19:39 +0100, Jan Jurzitza [email protected], wrote:

can you send me some source that is as minimal as possible to replicate the problem? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

carlca avatar Jul 26 '17 19:07 carlca

Could you provide me with build instructions?

I tried lazbuild webfreak.lpi but it errored:

Error: (lazarus) invalid Lazarus directory "": directory lcl not found
Error: (lazarus) Building failed: webfreak.lpi

WebFreak001 avatar Jul 26 '17 20:07 WebFreak001

Give me a few minutes. I built it from within Lazarus itself with no special parameters, but I’ll try and see what are the correct parameters for using Lazbuild...

On 26 Jul 2017, 21:09 +0100, Jan Jurzitza [email protected], wrote:

Could you provide me with build instructions? I tried lazbuild webfreak.lpi but it errored:

Error: (lazarus) invalid Lazarus directory "": directory lcl not found Error: (lazarus) Building failed: webfreak.lpi

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

carlca avatar Jul 26 '17 20:07 carlca

I do have the following environment variables set:

Lazarus stuff

export PP=/usr/local/bin/fpc export FPCDIR=/usr/local/share/fpcsrc export LAZARUSDIR=/Developer/lazarus export FPCTARGET=i386-darwin export FPCTARGETCPU=i386

The paths are based on standard default installations of Lazarus.

I don’t know if Lazbuild uses them or not...

On 26 Jul 2017, 21:16 +0100, Carl Caulkett [email protected], wrote:

Give me a few minutes. I built it from within Lazarus itself with no special parameters, but I’ll try and see what are the correct parameters for using Lazbuild...

On 26 Jul 2017, 21:09 +0100, Jan Jurzitza [email protected], wrote:

Could you provide me with build instructions? I tried lazbuild webfreak.lpi but it errored:

Error: (lazarus) invalid Lazarus directory "": directory lcl not found Error: (lazarus) Building failed: webfreak.lpi

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

carlca avatar Jul 26 '17 20:07 carlca

Do you have the full Lazarus installed or just Free Pascal?

On 26 Jul 2017, 21:24 +0100, Carl Caulkett [email protected], wrote:

I do have the following environment variables set:

Lazarus stuff

export PP=/usr/local/bin/fpc export FPCDIR=/usr/local/share/fpcsrc export LAZARUSDIR=/Developer/lazarus export FPCTARGET=i386-darwin export FPCTARGETCPU=i386

The paths are based on standard default installations of Lazarus.

I don’t know if Lazbuild uses them or not...

On 26 Jul 2017, 21:16 +0100, Carl Caulkett [email protected], wrote:

Give me a few minutes. I built it from within Lazarus itself with no special parameters, but I’ll try and see what are the correct parameters for using Lazbuild...

On 26 Jul 2017, 21:09 +0100, Jan Jurzitza [email protected], wrote:

Could you provide me with build instructions? I tried lazbuild webfreak.lpi but it errored:

Error: (lazarus) invalid Lazarus directory "": directory lcl not found Error: (lazarus) Building failed: webfreak.lpi

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

carlca avatar Jul 26 '17 20:07 carlca

both, are you sure the lpi file is correct? It references <PackageName Value="LCL"/> and stuff

WebFreak001 avatar Jul 26 '17 20:07 WebFreak001

That lip should have compiled, but I have removed the lcl dependency.

Try this…

https://dropfile.to/EjVxCW9 access key: fSNzkRg

On 26 Jul 2017, 21:36 +0100, Jan Jurzitza [email protected], wrote:

both, are you sure the lpi file is correct? It references <PackageName Value="LCL"/> and stuff — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

carlca avatar Jul 26 '17 20:07 carlca

I’m sorry to mess you around. I do appreciate the effort you are taking over this!

On 26 Jul 2017, 21:44 +0100, Carl Caulkett [email protected], wrote:

That lip should have compiled, but I have removed the lcl dependency.

Try this…

https://dropfile.to/EjVxCW9 access key: fSNzkRg

On 26 Jul 2017, 21:36 +0100, Jan Jurzitza [email protected], wrote:

both, are you sure the lpi file is correct? It references <PackageName Value="LCL"/> and stuff — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

carlca avatar Jul 26 '17 20:07 carlca

what's your build procedure, I haven't setup anything yet, I just installed lazarus and fpc from the arch repositories

WebFreak001 avatar Jul 26 '17 20:07 WebFreak001

Did you start Lazarus so far? AFAIK it's doing some configuration on first start up.

Wosi avatar Jul 26 '17 20:07 Wosi

uhh I didn't install any gui with it yet, but I can get the gui for lazarus and try that

WebFreak001 avatar Jul 26 '17 21:07 WebFreak001

I installed Lazarus/Free Pascal by this procedure:

From this page https://sourceforge.net/projects/lazarus/files/Lazarus%20Mac%20OS%20X%20i386/Lazarus%201.8.0RC3/

Download

fpc-3.0.2.intel-macosx.dmg

fpc-src-3.0.2-macosx.dmg

lazarus-1.8.0-RC3-i686-macosx.dmg

Very important. Install the above disk images in the above sequence.

That should give you an environment capable of building any standard Lazarus app, such as the one I sent.

On 26 Jul 2017, 21:49 +0100, Jan Jurzitza [email protected], wrote:

what's your build procedure, I haven't setup anything yet, I just installed lazarus and fpc from the arch repositories — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

carlca avatar Jul 26 '17 21:07 carlca

ok I managed to build it and I can reproduce crashes now when trying to expand the variable, I will try to find out the reason.

WebFreak001 avatar Jul 26 '17 21:07 WebFreak001

This seems like an lldb issue to me

(lldb) breakpoint set -f uwebfreak.pas -l 51
Breakpoint 1: where = webfreak`RUNWEBFREAK + 180 at uwebfreak.pas:51, address = 0x00000000004724e4
(lldb) run
Process 1755 launched: './webfreak' (x86_64)
Process 1755 stopped
* thread #1, name = 'webfreak', stop reason = breakpoint 1.1
    frame #0: webfreak`RUNWEBFREAK(this=0x00007ffff7fa3100) at uwebfreak.pas:51
   48  	  List := TStringList.Create;
   49  	  try
   50  	    for I := 0 to 99 do
-> 51  	      List.Add(IntToStr(I));
   52  	    writeLn(List.Text);
   53  	  finally
   54  	    List.Free;
(lldb) bt
* thread #1, name = 'webfreak', stop reason = breakpoint 1.1
  * frame #0: webfreak`RUNWEBFREAK(this=0x00007ffff7fa3100) at uwebfreak.pas:51
    frame #1: webfreak`RUN(this=0x00007ffff7fa3100) at uwebfreak.pas:30
    frame #2: webfreak`main at webfreak.lpr:15
    frame #3: 0x000000000040018c webfreak`_start + 64
(lldb) print LIST
error: need to add support for DW_TAG_base_type 'FormalDef' encoded with DW_ATE = 0x7, bit_size = 0
error: need to add support for DW_TAG_base_type 'EXTENDED' encoded with DW_ATE = 0x4, bit_size = 80
Stack dump:
0.	HandleCommand(command = "print LIST")
1.	<eof> parser at end of file
2.	Parse:41:16: Generating code for declaration 'TWEBFREAK::$__lldb_expr'
fish: “lldb ./webfreak” terminated by signal SIGSEGV (Address boundary error)

WebFreak001 avatar Jul 26 '17 21:07 WebFreak001

As I mentioned, though, on my system, if I run Xcode with LLDB, I can access the variables, It’s only with Native Debug with LLDB that I’m having problems. That’s what was shown in the screen shots I initially sent.

On 26 Jul 2017, 22:14 +0100, Jan Jurzitza [email protected], wrote:

This seems like an lldb issue to me

(lldb) breakpoint set -f uwebfreak.pas -l 51 Breakpoint 1: where = webfreak`RUNWEBFREAK + 180 at uwebfreak.pas:51, address = 0x00000000004724e4 (lldb) run Process 1755 launched: './webfreak' (x86_64) Process 1755 stopped

  • thread #1, name = 'webfreak', stop reason = breakpoint 1.1 frame #0: webfreak`RUNWEBFREAK(this=0x00007ffff7fa3100) at uwebfreak.pas:51 48 List := TStringList.Create; 49 try 50 for I := 0 to 99 do -> 51 List.Add(IntToStr(I)); 52 writeLn(List.Text); 53 finally 54 List.Free; (lldb) bt
  • thread #1, name = 'webfreak', stop reason = breakpoint 1.1
  • frame #0: webfreakRUNWEBFREAK(this=0x00007ffff7fa3100) at uwebfreak.pas:51 frame #1: webfreakRUN(this=0x00007ffff7fa3100) at uwebfreak.pas:30 frame #2: webfreakmain at webfreak.lpr:15 frame #3: 0x000000000040018c webfreak_start + 64 (lldb) print LIST error: need to add support for DW_TAG_base_type 'FormalDef' encoded with DW_ATE = 0x7, bit_size = 0 error: need to add support for DW_TAG_base_type 'EXTENDED' encoded with DW_ATE = 0x4, bit_size = 80 Stack dump:
  1.  HandleCommand(command = "print LIST")
    
  2.  <eof> parser at end of file
    
  3.  Parse:41:16: Generating code for declaration 'TWEBFREAK::$__lldb_expr'
    

fish: “lldb ./webfreak” terminated by signal SIGSEGV (Address boundary error)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

carlca avatar Jul 26 '17 21:07 carlca

well I used lldb without any extension or code in between there, and if I can't get the command line debugger to work I won't be able to fix an extension using it. I am using lldb version 4.0.1 which should be newer than your version there.

WebFreak001 avatar Jul 26 '17 21:07 WebFreak001

Maybe Xcode is using undocumented means of accessing the information then. Which would be a shame, but never mind. Just out of interest, where did you get lldb version 4.0.1 from?

On 26 Jul 2017, 22:28 +0100, Jan Jurzitza [email protected], wrote:

well I used lldb without any extension or code in between there, and if I can't get the command line debugger to work I won't be able to fix an extension using it. I am using lldb version 4.0.1 which should be newer than your version there. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

carlca avatar Jul 26 '17 21:07 carlca

yaourt -S lldb, it's an archlinux package https://www.archlinux.org/packages/extra/x86_64/lldb/

WebFreak001 avatar Jul 26 '17 21:07 WebFreak001

I think I have misunderstood something. I didn't realise that you were doing everything on ArchLinux. That would explain why you couldn't run Xcode! I hope you don't regard this as "the typical arrogance of the Apple Mac user" !!

carlca avatar Jul 26 '17 21:07 carlca

When you set the breakpoint in LLDB, did you try doing `print *LIST' ? Like I said, Lazarus and Delphi do some dereferencing tricks to make variables which should appear as *[varname] actually appear as [varname]. LLDB doesn't understand this, so you have to speak in real "pointer" terms to it.

carlca avatar Jul 26 '17 22:07 carlca

Hi Jan, if you have a moment, grab the latest version of the sample app at https://dropfile.to/cYpBezD access code Evzwk2x. Stick a break point in LLDB at line 69, then do 'p *OBJ.LIST`. You should see the contents of the List object which is a child property of the Obj object. In other words, LLDB does allow the display of child properties. Interestingly, I've just tried this via the Add Watch facility in VSCode and it seems to work here. It didn't seem to work in the actual app I'm working on, though.

So what would be good is if the list of Variables was able to detect which of the variables was a class reference, and to ask LLDB for the * value, so that we don't have to add the values manually as watches.

I hope that all makes sense.

Cheers, Carl

carlca avatar Jul 27 '17 01:07 carlca

Jan, something bad has happened! I no longer am able to stop at breakpoints at all. I've tried uninstalling and reinstalling Native Debug, but I cannot get breakpoints to work at all. This rather blows my progress out of the water. Do you have any idea what the problem might be?

carlca avatar Jul 27 '17 14:07 carlca

have you tried using a different compiler or different arguments to emit gdb compatible debug symbols?

WebFreak001 avatar Jul 27 '17 16:07 WebFreak001

No, I haven't done anything differently, as far as I know. It just stopped working suddenly.

carlca avatar Jul 27 '17 17:07 carlca

It hasn't worked since last night. Something has happened overnight to cause me to lose the use of breakpoints.

carlca avatar Jul 27 '17 17:07 carlca

It's OK my LLDB is working again. Not sure what the problem was, to be honest.

carlca avatar Jul 27 '17 20:07 carlca

Any thoughts about the P *OBJ.LIST thing I mentioned earlier?

carlca avatar Jul 27 '17 20:07 carlca

I was trying to get LLDB to work with Free Pascal and found this thread. On my system (10.13 lldb-900.0.45) the "p" command is broken and crashing but "fr v" works and displays members variables of classes.

Look at this example and notice how "p" crashes at the end but I get member variables using fr v. Not sure if this is relevant or helps.

(lldb) fr v MODEL
(TMODEL) MODEL = 0xbffff95c
(lldb) fr v *MODEL
(TMODEL) *MODEL = {
  TOBJECT = {
    REGISTEREDMETHODS = 0x000007c3
    MANAGEDOBJECTS = 0x0064bf00
    AUTORELEASECOUNT = 0
    RETAINCOUNT = 0
    DIDINITIALIZE = true
    INITIALIZEDFROMCOPYING = true
    COPYPARAMETERS = 0xb9938c00
  }
  MESH = (VERTEXATTRIBS = 0x3e45a200, VERTEXSIZE = -1476722686, V = 0x00000000, IND = 0xe04e6620)
  MATERIAL = {
    SHINEDAMPER = 0.961168169
    REFLECTIVITY = -5.949044E+19
    TEXTURES = (M_DATA = 0x3f760f1e, M_ACTUALSIZE = 19562528, M_GROWSIZE = -1073743432, DATA = 0x3f760f1e)
    COLOR = (X = 0.0000000000000000000000000000000000000000971225952, Y = 0.000000000000000000000000000000000000000100446475, Z = 0.00000000000000000000000000000000000000000112103877, R = 0.0000000000000000000000000000000000000000971225952, G = 0.000000000000000000000000000000000000000100446475, B = 0.00000000000000000000000000000000000000000112103877)
    ID = -1073743368
  }
  SHADER = 0x0001190c
  ID = 1599792
  VERTEXBUFFERID = 1599792
  INDEXARRAYBUFFERID = 3221223896
  VAO = 213793
}
(lldb) fr v *MODEL->SHADER
(TSHADER) *MODEL->SHADER = {
  TOBJECT = {
    REGISTEREDMETHODS = 0x8b042474
    MANAGEDOBJECTS = 0x8d08247c
    AUTORELEASECOUNT = 9316
    RETAINCOUNT = 49932
    DIDINITIALIZE = true
    INITIALIZEDFROMCOPYING = true
    COPYPARAMETERS = 0xf424648d
  }
  PROGRAMID = 2365623040
  VERTEXSHADERID = 3272352868
  FRAGMENTSHADERID = 4096025741
  UNIFORMS = 0x89241c89
}
(lldb) p *MODEL
Illegal instruction: 4

genericptr avatar Oct 30 '17 14:10 genericptr

@carlca @genericptr Any update on this? Could you possibly retry that, maybe with an updated LLDB and also with GDB?

GitMensch avatar Sep 17 '21 09:09 GitMensch