Recent

Author Topic: Debugger not working with Apple Silicon code  (Read 4258 times)

jwdietrich

  • Hero Member
  • *****
  • Posts: 1236
    • formatio reticularis
Debugger not working with Apple Silicon code
« on: July 05, 2023, 03:52:47 pm »
When trying to start a file compiled for Apple Silicon processors the debugger enters an error state. The program can be executed but without a debugger only.

This issue may have been discussed previously, but I am not sure if this is the same error and, obviously, no solution is available.

[Edit: clarified post title]
« Last Edit: May 05, 2024, 09:32:36 am by trev »
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 3.4.0 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Debugger crashes with Apple Silicon code
« Reply #1 on: July 05, 2023, 04:45:04 pm »
I assume you are using "lldb + fpdebug"?

What does the menu: View > IDE internals > Debug output show? (Note: First open the window, then try to run the app in the debugger)


Is it possible to load the app in lldb, and run it under lldb?
- See above output for lldb commands needed. / Do any of them need change?
- What does lldb report


jwdietrich

  • Hero Member
  • *****
  • Posts: 1236
    • formatio reticularis
Re: Debugger crashes with Apple Silicon code
« Reply #2 on: July 05, 2023, 05:49:44 pm »
Well, I can run my program from lldb.

The debug output from Lazarus is very long:

