xcodedebugginglldb

How do I place a breakpoint at the start of an application in Xcode lldb?


I would like to find out what is going on when my app binary is loaded but before any code is ran.

Following a stackoverflow answer here, I tried to do this:

(lldb) process launch --stop-at-entry -- <Process arguments>

by configuring the build n run settings in XCode I did so by adding --stop-at-entry into the Arguments of Run Debug settings as show below

enter image description here

But it just ran without stopping anywhere.

What am I doing wrongly? How do I place a breakpoint at the start of my application?


Solution

  • Xcode manages process launching itself, so running process launch in the Xcode console doesn't really work, as there's no one fetching events for the new process.

    The "Arguments passed on launch" are passed to the program you are debugging when it is launched, so they aren't meant not to change lldb's behavior, besides handing them on to the debugee lldb doesn't really look act on them.

    You can modify lldb's behind the scenes behavior by using lldb's settings. There isn't a setting for "stop at entry point" but there is one for "stop on each shared library load". So put:

    settings set target.process.stop-on-sharedlibrary-events true
    

    in your ~/.lldbinit, then launch and you will stop after the main binary is loaded, and (if you don't change the setting back) after each subsequent load.

    The start point is actually a fairly unfriendly place to stop, nothing has actually been initialized yet, and if you poke around too much you can mess up the state of environment of the program you are trying to run. Stopping after the first library load completes leaves you in a much saner place.

    However, if you really do want to watch the code very early in program startup, you'll have to use command-line lldb.