2

I am trying to work out why all the Mac system API calls I have tried calling - here CFStringCreateWithCString - in Lazarus 1.6.4 running in macOS Sierra 10.12.4 with GDB 8.0 and GDB 7.12.1 and all fails with:

"The debugge encountered and error when trying to run/step the application. Cannot find bounds of current function"

and the debugger jumps out of the function (or if the call is surrounded by try/except to the code following the except) - and later afterwards informs debugger unstable

...

Here is example code:

procedure myTest;
var
  TestStrUTF8: UTF8String;
  TmpStrPr_CSS: ConstCStringPtr;
  TmpCFStrRef: CFStringRef;
  TmpStrPtr: Pointer;
begin
  TestStrUTF8 := 'http://example.com';
  TmpStrPtr := Pointer(TestStrUTF8)
  TmpStrPtr_CSS := ConstCStringPtr(TmpStrPtr);
  TmpCFStrRef := CStringCreateWithCString(nil, TmpStrPtr_CSS, kCFStringEncodinguTF8); // Note1: we are only using ASCII, Note2: We have tried KCFStringEncodingWindowsLatin1 with same problem

  // jumps out of routine and reports "Cannot find bounds of current function" here

  showmessage('never reaches, crashes first');
end;
  • I do not otherwise have problems debugging. I can step through code not calling Mac system API functions fine. I guess Lazarus/LCL/FPC libraries are also calling native Mac API functions, but that code is compiled differently and thus works.
  • I am running above code in main thread.
  • This issue seems to happen for multiple Mac API calls I have tried, so I think it may be a (GDB) debugger/Lazarus issue of a sorts.

Note: I am aware there might be debugger problems with macOS Sierra 10.12.5 which is why I have not upgraded yet.

Could his be some problem with SIP / address relocation / similar?

  • In Debugger_Start_options I have added "--eval-command=set startup-with-shell off".
  • I have also signed GDB of course.
  • I use home brew for GDB installations
Tom
  • 3,587
  • 9
  • 69
  • 124

1 Answers1

1

Yes, there are indeed debugger issues with Sierra (I don't know if they are limited to 10.12.5, though).

I'm running 10.12.6 and I have had useful results using LLDB running under Xcode to debug my Lazarus/FPC apps.

Have a look at this page https://macpgmr.github.io/ObjP/ProjectXC.html for how to achieve this.

I've also been investigating the possibilities of using OmniPascal and VSCode on the Mac combined with LLDB to achieve the same ends, but in a much more pretty way!

You might want to follow this SO question to see if I get any answers about this How do I get OmniPascal to integrate with LLDB on the macOS 10.12.6