Recent

Author Topic: Lazarus / FPC / GDB - Good / Good / Bad  (Read 2651 times)

wcage03

  • New member
  • *
  • Posts: 5
Lazarus / FPC / GDB - Good / Good / Bad
« on: October 14, 2018, 04:13:57 pm »
First, many thanks for the work put in to making and maintaining these things.  I am an old programmer trying not to learn (too many) new tricks.  I grew up coding C, but took a chance on Pascal at one point and found it comfortable.  Borland came out with Delphi and I was hooked.  That was a long time ago.

Recently I found a need to do some coding; more hobby than work.  The world has changed so I knew that I was facing a learning curve so I looked around and figured, I would take on Swift.  I liked the language constructs, but quickly fell out of love with integrating the user interface with the code.  Out of curiosity, I wondered what ever happened to Delphi.

I was surprised to find Lazarus and FPC.  Amazing!  In minutes, I had a Delphi like IDE attached to a pascal compiler that felt comfortable to me.  Although, over the span of a couple of weeks, I have still yet to get the debugger to work.

First it was the error suggesting that GDB was not code signed.  The instructions for doing that are everywhere and they are consistent so I was confident that I had that completed.  Nonetheless, I varied the approach slightly and tried it dozens of times.  Found one post that said he could run DBG in a terminal as root, but not as his user ID. My case was similar, but ultimately that possibility died when I resolved running in a terminal only to find that this was not going to solve it for running in Lazarus.

I did make progress when I read that the SIT had to be set up for debugging to be an exception.  Went down that path and, while I still get the occasional error popups, the one suggesting that GDB needs to be code signed have disappeared.

Now what is happening is that when I click the "play" button, the code is compiled and the title bar changes to indicate that it is "debugging", but nothing happens.  The window does not run and no code appears to be executing.  I can see DBG has a thread in the process status (started as "/usr/local/bin/gdb -silent -i mi -nx"), but no action.  The test code is simply a window with a single button that has the command "close" tied to the click event.  If I run the program without invoking the debugger it works as expected.

What I am hoping someone can tell me is whether the GDB integration with Lazarus/FPC actually works or am I chasing unicorns and should go back and do the work to get comfortable with Swift.

A quick run down on what I have done so far...
I ensured that xcode and the associated command line tools are up-to-date.
I used brew to install GDB version.  That is version 8.2.  I have since tried where some recommend falling back to 8.0.1.
I have signed the GDB using a system certificate that I created following the many example for this that are posted.  I have verified the signing numerous times (and re-performed that step anyway)
After installing GDB, I have installed FPC, FPC Source and Lasarus (in that order)
I have tried Lazarus v 1.84 and v2 RC1 with the associated FPC and source.
I have performed all of this on two different machines, one running High Sierra and the other Majove.

Again, kudos to the developers for Lazarus and FPC... those worked flawlessly every combination, every time.  I am sure DBG by itself is a wonderful tool also... but I am beginning to suspect that the integration between the two has fallen through the cracks.

Thanks again in advance for any wisdom that can be shared on this topic.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5567
    • wiki
Re: Lazarus / FPC / GDB - Good / Good / Bad
« Reply #1 on: October 14, 2018, 04:37:17 pm »
1) Do you code a console app (writeln/readln) or a GUI app?
Debugging console apps an Mac is currently a problem...

2) Does your app do anything, if you start it outside the IDE?
It seems from your description that it compiles, so you should have the app in the project folder

3) About GDB.
The next version of lazarus (2.0) will have some support for debugging using lldb instead (you would need to install package "LazDebuggerFpLldb"). A release canditate is available on our sourceforge page.
But since/if you got gdb running, you may not currently need to get this.
(I dont know which one will currently work better)

-------------------
I am not an expert on the Mac site, but IIRC there are some posts on this forum, suggesting that gdb on mac my need additional settings, such as "disable startup shell". (Need to search the forum)

Also some 8.x (I think 8.1) did not work on some versions of MacOS.

-------------------
Check this page for correct config: http://wiki.lazarus.freepascal.org/Debugger_Setup

And this http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session
for how to provide a log file

wcage03

  • New member
  • *
  • Posts: 5
Re: Lazarus / FPC / GDB - Good / Good / Bad
« Reply #2 on: October 14, 2018, 07:00:31 pm »
The apps will primarily be GUI style.  My test app runs fine both in Lazarus without the debugger and directly from the OS.  I am game trying release 2; actually tried it already... works great in my limited testing except for GDB.  I will get the LazDebuggerFpLidb package and give it a shot.  Do you know offhand if the package has instructions for installation?

The disable startup shell was noted in many of the posts and I made the change to the user config file as suggested.  I see, however, in the gdb startup command as listed in process status has the command option -nx in the string.  That option says to not read any user options files.  In release 2.0 of Lazarus, I noted that there is a checkbox option for not starting in shell mode.  In either case, I didn't make progress.  I assume (maybe incorrectly) that the startup string for gdb is hard coded in Lazarus.

Thanks for your help.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5567
    • wiki
Re: Lazarus / FPC / GDB - Good / Good / Bad
« Reply #3 on: October 14, 2018, 08:35:30 pm »
"LazDebuggerFpLLdb" not LazDebuggerFpLidb.

It is part of Lazarus, from version 2.0 upward (so you need the 2.0RC1, since 2.0 is not yet released).

As for setup:

- Install the package. It should be in the list, but if not it is in components/lazdebuggers/lazdebuggerfplldb
Make sure to use the one with "fp" in the name. There also is LazDebuggerLLdb, but it is not as good.
Restart the IDE.

- Go to Tools > options > debugger
  In the "debugger type" dropdown, you should find and select "LLDB debugger (with fpdebug)"
  The edit below this (where you have the path to gdb), should be changed to the path of lldb.
  (lldb comes with the tools from apple; and as such it is already codesigned by apple)

That should be it.


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5567
    • wiki
Re: Lazarus / FPC / GDB - Good / Good / Bad
« Reply #4 on: October 14, 2018, 08:37:22 pm »
If you have any troubles (gdb or lldb):

Attach a logfile, as detailed here: http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session

For lldb there may be a few changes to the args, I need to look that up...

--
EDIT:
See here: http://forum.lazarus-ide.org/index.php/topic,42869.msg299444
« Last Edit: October 15, 2018, 03:04:14 am by Martin_fr »

wcage03

  • New member
  • *
  • Posts: 5
Re: Lazarus / FPC / GDB - Good / Good / Bad
« Reply #5 on: October 15, 2018, 02:57:24 am »
I will give it shot and let you know my results.  Thanks for taking the time to help.

wcage03

  • New member
  • *
  • Posts: 5
Re: Lazarus / FPC / GDB - Good / Good / Bad
« Reply #6 on: October 15, 2018, 03:47:29 am »
OK.  Installed v2RC1.  Added the LazDebuggerFpLLdb package.  Selected the debugger and pointed it to the lldb executable as directed. 

Fired up my simple test and Voilà! it worked! 
Grabbed one of the sample projects and tried it... it also worked!

I am sure that I will hit other challenges, but this hurdle is now behind me.  Thanks for your patience and guidance!