From 42999a48f9cfce6f84c3a6f9b8f0a263130a0ce8 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Wed, 22 Feb 2012 02:18:59 +0000 Subject: [PATCH] Change #ifdef markers around lockdown and SpringBoard calls to dpeend on WITH_SPRINGBOARD and WITH_LOCKDOWN instead of __arm__. Add an RNBSocket::useFD method. llvm-svn: 151119 --- .../debugserver.xcodeproj/project.pbxproj | 20 ++++++++++++++++- lldb/tools/debugserver/source/DNBDefs.h | 2 +- lldb/tools/debugserver/source/DNBError.cpp | 4 ++-- lldb/tools/debugserver/source/DNBError.h | 2 +- .../debugserver/source/MacOSX/MachProcess.cpp | 18 +++++++-------- .../debugserver/source/MacOSX/MachProcess.h | 2 +- .../debugserver/source/MacOSX/MachTask.cpp | 12 +++++----- lldb/tools/debugserver/source/RNBDefs.h | 2 +- lldb/tools/debugserver/source/RNBServices.cpp | 6 ++--- lldb/tools/debugserver/source/RNBSocket.cpp | 22 +++++++++++++++---- lldb/tools/debugserver/source/RNBSocket.h | 10 ++++++++- lldb/tools/debugserver/source/debugserver.cpp | 10 ++++----- 12 files changed, 74 insertions(+), 36 deletions(-) diff --git a/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj b/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj index 20137fa8ba22..e9ec94130b10 100644 --- a/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj +++ b/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj @@ -383,7 +383,7 @@ 08FB7793FE84155DC02AAC07 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0420; + LastUpgradeCheck = 0430; }; buildConfigurationList = 1DEB914E08733D8E0010E9CD /* Build configuration list for PBXProject "debugserver" */; compatibilityVersion = "Xcode 3.2"; @@ -563,6 +563,12 @@ INSTALL_PATH = /usr/bin; LLDB_DEBUGSERVER = 1; OTHER_CFLAGS = "-Wparentheses"; + "OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = ( + "-Wparentheses", + "-DWITH_LOCKDOWN", + "-DWITH_SPRINGBOARD", + ); + "OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)"; OTHER_LDFLAGS = ( "-sectcreate", __TEXT, @@ -603,6 +609,12 @@ INSTALL_PATH = /usr/bin; LLDB_DEBUGSERVER = 1; OTHER_CFLAGS = "-Wparentheses"; + "OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = ( + "-Wparentheses", + "-DWITH_LOCKDOWN", + "-DWITH_SPRINGBOARD", + ); + "OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)"; OTHER_LDFLAGS = ( "-sectcreate", __TEXT, @@ -642,6 +654,12 @@ INSTALL_PATH = /usr/bin; LLDB_DEBUGSERVER = 1; OTHER_CFLAGS = "-Wparentheses"; + "OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = ( + "-Wparentheses", + "-DWITH_LOCKDOWN", + "-DWITH_SPRINGBOARD", + ); + "OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)"; OTHER_LDFLAGS = ( "-sectcreate", __TEXT, diff --git a/lldb/tools/debugserver/source/DNBDefs.h b/lldb/tools/debugserver/source/DNBDefs.h index 87926327504a..fce2cac052a5 100644 --- a/lldb/tools/debugserver/source/DNBDefs.h +++ b/lldb/tools/debugserver/source/DNBDefs.h @@ -98,7 +98,7 @@ typedef enum eLaunchFlavorDefault = 0, eLaunchFlavorPosixSpawn, eLaunchFlavorForkExec, -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD eLaunchFlavorSpringBoard, #endif } nub_launch_flavor_t; diff --git a/lldb/tools/debugserver/source/DNBError.cpp b/lldb/tools/debugserver/source/DNBError.cpp index 8f6294bfb51e..84727e77fa20 100644 --- a/lldb/tools/debugserver/source/DNBError.cpp +++ b/lldb/tools/debugserver/source/DNBError.cpp @@ -16,7 +16,7 @@ #include "DNBLog.h" #include "PThreadMutex.h" -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD #include #endif @@ -39,7 +39,7 @@ DNBError::AsString() const s = ::strerror (m_err); break; -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD case SpringBoard: { CFStringRef statusStr = SBSApplicationLaunchingErrorString (m_err); diff --git a/lldb/tools/debugserver/source/DNBError.h b/lldb/tools/debugserver/source/DNBError.h index 10c6638c7372..78b2c8b50f38 100644 --- a/lldb/tools/debugserver/source/DNBError.h +++ b/lldb/tools/debugserver/source/DNBError.h @@ -28,7 +28,7 @@ public: Generic = 0, MachKernel, POSIX -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD , SpringBoard #endif } FlavorType; diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp index 264c7362e617..d0d4c8d09bef 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp @@ -40,13 +40,12 @@ static CFStringRef CopyBundleIDForPath (const char *app_buncle_path, DNBError &err_str); -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD #include #include #include - static bool IsSBProcess (nub_process_t pid) { @@ -74,7 +73,6 @@ IsSBProcess (nub_process_t pid) return false; } - #endif #if 0 @@ -1328,7 +1326,7 @@ MachProcess::AttachForDebug (pid_t pid, char *err_str, size_t err_len) SetState(eStateAttaching); m_pid = pid; // Let ourselves know we are going to be using SBS if the correct flag bit is set... -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD if (IsSBProcess(pid)) m_flags |= eMachProcessFlagsUsingSBS; #endif @@ -1377,7 +1375,7 @@ MachProcess::AttachForDebug (pid_t pid, char *err_str, size_t err_len) const void * MachProcess::PrepareForAttach (const char *path, nub_launch_flavor_t launch_flavor, bool waitfor, DNBError &err_str) { -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD // Tell SpringBoard to halt the next launch of this application on startup. if (!waitfor) @@ -1444,7 +1442,7 @@ MachProcess::CheckForProcess (const void *attach_token) if (attach_token == NULL) return INVALID_NUB_PROCESS; -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD CFStringRef bundleIDCFStr = (CFStringRef) attach_token; Boolean got_it; nub_process_t attach_pid; @@ -1465,7 +1463,7 @@ MachProcess::CheckForProcess (const void *attach_token) void MachProcess::CleanupAfterAttach (const void *attach_token, bool success, DNBError &err_str) { -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD if (attach_token == NULL) return; @@ -1540,7 +1538,7 @@ MachProcess::LaunchForDebug launch_err); break; -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD case eLaunchFlavorSpringBoard: { @@ -1898,7 +1896,7 @@ MachProcess::ForkChildForPTraceDebugging return pid; } -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD pid_t MachProcess::SBLaunchForDebug (const char *path, char const *argv[], char const *envp[], bool no_stdio, DNBError &launch_err) @@ -2151,6 +2149,6 @@ MachProcess::SBForkChildForPTraceDebugging (const char *app_bundle_path, char co return INVALID_NUB_PROCESS; } -#endif // #if defined (__arm__) +#endif // #ifdef WITH_SPRINGBOARD diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.h b/lldb/tools/debugserver/source/MacOSX/MachProcess.h index d52735adba71..af9fb698bfb7 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.h +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.h @@ -77,7 +77,7 @@ public: static const void * PrepareForAttach (const char *path, nub_launch_flavor_t launch_flavor, bool waitfor, DNBError &err_str); static void CleanupAfterAttach (const void *attach_token, bool success, DNBError &err_str); static nub_process_t CheckForProcess (const void *attach_token); -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD pid_t SBLaunchForDebug (const char *app_bundle_path, char const *argv[], char const *envp[], bool no_stdio, DNBError &launch_err); static pid_t SBForkChildForPTraceDebugging (const char *path, char const *argv[], char const *envp[], bool no_stdio, MachProcess* process, DNBError &launch_err); #endif diff --git a/lldb/tools/debugserver/source/MacOSX/MachTask.cpp b/lldb/tools/debugserver/source/MacOSX/MachTask.cpp index 88f3f46b45ee..49605a95e654 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachTask.cpp +++ b/lldb/tools/debugserver/source/MacOSX/MachTask.cpp @@ -33,7 +33,7 @@ #include "DNBDataRef.h" #include "stack_logging.h" -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD #include #include @@ -444,7 +444,7 @@ MachTask::ExceptionThread (void *arg) task_t task = mach_task->TaskPort(); mach_msg_timeout_t periodic_timeout = 0; -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD mach_msg_timeout_t watchdog_elapsed = 0; mach_msg_timeout_t watchdog_timeout = 60 * 1000; pid_t pid = mach_proc->ProcessID(); @@ -474,7 +474,7 @@ MachTask::ExceptionThread (void *arg) if (periodic_timeout == 0 || periodic_timeout > watchdog_timeout) periodic_timeout = watchdog_timeout; } -#endif // #if defined (__arm__) +#endif // #ifdef WITH_SPRINGBOARD while (mach_task->ExceptionPortIsValid()) { @@ -555,7 +555,7 @@ MachTask::ExceptionThread (void *arg) continue; } -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD if (watchdog.get()) { watchdog_elapsed += periodic_timeout; @@ -583,7 +583,7 @@ MachTask::ExceptionThread (void *arg) } } -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD if (watchdog.get()) { // TODO: change SBSWatchdogAssertionRelease to SBSWatchdogAssertionCancel when we @@ -593,7 +593,7 @@ MachTask::ExceptionThread (void *arg) DNBLogThreadedIf(LOG_TASK, "::SBSWatchdogAssertionRelease(%p)", watchdog.get()); ::SBSWatchdogAssertionRelease (watchdog.get()); } -#endif // #if defined (__arm__) +#endif // #ifdef WITH_SPRINGBOARD DNBLogThreadedIf(LOG_EXCEPTIONS, "MachTask::%s (%p): thread exiting...", __FUNCTION__, arg); return NULL; diff --git a/lldb/tools/debugserver/source/RNBDefs.h b/lldb/tools/debugserver/source/RNBDefs.h index f603d3d22a66..bf3549747d38 100644 --- a/lldb/tools/debugserver/source/RNBDefs.h +++ b/lldb/tools/debugserver/source/RNBDefs.h @@ -42,7 +42,7 @@ extern "C" const double debugserverVersionNumber; #elif defined (__arm__) -#define RNB_ARCH "armv6" +#define RNB_ARCH "armv7" #else diff --git a/lldb/tools/debugserver/source/RNBServices.cpp b/lldb/tools/debugserver/source/RNBServices.cpp index 846c469faa29..5e793dbf279b 100644 --- a/lldb/tools/debugserver/source/RNBServices.cpp +++ b/lldb/tools/debugserver/source/RNBServices.cpp @@ -18,14 +18,14 @@ #import "DNBLog.h" #include "MacOSX/CFUtils.h" -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD #import #endif int ListApplications(std::string& plist, bool opt_runningApps, bool opt_debuggable) { -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD int result = -1; CFAllocatorRef alloc = kCFAllocatorDefault; @@ -118,7 +118,7 @@ ListApplications(std::string& plist, bool opt_runningApps, bool opt_debuggable) bool IsSBProcess (nub_process_t pid) { -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD bool opt_runningApps = true; bool opt_debuggable = false; diff --git a/lldb/tools/debugserver/source/RNBSocket.cpp b/lldb/tools/debugserver/source/RNBSocket.cpp index 5bc27802d386..744f9ea7f0ee 100644 --- a/lldb/tools/debugserver/source/RNBSocket.cpp +++ b/lldb/tools/debugserver/source/RNBSocket.cpp @@ -22,7 +22,7 @@ #include "DNBLog.h" #include "DNBError.h" -#if defined (__arm__) +#ifdef WITH_LOCKDOWN #include "lockdown.h" #endif @@ -169,7 +169,19 @@ RNBSocket::Connect (const char *host, uint16_t port) return rnb_success; } -#if defined (__arm__) +rnb_err_t +RNBSocket::useFD(int fd) +{ + if (fd < 0) { + DNBLogThreadedIf(LOG_RNB_COMM, "Bad file descriptor passed in."); + return rnb_err; + } + + m_fd = fd; + return rnb_success; +} + +#ifdef WITH_LOCKDOWN rnb_err_t RNBSocket::ConnectToService() { @@ -222,8 +234,10 @@ RNBSocket::SetSocketOption(int fd, int level, int option_name, int option_value) rnb_err_t RNBSocket::Disconnect (bool save_errno) { +#ifdef WITH_LOCKDOWN if (m_fd_from_lockdown) m_fd_from_lockdown = false; +#endif return ClosePort (m_fd, save_errno); } @@ -278,12 +292,12 @@ RNBSocket::Write (const void *buffer, size_t length) return rnb_err; DNBError err; - int bytessent = send (m_fd, buffer, length, 0); + int bytessent = write (m_fd, buffer, length); if (bytessent < 0) err.SetError(errno, DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_RNB_COMM)) - err.LogThreaded("::send ( socket = %i, buffer = %p, length = %zu, flags = 0 ) => %i", m_fd, buffer, length, bytessent); + err.LogThreaded("::write ( socket = %i, buffer = %p, length = %zu) => %i", m_fd, buffer, length, bytessent); if (bytessent < 0) return rnb_err; diff --git a/lldb/tools/debugserver/source/RNBSocket.h b/lldb/tools/debugserver/source/RNBSocket.h index 5fd6ac2a5704..97fd632fd16a 100644 --- a/lldb/tools/debugserver/source/RNBSocket.h +++ b/lldb/tools/debugserver/source/RNBSocket.h @@ -27,7 +27,9 @@ public: RNBSocket () : m_fd (-1), +#ifdef WITH_LOCKDOWN m_fd_from_lockdown (false), +#endif m_timer (true) // Make a thread safe timer { } @@ -39,7 +41,9 @@ public: rnb_err_t Listen (in_port_t port, PortBoundCallback callback, const void *callback_baton); rnb_err_t Connect (const char *host, uint16_t port); -#if defined (__arm__) + rnb_err_t useFD(int fd); + +#ifdef WITH_LOCKDOWN rnb_err_t ConnectToService(); #endif rnb_err_t OpenFile (const char *path); @@ -60,7 +64,11 @@ protected: rnb_err_t ClosePort (int& fd, bool save_errno); int m_fd; // Socket we use to communicate once conn established + +#ifdef WITH_LOCKDOWN bool m_fd_from_lockdown; +#endif + DNBTimer m_timer; }; diff --git a/lldb/tools/debugserver/source/debugserver.cpp b/lldb/tools/debugserver/source/debugserver.cpp index 00bd3cdd6074..327492577101 100644 --- a/lldb/tools/debugserver/source/debugserver.cpp +++ b/lldb/tools/debugserver/source/debugserver.cpp @@ -192,7 +192,7 @@ RNBRunLoopLaunchInferior (RNBRemote *remote, const char *stdin_path, const char // Our default launch method is posix spawn launch_flavor = eLaunchFlavorPosixSpawn; -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD // Check if we have an app bundle, if so launch using SpringBoard. if (strstr(inferior_argv[0], ".app")) { @@ -955,7 +955,7 @@ main (int argc, char *argv[]) g_launch_flavor = eLaunchFlavorPosixSpawn; else if (strcasestr(optarg, "fork") == optarg) g_launch_flavor = eLaunchFlavorForkExec; -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD else if (strcasestr(optarg, "spring") == optarg) g_launch_flavor = eLaunchFlavorSpringBoard; #endif @@ -966,7 +966,7 @@ main (int argc, char *argv[]) RNBLogSTDERR (" auto Auto-detect the best launch method to use.\n"); RNBLogSTDERR (" posix Launch the executable using posix_spawn.\n"); RNBLogSTDERR (" fork Launch the executable using fork and exec.\n"); -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD RNBLogSTDERR (" spring Launch the executable through Springboard.\n"); #endif exit (5); @@ -1234,7 +1234,7 @@ main (int argc, char *argv[]) switch (mode) { case eRNBRunLoopModeGetStartModeFromRemoteProtocol: -#if defined (__arm__) +#ifdef WITH_LOCKDOWN if (g_lockdown_opt) { if (!remote->Comm().IsConnected()) @@ -1308,7 +1308,7 @@ main (int argc, char *argv[]) // Our default launch method is posix spawn launch_flavor = eLaunchFlavorPosixSpawn; -#if defined (__arm__) +#ifdef WITH_SPRINGBOARD // Check if we have an app bundle, if so launch using SpringBoard. if (waitfor_pid_name.find (".app") != std::string::npos) {