>> settings set -- frame-format "frame #${frame.index}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME\n"
(lldb) settings set -- frame-format "frame #${frame.index}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME\n"
>> settings set -- thread-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
(lldb) settings set -- thread-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
>> settings set -- thread-stop-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
(lldb) settings set -- thread-stop-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
>> target stop-hook add -o "thread list"
(lldb) target stop-hook add -o "thread list"
Stop hook #1 added.
>> settings set -- stop-line-count-after 0
(lldb) settings set -- stop-line-count-after 0
>> settings set -- stop-line-count-before 0
(lldb) settings set -- stop-line-count-before 0
>> settings set -- stop-disassembly-count 0
(lldb) settings set -- stop-disassembly-count 0
>> settings set -- target.env-vars "USER=johannes"
(lldb) settings set -- target.env-vars "USER=johannes"
>> settings set -- target.env-vars "COMMAND_MODE=unix2003"
(lldb) settings set -- target.env-vars "COMMAND_MODE=unix2003"
>> settings set -- target.env-vars "__CFBundleIdentifier=lazarus.freepascal.ide"
(lldb) settings set -- target.env-vars "__CFBundleIdentifier=lazarus.freepascal.ide"
>> settings set -- target.env-vars "PATH=/usr/bin:/bin:/usr/sbin:/sbin"
(lldb) settings set -- target.env-vars "PATH=/usr/bin:/bin:/usr/sbin:/sbin"
>> settings set -- target.env-vars "LOGNAME=johannes"
(lldb) settings set -- target.env-vars "LOGNAME=johannes"
>> settings set -- target.env-vars "SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.0uHEBrpxu5/Listeners"
(lldb) settings set -- target.env-vars "SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.0uHEBrpxu5/Listeners"
>> settings set -- target.env-vars "SQLITE_EXEMPT_PATH_FROM_VNODE_GUARDS=/Users/johannes/Library/WebKit/Databases"
(lldb) settings set -- target.env-vars "SQLITE_EXEMPT_PATH_FROM_VNODE_GUARDS=/Users/johannes/Library/WebKit/Databases"
>> settings set -- target.env-vars "HOME=/Users/johannes"
(lldb) settings set -- target.env-vars "HOME=/Users/johannes"
>> settings set -- target.env-vars "SHELL=/bin/zsh"
(lldb) settings set -- target.env-vars "SHELL=/bin/zsh"
>> settings set -- target.env-vars "TMPDIR=/var/folders/fh/2r9_mhf953l9f10kmr7by46w0000gn/T/"
(lldb) settings set -- target.env-vars "TMPDIR=/var/folders/fh/2r9_mhf953l9f10kmr7by46w0000gn/T/"
>> settings set -- target.env-vars "__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x3"
(lldb) settings set -- target.env-vars "__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x3"
>> settings set -- target.env-vars "XPC_SERVICE_NAME=application.lazarus.freepascal.ide.1177857.3841679"
(lldb) settings set -- target.env-vars "XPC_SERVICE_NAME=application.lazarus.freepascal.ide.1177857.3841679"
>> settings set -- target.env-vars "XPC_FLAGS=0x0"
(lldb) settings set -- target.env-vars "XPC_FLAGS=0x0"
>> target create '/Users/Shared/Projekte/Endokrinologie/SD/TFC und SD-Homöostase/SimThyr/code/trunk/SimThyr GUI/SimThyr.app'
(lldb) target create '/Users/Shared/Projekte/Endokrinologie/SD/TFC und SD-Homöostase/SimThyr/code/trunk/SimThyr GUI/SimThyr.app'
Current executable set to '/Users/Shared/Projekte/Endokrinologie/SD/TFC und SD-Homöostase/SimThyr/code/trunk/SimThyr GUI/SimThyr.app' (arm64).
>> settings clear target.run-args
(lldb) settings clear target.run-args
>> breakpoint set --func fpc_break_error -K false
(lldb) breakpoint set --func fpc_break_error -K false
Breakpoint 1: no locations (pending).
>> breakpoint set --func fpc_runerror -K false
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) breakpoint set --func fpc_runerror -K false
Breakpoint 2: no locations (pending).
>> breakpoint set --func fpc_raiseexception -K false
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) breakpoint set --func fpc_raiseexception -K false
Breakpoint 3: where = SimThyr`FPC_RAISEEXCEPTION, address = 0x0000000100013c50
>> breakpoint command add 3
>> p/x $x0
>> p/x $x2
>> p ((char ***)$x0)[0][3]
>> p ((char **)$x0)[1]
>> DONE
>> version
(lldb) breakpoint command add 3
(lldb) version
>> breakpoint command add 2
>> p/x $x0
>> DONE
>> version
lldb-1403.0.17.67
Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
(lldb) breakpoint command add 2
(lldb) version
>> breakpoint command add 1
>> p/x $x0
>> DONE
>> version
lldb-1403.0.17.67
Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
(lldb) breakpoint command add 1
(lldb) version
>> process launch -n
lldb-1403.0.17.67
Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
(lldb) process launch -n
error: the platform is not currently connected
>> process kill
>> quit


lldb reports a lot of warnings:

(lldb) target create "/Users/Shared/Projekte/Endokrinologie/SD/TFC und SD-Homöostase/SimThyr/code/trunk/SimThyr GUI/SimThyr"
Current executable set to '/Users/Shared/Projekte/Endokrinologie/SD/TFC und SD-Homöostase/SimThyr/code/trunk/SimThyr GUI/SimThyr' (arm64).
(lldb) r
Process 38671 launched: '/Users/Shared/Projekte/Endokrinologie/SD/TFC und SD-Homöostase/SimThyr/code/trunk/SimThyr GUI/SimThyr' (arm64)
2023-07-05 17:42:54.070356+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x106906d10 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.070997+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x106906d10 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.222083+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x104d0a4b0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.324564+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x1020058f0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.350967+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x100f13b80 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.365819+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x100f61e40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.395551+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x104d232a0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.397030+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x104d232a0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.397194+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x104d232a0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.397724+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x104d232a0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.401484+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x100f85ad0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.411120+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x106906f40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.421616+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x10208de40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.423126+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x10208de40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.423304+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x10208de40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.423971+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x10208de40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.428609+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x10209c2a0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.429348+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x10209c2a0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.432052+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x1020a8160 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.439699+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x104d0a4b0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.439884+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x104d0a4b0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.440370+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x104d0a4b0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.441026+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x106906f40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.441556+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x106906f40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.442017+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x106906f40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.443000+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x100f85ad0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.443190+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x100f85ad0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.443620+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x100f85ad0 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.455275+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x100fa5a20 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.468162+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x12543cc50 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.480620+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x1020f4e40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.481435+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x1020f4e40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.481940+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x1020f4e40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.482730+0200 SimThyr[38671:1729295] [Window] Warning: Window TCocoaWindow 0x1020f4e40 ordered front from a non-active application and may order beneath the active application's windows.
2023-07-05 17:42:54.499202+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.499390+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.499548+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.499680+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.499819+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.499961+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.500089+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.501003+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.501394+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.501532+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.501659+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.501798+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.502092+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.502959+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.503088+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.503306+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.503434+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.503570+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.504553+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.504690+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-07-05 17:42:54.504823+0200 SimThyr[38671:1729295] [default] CGSWindowShmemCreateWithPort failed on port 0


I don't think that they are too important. At least the program starts.

Could the line "the platform is not currently connected" in the Lazarus output be the key?
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 3.4.0 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Debugger crashes with Apple Silicon code
« Reply #3 on: July 06, 2023, 12:13:47 am »
Quote
Could the line "the platform is not currently connected" in the Lazarus output be the key?

Quite possible.
Or "r" vs "process launch -n"
Also a diff in your test, the name of the app. Under the IDE it ended in ".app"

The problem is I don't develop on Mac, so I can't test it.
I know some people are (or at least were) able to start M1 apps. But I can't tell what changed.

jwdietrich

  • Hero Member
  • *****
  • Posts: 1236
    • formatio reticularis
Re: Debugger crashes with Apple Silicon code
« Reply #4 on: July 06, 2023, 08:23:35 am »
The problem is I don't develop on Mac, so I can't test it.
I know some people are (or at least were) able to start M1 apps. But I can't tell what changed.

OK. Thanks for your advice anyway.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 3.4.0 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

geraldholdsworth

  • Full Member
  • ***
  • Posts: 214
Re: Debugger crashes with Apple Silicon code
« Reply #5 on: September 28, 2023, 03:51:37 pm »
I got this error, after I had some application updates (notably X-Code) and an OS update (this is on Ventura, by the way). It confused me as it was working before. When I then tried to install with FPCUpDeluxe I got the message that I hadn't accepted the licence agreement with X-Code (obviously, the updated version)...so maybe yours is the same issue?
Code: [Select]
sudo xcodebuild -license

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2032
  • Former Delphi 1-7, 10.2 user
Re: Debugger crashes with Apple Silicon code
« Reply #6 on: April 23, 2024, 04:44:57 am »
Same issue with new install of Lazarus 2.2.2:

Code: [Select]
>> target create /Users/trev/Documents/laz_lnet_smtp/project1.app
(lldb) target create /Users/trev/Documents/laz_lnet_smtp/project1.app
Current executable set to '/Users/trev/Documents/laz_lnet_smtp/project1.app' (arm64).
>> settings clear target.run-args
(lldb) settings clear target.run-args
>> breakpoint set --func fpc_break_error -K false
(lldb) breakpoint set --func fpc_break_error -K false
Breakpoint 1: no locations (pending).
>> breakpoint set --func fpc_runerror -K false
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) breakpoint set --func fpc_runerror -K false
Breakpoint 2: no locations (pending).
>> breakpoint set --func fpc_raiseexception -K false
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) breakpoint set --func fpc_raiseexception -K false
Breakpoint 3: where = project1`FPC_RAISEEXCEPTION, address = 0x000000010001ae30
>> breakpoint command add 3
>> p/x $x0
>> p/x $x2
>> p ((char ***)$x0)[0][3]
>> p ((char **)$x0)[1]
>> DONE
>> version
(lldb) breakpoint command add 3
(lldb) version
>> breakpoint command add 2
>> p/x $x0
>> DONE
>> version
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
(lldb) breakpoint command add 2
(lldb) version
>> breakpoint command add 1
>> p/x $x0
>> DONE
>> version
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
(lldb) breakpoint command add 1
(lldb) version
>> process launch -n
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
(lldb) process launch -n
error: the platform is not currently connected
>> process kill
>> quit

Also using lldb on the command line works for the Lazarus 2.2.2 program - just a default form1 project1.app.

Curiously, a just compiled Lazarus main branch works without issue as below:

Code: [Select]
>> target create /Users/trev/tmp/project1.app
(lldb) target create /Users/trev/tmp/project1.app
Current executable set to '/Users/trev/tmp/project1.app' (arm64).
>> settings clear target.run-args
(lldb) settings clear target.run-args
>> breakpoint set --func fpc_break_error -K false
(lldb) breakpoint set --func fpc_break_error -K false
Breakpoint 1: no locations (pending).
>> breakpoint set --func fpc_runerror -K false
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) breakpoint set --func fpc_runerror -K false
Breakpoint 2: no locations (pending).
>> breakpoint set --func fpc_raiseexception -K false
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) breakpoint set --func fpc_raiseexception -K false
Breakpoint 3: where = project1`FPC_RAISEEXCEPTION, address = 0x000000010001b4d0
>> breakpoint command add 3
>> p/x $x0
>> p/x $x2
>> p ((char ***)$x0)[0][3]
>> p ((char **)$x0)[1]
>> DONE
>> version
(lldb) breakpoint command add 3
(lldb) version
>> breakpoint command add 2
>> p/x $x0
>> DONE
>> version
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
(lldb) breakpoint command add 2
(lldb) version
>> breakpoint command add 1
>> p/x $x0
>> DONE
>> version
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
(lldb) breakpoint command add 1
(lldb) version
>> process launch -n
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
(lldb) process launch -n
Process 56020 launched: '/Users/trev/tmp/project1.app/Contents/MacOS/project1' (arm64)
Process 56020 exited with status = 0 (0x00000000)
>> process kill
>> quit

Prof Googly was unhelpful.
« Last Edit: April 23, 2024, 04:49:45 am by trev »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2032
  • Former Delphi 1-7, 10.2 user
Re: Debugger crashes with Apple Silicon code
« Reply #7 on: April 23, 2024, 05:37:55 am »
Same issue with a new install of Lazarus 3.2.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2032
  • Former Delphi 1-7, 10.2 user
Re: Debugger crashes with Apple Silicon code
« Reply #8 on: April 23, 2024, 06:00:08 am »
I found the lldb source code for this error message, but I am none the wiser:

From https://github.com/llvm/llvm-project/blob/883887493c882d656d5da100ee637a348e81357c/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp#L123

Code: [Select]
lldb::ProcessSP PlatformDarwin::DebugProcess(ProcessLaunchInfo &launch_info,
                                             Debugger &debugger, Target &target,
                                             Status &error) {
  ProcessSP process_sp;

  if (IsHost()) {
    // We are going to hand this process off to debugserver which will be in
    // charge of setting the exit status.  However, we still need to reap it
    // from lldb. So, make sure we use a exit callback which does not set exit
    // status.
    launch_info.SetMonitorProcessCallback(
        &ProcessLaunchInfo::NoOpMonitorCallback);
    process_sp = Platform::DebugProcess(launch_info, debugger, target, error);
  } else {
    if (m_remote_platform_sp)
      process_sp = m_remote_platform_sp->DebugProcess(launch_info, debugger,
                                                      target, error);
    else
      error.SetErrorString("the platform is not currently connected");
  }
  return process_sp;
}

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Debugger crashes with Apple Silicon code
« Reply #9 on: April 23, 2024, 09:29:46 am »
It is possible that this is a timing issue. I.e., the IDE sends the commands faster than a human...

I was not able to reproduce it myself (for the limited testing I can do...)

When last discussed, I proposed a patch for testing, but did not get feedback (neither ok no  not ok).
One version of the patch is here
https://gitlab.com/martin_frb/lazarus/-/commit/092c51fc6fed9efb73e4e05778e31fdbb079caea

And that is the preferred version, as it only waits if the error happens.
It may need tweaking => please try the sleep with a factor of 50 or 30 instead of 100, and report what works (if any).
For each sleep time, check in the log, how often "process launch" was send (minus the echo).

If that does not work (not even with a sleep time factor of 500), then go a few lines down in the same file, and find
    constructor TLldbInstructionProcessLaunch.Create(AOpenTerminal: Boolean);
as first line in the constructor add a sleep(3000)
And see if that works (if yes, reduce the time as much as possible).




trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2032
  • Former Delphi 1-7, 10.2 user
Re: Debugger crashes with Apple Silicon code
« Reply #10 on: April 26, 2024, 12:39:25 am »
Thanks Martin - I'll give it a go later tonight and let you know how I go.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2032
  • Former Delphi 1-7, 10.2 user
Re: Debugger crashes with Apple Silicon code
« Reply #11 on: May 05, 2024, 09:22:53 am »
OK, it did not go smoothly so I needed to wait until I had more time which was today.

Tests were done with Lazarus v2.2.2 which was previously not working for debugging on macOS 14.4.1 (Sonoma) on a base model M1 Mac mini.

* To compile lldbinstructions.pas with the patch code I needed to add the math unit for the min() function.

* The installation directory for Lazarus 2.2.2 was owned by admin and an unknown group id which prevented recompilation of Lazarus until I chown'd it to my username.

* Lazarus kept starting with the old executable, so I had to (1) find the new executable in my dot laz222 directory and (2) start it from there with the correct pcp file.

* Having reached this point, Lazarus started (checked about to make sure it was the new version) and lo and behold, the debugger worked ! SUCCESS.

* I could not however find any log output to indicate the number of times process launch was sent. Maybe it wasn't sent at all and the new code introduced a sufficient delay? Maybe I looked in the wrong logs? I checked the IDE Internal log and messages.

Here's the log output:

Code: [Select]
>> version
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
(lldb) breakpoint command add 1
(lldb) version
>> process launch -n
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
(lldb) process launch -n
Process 31180 launched: '/Users/trev/tmp/project1.app/Contents/MacOS/project1' (arm64)
Process 31180 exited with status = 0 (0x00000000)
>> process kill
>> quit

If you need me to do more, please ask and I'll try to accommodate in a  timely manner.

Thank You Martin
« Last Edit: May 05, 2024, 09:25:17 am by trev »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10553
  • Debugger - SynEdit - and more
    • wiki
Re: Debugger not working with Apple Silicon code
« Reply #12 on: May 05, 2024, 09:50:53 am »
Thanks, Ok, so the most important is: It worked with the path, right?



About the "debug output" => Are that the last few lines, or all of them?

Did you open that Window before you started the debugger? (before running with F9)? If you open it later, it only contains the last few lines.

But it does look like it did work on the first attempt. ((*1)) I.e. in your test the error was never triggered, yet the patch only adds delay after the first send of the command. (Having the Window open adds a little extra work, and might slow down a few milliseconds...)

You might run from a terminal:
./lazarus.app/MacOS/Content/lazarus  --debug-log=YOURLOGFILE  --debug-enable=DBG_VERBOSE,DBG_WARNINGS,DBG_ERRORS
DBG_STATE,DBGMI_QUEUE_DEBUG,FPDBG_COMMANDS,FPDBG_QUEUE,DBG_THREAD_AND_FRAME,DBG_CMD_ECHO,DBG_CMD_ECHO_FULL

You can then grep the log for the error message.

((*1))
The last statement before "process launch" was "breakpoind command add".
The reason "process launch" is seen twice is that there is an echo.


trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2032
  • Former Delphi 1-7, 10.2 user
Re: Debugger not working with Apple Silicon code
« Reply #13 on: May 05, 2024, 09:59:17 am »
Debug window open before hitting run - yes, I just cut 'n pasted the last few lines -  here's the full output from the debug window:

Code: [Select]
>> settings set -- frame-format "frame #${frame.index}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME\n"
(lldb) settings set -- frame-format "frame #${frame.index}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME\n"
>> settings set -- thread-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
(lldb) settings set -- thread-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
>> settings set -- thread-stop-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
(lldb) settings set -- thread-stop-format "thread #${thread.index}: tid=${thread.id%tid}: ${frame.pc}, {${frame.sp}}, {${frame.fp}} &&//FULL: {${line.file.fullpath}} &&//SHORT: {${line.file.basename}} &&//LINE: {${line.number}} &&//MOD: {${module.file.basename}} &&//FUNC: {${function.name-with-args}} <<&&//FRAME{, stop reason = ${thread.stop-reason}}\n"
>> target stop-hook add -o "thread list"
(lldb) target stop-hook add -o "thread list"
Stop hook #1 added.
>> settings set -- stop-line-count-after 0
(lldb) settings set -- stop-line-count-after 0
>> settings set -- stop-line-count-before 0
(lldb) settings set -- stop-line-count-before 0
>> settings set -- stop-disassembly-count 0
(lldb) settings set -- stop-disassembly-count 0
>> settings set -- target.env-vars "PRINTER=xerox"
(lldb) settings set -- target.env-vars "PRINTER=xerox"
>> settings set -- target.env-vars "PWD=/Users/trev/.laz222/bin/aarch64-darwin"
(lldb) settings set -- target.env-vars "PWD=/Users/trev/.laz222/bin/aarch64-darwin"
>> settings set -- target.env-vars "PAPERSIZE=A4"
(lldb) settings set -- target.env-vars "PAPERSIZE=A4"
>> settings set -- target.env-vars "BLOCKSIZE=K"
(lldb) settings set -- target.env-vars "BLOCKSIZE=K"
>> settings set -- target.env-vars "USER=trev"
(lldb) settings set -- target.env-vars "USER=trev"
>> settings set -- target.env-vars "EXINIT=set autoindent"
(lldb) settings set -- target.env-vars "EXINIT=set autoindent"
>> settings set -- target.env-vars "HOST=macmini8.sentry.org"
(lldb) settings set -- target.env-vars "HOST=macmini8.sentry.org"
>> settings set -- target.env-vars "__CFBundleIdentifier=com.company.lazarus"
(lldb) settings set -- target.env-vars "__CFBundleIdentifier=com.company.lazarus"
>> settings set -- target.env-vars "COMMAND_MODE=unix2003"
(lldb) settings set -- target.env-vars "COMMAND_MODE=unix2003"
>> settings set -- target.env-vars "LANG=en_AU.UTF-8"
(lldb) settings set -- target.env-vars "LANG=en_AU.UTF-8"
>> settings set -- target.env-vars "EDITOR=vi"
(lldb) settings set -- target.env-vars "EDITOR=vi"
>> settings set -- target.env-vars "PATH=/Users/trev/bin:/Users/trev/svn/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin"
(lldb) settings set -- target.env-vars "PATH=/Users/trev/bin:/Users/trev/svn/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin"
>> settings set -- target.env-vars "TERM=xterm-256color"
(lldb) settings set -- target.env-vars "TERM=xterm-256color"
>> settings set -- target.env-vars "LOGNAME=trev"
(lldb) settings set -- target.env-vars "LOGNAME=trev"
>> settings set -- target.env-vars "SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.hZF8lnyJMB/Listeners"
(lldb) settings set -- target.env-vars "SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.hZF8lnyJMB/Listeners"
>> settings set -- target.env-vars "PAGER=more"
(lldb) settings set -- target.env-vars "PAGER=more"
>> settings set -- target.env-vars "TERM_PROGRAM_VERSION=453"
(lldb) settings set -- target.env-vars "TERM_PROGRAM_VERSION=453"
>> settings set -- target.env-vars "MACHTYPE=unknown"
(lldb) settings set -- target.env-vars "MACHTYPE=unknown"
>> settings set -- target.env-vars "SHLVL=1"
(lldb) settings set -- target.env-vars "SHLVL=1"
>> settings set -- target.env-vars "TERM_SESSION_ID=AE81EE5E-D76C-4F34-BB7A-D072B4B8406A"
(lldb) settings set -- target.env-vars "TERM_SESSION_ID=AE81EE5E-D76C-4F34-BB7A-D072B4B8406A"
>> settings set -- target.env-vars "SHELL=/bin/tcsh"
(lldb) settings set -- target.env-vars "SHELL=/bin/tcsh"
>> settings set -- target.env-vars "HOME=/Users/trev"
(lldb) settings set -- target.env-vars "HOME=/Users/trev"
>> settings set -- target.env-vars "OSTYPE=darwin"
(lldb) settings set -- target.env-vars "OSTYPE=darwin"
>> settings set -- target.env-vars "VENDOR=apple"
(lldb) settings set -- target.env-vars "VENDOR=apple"
>> settings set -- target.env-vars "HOSTTYPE=unknown"
(lldb) settings set -- target.env-vars "HOSTTYPE=unknown"
>> settings set -- target.env-vars "FTP_PASSIVE_MODE=NO"
(lldb) settings set -- target.env-vars "FTP_PASSIVE_MODE=NO"
>> settings set -- target.env-vars "TMPDIR=/var/folders/q1/0mydv3hj1qb57xqgslfpg57h0000gn/T/"
(lldb) settings set -- target.env-vars "TMPDIR=/var/folders/q1/0mydv3hj1qb57xqgslfpg57h0000gn/T/"
>> settings set -- target.env-vars "GROUP=staff"
(lldb) settings set -- target.env-vars "GROUP=staff"
>> settings set -- target.env-vars "TERM_PROGRAM=Apple_Terminal"
(lldb) settings set -- target.env-vars "TERM_PROGRAM=Apple_Terminal"
>> settings set -- target.env-vars "FTP_TIMEOUT=300"
(lldb) settings set -- target.env-vars "FTP_TIMEOUT=300"
>> settings set -- target.env-vars "__CF_USER_TEXT_ENCODING=0x1F5:0x0:0xF"
(lldb) settings set -- target.env-vars "__CF_USER_TEXT_ENCODING=0x1F5:0x0:0xF"
>> settings set -- target.env-vars "XPC_SERVICE_NAME=application.com.company.lazarus.60206869.60599802"
(lldb) settings set -- target.env-vars "XPC_SERVICE_NAME=application.com.company.lazarus.60206869.60599802"
>> settings set -- target.env-vars "XPC_FLAGS=0x0"
(lldb) settings set -- target.env-vars "XPC_FLAGS=0x0"
>> target create /Users/trev/tmp/project1.app
(lldb) target create /Users/trev/tmp/project1.app
Current executable set to '/Users/trev/tmp/project1.app' (arm64).
>> settings clear target.run-args
(lldb) settings clear target.run-args
>> breakpoint set --func fpc_break_error -K false
(lldb) breakpoint set --func fpc_break_error -K false
Breakpoint 1: no locations (pending).
>> breakpoint set --func fpc_runerror -K false
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) breakpoint set --func fpc_runerror -K false
Breakpoint 2: no locations (pending).
>> breakpoint set --func fpc_raiseexception -K false
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) breakpoint set --func fpc_raiseexception -K false
Breakpoint 3: where = project1`FPC_RAISEEXCEPTION, address = 0x000000010001c150
>> breakpoint command add 3
>> p/x $x0
>> p/x $x2
>> p ((char ***)$x0)[0][3]
>> p ((char **)$x0)[1]
>> DONE
>> version
(lldb) breakpoint command add 3
(lldb) version
>> breakpoint command add 2
>> p/x $x0
>> DONE
>> version
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
(lldb) breakpoint command add 2
(lldb) version
>> breakpoint command add 1
>> p/x $x0
>> DONE
>> version
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
(lldb) breakpoint command add 1
(lldb) version
>> process launch -n
lldb-1500.0.404.7
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
(lldb) process launch -n
Process 31267 launched: '/Users/trev/tmp/project1.app/Contents/MacOS/project1' (arm64)
Process 31267 exited with status = 0 (0x00000000)
>> process kill
>> quit

