Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run iOS apps in an lldb session #77

Closed
wants to merge 1 commit into from

Conversation

sharplet
Copy link
Contributor

Getting an lldb session running in the simulator is a two-step process:

  1. The binary itself must be launched from within lldb in order to capture the processes output streams.
  2. Once the binary is launched, the app must then be "launched" from within the simulator. This doesn't actually create a new process, but instead brings the app into the foreground of the simulator, and is analogous to tapping on the app icon.

Because of the order of these steps, the xcrun simctl launch command has to be run from with the lldb session.

Because lldb won't normally accept further commands after process launch, we use the -s argument to have the app pause just after starting (like stopping at a breakpoint). However, running xcrun simctl launch at this very early stage (before main has even executed) causes a separate instance of the app to start up in the simulator.

In order to work around this we set a breakpoint on -[UIApplication _run], which is early enough that the application hasn't actually started yet, but after UIApplicationMain has set everything up and started the main run loop. Breaking here is a safe place to shell out to xcrun simctl launch, which will no longer start a separte process because the app is already "running".

The other quirk is that in order to feed commands to lldb we need to use the -s option, which requires a file. So the launch script is written to a temporary file first so that it can be passed to lldb. Bash process substitution may also work (e.g., <(cat "$script")).

Getting an lldb session running in the simulator is a two-step process:

 1. The binary itself must be launched from within lldb in order to
    capture the processes output streams.

 2. Once the binary is launched, the app must then be "launched" from
    within the simulator. This doesn't actually create a new process,
    but instead brings the app into the foreground of the simulator, and
    is analogous to tapping on the app icon.

Because of the order of these steps, the `xcrun simctl launch` command
has to be run from with the lldb session.

Because lldb won't normally accept further commands after `process
launch`, we use the `-s` argument to have the app pause just after
starting (like stopping at a breakpoint). However, running `xcrun simctl
launch` at this very early stage (before `main` has even executed)
causes a separate instance of the app to start up in the simulator.

In order to work around this we set a breakpoint on `-[UIApplication _run]`,
which is early enough that the application hasn't actually started yet,
but after `UIApplicationMain` has set everything up and started the main
run loop. Breaking here is a safe place to shell out to `xcrun simctl
launch`, which will no longer start a separte process because the app is
already "running".

The other quirk is that in order to feed commands to lldb we need to use
the `-s` option, which requires a file. So the launch script is written
to a temporary file first so that it can be passed to lldb. Bash process
substitution may also work (e.g., `<(cat "$script")`).
@keith keith mentioned this pull request Jul 25, 2016
@keith
Copy link
Contributor

keith commented Jul 29, 2016

Related conversation: #76 (comment)

@sharplet sharplet closed this Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants