命令行应用程序:如何将子进程附加到xcode调试器? [英] Command line application: How to attach a child process to xcode debugger?

查看:981
本文介绍了命令行应用程序:如何将子进程附加到xcode调试器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在C中创建一个命令行应用程序,其中创建了许多子进程。所以我需要调试这个孩子代码。我已经在Xcode上创建了一个子进程,如下所示。 (见断点和运行光标。)





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





它不起作用。如何将子进程附加到xcode调试器?谢谢你提前。

解决方案

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





为了避免这种刺激性的消息,首先把 kill(0,SIGSTOP)语句放在你想要停止子进程的地方。在下图中,我已经在孩子创建之后放置了 kill 语句。





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

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

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

现在,我们要做的就是告诉Xcode调试器通过pid附加到进程。点击 Debug 菜单,然后找到附加到选项,点击按进程标识符PID)或名称选项。然后键入子进程(或父进程)的pid,然后单击附加按钮。





享受调试!




I'm currently making a command line app in C in which many child process is created. So I need to debug this children code. I have created a child process on Xcode as follow. (see the break point and running cursor.)

After executing some statements, I get xcode to attach GBN(885) to the xcode debugger as shown in below figure.

It doesn't work. How can I attach the child process to xcode debugger? Thank you in advance.

解决方案

Google and Apple developer page are really silent on this issue and finally I've found a good workaround. This error message appears when we get Xcode debugger to attach to the process that is a child process of process being debugged or that is a process already being debugged by Xcode debugger, gdb, or lldb.

In order to avoid this irritating message, First put kill(0, SIGSTOP) statement where you want to stop the child process. In the following figure, I have put the kill statement right after the child is created.

Second, use gcc to compile your source codes with -g option.

$ 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

Now, all we have to do is to tell Xcode debugger to attach to the process by pid. Click the Debug menu and then find the Attach to process option to click By Process Identifier (PID) or name option. Then type the pid for child process (or parent process) and click attach button.

Enjoy Debugging!

这篇关于命令行应用程序:如何将子进程附加到xcode调试器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