It seems that the official toolchains on swift.org don't have the proper entitlements to debug processes.
This breaks the REPL as well:
lldb ls
(lldb) target create "ls"
Current executable set to 'ls' (x86_64).
(lldb) r
error: process exited with status -1 (attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.))
(lldb) q
------------
Apple Swift version 5.6-dev (LLVM 7aef0efea99e2c6, Swift e4f71c8e118fc09)
Target: x86_64-apple-macosx11.0
Welcome to Swift!
Subcommands:
swift build Build Swift packages
swift package Create and work on packages
swift run Run a program from a package
swift test Run package tests
swift repl Experiment with Swift code interactively (default)
Use `swift --help` for descriptions of available options and flags.
Use `swift help <subcommand>` for more information about a subcommand.
error: failed to launch REPL process: process exited with status -1 (attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.))
EDIT
Console:
macOSTaskPolicy: (com.apple.debugserver) may not get the task control port of (repl_swift) (pid: 86426):
(repl_swift) is hardened, (repl_swift) doesn't have get-task-allow, (com.apple.debugserver) is a declared debugger
(com.apple.debugserver) is not a declared read-only debugger
Agree, I got many problems when building the swift toolchain, and ask questions on this forum, but no one can help me to solve these problems, disappointing.
Still happens, but I was able to fix it without creating a new code-signing certificate. If you sign with the identity name "-", it uses ad-hoc signing, which apparently is sufficient: