Xcode 8文件中的断点不起作用

时间:2021-11-11 23:38:59

I have one file,SignInViewController.swift, in my Xcode project that out of nowhere has begun not stopping on breakpoints. I have a breakpoint in viewDidLoad() and a few in viewDidAppear(). I have several print() calls in both functions to make sure they are executing. Breakpoints work fine in other files including AppDelegate.swift.

我有一个文件,SignInViewController.swift,在我的Xcode项目中,无处不在已经开始没有停在断点上。我在viewDidLoad()中有一个断点,在viewDidAppear()中有一些断点。我在两个函数中都有几个print()调用,以确保它们正在执行。断点在其他文件中工作正常,包括AppDelegate.swift。

There was a point when I trying to figure out what was wrong where I noticed that while I was building the project an error would appear saying Invalid redeclaration of 'signInViewController.swift' and then go away before the build finished and the app would run fine, except for the breakpoints in the file. signInViewController.swift is the old name of the file from months ago before I renamed it to SignInViewController.swift. I haven't seen it before until the breakpoint issue occurred and since I have cleaned the project's build folder and Xcode's derived data I have been unable to replicate. I have a feeling that it is factoring into the problem but I am not sure how/why.

有一点,当我试图找出错误的地方时,我注意到在我构建项目的过程中会出现一个错误,表示“signInViewController.swift”的重新声明无效,然后在构建完成之前消失并且应用程序运行正常,除了文件中的断点。 signInViewController.swift是几个月前我重命名为SignInViewController.swift之前的文件的旧名称。我之前没有看到它,直到断点问题发生,因为我已经清理了项目的构建文件夹和Xcode的派生数据,我无法复制。我有一种感觉,它正在考虑问题,但我不确定如何/为什么。

Anyways, here is things I've tried already. Most of them are just for breakpoints not working in general but I figure I should list them anyways even though that is not the case:

无论如何,这是我已经尝试过的事情。他们中的大多数只是一般不起作用的断点,但我想我应该列出它们,即使事实并非如此:

  1. Clean Project
  2. 清洁项目
  3. Clean Build Folder
  4. 清理构建文件夹
  5. Clear Xcode's DerivedData
  6. 清除Xcode的DerivedData
  7. Making sure breakpoints are enabled (Cmd Y)
  8. 确保断点已启用(Cmd Y)
  9. Build Settings are set to Debug
  10. Build Settings设置为Debug
  11. Always Show Disassembly enabled and disabled
  12. 始终显示反汇编启用和禁用
  13. Debugging enabled in run config
  14. 在运行配置中启用调试

Any help would be very much appreciated.

任何帮助将非常感谢。

UPDATE 1 (still no luck):

更新1(仍然没有运气):

  1. Tried deleting the Xcode preference as suggested by neprocker's answer here
  2. 尝试删除neprocker的答案所建议的Xcode偏好

UPDATE 2:

更新2:

I have isolated the breakpoint issue to just viewDidLoad() and viewDidAppear() breakpoints elsewhere in the file are working.

我已经将断点问题隔离到viewDidLoad()和viewDidAppear()文件中其他地方的断点正在工作。

UPDATE 3:

更新3:

Isolated to a specific block of code in viewDidLoad(). viewDidAppear() still not working though.

隔离到viewDidLoad()中的特定代码块。 viewDidAppear()仍然无法正常工作。

10 个解决方案

#1


19  

I had the same problem with an old project. Select Product(located at top menu bar) -> Scheme -> EditScheme and I solved this issue by clicking on "Debug Executable", as shown in Picture. Maybe this will help someone else too.

我对旧项目遇到了同样的问题。选择产品(位于顶部菜单栏) - > Scheme - > EditScheme,我点击“Debug Executable”解决了这个问题,如图所示。也许这也会帮助别人。

Xcode 8文件中的断点不起作用

#2


12  

In my case breakpoint was not hit in just one callback, so I changed "Swift Compiler" "Optimization Level" to "No optimization" in project target build settings for debug, and it started working in Xcode 9.3 as well as AppCode.

在我的例子中,断点没有在一次回调中被击中,因此我在调试的项目目标构建设置中将“Swift编译器”“优化级别”更改为“无优化”,并且它开始在Xcode 9.3以及AppCode中工作。

Xcode 8文件中的断点不起作用

#3


5  

What helped for me was deleting the file Breakpoints_v2.xcbkptlist which is located under the project directory (*.xcodeproj) in the directory: xcuserdata/Fred.xcuserdatad/xcdebugger (replace "Fred" with your username). Use a terminal program to go there.

