Attach lldb to iPhone from command line - ios

While attaching lldb to iPhone works from within Xcode. It is flaky at times. I wonder if it is because XCode has some additional checks before attaching to a process in iPhone. I'd like to debug an iPhone app from command line. lldb has some tutorial that suggest using platform select but that command is unsuccessful in even connecting.
$ (lldb) platform select remote-ios
Platform: remote-ios
Connected: no
Am I missing something?
This question has been asked earlier but has no correct answers:
Debugging iPhone App from Command Line
Attach LLDB to app on iPhone connected to computer - Command line

Probably the easiest way to do this is using ios-deploy e.g.
ios-deploy --bundle=<bundle.app> --debug
The above command will install your application bundle to the attached iOS device, and launch it with an lldb session connected.

Related

Xcode 14 is not getting attached to Simulator in Debug mode

While debugging any iOS application, Xcode builds and run successfully, also launches a simulator but it is not able to attach debugger from Xcode 14 to Simulator iOS app.
It throws an error in Xcode:
Xcode console says:
Could not attach to pid : “75997” Domain: IDEDebugSessionErrorDomain
Code: 3 Failure Reason: attach failed (Not allowed to attach to
process. Look in the console messages (Console.app), near the
debugserver entries, when the attach failed. The subsystem that
denied the attach permission will likely have logged an informative
message about why it was denied.) User Info: {
DVTRadarComponentKey = 855031;
IDERunOperationFailingWorker = DBGLLDBLauncher;
RawUnderlyingErrorMessage = "attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the
debugserver entries, when the attach failed. The subsystem that
denied the attach permission will likely have logged an informative
message about why it was denied.)"; }
Tried with re-installing Xcode and Command line tools, but issue persists.
Steps:
Build and run app with Debug executables true
Simulator gets launched
Error on Xcode and it gets disconnected from simulator
Is there a possibility that it can be blocked by any other app, if so how to identify ?
I solved the issue by doing the steps below:
SOLUTION 1:
Edit the scheme
Select Run
Select Build Configuration "Debug"
Select "Wait for the executable to be launched"
Close
Run the app
see the screenshot here
You will receive an error message when you run the app again.
Close the app.
Edit the scheme again and change "Wait for the executable to be launched" to "Automatically".
Now your simulator will work as expected.
SOLUTION 2:
Delete your app folder in Derived Data
/Users/[your username]/Library/Developer/Xcode/DerivedData/
Search your app name folders and delete them.
SOLUTION 3:
Open the terminal and run:
sudo DevToolsSecurity -enable
This command enables the Developer Mode. After running the command you will receive this message: [Developer mode is now enabled].
Sometimes it's happen, when you are trying to build too fast after a build has started.
First of all, quit your current simulator, delete derived data and clean the project, wait until whole processing is complete. Then do some changes / editing if required (as we clean all data) and try running on a different simulator.
Check certificates in key-chain access, if you found any untrusted certificates in key-chain access remove it.
Also if you are using beta version just make sure it is downloaded from Apple official website.
Came here to share my (strange) solution if anybody crosses the same problem with no answers working. In my case, no solution from this nor other SO answers to similar questions worked (cleaning, rebuilding project, updating, clearing derived data..)
My setup is:
Macbook M1 2022 + Xcode Version 14.2 (14C18)
This Xcode version could not attach to any of my apps (fresh new or previously developed) on different simulators (11, 12, 14) with iOS versions 13.7 - 16.2.
Editing scheme solution from answer above was not working also so I ended up in leaving scheme as:
Build configuration: Release
Debug executable Deselected(!)
Launch Automatically
And magically debugging app in Xcode started working even though it's release version with debug option deselected.. Selecting Debug executable again makes Xcode not possible in attaching to app process
Just to clarify: above steps actually makes app to run as in DEBUG mode - Xcode attaches to pid, I can do console logs and breakpoints. This Xcode version behaves opposite than options selected

Not able to launch app in iOS simulator in vscode

I am new to vscode, I tried running my code in iOS simulator but its not showing the simulator in the first place.
the options i get are
view android emulators
view iOS simulators
But when I click on view iOS simulators I get a pop up saying
" Something went wrong fetching you iOS simulators! Make sure you have Xcode installed. Try running this command in your terminal: instruments -s devices "
You may need to run this command, when VSCode tries access the simulator there may be error which says
Cannot find "xcodebuild". Xcode 11.0.0 or greater is required to
develop for iOS. Encountered error while building for device.
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

Calabash can't connect to simulator

I'm trying to run some Calabash UI tests in my app but am running into trouble connecting to my simulator. I'm trying to just connect view the calabash-ios console, but am running into the following error:
WARNING
Warning Trying to connect to simulator that was not launched by Calabash/instruments.
To fix this you must let Calabash or instruments launch the app.
Query will work, but gestures will not.
I've run the app view my -cal target and have successfully seen the message Started LPHTTP server on port 37265. Here's some more info on Calabash/my setup:
xcode-select --print-path
/Applications/Xcode.app/Contents/Developer
xcodebuild -version
Xcode 7.0
Build version 7A218
calabash-ios version
0.14.3
server_version
=> {"app_id"=>"com.solstice.discoverfinancialenterprise.mobile", "outcome"=>"SUCCESS", "server_port"=>37265, "version"=>"0.14.3", "app_name"=>"Discover", "system"=>"x86_64", "simulator_device"=>"iPhone", "simulator"=>"", "app_version"=>"1", "short_version_string"=>"6.6.1 UAT", "iphone_app_emulated_on_ipad"=>false, "app_base_sdk"=>"iphonesimulator9.0", "form_factor"=>"iphone 4in", "git"=>{"revision"=>"c2d009b", "remote_origin"=>"git#github.com:calabash/calabash-ios-server.git", "branch"=>"master"}, "screen_dimensions"=>{"sample"=>1, "height"=>1136, "width"=>640, "scale"=>2}, "4inch"=>true, "iOS_version"=>"8.4"}
Sorry the JSON isn't formatted, my console spat it out in an unformatted way.
I've used a few different simulators, iPhone 6, iOS 9 and iOS 8.3, and an iPhone 5s iOS 8.4. Does anyone know anything I need to do differently to get this to connect to my simulator?
+100 for including all the information about your environment.
Please update to Calabash 0.16.4 which is compatible with your Xcode version.
I'm trying to just connect view the calabash-ios console, but am running into the following error:
Can you show how you launched console and what command you tried to run?
Typically, you want something like this:
$ APP=/path/to/Your.app calabash-ios console
> start_test_server_in_background
You must let calabash launch the app or you will not be able to perform gestures.
APP and APP_BUNDLE_PATH are synonymous.
http://calabashapi.xamarin.com/ios/file.ENVIRONMENT_VARIABLES.html#label-APP+and+APP_BUNDLE_PATH

How to debug an iOS app with lldb on the command line on a device without Xcode

Is is possible to launch and debug one of my iOS apps in development on an iPhone (or other iOS device) without using Xcode?
I would like to do this from the command line using lldb.
I figure that since it can be done with Xcode that it may be possible to debug strictly from within the terminal.
ios-deploy can do that.
brew install node
npm install -g ios-deploy
ios-deploy -d -W -b path/to/foo.app
It will copy the app bundle to your connected device, launch the app, and start an lldb session for the app.
I just tested it right now. OSX 10.12.6, iOS 11.0.2, Xcode 9.0.1.
it is possible to debug your app without using xcode on a jailbroken device all you need is to add entitlements on debug server if you wish to debug apps you did not build , there is a great explanation here http://iphonedevwiki.net/index.php/Debugserver , once you attached to the process on the device just launch lldb on your computer and debug

Terminal command-line debug of iOS Simulator apps?

Is it possible to use GDB or LLDB from the Terminal command-line under Mac OS X to debug apps running on the iOS Simulator? (e.g. not from within Xcode's GUI or console, but using an external command-line or process). If so, how?
You'll need to have the app already in the simulator's Springboard; you can't launch the app in the simulator from Xcode and then expect to be able to have a command line instance of gdb attach to it.
So:
Run the iOS Simulator, having already gotten your app into it.
In a terminal window:
% gdb
...
(gdb) attach --waitfor 'Name Of Your App'
Launch your app from the simulator Springboard.
gdb should attach to the process before main() is executed. So you can set some breakpoints, or whatever. Then:
(gdb) continue
The procedure for lldb is similar:
% lldb
(lldb) process attach -n 'Name Of Your App' --waitfor
<launch your app in the simulator>
(lldb) continue
I am not sure why you'd want or need to do this, but as an old command line gdb (and dbx) guy, I can appreciate it. :-)

Resources