我参考了该文章
https://juejin.cn/post/7025992880464330766 ,已经关闭了 SIP ,在 iOS simulator 上可以正常使用 Xcode 来 attach 其他应用(如
Maps.app 等),但是在真机上 attach 其他应用时却总是报错(测试了许多不同的第三方应用),如图所示:
![1.png](
https://s2.loli.net/2023/06/24/JuYDjfzUpnkAcb7.png)
> Could not attach to pid: “34569”
> attach failed (Not allowed to attach to process. Look in the console messages (
Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)
在
Console.app 中,搜索 debugserver 得到的记录是:
```
15:22:13.862180+0800 debugserver [LaunchAttach] (38215) about to task_for_pid(34569)
15:22:13.862271+0800 debugserver error: [LaunchAttach] MachTask::TaskPortForProcessID task_for_pid(34569) failed: ::task_for_pid ( target_tport = 0x0203, pid = 34569, &task ) => err = 0x00000005 ((os/kern) failure)
15:22:13.862366+0800 debugserver 10 +0.011235 sec [9547/0103]: error: ::task_for_pid ( target_tport = 0x0203, pid = 34569, &task ) => err = 0x00000005 ((os/kern) failure) err = ::task_for_pid ( target_tport = 0x0203, pid = 34569, &task ) => err = 0x00000005 ((os/kern) failure) (0x00000005)
15:22:13.873606+0800 debugserver error: MachTask::StartExceptionThread (): task invalid, exception thread start failed.
15:22:13.873711+0800 debugserver error: [LaunchAttach] END (38215) MachProcess::AttachForDebug failed to start exception thread attaching to pid 34569: unable to start the exception thread
15:22:13.873790+0800 debugserver error: Attach failed
15:22:13.876379+0800 debugserver error: Attach failed: "Not allowed to attach to process. Look in the console messages (
Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.".
15:22:13.876475+0800 debugserver error: attach failed.
15:22:13.876552+0800 debugserver debugserver about to shut down packet communications to lldb.
15:22:13.876640+0800 debugserver 11 +0.014034 sec [9547/1307]: error: ::read ( 6, 0x16b7a6b18, 1024 ) => -1 err = Bad file descriptor (0x00000009)
15:22:13.877361+0800 debugserver debugserver secure socket proxy finish-block shut down.
15:22:13.877499+0800 debugserver debugserver expedited exit.
```
我在网上参考了其他网页,已经设置了`sudo DevToolsSecurity -enable`,检查了`get-task-allow`在我的应用中已经设为`true`,甚至是抹掉了 iPhone ,但是依然没有解决问题。
不知有没有 iOS 开发大佬遇到类似的问题,能够提供解决方案的。
我测试的 Xcode 版本为 14.3.1 (14E300c)和 15.0 beta 2 (15A5161b),macOS 版本为 13.4.1 ( Intel 处理器),真机试了两台,iOS 版本分别为 16.5 和 17.0 beta 2 ,均出现上述问题。
莫非这个 feature 是必须加入 Developer Program 才可以使用吗,或是 Apple 芯片专用?
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/951206
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.