How does one automatically attach a debugger to a process at process start on OS X?

戏子无情 提交于 2021-02-07 19:22:29

问题


I have a process that spawns a helper process. Sometimes I need to debug start-up failures in the second process.

On Windows, I would use Image File Execution Options, or ntsd -o. However, I have no idea how to do this with gdb on OS X.


回答1:


Use gdb --wait. For example, try

gdb --wait TextEdit

from the command line, then launch TextEdit.




回答2:


I don't think that you can have gdb launch in the same manner. Instead, run your parent process from within gdb or attach to the running process before it forks the helper off. There is a setting called follow-fork-mode that controls which process the debugger follows. Take a look at the GDB Manual for a nice description.




回答3:


If you're using launchd to spawn processes, then there's a WaitForDebugger boolean key which goes in the job's plist file. If it's yes, then launchd waits (surprisingly!) for the debugger before exec()ing the job.



来源:https://stackoverflow.com/questions/1384284/how-does-one-automatically-attach-a-debugger-to-a-process-at-process-start-on-os

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!