LLDB:无法IRGen表达式 [英] LLDB: Couldn't IRGen expression

查看:95
本文介绍了LLDB:无法IRGen表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行单元测试并想要调试某些东西时,我设置一个断点并键入例如"po myVariable".我从LLDB获得的响应是​​:

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:

error: Couldn't IRGen expression, no additional error

示例:

我在这里定义了最小的小单元测试:

I have the smallest little unit test defined here:

class MyExampleTests: XCTestCase {
    func testLLDB() {
        let world = "World"
        print("Breakpoint goes here")
        print("Hello \(world)")
    }
}

我将断点设置为"Breakpoint go here",当我跑步时,我会执行"po world":

I set my breakpoint in "Breakpoint goes here", and when I run, I do '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?

推荐答案

如果您使用的是 CocoaPods ,则可能适用于您.有两件事要确保.

If you are using CocoaPods, this may apply to you. There are two things to make sure of.

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

就我而言,我有很多框架,其中至少有一个正在使用二进制文件,并且如果将LLDB添加到测试目标中,则会导致LLDB异常.

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.

作为旁注/提示,如果您需要使用应用程序中的任何依赖项,则需要通过启动参数而不是在测试代码中执行操作来更改主应用程序的运行时行为. (这是我偏离路径的地方,它导致了我的问题.)您可以通过将其添加到测试文件中来做到这一点:

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()

,然后在您的主应用代码中(例如,在AppDelegateSceneDelegate中):

and then in your main app code (e.g. in AppDelegate or SceneDelegate):

#if DEBUG
if CommandLine.arguments.contains("testing-enabled") {
    configureAppForTesting()
}
#endif

#if DEBUG不是必需的,但是最好不要发布将不会在已发布的应用程序中执行的代码.

The #if DEBUG is not necessary but it's good practice to not ship code that will not be executed in the published app.

例如,如果我们基于Release创建了名为App Store的构建配置,并基于Debug创建了测试配置,那么我们需要在Podfile中执行以下操作:

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:

target 'MyApp' do # do it for MyAppTests also!
  project 'MyApp', 'App Store' => :release, 'Test' => :debug

  # ... pod dependencies, etc.
end

如果没有此设置,则将使用默认的iOS配置(Release配置类型)来构建依赖项(对

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 Swift and GCC that the debugger won't like).

最后,请确保将方案的测试"模式设置为使用正确的构建配置(在本例中为Test),如下面的屏幕截图所示.

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.

这篇关于LLDB:无法IRGen表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