在Cocoa程序中访问Swift REPL

问题描述 投票:3回答:2

我可以将LLDB附加到用Swift编写的程序中,并从Xcode内部或通过运行来访问REPL:

lldb -n ProcessName
(lldb) repl
  1>

但是,如果我将LLDB附加到没有Swift运行时的进程,则REPL不是很有用。例如:

lldb -n Finder
Process 218 stopped
Executable module set to "/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder".
Architecture set to: x86_64-apple-macosx.
(lldb) repl
  1> import Cocoa
error: Couldn't lookup symbols:
  __swift_FORCE_LOAD_$_swiftAppKit
  __swift_FORCE_LOAD_$_swiftCoreGraphics
  __swift_FORCE_LOAD_$_swiftObjectiveC
  __swift_FORCE_LOAD_$_swiftDispatch
  __swift_FORCE_LOAD_$_swiftDarwin
  __swift_FORCE_LOAD_$_swiftFoundation

有关如何将Swift运行时加载到尚未链接的进程中的任何想法?这可能是例如非常有用的替代方案。注入F脚本。

cocoa swift read-eval-print-loop lldb f-script
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.