命令行应用程序:如何安装一个子进程为x code调试? [英] Command line application: How to attach a child process to xcode debugger?

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

问题描述

我目前正在在C命令行应用程序在其中创建许多子进程。所以,我需要调试这个孩子code。我建立了X code作为遵循一个子进程。 (见破发点并运行光标。)

执行某个语句之后,我得到如下面图中x code到GBN(885)连接到X code调试。

这是行不通的。我怎么能把子进程x code调试?谢谢你在前进。


解决方案

谷歌和苹果开发者页面是关于这个问题真是无语了,最后我找到了一个很好的解决方法。当我们得到X code调试器附加到过程,是过程的一个子进程正在调试或者说是已经被X code调试器,GDB,或者LLDB调试的进程出现此错误消息。

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

二,使用 GCC 来编译源$ C ​​$ CS与-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 ttys000 0:00.00 ./a.out
  501 629 628 0上午9:33 ttys000 0:00.00 ./a.out

现在,我们所要做的就是告诉X code调试由pid附加到进程。点击调试菜单,然后找到附加到进程选项,点击通过进程标识符( PID)或名称选项。然后键入子进程(或者父进程)PID和点击连接按钮。<​​/ P>

享受调试!

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!

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

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