No difference with debug window open/closed before run.

I shall rerun with the extra parms and report back.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2032
  • Former Delphi 1-7, 10.2 user
Re: Debugger not working with Apple Silicon code
« Reply #14 on: May 05, 2024, 10:06:41 am »
Abbreviated debug log file saved to /tmp showing what I thought were the apposite lines:

Code: [Select]
<< Current Instruction:
TDBGInstructionQueue.RunQueue nil / nil
>> Current Instruction: breakpoint command add 1
  >> Running Instruction: breakpoint command add 1
    TTTTT data avail continue
    TTTTT data avail
    TTTTT data avail continue
    TTTTT data avail
    TDBGInstruction.MarkAsSuccess SUCCESS breakpoint command add 1
  << Finished Instruction: breakpoint command add 1 // True
<< Current Instruction:
TDBGInstructionQueue.RunQueue nil / nil
>> Current Instruction: process launch -n
  >> Running Instruction: process launch -n
    TTTTT data avail continue
    TTTTT data avail
    TTTTT data avail continue
    TTTTT data avail
    TTTTT data avail continue
    disContentReceived
    TDBGInstruction.MarkAsSuccess SUCCESS process launch -n
  << Finished Instruction: process launch -n // True
<< Current Instruction:
TDBGInstructionQueue.RunQueue nil / nil
TTTTT data avail
TTTTT data avail continue
TCocoaWidgetSet.GetSystemMetrics TODO 4
TCocoaWidgetSet.GetSystemMetrics TODO 33
TCocoaWidgetSet.GetSystemMetrics TODO 8
TTTTT data avail
TDebugProcess.StopDebugProcess FDbgProcess = nil False
TTTTT data avail continue
TTTTT loop end True
DESTROY thread destroying
DESTROY thread destroyed
TDBGInstructionQueue.QueueInstruction TLldbInstructionTargetDelete: "target delete 0", , disNew # refcnt 1
TDBGInstructionQueue.RunQueue nil / nil
>> Current Instruction: target delete 0

Again no sign of an error.

 

TinyPortal © 2005-2018