gpt4 book ai didi

命令行应用程序 : How to attach a child process to xcode debugger?

转载 作者:太空宇宙 更新时间:2023-11-04 02:06:29 26 4
gpt4 key购买 nike

我目前正在用 C 语言制作一个命令行应用程序,其中创建了许多子进程。所以我需要调试这个子代码。我在 Xcode 上创建了一个子进程,如下所示。 (查看断点和运行光标。)

enter image description here

执行一些语句后,我让 xcode 将 GBN(885) 附加到 xcode 调试器,如下图所示。

enter image description here enter image description here

这是行不通的。如何将子进程附加到 xcode 调试器?提前谢谢你。

最佳答案

Google 和 Apple 开发者页面在这个问题上真的很沉默,最后我找到了一个很好的解决方法。当我们让 Xcode 调试器附加到正在调试的进程的子进程或者已经被 Xcode 调试器、gdb 或 lldb 调试的进程时,会出现此错误消息。

error message

为了避免这个恼人的信息,首先把kill(0, SIGSTOP)语句放在你想停止子进程的地方。在下图中,我将 kill 语句放在了子对象创建之后。

enter image description here

其次,使用 gcc 编译带有 -g 选项的源代码。

$ ls
GBN.1 gbn.c gbn.h type.h util.c util.h
$ gcc *.c -g
$ ./a.out

[1]+ Stopped ./a.out
$ ps -ef | grep a.out
501 628 600 0 9:33AM ttys000 0:00.00 ./a.out
501 629 628 0 9:33AM ttys000 0:00.00 ./a.out

现在,我们所要做的就是告诉 Xcode 调试器通过 pid 附加到进程。点击Debug菜单,然后找到Attach to process选项,点击By Process Identifier (PID) or name选项。然后键入子进程(或父进程)的 pid 并单击附加按钮。

enter image description here

享受调试吧!

enter image description here

关于命令行应用程序 : How to attach a child process to xcode debugger?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20161144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com