对我有帮助的是删除文件Breakpoints_v2.xcbkptlist,该文件位于目录中的项目目录(* .xcodeproj)下:xcuserdata / Fred.xcuserdatad / xcdebugger(用您的用户名替换“Fred”)。使用终端程序去那里。

#4


5  

I solved this by going to my Xcode project's 'Build Settings' and setting 'Generate Debug Symbols' to 'Yes'

我通过转到我的Xcode项目的'Build Settings'并将'Generate Debug Symbols'设置为'Yes'来解决这个问题

#5


4  

I'm not really sure how this ended up fixing it but I isolated the issue to a specific block of code in viewDidLoad(). Then I commented out that code and built and ran the project. Then I uncommented the code and built and ran it again and the breakpoints worked.

我不确定这最终是如何修复它但我将问题隔离到viewDidLoad()中的特定代码块。然后我注释掉了代码并构建并运行了项目。然后我取消注释代码并构建并再次运行它并且断点有效。

#6


3  

Sometimes the values may have changed in Xcode userdefaults itself, At times, I had similar issue with debugger stopping at stacktrace Few ways to clear this

有时,Xcode userdefaults本身的值可能已经发生变化,有时,我遇到类似的问题,调试器在stacktrace停止。很少有方法可以清除这个

1.Delete the Xcode preference
defaults delete com.apple.dt.Xcode

Other Issue could be the optimization level for the target, changing it to none will stop at the debugger

其他问题可能是目标的优化级别,将其更改为none将停止在调试器上

#7


3  

I was also dealing with the same issue in xcode 9.

我也在xcode 9中处理同样的问题。

I resolved the issue in below ways:

我通过以下方式解决了这个问题:

  • Remove XCode defaults Using below terminal command

    删除XCode默认值使用下面的terminal命令

    defaults delete com.apple.dt.Xcode.LSSharedFileList   
    defaults delete com.apple.dt.Xcode
    
  • Clear(or delete) Xcode's DerivedData from

    从中清除(或删除)Xcode的DerivedData

    /Users/[Your Mac Username]/Library/Developer/Xcode/DerivedData
    
  • Delete(or uninstall) Xcode.app from Applications and then restart PC

    从Applications中删除(或卸载)Xcode.app,然后重新启动PC

  • Install fresh copy of Xcode 9

    安装Xcode 9的新副本

  • [Mandatory] Set user permission to your app project like

    [强制]为您的应用项目设置用户权限

    chmod -R 777 "/Users/[Your Mac Username]/Desktop/TestApp/"
    

    [where TestApp is the app project keeping on Desktop]

    [TestApp是保持在桌面上的应用程序项目]

  • Open the project and check Build Settings are set to Debug

    打开项目并检查Build Settings是否设置为Debug

  • Make sure breakpoints are enabled and set debug point in your code
  • 确保断点已启用并在代码中设置调试点

#8


3  

Below patch is work for me. From the menu bar, select Product -> Scheme -> Edit Scheme -> Select Profile -> Set Build Configuration to BUILD. Please review below-attached screenshot.

下面的补丁对我有用。从菜单栏中,选择产品 - >方案 - >编辑方案 - >选择配置文件 - >将构建配置设置为BUILD。请查看下面附带的屏幕截图。

Xcode 8文件中的断点不起作用

#9


1  

In my case, it turns out that the Dev build configuration is not configured properly.

在我的例子中,事实证明Dev build配置没有正确配置。

Xcode 8文件中的断点不起作用

The Dev configuration should be copied from Debug, not Release.

Dev配置应该从Debug而不是Release中复制。

You can search with word debug in your Build settings to see the differences.

您可以在Build设置中使用word debug进行搜索,以查看差异。

For example:

例如:

Xcode 8文件中的断点不起作用

Hope this helps.

希望这可以帮助。

#10


0  

Building up on what @neprocker said, I had "Optimize for Speed" for both debug/release. Simply changed the value for debug and I was good to go.Xcode 8文件中的断点不起作用

在@neprocker所说的基础上,我为调试/发布提供了“Optimize for Speed”。只需更改调试值,我就可以了。

#1


19  

I had the same problem with an old project. Select Product(located at top menu bar) -> Scheme -> EditScheme and I solved this issue by clicking on "Debug Executable", as shown in Picture. Maybe this will help someone else too.

我对旧项目遇到了同样的问题。选择产品(位于顶部菜单栏) - > Scheme - > EditScheme,我点击“Debug Executable”解决了这个问题,如图所示。也许这也会帮助别人。

Xcode 8文件中的断点不起作用

#2


12  

In my case breakpoint was not hit in just one callback, so I changed "Swift Compiler" "Optimization Level" to "No optimization" in project target build settings for debug, and it started working in Xcode 9.3 as well as AppCode.

