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

Allow multiple connection to debugserver when running with --nolldb #527

Merged
merged 1 commit into from
Mar 7, 2023

Conversation

nisargjhaveri
Copy link

Fix #523: Allow server mode for debugserver

With this, when running with --nolldb, we create a new debugserver connection every time we accept a connection on the local port and start the proxy loop. This way, multiple connections including simultaneous connections are possible as long as the device is connected.
This still does not behave nicely when device disconnects and reconnects.

@N9o4455
Copy link

N9o4455 commented Jan 10, 2022

🥲

@ivanhernandez13
Copy link

Sorry that I managed to miss this and it did not pop up in my radar in the last 6 months. I will review this today

server_callback (CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info)

CFSocketContext get_socket_context(int connection_id) {
CFSocketContext context = { 0, (void*)CFNumberCreate(NULL, kCFNumberIntType, &connection_id), NULL, NULL, NULL };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These calls to CFNumberCreate need to be CFRelease'd. You may need to pass around a CFNumber instead of an int and the caller handles releasing the CFNumber.

{
CFMutableDictionaryRef connection_properties = get_connection_properties(connection_id);

ServiceConnRef dbgServiceConnection = (ServiceConnRef)CFDictionaryGetValue(connection_properties, @"service_connection");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we store these dictionary keys that are used multiple times as CFString constants and replace the literals with the constants?

@gabebear
Copy link

gabebear commented Mar 6, 2023

I just merged in #575

If we get the issues here addressed we should be able to merge this in as well and get them both into the same mainline release.

@nisargjhaveri
Copy link
Author

nisargjhaveri commented Mar 7, 2023

@gabebear, I've pushed some changes with a couple of improvements.

  • Addressed the issues in the comments
  • Handle device disconnection and exit if the device is disconnected, also improve the logging to get parity in json and non-json logging in case of --detect

Also, I was thinking if we should have a separate flag to allow this "server" mode and keep the old behaviour for the simple --nolldb flag? Suggestions?

@gabebear
Copy link

gabebear commented Mar 7, 2023

I think we are OK without a server flag here. Ideally the old --nolldb usages should just continue working. I think most usags of --nolldb are by IDEs which will likely want to incorporate this change when it hits mainline and lock ios-depoy within the IDE to a specific version.

@gabebear gabebear merged commit d0c383a into ios-control:master Mar 7, 2023
@nisargjhaveri nisargjhaveri deleted the debugserver_server_mode branch March 9, 2023 19:36
@Timen
Copy link

Timen commented Mar 15, 2023

This PR causes launches with the --justlaunch argument to fail with this backtrace:

*** First throw call stack:
(
	0   CoreFoundation                      0x00000001b31c5148 __exceptionPreprocess + 240
	1   libobjc.A.dylib                     0x00000001b2f0fe04 objc_exception_throw + 60
	2   CoreFoundation                      0x00000001b329716c -[__NSCFString characterAtIndex:].cold.1 + 0
	3   CoreFoundation                      0x00000001b329a6ec -[NSMutableDictionary __setObject:forKey:].cold.1 + 0
	4   CoreFoundation                      0x00000001b30fd458 -[__NSDictionaryM setObject:forKey:] + 0
	5   ios-deploy                          0x0000000102fcd618 get_connection_properties + 72
	6   ios-deploy                          0x0000000102fcdc80 create_remote_debug_server_socket + 32
	7   ios-deploy                          0x0000000102fce4b8 setup_lldb + 292
	8   ios-deploy                          0x0000000102fce724 launch_debugger_and_exit + 20
	9   ios-deploy                          0x0000000102fd55a4 handle_device + 1848
	10  MobileDevice                        0x0000000103b78bc4 _AMDDeviceAttachedCallbackv3 + 376
	11  MobileDevice                        0x0000000103ad3a20 _USBMuxCustomRunLoopSourcePerformCallback + 1196
	12  CoreFoundation                      0x00000001b3144f94 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
	13  CoreFoundation                      0x00000001b3144ee0 __CFRunLoopDoSource0 + 208
	14  CoreFoundation                      0x00000001b3144be0 __CFRunLoopDoSources0 + 268
	15  CoreFoundation                      0x00000001b3143560 __CFRunLoopRun + 828
	16  CoreFoundation                      0x00000001b3142a84 CFRunLoopRunSpecific + 600
	17  CoreFoundation                      0x00000001b31cfc68 CFRunLoopRun + 64
	18  ios-deploy                          0x0000000102fd69ac main + 1960
	19  dyld                                0x000000010316508c start + 520
)

@gabebear
Copy link

@Timen mind filing an issue for this? https://github.com/ios-control/ios-deploy/issues/new

If not, we will test this and get it filed later. I haven't tried to repro this yet, but it can sometimes help to have versions of Xcode/gcc/etc when tracking down bugs.

@Timen
Copy link

Timen commented Mar 16, 2023

done: #578

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.

Allow server mode for debugserver
5 participants