7 Replies
      Latest reply on Dec 7, 2018 2:22 AM by eskimo
      ElenaS Level 1 Level 1 (10 points)

        Currently we're debugging our custom built Automator Actions using os_log, but it's time consuming.

        Is it possible to debug custom action using Xcode ?

         

        As we see workflow is run on behalf of app's processs(not Automator).

        We tried to debug by attaching app's process, but unsuccessfully.

         

        Our mac app has AMWorkflowController bound to AMWorkflowView

        and in it we're adding custom Automator actions located in app's Library Automator folder.

        • Re: Debugging custom automator action in Xcode
          eskimo Apple Staff Apple Staff (10,285 points)

          We tried to debug by attaching app's process, but unsuccessfully.

          Can you be more specific about what actually failed here?

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: Debugging custom automator action in Xcode
              ElenaS Level 1 Level 1 (10 points)

              Sorry. Should have been more specific.

              It fails to stop at breakpoints and we see that these code lines are executed.

                • Re: Debugging custom automator action in Xcode
                  eskimo Apple Staff Apple Staff (10,285 points)

                  I suspect what’s happening here is that your custom automator action is being run in a separate process, and thus attaching to your main app doesn’t help you debug it.  However, I’m not sufficiently up-to-speed on Automator to say that definitively.

                  Earlier you wrote:

                  Currently we're debugging our custom built Automator Actions using os_log, but it's time consuming.

                  Those log entries should contain a process ID (in Console you’ll need to click Details to see the PID field).  Does that process ID match that of your app?  Or some system process?  And if it’s the latter, what process is that?

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"

                    • Re: Debugging custom automator action in Xcode
                      ElenaS Level 1 Level 1 (10 points)

                      We've logged ProcessInfo.processInfo.processIdentifier both in app and in attached Automator action bundle.

                      And It seems process is the same.

                      Could it be because of this bundle architecture ?

                        • Re: Debugging custom automator action in Xcode
                          eskimo Apple Staff Apple Staff (10,285 points)

                          If your bundle is being loaded into the debugged process Xcode should be able to set breakpoints on it.  Generally I’ve found that to be pretty reliable, but there are things that can go wrong.

                          Here’s one thing you can try:

                          1. At the start of the code you want to debug, add code like this:

                            os_log(… something unique …);
                            pause();

                            .

                          2. Use Console to watch to that unique thing being logged.

                          3. Break into the debugger and inspect each thread.  One of them should be the thread on which you called pause.

                          4. Navigate up that thread’s backtrace to see if Xcode is showing source code for your frames.

                          5. If it is, set a breakpoint in your code, immediately after the pause call.

                          6. Continue execution.

                          Do you hit the breakpoint?


                          The pause function causes the thread to stop and wait for a signal.  Attaching with the debugger generates a signal, and thus gets you out of the pause.  This is super helpful in situations where you want to debug something that’s otherwise hard to catch in the debugger.

                          You can read more about pause in its man page.

                          Share and Enjoy

                          Quinn “The Eskimo!”
                          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                          let myEmail = "eskimo" + "1" + "@apple.com"

                            • Re: Debugging custom automator action in Xcode
                              ElenaS Level 1 Level 1 (10 points)

                              You're right.

                              Automator action is run by another process: com.apple.automator.runner.

                              Is there anything we can do about it ?

                               

                              There's property in plist: AMApplication.

                              Can it be used to make it run this applications process ?

                                • Re: Debugging custom automator action in Xcode
                                  eskimo Apple Staff Apple Staff (10,285 points)

                                  Automator action is run by another process: com.apple.automator.runner.

                                  Yeah, that’s an XPC Service within the Automator framework (/System/Library/Frameworks/Automator.framework/XPCServices/com.apple.automator.runner.xpc).  As this is built in to the system you won’t be able to attach to it with the debugger, at least not while System Integrity Protection (SIP) is enabled.

                                  You should try disabling SIP to see if that allows you to debug.  To learn more, see the System Integrity Protection Guide.

                                  IMPORTANT Don’t disable SIP permanently, just for the sake of this test and then, in the future, for any debugging efforts.

                                  Share and Enjoy

                                  Quinn “The Eskimo!”
                                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                                  let myEmail = "eskimo" + "1" + "@apple.com"