在我的例子中,断点没有在一次回调中被击中,因此我在调试的项目目标构建设置中将“Swift编译器”“优化级别”更改为“无优化”,并且它开始在Xcode 9.3以及AppCode中工作。

Xcode 8文件中的断点不起作用

#3


5  

What helped for me was deleting the file Breakpoints_v2.xcbkptlist which is located under the project directory (*.xcodeproj) in the directory: xcuserdata/Fred.xcuserdatad/xcdebugger (replace "Fred" with your username). Use a terminal program to go there.

对我有帮助的是删除文件Breakpoints_v2.xcbkptlist,该文件位于目录中的项目目录(* .xcodeproj)下:xcuserdata / Fred.xcuserdatad / xcdebugger(用您的用户名替换“Fred”)。使用终端程序去那里。

#4


5  

I solved this by going to my Xcode project's 'Build Settings' and setting 'Generate Debug Symbols' to 'Yes'

我通过转到我的Xcode项目的'Build Settings'并将'Generate Debug Symbols'设置为'Yes'来解决这个问题

#5


4  

I'm not really sure how this ended up fixing it but I isolated the issue to a specific block of code in viewDidLoad(). Then I commented out that code and built and ran the project. Then I uncommented the code and built and ran it again and the breakpoints worked.

我不确定这最终是如何修复它但我将问题隔离到viewDidLoad()中的特定代码块。然后我注释掉了代码并构建并运行了项目。然后我取消注释代码并构建并再次运行它并且断点有效。

#6


3  

Sometimes the values may have changed in Xcode userdefaults itself, At times, I had similar issue with debugger stopping at stacktrace Few ways to clear this

有时,Xcode userdefaults本身的值可能已经发生变化,有时,我遇到类似的问题,调试器在stacktrace停止。很少有方法可以清除这个

1.Delete the Xcode preference
defaults delete com.apple.dt.Xcode

Other Issue could be the optimization level for the target, changing it to none will stop at the debugger

其他问题可能是目标的优化级别,将其更改为none将停止在调试器上

#7


3  

I was also dealing with the same issue in xcode 9.

我也在xcode 9中处理同样的问题。

I resolved the issue in below ways:

我通过以下方式解决了这个问题:

  • Remove XCode defaults Using below terminal command

    删除XCode默认值使用下面的terminal命令

    defaults delete com.apple.dt.Xcode.LSSharedFileList   
    defaults delete com.apple.dt.Xcode
    
  • Clear(or delete) Xcode's DerivedData from

    从中清除(或删除)Xcode的DerivedData

    /Users/[Your Mac Username]/Library/Developer/Xcode/DerivedData
    
  • Delete(or uninstall) Xcode.app from Applications and then restart PC

    从Applications中删除(或卸载)Xcode.app,然后重新启动PC

  • Install fresh copy of Xcode 9

    安装Xcode 9的新副本

  • [Mandatory] Set user permission to your app project like

    [强制]为您的应用项目设置用户权限

    chmod -R 777 "/Users/[Your Mac Username]/Desktop/TestApp/"
    

    [where TestApp is the app project keeping on Desktop]

    [TestApp是保持在桌面上的应用程序项目]

  • Open the project and check Build Settings are set to Debug

    打开项目并检查Build Settings是否设置为Debug

  • Make sure breakpoints are enabled and set debug point in your code
  • 确保断点已启用并在代码中设置调试点

#8


3  

Below patch is work for me. From the menu bar, select Product -> Scheme -> Edit Scheme -> Select Profile -> Set Build Configuration to BUILD. Please review below-attached screenshot.

下面的补丁对我有用。从菜单栏中,选择产品 - >方案 - >编辑方案 - >选择配置文件 - >将构建配置设置为BUILD。请查看下面附带的屏幕截图。

Xcode 8文件中的断点不起作用

#9


1  

In my case, it turns out that the Dev build configuration is not configured properly.

在我的例子中,事实证明Dev build配置没有正确配置。

Xcode 8文件中的断点不起作用

The Dev configuration should be copied from Debug, not Release.

Dev配置应该从Debug而不是Release中复制。

You can search with word debug in your Build settings to see the differences.

您可以在Build设置中使用word debug进行搜索,以查看差异。

For example:

例如:

Xcode 8文件中的断点不起作用

Hope this helps.

希望这可以帮助。

#10


0  

Building up on what @neprocker said, I had "Optimize for Speed" for both debug/release. Simply changed the value for debug and I was good to go.Xcode 8文件中的断点不起作用

在@neprocker所说的基础上,我为调试/发布提供了“Optimize for Speed”。只需更改调试值,我就可以了。