Recent

Author Topic: Debugging in VSCode with LLDB on Apple Mac  (Read 6478 times)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Debugging in VSCode with LLDB on Apple Mac
« on: July 26, 2017, 04:45:08 pm »
Hello, I've been using Xcode with LLDB to debug my Lazarus/FPC apps for a few weeks now using Phil's ProjectXC project as described at https://macpgmr.github.io/ObjP/ProjectXC.html and it has served me well.

I've just discovered that it's possible to do the same thing with VSCode using the latest OmniPascal (v0.14) plugin and a debugging plugin called Native Debug (v0.21.2). Together with a key bindings plugin called Delphi Keymap (v0.3.0), it gives a usable debugging environment for Lazarus/FPC apps using LLDB as the underlying debugger. And, I have to say, that VSCode is much prettier than Xcode, which helps!

Don't let the low version numbers fool you. After an hour of using this arrangement, I haven't encountered any major problems so far, though of course YMMV. Hope this helps someone.
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Debugging in VSCode with LLDB on Apple Mac
« Reply #1 on: July 26, 2017, 05:41:38 pm »
I have spotted one quite serious drawback. When any variable which is a class reference is displayed in the top Variables list, it just shows <unknown> next to it. This, I think is a result of FPC's (and Delphi's) behaviour of displaying class references in a dereferenced form.

The problem can be mitigated to a small degree by setting a watch on the class variable in question and specifying it in its true pointer form. For example, in my code, I have a variable called `Code` which is displayed as `CODE: <unknown>`. If I set the watch to `*CODE`, I can then see the Class name, and if I hover over the entry I see a lot more info.

I'm going to try to get in touch with the plugin's author, a gentleman called WebFreak (not the name he was given at birth, I'll warrant!), and see if this is a limitation of the plugin. Given that Xcode manages to retrieve the info from LLDB, then presumably this plugin should be able to as well.

If anyone else wants to try this arrangement out and see if there is a way of getting the class variables to display more of their contents, that would be very useful.
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Debugging in VSCode with LLDB on Apple Mac
« Reply #2 on: July 26, 2017, 11:58:30 pm »
I managed to contact https://github.com/WebFreak001 and had the following exchange with him. The thing I didn't realise till the end of the conversation was that he is evidently developing on ArchLinux and so had no way of checking the stuff I was mentioning about Xcode.

He made the good point that if he was unable to get the missing information using the bare-bones LLDB app, then he was unlikely to be able to do it using a VSCode plugin. I suggested that maybe the Xcode developers were using undocumented means of accessing LLDB internals, but neither he nor I had any way of confirming that.

https://github.com/WebFreak001/code-debug/issues/118#issuecomment-318144568
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Debugging in VSCode with LLDB on Apple Mac
« Reply #3 on: July 27, 2017, 12:39:25 am »
The thing I didn't realise till the end of the conversation was that he is evidently developing on ArchLinux

Yes, lldb is available on Linux too. When you install the Swift compiler on Linux, you get lldb too.

You could check lldb code to see how it's doing it. I doubt if it's undocumented means.

http://lldb.llvm.org/

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Debugging in VSCode with LLDB on Apple Mac
« Reply #4 on: July 27, 2017, 01:14:03 am »
Good point, Phil. I keep forgetting that the thing about open-source is that it's, well, open!

"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Debugging in VSCode with LLDB on Apple Mac
« Reply #5 on: July 27, 2017, 09:54:02 pm »
Something bad has happened to my debugging with LLDB. Suddenly I can no longer debug in Xcode. Despite every available option I can discover being set to `debug`, all my options on the Debug menu are greyed out, and my breakpoints are no longer being hit.

The problem seems to be on my main project. A separate little test app loads up in Xcode just fine and is able to be debugged. I've googled extensively but I must be missing something obvious because I just cannot get debug working on my main project. What am I missing?

"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Debugging in VSCode with LLDB on Apple Mac
« Reply #6 on: July 27, 2017, 10:00:40 pm »
What am I missing?

Have no idea, but it wouldn't hurt to clean out the project:

Under ~/Developer/Xcode/DerivedData, just delete your project's build folder altogether. Xcode will create this folder again the next time you open the project.

That may not make any difference, but at least you'll eliminate the presence of odd artifacts as a cause.

If you have backed up versions of your Lazarus .lpi file, do a diff with the current one just to see if anything has changed.

The key Xcode file is the project.pbxproj file. Do a diff of that against a backed up copy, again to see if you can spot any changes that might have anything to do with debugging.


Edit: Oops, that's ~/Library/Developer/Xcode/DerivedData
« Last Edit: July 27, 2017, 10:12:06 pm by Phil »

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Debugging in VSCode with LLDB on Apple Mac
« Reply #7 on: July 27, 2017, 10:22:34 pm »
I deleted the contents of my DerivedData folder and reran the `makeproj` utility to recreate my Xcode project. Normal service has been resumed. Hurrah!  :D
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Debugging in VSCode with LLDB on Apple Mac
« Reply #8 on: July 27, 2017, 10:28:38 pm »
I deleted the contents of my DerivedData folder and reran the `makeproj` utility to recreate my Xcode project. Normal service has been resumed. Hurrah!  :D

Normally when you do a Product | Clean in Xcode, it deletes most of the stuff under the project's DerivedData folder, but not everything. If you have multiple schemes, it will only delete the current scheme's build files, I believe.

Note that makeproj doesn't have anything to do with the build folders. It only deals with the .xcodeproj folder.


carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Debugging in VSCode with LLDB on Apple Mac
« Reply #9 on: July 27, 2017, 11:10:33 pm »
Strangely the DerivedData folder only had 2 really old folders relating to old test projects, so I don't know if deleting the DerivedData contents did anything or not. While I would like to know for future reference, I'm happy enough that it's working again.
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Debugging in VSCode with LLDB on Apple Mac
« Reply #10 on: July 28, 2017, 12:26:17 am »
Edit: Oops, that's ~/Library/Developer/Xcode/DerivedData

Oh! *That* DerivedData folder. I did wonder! So are you saying that in cases of difficulties with Xcode, it's a good idea to delete the DerivedData folder associated with the project?
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

 

TinyPortal © 2005-2018