Recent

Author Topic: Getting DebugServer (dbugsvr) to work on Apple Mac  (Read 6800 times)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Getting DebugServer (dbugsvr) to work on Apple Mac
« on: May 15, 2017, 12:35:57 am »
Hello, I'm trying to get DebugServer to work with Lazarus 1.6.4 + FPC 3 + El Capitan 10.11.6. The application builds and runs from within Lazarus. However, any attempt to run it from its build location from Finder by double clicking it, results in the app failing to start and displaying:

/Developer/lazarus/tools/debugserver/debugserver; exit;
in the shell

and then hanging, requiring a ^C to get back to the command line. 

I don't know if it's significant but I'm using a combination of iTerm2 + Fish + Oh My Fish for my shell.

For the purposes of using the FPC DBugIntf unit, I renamed the debugserver executable to dbugsvr as that is what DBugIntf tries to invoke. Nothing works apart from running debugserver from within Lazarus. Ideally I would run it from the external tools menu item within Lazarus - effectively running it as a separate item - and then build and debug my own code within Lazarus. Can any one shed some light on how to achieve this?

Thanks,
Carl
"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: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #1 on: May 15, 2017, 01:04:27 am »
I solved the problem by running DebugServer within one instance of Lazarus, and then starting a second instance of Lazarus which you can easily do by entering open -n /Applications/Lazarus.app. Strangely, even though the DbugIntf code definitely tries to invoke DbugSvr, debug info appears to be getting through to debugserver, for reasons that I don't understand, and frankly am too tired to investigate now!
« Last Edit: May 15, 2017, 01:08:56 am by carl_caulkett »
"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: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #2 on: May 15, 2017, 01:08:41 am »
I solved the problem by running DebugServer within one instance of Lazarus, and the starting a second instance of Lazarus which you can easily do by entering open -n /Applications/Lazarus.app. Strangely, even though the DbugIntf code definitely tries to invoke DbugSvr, debug info appears to be getting through to debugserver, for reasons that I don't understand, and frankly am to tired to investigate now!

I'm not familiar with DebugServer, but it looks like a standard LCL app, meaning it only makes sense to run the app bundle (.app), not the executable itself.

Also, I'm not seeing that the dbugintf unit is trying to run DbugSvr. I see this on line 202 of dbugintf.pp:

      CommandLine:='debugserver';


carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #3 on: May 15, 2017, 01:27:22 am »
Hi Phil, thanks for the reply. So are you saying I should try to invoke debugserver.app from my Tools menu? I've just tried that and it didn't seem to work, though no doubt I'm doing something wrong. I've had the Apple Mac less than a week now, and although I'm learning lots, I'm aware that there's an awful lot I don't yet understand! For instance I didn't know about the distinction between raw executables and the enclosing app bundle. So thanks for that!

It's strange what you say about dbugintf. The code around circa line 200 is this, on my machine:

function StartDebugServer : Integer;

begin
  With TProcess.Create(Nil) do
    begin
    Try
      CommandLine:='dbugsrv';
      Execute;
      Result:=ProcessID;
    Except On E: Exception do
      begin
      SendError := Format(SServerStartFailed,[E.Message]);
      Result := 0;
      end;
    end;
    Free;
    end;
end;



It's possible that back in the dim and distant past I may have tweaked the code for some nefarious reason. If I did, I can't remember why or how. It was back in the days when, as far as I was concerned, "Git" was a term of abuse, and not a version control system!

Cheers,
Carl
« Last Edit: May 15, 2017, 01:28:53 am by carl_caulkett »
"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: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #4 on: May 15, 2017, 01:33:31 am »
It's strange what you say about dbugintf. The code around circa line 200 is this, on my machine:

That's not the code in FPC 3.0.2 or trunk.

GUI apps on Mac always run inside a bundle (.app). Only console apps can be run by executing the executable directly.

In general, to launch a GUI app with, say, TProcess, you would execute, eg,

open path/to/appbundle.app

You can try that with any .app from a Terminal.

I would assume that dbugintf.pp was not tested on a Mac.

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #5 on: May 15, 2017, 01:38:22 am »
No, I couldn't have tweaked the code, because, of course dbugintf.pp is part of a freshly installed Apple Mac version of FPC, and I notice that the date of the file is 7 Mar 2009. What vintage of dbugintf.pp do you have?

Cheers,
Carl
"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: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #6 on: May 15, 2017, 01:45:07 am »
No, I couldn't have tweaked the code, because, of course dbugintf.pp is part of a freshly installed Apple Mac version of FPC, and I notice that the date of the file is 7 Mar 2009. What vintage of dbugintf.pp do you have?

The date of FPC 3.0.2's dbugintf.pp is March 3, 2007, same as when it was committed to SVN. That's under utils/debugsvr.

However, I see that there's also a copy of that file in packages/fcl-process/src - that's probably what you're using.

Have no idea why there are two copies or which you should use. I had never heard of this previously.

I always debug apps with lldb anyway.



carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #7 on: May 15, 2017, 01:47:56 am »
Thanks again for your time Phil. I guess it's going to have to remain a mystery, though it does seem like a version based issue of some description. I would like to understand how to run debugserver.app either from the command line or from the Tools menu, but it's not a a pressing issue because I can debug using the 2 instances of Lazarus approach.

This all stems from the fact that I have had various difficulties using GDB based debugging with Lazarus, but that's another story. It too can wait till tomorrow!

Cheers,
Carl
"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: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #8 on: May 15, 2017, 01:49:58 am »
I've seen fleeting mentions of lldb but know nothing of it. Tell me more, or point me to somewhere I can read up about it.

Thanks,
Carl
"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: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #9 on: May 15, 2017, 01:57:01 am »
I've seen fleeting mentions of lldb but know nothing of it. Tell me more, or point me to somewhere I can read up about it.

https://developer.apple.com/library/content/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/lldb-terminal-workflow-tutorial.html

If you're familiar with gdb, this will be helpful:

http://lldb.llvm.org/lldb-gdb.html

lldb is part of llvm, as is Swift and Objective C compilers.

http://lldb.llvm.org/

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #10 on: May 15, 2017, 09:42:22 am »
I'll check out lldb right now. I may get back to you. Be warned!  >:D
"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: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #11 on: May 15, 2017, 02:37:00 pm »
I used the info translated from this page https://alexconesa.wordpress.com/2016/11/16/lldb-and-gdb-debug-in-lazarus/ in order to install lldb. My question though is what is the typical workflow for using lldb given that Lazarus doesn't support it directly yet (unless I'm mistaken about that)?
"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: Getting DebugServer (dbugsvr) to work on Apple Mac
« Reply #12 on: May 16, 2017, 01:24:32 am »
I used the info translated from this page https://alexconesa.wordpress.com/2016/11/16/lldb-and-gdb-debug-in-lazarus/ in order to install lldb. My question though is what is the typical workflow for using lldb given that Lazarus doesn't support it directly yet (unless I'm mistaken about that)?

lldb is already installed on your Mac when you installed the command line tools.

Lazarus will probably never support lldb.

Workflow?

  1. Build app.
  2. From Terminal: lldb yourprogram.app


 

TinyPortal © 2005-2018