Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i debug the opening of my application from a file on OSX?

I linked my application to a file extension, so when i double click those files it opens my application. However i experience crash when doing so, and i am looking for a way to breakpoint that and see what's going wrong. I'm using Xcode, it's an OSX app.

Any idea?

like image 558
BaptisteB Avatar asked Dec 04 '25 15:12

BaptisteB


1 Answers

lldb doesn't have a "launch with open AppleEvent" feature, so you can't do this directly.

But you can use lldb's "attach wait" feature to catch the app early in startup. You can do this in Xcode by turning on "Wait for the executable to be launched" in the Info tab of the Run scheme of your App target. Then click the Run button, and go to Finder to launch your app by double-clicking on one of its files.

If your system is not heavily loaded, lldb will generally stop the app pretty early in its startup, usually before it gets to handling the open event. Xcode will auto-continue the app, so it should just proceed right to the crash.

If for some reason lldb doesn't attach early enough, edit the main function of your application, and at the very top put in:

int go_on = 0;
while(!go_on) {
  sleep(1);
}

That way your app will stall in launching before it handles the open event, giving lldb time to attach. Once it has attached, Pause the app in the debugger, select the thread and frame containing this main function, go to the lldb Console and do:

(lldb) expr go_on = 1

and then continue. Now your app should finish starting up, handle the open event and crash into the debugger.

like image 127
Jim Ingham Avatar answered Dec 07 '25 15:12

Jim Ingham