Command line application: How to attach a child process to xcode debugger?

前端 未结 1 1091
暖寄归人
暖寄归人 2021-01-06 17:00

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 follo

相关标签:
1条回答
  • 2021-01-06 17:37

    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.

    error message

    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.

    enter image description here

    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.

    enter image description here

    Enjoy Debugging!

    enter image description here

    0 讨论(0)
提交回复
热议问题