当从Xcode外部启动应用程序时,Xcode调试断点

时间:2023-01-18 11:23:39

Bottom-line question: Is it possible to have Xcode wait for an application to launch, then launch the application from outside of Xcode, then have Xcode stop at a breakpoint?

底线问题:是否有可能让Xcode等待应用程序启动,然后从Xcode外部启动应用程序,然后让Xcode停在断点处?

--detailed description below--

- 下面详细说明 -

I would like to debug (step through line-by-line) a simple C program that requires text to be piped in to stdin using Xcode 4.6.3 on 10.8.5.

我想调试(逐行逐行)一个简单的C程序,它需要使用10.8.5上的Xcode 4.6.3将文本传送到stdin。

In order to do-so I need to launch the program like this $ cat in.txt | ./mysimpleprogram > out.txt and have the Xcode debugger stop at a breakpoint.

为了做到这一点,我需要像这个$ cat in.txt |一样启动程序./mysimpleprogram> out.txt并让Xcode调试器在断点处停止。

I followed the instructions that I found in this answer https://*.com/a/13006633/2779792 but Xcode does not stop at the breakpoints.

我按照我在这个答案https://*.com/a/13006633/2779792中找到的说明进行操作,但Xcode不会在断点处停止。

To reproduce the issue

重现这个问题

  1. Open Xcode 4.6.3

    打开Xcode 4.6.3

  2. In the "Welcome to Xcode" screen choose "Create a new Xcode project"

    在“欢迎使用Xcode”屏幕中选择“创建新的Xcode项目”

  3. In the "Choose a template for your new project" screen choose Mac OS X -> Application -> Command Line Tool then click Next

    在“为新项目选择模板”屏幕中,选择Mac OS X - >应用程序 - >命令行工具,然后单击下一步

  4. In the "Choose options for your new project:" screen Product Name: HelloWorld, Type: C -> Next, Use Automatic Reference Counting = False

    在“为新项目选择选项:”屏幕产品名称:HelloWorld,类型:C - >下一步,使用自动引用计数= False

  5. Choose a location for the project.

    选择项目的位置。

Note: In Xcode preferences -> Locations -> Derived data, I have selected "Relative"

注意:在Xcode首选项 - >位置 - >派生数据中,我选择了“相对”

  1. Go to Product menu -> Scheme -> Edit Scheme

    转到产品菜单 - >方案 - >编辑方案

  2. On the left side of the Scheme Editing window, selected by default is "Run HelloWorld Debug". On the right side of the Scheme Editing window I changed the Launch Automatically radio button to "Wait for HelloWorld to launch". Debugger = LLDB, Debug Process As = me

    在Scheme Editing窗口的左侧,默认选择“Run HelloWorld Debug”。在Scheme Editing窗口的右侧,我将Launch Automatically单选按钮更改为“Wait for HelloWorld to launch”。 Debugger = LLDB,Debug Process As = me

  3. Set one or more breakpoints in the code.

    在代码中设置一个或多个断点。

  4. Select Product -> Run (or click the Play button). Now the main Xcode window says "Waiting for HelloWorld to launch".

    选择产品 - >运行(或单击“播放”按钮)。现在主要的Xcode窗口显示“等待HelloWorld启动”。

  5. Open a terminal window and navigate to the HelloWorld executable, in my case .../HelloWorld/DerivedData/HelloWorld/Build/Products/Debug/

    打开一个终端窗口并导航到HelloWorld可执行文件,在我的例子中... / HelloWorld / DerivedData / HelloWorld / Build / Products / Debug /

  6. run the program with the command ./HelloWord

    使用./HelloWord命令运行程序

The program runs and prints Hello, World! as expected, Xcode says "Finished running HelloWorld : HelloWorld". It did not stop at any of the breakpoints.

该程序运行并打印Hello,World!正如预期的那样,Xcode说“完成了运行HelloWorld:HelloWorld”。它并没有停留在任何断点上。

Desired behavior, Xcode should stop at the breakpoints and allow me to step through the code.

期望的行为,Xcode应该停在断点处,并允许我单步执行代码。

Thank you for any help or hints.

感谢您提供任何帮助或提示。

1 个解决方案

#1


11  

In the time it takes the debugger to notice and attach to your process execution of the process has proceeded past the breakpoints. To get deterministic behavior from the debugger in this setup you need to pause execution of your process prior to the first breakpoint and wait for the debugger to attach. A simple way to do this is by adding code to send the STOP signal:

在调试器注意到并附加到您的流程所花费的时间内,流程的执行已经过了断点。要在此设置中从调试器获取确定性行为,您需要在第一个断点之前暂停执行进程并等待调试器附加。一种简单的方法是添加代码来发送STOP信号:

raise(SIGSTOP);

Execution will stop at this point and the debugger will automatically continue when it attaches.

执行将在此时停止,调试器将在附加时自动继续。

#1


11  

In the time it takes the debugger to notice and attach to your process execution of the process has proceeded past the breakpoints. To get deterministic behavior from the debugger in this setup you need to pause execution of your process prior to the first breakpoint and wait for the debugger to attach. A simple way to do this is by adding code to send the STOP signal:

在调试器注意到并附加到您的流程所花费的时间内,流程的执行已经过了断点。要在此设置中从调试器获取确定性行为,您需要在第一个断点之前暂停执行进程并等待调试器附加。一种简单的方法是添加代码来发送STOP信号:

raise(SIGSTOP);

Execution will stop at this point and the debugger will automatically continue when it attaches.

执行将在此时停止,调试器将在附加时自动继续。