简体   繁体   中英

Xcode 8 Breakpoint in file not working

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 .

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.

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. Clean Build Folder
  3. Clear Xcode's DerivedData
  4. Making sure breakpoints are enabled (Cmd Y)
  5. Build Settings are set to Debug
  6. Always Show Disassembly enabled and disabled
  7. Debugging enabled in run config

Any help would be very much appreciated.

UPDATE 1 (still no luck):

  1. Tried deleting the Xcode preference as suggested by neprocker's answer here

UPDATE 2 :

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

UPDATE 3 :

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

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.

在此输入图像描述

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.

在此输入图像描述

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.

在此输入图像描述

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.

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.

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

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

I resolved the issue in below ways:

  • Remove XCode defaults Using below terminal command

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

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

  • Install fresh copy of 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 ]

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

  • Make sure breakpoints are enabled and set debug point in your code

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

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

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

构建配置

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

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

For example:

宏

Hope this helps.

在标准编辑器中打开viewController.swift文件以获取初始视图,并在viewDidLoad中打印一些内容并运行应用程序..如果打印工作正常,请确保在助手编辑器中正确选择了viewController.swift文件。

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. 在Build Settings下搜索目标的优化级别

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM