From d28b8882d7600078bfaf78ca4b5d5506c404bc72 Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Wed, 26 Sep 2018 17:29:46 +0300 Subject: [PATCH] fix: close the gdb socket on start application in order to avoid app freeze on unhandled exception --- IOSDeviceLib/GDBHelper.cpp | 8 ++++++-- IOSDeviceLib/GDBHelper.h | 2 +- IOSDeviceLib/IOSDeviceLib.cpp | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/IOSDeviceLib/GDBHelper.cpp b/IOSDeviceLib/GDBHelper.cpp index 6400b84..7e11135 100644 --- a/IOSDeviceLib/GDBHelper.cpp +++ b/IOSDeviceLib/GDBHelper.cpp @@ -62,9 +62,9 @@ bool init(std::string& executable, SOCKET socket, std::string& application_ident return true; } -bool run_application(std::string& executable, SOCKET socket, std::string& application_identifier, std::map& apps_cache) +bool run_application(std::string& executable, SOCKET socket, std::string& application_identifier, DeviceData* device_data) { - RETURN_IF_FALSE(init(executable, socket, application_identifier, apps_cache)); + RETURN_IF_FALSE(init(executable, socket, application_identifier, device_data->apps_cache)); // Couldn't find official info on this but I'm guessing this is the method we need to call RETURN_IF_FALSE(await_response("qLaunchSuccess", socket)); // vCont specifies a command to be run - c means continue @@ -81,6 +81,9 @@ bool run_application(std::string& executable, SOCKET socket, std::string& applic // We have decided we do not need this at the moment, but it is vital that it be read from the pipe // Else it will remain there and may be read later on and mistaken for a response to same other package std::string answer = receive_message_raw(socket); + + detach_connection(socket, application_identifier, device_data); + return true; } @@ -130,4 +133,5 @@ void detach_connection(SOCKET socket, std::string& application_identifier, Devic std::string answer = receive_message_raw(socket); device_data->apps_cache[application_identifier].has_initialized_gdb = false; device_data->services.erase(kDebugServer); + close(socket); } diff --git a/IOSDeviceLib/GDBHelper.h b/IOSDeviceLib/GDBHelper.h index b5a53c4..527ae17 100644 --- a/IOSDeviceLib/GDBHelper.h +++ b/IOSDeviceLib/GDBHelper.h @@ -6,7 +6,7 @@ std::string get_gdb_message(std::string message); int gdb_send_message(std::string message, SOCKET socket, long long length = -1); -bool run_application(std::string& executable, SOCKET socket, std::string& application_identifier, std::map& apps_cache); +bool run_application(std::string& executable, SOCKET socket, std::string& application_identifier, DeviceData* device_data); bool stop_application(std::string& executable, SOCKET socket, std::string& application_identifier, std::map& apps_cache); void detach_connection(SOCKET socket, std::string& application_identifier, DeviceData* device_data); diff --git a/IOSDeviceLib/IOSDeviceLib.cpp b/IOSDeviceLib/IOSDeviceLib.cpp index f891bef..189c399 100644 --- a/IOSDeviceLib/IOSDeviceLib.cpp +++ b/IOSDeviceLib/IOSDeviceLib.cpp @@ -1260,7 +1260,7 @@ void start_app(std::string device_identifier, std::string application_identifier } std::string executable = map[application_identifier][kPathPascalCase] + "/" + map[application_identifier]["CFBundleExecutable"]; - if (run_application(executable, (SOCKET)gdb, application_identifier, devices[device_identifier].apps_cache)) + if (run_application(executable, (SOCKET)gdb, application_identifier, &devices[device_identifier])) print(json({ { kResponse, "Successfully started application" },{ kId, method_id },{ kDeviceId, device_identifier } })); else print_error("Could not start application", device_identifier, method_id, kApplicationsCustomError);