xcode LLDB:无法表达 IRGen
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43977271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LLDB: Couldn't IRGen expression
提问by niklassaers
When I'm running a unit test and want to debug something, I set a breakpoint and type for instance "po myVariable". The response I get from LLDB is:
当我运行单元测试并想要调试某些东西时,我设置了一个断点并键入例如“po myVariable”。我从 LLDB 得到的回应是:
error: Couldn't IRGen expression, no additional error
Example:
例子:
I have the smallest little unit test defined here:
我在这里定义了最小的单元测试:
class MyExampleTests: XCTestCase {
func testLLDB() {
let world = "World"
print("Breakpoint goes here")
print("Hello \(world)")
}
}
I set my breakpoint in "Breakpoint goes here", and when I run, I do 'po world':
我在“Breakpoint go here”中设置了我的断点,当我运行时,我会执行“po world”:
(lldb) po world
error: Couldn't IRGen expression, no additional error
Any suggestions to how I can make it evaluate my expression instead?
关于如何让它评估我的表达式的任何建议?
采纳答案by istvanp
If you are using CocoaPods, this may apply to you. There are two things to make sure of.
如果您使用的是CocoaPods,这可能适用于您。有两件事需要确保。
Gotcha 1: Make sure you have not added pod
dependencies to your Test target(s) in your Podfile
:
问题 1:确保您没有pod
在您的测试目标中添加依赖项Podfile
:
target 'MyApp' do
project 'MyApp'
pod 'Alamofire'
# ... other pods ...
end
target 'MyAppTests' do
project 'MyApp'
inherit! :search_paths
# Do not add your main app pods here
# You can use pods for writing your test cases though (e.g. mocks)
end
In my case I had quite a few frameworks and at least one of them was using binaries and caused LLDB to freak out if I added it to my test target.
就我而言,我有很多框架,其中至少有一个使用二进制文件,如果我将它添加到我的测试目标,则会导致 LLDB 崩溃。
As a side note/tip, if you need to use any dependencies from within your app, you need to change the runtime behavior of your main app via launch arguments instead of doing things in your testing code. (This is where I strayed from the path and it caused me problems.) You can do this by adding this to your test file:
作为旁注/提示,如果您需要在应用程序中使用任何依赖项,则需要通过启动参数更改主应用程序的运行时行为,而不是在测试代码中执行操作。(这是我偏离路径的地方,它给我带来了问题。)您可以通过将它添加到您的测试文件中来做到这一点:
# When you launch your app (e.g. in `setUpWithError()`)
let app = XCUIApplication()
app.launchArguments = ["testing-enabled"]
app.launch()
and then in your main app code (e.g. in AppDelegate
or SceneDelegate
):
然后在您的主应用程序代码中(例如 inAppDelegate
或SceneDelegate
):
#if DEBUG
if CommandLine.arguments.contains("testing-enabled") {
configureAppForTesting()
}
#endif
The #if DEBUG
is not necessary but it's good practice to not ship code that will not be executed in the published app.
这#if DEBUG
不是必需的,但最好不要发布不会在已发布的应用程序中执行的代码。
Gotcha 2: If you have custom build configurations, make sure your tests run in Debug
mode.
问题 2:如果您有自定义构建配置,请确保您的测试在Debug
模式下运行。
For example, if we have created a build config called App Store
based on Release
and a test config based on Debug
, then we need to do the following in our Podfile
:
例如,如果我们创建了一个名为App Store
based的构建配置Release
和一个基于 的测试配置Debug
,那么我们需要在我们的 中执行以下操作Podfile
:
target 'MyApp' do # do it for MyAppTests also!
project 'MyApp', 'App Store' => :release, 'Test' => :debug
# ... pod dependencies, etc.
end
Without this setting, your dependencies will be built using the default iOS config which is a Release
type of configuration (with compiler optimizations for both Swiftand GCCthat the debugger won't like).
如果没有此设置,您的依赖项将使用默认的 iOS 配置构建,这是一种Release
配置(对调试器不喜欢的Swift和GCC进行编译器优化)。
Finally, make sure that your scheme's Test mode is set to use the proper build configuration (in this case Test
) as in the screenshot below.
最后,确保您的方案的测试模式设置为使用正确的构建配置(在本例中Test
),如下面的屏幕截图所示。
回答by Jonathan Cabrera
I was having the same issue using Carthage frameworks, and got the LLDB debugger working again by deleting the Carthagefolder in the project root and forcing Carthage to rebuild the frameworks from source:
我在使用 Carthage 框架时遇到了同样的问题,通过删除项目根目录中的Carthage文件夹并强制 Carthage 从源代码重建框架,LLDB 调试器再次工作:
carthage update --platform iOS --no-use-binaries
回答by Jorge Omar MH
you can try with netx command: Depend where you have install swift, in my case is in /opt/swift/
您可以尝试使用 netx 命令:取决于您安装 swift 的位置,在我的情况下是在 /opt/swift/
sudo chmod 644 /opt/swift-3.1.1/usr/lib/swift/CoreFoundation/*
回答by Anton Malmygin
In my case, I just restarted Xcode, and it's good :)
就我而言,我刚刚重新启动了 Xcode,这很好 :)
回答by de.
I have a quick and dirty solution that makes this work.
我有一个快速而肮脏的解决方案,可以使这项工作发挥作用。
select the first accessible frame in your debug navigator, usually
main
type something in the debugger, for example
po self
- select the original frame in the debug navigator and execute your command, it should work now
I don't know why it works, but it does for me. I just found out by chance.
I'd be interested to hear an explanation from somebody with more insights (I am using Carthage in my project).
我不知道为什么它有效,但它对我有用。我只是偶然发现的。
我很想听听有更多见解的人的解释(我在我的项目中使用 Carthage)。
回答by arturgrigor
I had the exact same problem because of the Instabug
framework.
由于Instabug
框架,我遇到了完全相同的问题。
If you can't find a solution then you should export the LLDB logs by running the log enable lldb expr -f /some/path/to/save/logs
command in the debugger and check for failures in that file because that's what helped me.
如果您找不到解决方案,那么您应该通过log enable lldb expr -f /some/path/to/save/logs
在调试器中运行命令来导出 LLDB 日志并检查该文件中的故障,因为这对我有帮助。
Also, you should file a bug report on http://bugs.swift.org/with the LLDB logs attached to it.
此外,您应该在http://bugs.swift.org/上提交错误报告,并附上 LLDB 日志。