无法附加到进程 ID Xcode
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11535844/
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
Failed to Attach to Process ID Xcode
提问by Rendy
Anyone has experienced this problem? Yesterday I still can run my app in simulator but now I cannot run my app since Xcode prints this error in console:
任何人都遇到过这个问题?昨天我仍然可以在模拟器中运行我的应用程序,但现在我无法运行我的应用程序,因为 Xcode 在控制台中打印了这个错误:
error: failed to attach to process ID <ID number>
I have tried to reinstall, do this postand create new project but returns no luck. Anyone can resolve this issue?
我试图重新安装,做这篇文章并创建新项目,但没有返回任何运气。任何人都可以解决这个问题?
I use Xcode 4.5 Preview 2 and try to run iOS simulator 6
我使用 Xcode 4.5 Preview 2 并尝试运行 iOS 模拟器 6
回答by Robert Zahm
Resetting the content and settings in the simulator worked for me. This is available in the "iOS Simulator" menu.
重置模拟器中的内容和设置对我有用。这在“iOS 模拟器”菜单中可用。
回答by Imran
go to the Product menu and find the Edit Scheme menu there.
转到产品菜单并在那里找到编辑方案菜单。
While in Edit Scheme window, select the "Run" option on the left hand side of the screen and then on the right hand side, change the debugger from LLDB to GDB.
在 Edit Scheme 窗口中,选择屏幕左侧的“Run”选项,然后在右侧,将调试器从 LLDB 更改为 GDB。
回答by Mirko Luchi
I experienced the same problem, and after a while I found out that it was due to the fact that my XCode project included a Folder Referenceto a folder named Resources.
我遇到了同样的问题,一段时间后我发现这是由于我的 XCode 项目包含一个名为Resources的文件夹的文件夹引用。
It seems that XCode doesn't like that name.
似乎 XCode 不喜欢这个名字。
Just removing the folder referenceor renaming the foldersolved the issue.
只需删除文件夹引用或重命名文件夹即可解决问题。
回答by Ambili B Menon
TWO METHODS
两种方法
Method 1: Inside the folder Application Support -> iPhone Simulator -> In the each simulator version of iOS-> Applications -> Delete all the files present here.
方法 1:在文件夹Application Support -> iPhone Simulator ->在 iOS 的每个模拟器版本中-> Applications ->删除这里存在的所有文件。
Now go to Products -> Clean
现在去产品 -> 清洁
Now run it on any simulator and it will work.
现在在任何模拟器上运行它,它会工作。
Method 2:
方法二:
回答by Intentss
Step1: ping
第一步:ping
$ ping localhost
This should return something like
这应该返回类似
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.028 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.048 ms
...
If this works, this answer won't fix your problem, try something else.
如果这有效,则此答案无法解决您的问题,请尝试其他方法。
If ping return something else for example: ping: cannot resolve localhost: Unknown host
something is screwed up with your /etc/hosts
file, go to Step 2
如果 ping 返回其他内容,例如:ping: cannot resolve localhost: Unknown host
您的/etc/hosts
文件搞砸了,请转到第 2 步
Step2: Check /etc/hosts
步骤 2:检查 /etc/hosts
Check that the top of your /etc/hosts
file looks like this
检查/etc/hosts
文件顶部是否如下所示
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
If it doesn't have these entries in the file, enter them at the top of the file, flush the dns cache using $ dscacheutil -flushcache
and go back to Step 1, otherwise continue to Step 3.
如果文件中没有这些条目,请在文件顶部输入它们,使用刷新 dns 缓存$ dscacheutil -flushcache
并返回步骤 1,否则继续步骤 3。
Step3: Correct File Format: It should be unix or LF *
步骤 3:正确的文件格式:应该是 unix 或 LF *
$ file /etc/hosts
This should return: /etc/hosts: ASCII English text
这应该返回: /etc/hosts: ASCII English text
If it returns something like /etc/hosts: ASCII English text, with CR line terminators
then the file is in the wrong format and is likely being ignored.
如果它返回类似的内容,/etc/hosts: ASCII English text, with CR line terminators
则该文件的格式错误并且很可能被忽略。
Change the file line endings to unix or LF using your favorite text editor.
使用您喜欢的文本编辑器将文件行结尾更改为 unix 或 LF。
- In Sublime Text 2 this can be done throught the view menue: View > Line Endings > Unix
- 在 Sublime Text 2 中,这可以通过视图菜单完成: View > Line Endings > Unix
Flush the dns cache ($ dscacheutil -flushcache
) and go back to step 1
刷新 dns 缓存 ( $ dscacheutil -flushcache
) 并返回到步骤 1
回答by amattn
Similar to fundtimer's answer, the local hosts file seems to have been the culprit.
与fundtimer 的回答类似,本地主机文件似乎是罪魁祸首。
I had to change my /etc/hosts
permissions back to the default after an inadvertent change:
/etc/hosts
在无意中更改后,我不得不将我的权限更改回默认值:
sudo chmod 644 /etc/hosts
After that, simulator/LLDB worked for me.
之后,模拟器/LLDB 对我来说有效。
回答by eploko
This is an old topic, but I believe things have changed a bit for the latest version of macOS.
这是一个老话题,但我相信最新版本的 macOS 发生了一些变化。
I've stumbled on the issue while trying to run an UI test suite for an iOS app in the simulator on macOS Mojave Beta and Xcode 9.4.1.
我在 macOS Mojave Beta 和 Xcode 9.4.1 上的模拟器中尝试为 iOS 应用程序运行 UI 测试套件时偶然发现了这个问题。
Turns out, on macOS Mojave the codesign
tool (which is a part of the OS itself and not a part of the Command Line Tools or Xcode) signs processes into a hardened runtimeenvironment which includes runtime code signing enforcement, library validation, hard, kill, and debugging restrictions. This, together with the System Integrity Protection in macOS Mojave, prevents the lldb debugger from connecting to the running target.
事实证明,在 macOS Mojave 上,该codesign
工具(它是操作系统本身的一部分,而不是命令行工具或 Xcode 的一部分)将进程签名到强化的运行时环境中,其中包括运行时代码签名实施、库验证、硬、杀死、和调试限制。这与 macOS Mojave 中的系统完整性保护一起可防止 lldb 调试器连接到正在运行的目标。
To resolve this, you have to options:
要解决此问题,您必须选择:
An obvious one, probably, is just to use Xcode 10. It does seem to handle the connection gracefully.
Reboot the OS into the Recovery Mode and turn off the System Integrity Protection from the Terminal with
csrutil disable
. The debugger then connects happily.
一个显而易见的可能就是使用 Xcode 10。它似乎确实可以优雅地处理连接。
将操作系统重新启动到恢复模式并从终端关闭系统完整性保护
csrutil disable
。然后调试器愉快地连接。
I've spent quite an amount of time banging my head on this and was able to resolve it all after reading the following article: http://www.lapcatsoftware.com/articles/debugging-mojave.html
我花了相当多的时间来解决这个问题,并在阅读以下文章后解决了所有问题:http: //www.lapcatsoftware.com/articles/debugging-mojave.html
Just my two cents. Hope this helps someone.
只有我的两分钱。希望这可以帮助某人。
回答by Christopher Larsen
I know this is an old question, but it came up first for me when I did a google search for "failed to attach to process ID". I'm using Xcode 7. Happened after iOS9 was released and I had updated my swift app for swift 2.
我知道这是一个老问题,但是当我在谷歌搜索“无法附加到进程 ID”时,它首先出现在我身上。我正在使用 Xcode 7。发生在 iOS9 发布之后,我已经为 swift 2 更新了我的 swift 应用程序。
Deleting my app in the simulator and doing a new build and run cleared it up.
在模拟器中删除我的应用程序并进行新构建并运行清除它。
回答by pedrouan
I had somehow removed or deleted records from my /etc/hosts file and I got the same error. You should check whether you have in your /etc/hosts file the line "127.0.0.1 localhost". This helped me!
我以某种方式从我的 /etc/hosts 文件中删除或删除了记录,我遇到了同样的错误。您应该检查您的 /etc/hosts 文件中是否有“127.0.0.1 localhost”这一行。这对我有帮助!
回答by Nic Foster
I just removed the application from the simulator (just like you would on an actual device), and when I re-ran it everything worked fine.
我刚刚从模拟器中删除了应用程序(就像在实际设备上一样),当我重新运行它时一切正常。