diff options
20 files changed, 140 insertions, 58 deletions
diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h index 63bc73b796b..c020b774a62 100644 --- a/lldb/include/lldb/API/SBTarget.h +++ b/lldb/include/lldb/API/SBTarget.h @@ -59,6 +59,7 @@ public: LaunchProcess (char const **argv, char const **envp, const char *tty, + uint32_t launch_flags, // See lldb::LaunchFlags bool stop_at_entry); lldb::SBFileSpec diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 1eaaacbeb04..77c0c77bfda 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -166,6 +166,9 @@ public: const Args * GetEnvironmentVariables (); + int + GetDisableASLR (); + const char * ProcessEmbeddedScriptCommands (const char *arg); diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index f4961e90fff..9664e94bb8d 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -251,6 +251,9 @@ public: /// @param[in] envp /// The environment array. /// + /// @param[in] launch_flags + /// Flags to modify the launch (@see lldb::LaunchFlags) + /// /// @param[in] stdin_path /// The path to use when re-directing the STDIN of the new /// process. If all stdXX_path arguments are NULL, a pseudo @@ -273,6 +276,7 @@ public: virtual Error Launch (char const *argv[], char const *envp[], + uint32_t launch_flags, const char *stdin_path, const char *stdout_path, const char *stderr_path); @@ -620,6 +624,9 @@ public: /// @param[in] envp /// The environment array. /// + /// @param[in] launch_flags + /// Flags to modify the launch (@see lldb::LaunchFlags) + /// /// @param[in] stdin_path /// The path to use when re-directing the STDIN of the new /// process. If all stdXX_path arguments are NULL, a pseudo @@ -643,6 +650,7 @@ public: DoLaunch (Module* module, char const *argv[], char const *envp[], + uint32_t launch_flags, const char *stdin_path, const char *stdout_path, const char *stderr_path) = 0; diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h index 0f4097d2b43..3fa2362acf6 100644 --- a/lldb/include/lldb/lldb-enumerations.h +++ b/lldb/include/lldb/lldb-enumerations.h @@ -50,6 +50,15 @@ typedef enum StepType } StepType; //---------------------------------------------------------------------- +// Launch Flags +//---------------------------------------------------------------------- +typedef enum LaunchFlags +{ + eLaunchFlagNone = 0u, + eLaunchFlagDisableASLR = (1u << 0) ///< Disable Address Space Layout Randomization +} LaunchFlags; + +//---------------------------------------------------------------------- // Thread Run Modes //---------------------------------------------------------------------- typedef enum RunMode { diff --git a/lldb/lldb.xcodeproj/project.pbxproj b/lldb/lldb.xcodeproj/project.pbxproj index c3149dd4fad..41a1eb6d3c1 100644 --- a/lldb/lldb.xcodeproj/project.pbxproj +++ b/lldb/lldb.xcodeproj/project.pbxproj @@ -2308,6 +2308,7 @@ isa = PBXProject; buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "lldb" */; compatibilityVersion = "Xcode 3.1"; + developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( en, @@ -2811,7 +2812,10 @@ GCC_INLINES_ARE_PRIVATE_EXTERN = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_VERSION = 4.2; - HEADER_SEARCH_PATHS = /usr/include/python2.6; + HEADER_SEARCH_PATHS = ( + /System/Library/Frameworks/System.framework/PrivateHeaders, + /usr/include/python2.6, + ); INFOPLIST_FILE = "resources/LLDB-Info.plist"; INSTALL_PATH = /Developer/Library/PrivateFrameworks; LD_DYLIB_INSTALL_NAME = "@rpath/LLDB.framework/Versions/A/LLDB"; @@ -2864,7 +2868,10 @@ GCC_ENABLE_OBJC_GC = supported; GCC_INLINES_ARE_PRIVATE_EXTERN = NO; GCC_VERSION = 4.2; - HEADER_SEARCH_PATHS = /usr/include/python2.6; + HEADER_SEARCH_PATHS = ( + /System/Library/Frameworks/System.framework/PrivateHeaders, + /usr/include/python2.6, + ); INFOPLIST_FILE = "resources/LLDB-Info.plist"; INSTALL_PATH = /Developer/Library/PrivateFrameworks; LD_DYLIB_INSTALL_NAME = "@rpath/LLDB.framework/Versions/A/LLDB"; @@ -2974,7 +2981,10 @@ GCC_ENABLE_OBJC_GC = supported; GCC_INLINES_ARE_PRIVATE_EXTERN = NO; GCC_VERSION = 4.2; - HEADER_SEARCH_PATHS = /usr/include/python2.6; + HEADER_SEARCH_PATHS = ( + /System/Library/Frameworks/System.framework/PrivateHeaders, + /usr/include/python2.6, + ); INFOPLIST_FILE = "resources/LLDB-Info.plist"; INSTALL_PATH = /Developer/Library/PrivateFrameworks; LD_DYLIB_INSTALL_NAME = "@rpath/LLDB.framework/Versions/A/LLDB"; diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index c863bc779b6..6c55c684bad 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -121,6 +121,7 @@ SBTarget::LaunchProcess char const **argv, char const **envp, const char *tty, + uint32_t launch_flags, bool stop_at_entry ) { @@ -129,7 +130,7 @@ SBTarget::LaunchProcess process = CreateProcess(); if (process.IsValid()) { - Error error (process->Launch (argv, envp, tty, tty, tty)); + Error error (process->Launch (argv, envp, launch_flags, tty, tty, tty)); if (error.Success()) { if (!stop_at_entry) diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index dd2d54595a9..73386b4fe17 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -163,6 +163,9 @@ public: const Args *environment = interpreter.GetEnvironmentVariables(); const Args *run_args = interpreter.GetProgramArguments(); + uint32_t launch_flags = eLaunchFlagNone; + if (interpreter.GetDisableASLR()) + launch_flags |= eLaunchFlagDisableASLR; // There are two possible sources of args to be passed to the process upon launching: Those the user // typed at the run command (launch_args); or those the user pre-set in the run-args variable (run_args). @@ -204,6 +207,7 @@ public: Error error (process->Launch (launch_args.GetConstArgumentVector(), environment ? environment->GetConstArgumentVector() : NULL, + launch_flags, stdin_path, stdout_path, stderr_path)); diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm index 70f2886e093..00450ac5e4a 100644 --- a/lldb/source/Host/macosx/Host.mm +++ b/lldb/source/Host/macosx/Host.mm @@ -834,17 +834,17 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no) file_and_line_desc.descKey = keyAEPosition; + static FSRef g_app_fsref; + LSApplicationParameters app_params; - static FSRef app_to_use; - static std::string app_name; - bzero (&app_params, sizeof (app_params)); + ::bzero (&app_params, sizeof (app_params)); app_params.flags = kLSLaunchDefaults | kLSLaunchDontAddToRecents | kLSLaunchDontSwitch; - + char *external_editor = ::getenv ("LLDB_EXTERNAL_EDITOR"); - if (external_editor != NULL) + if (external_editor) { bool calculate_fsref = true; if (log) @@ -852,20 +852,15 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no) if (app_name.empty() || strcmp (app_name.c_str(), external_editor) != 0) { - calculate_fsref = true; - } - else - calculate_fsref = false; - - if (calculate_fsref) - { CFCString editor_name (external_editor, kCFStringEncodingUTF8); - error = ::LSFindApplicationForInfo(kLSUnknownCreator, NULL, editor_name.get(), &app_to_use, NULL); + error = ::LSFindApplicationForInfo (kLSUnknownCreator, + NULL, + editor_name.get(), + &g_app_fsref, + NULL); // If we found the app, then store away the name so we don't have to re-look it up. - if (error == noErr) - app_name.assign (external_editor); - else + if (error != noErr) { if (log) log->Printf("Could not find External Editor application, error: %d.\n", error); @@ -873,12 +868,9 @@ Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no) } } - - app_params.application = &app_to_use; + app_params.application = &g_app_fsref; } - - ProcessSerialNumber psn; CFCReleaser<CFArrayRef> file_array(CFArrayCreate (NULL, (const void **) file_URL.ptr_address(false), 1, NULL)); error = ::LSOpenURLsWithRole (file_array.get(), diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index eaf886f76ad..f127fde251f 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -161,6 +161,11 @@ CommandInterpreter::InitializeVariables () 80, "The maximum number of columns to use for displaying text.")); + m_variables["disable-aslr"] = + StateVariableSP (new StateVariable ("disable-aslr", + 1, + "Disable Address Space Layout Randomization (ASLR).")); + } const char * @@ -898,6 +903,14 @@ CommandInterpreter::GetEnvironmentVariables () return NULL; } +int +CommandInterpreter::GetDisableASLR () +{ + StateVariable *var = GetStateVariable ("disable-aslr"); + int disable_aslr = var->GetIntValue(); + + return disable_aslr; +} CommandInterpreter::~CommandInterpreter () { diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp index fc33c755cad..80ee9ef7ef6 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp @@ -64,6 +64,9 @@ #define MACH_PROCESS_USE_POSIX_SPAWN 1 #endif +#ifndef _POSIX_SPAWN_DISABLE_ASLR +#define _POSIX_SPAWN_DISABLE_ASLR 0x0100 +#endif #if defined (__arm__) @@ -312,6 +315,7 @@ ProcessMacOSX::DoLaunch Module* module, char const *argv[], char const *envp[], + uint32_t flags, const char *stdin_path, const char *stdout_path, const char *stderr_path @@ -328,7 +332,7 @@ ProcessMacOSX::DoLaunch ArchSpec arch_spec(module->GetArchitecture()); // Set our user ID to our process ID. - SetID (LaunchForDebug(argv[0], argv, envp, arch_spec, stdin_path, stdout_path, stderr_path, eLaunchDefault, error)); + SetID (LaunchForDebug(argv[0], argv, envp, arch_spec, stdin_path, stdout_path, stderr_path, eLaunchDefault, flags, error)); } else { @@ -1557,6 +1561,7 @@ ProcessMacOSX::LaunchForDebug const char *stdout_path, const char *stderr_path, PDLaunchType launch_type, + uint32_t flags, Error &launch_err) { // Clear out and clean up from any current state @@ -1569,7 +1574,7 @@ ProcessMacOSX::LaunchForDebug Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS); if (log) - log->Printf ("%s( path = '%s', argv = %p, envp = %p, launch_type = %u )", __FUNCTION__, path, argv, envp, launch_type); + log->Printf ("%s( path = '%s', argv = %p, envp = %p, launch_type = %u, flags = %x )", __FUNCTION__, path, argv, envp, launch_type, flags); // Fork a child process for debugging SetPrivateState (eStateLaunching); @@ -1580,7 +1585,7 @@ ProcessMacOSX::LaunchForDebug break; case eLaunchPosixSpawn: - SetID(ProcessMacOSX::PosixSpawnChildForPTraceDebugging(path, argv, envp, arch_spec, stdin_path, stdout_path, stderr_path, this, launch_err)); + SetID(ProcessMacOSX::PosixSpawnChildForPTraceDebugging(path, argv, envp, arch_spec, stdin_path, stdout_path, stderr_path, this, flags & eLaunchFlagDisableASLR ? 1 : 0, launch_err)); break; #if defined (__arm__) @@ -1683,11 +1688,12 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging const char *stdout_path, const char *stderr_path, ProcessMacOSX* process, + int disable_aslr, Error &err ) { posix_spawnattr_t attr; - + short flags; Log *log = ProcessMacOSXLog::GetLogIfAllCategoriesSet (PD_LOG_PROCESS); Error local_err; // Errors that don't affect the spawning. @@ -1699,9 +1705,13 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging if (err.Fail()) return LLDB_INVALID_PROCESS_ID; - err.SetError( ::posix_spawnattr_setflags (&attr, POSIX_SPAWN_START_SUSPENDED), eErrorTypePOSIX); + flags = POSIX_SPAWN_START_SUSPENDED; + if (disable_aslr) + flags |= _POSIX_SPAWN_DISABLE_ASLR; + + err.SetError( ::posix_spawnattr_setflags (&attr, flags), eErrorTypePOSIX); if (err.Fail() || log) - err.PutToLog(log, "::posix_spawnattr_setflags ( &attr, POSIX_SPAWN_START_SUSPENDED )"); + err.PutToLog(log, "::posix_spawnattr_setflags ( &attr, POSIX_SPAWN_START_SUSPENDED%s )", disable_aslr ? " | _POSIX_SPAWN_DISABLE_ASLR" : ""); if (err.Fail()) return LLDB_INVALID_PROCESS_ID; diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h index a3585dbebbd..9a6e1499499 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h @@ -93,6 +93,7 @@ public: DoLaunch (lldb_private::Module* module, char const *argv[], // Can be NULL char const *envp[], // Can be NULL + uint32_t launch_flags, const char *stdin_path, // Can be NULL const char *stdout_path, // Can be NULL const char *stderr_path); // Can be NULL @@ -261,6 +262,7 @@ protected: const char *stdout_path, const char *stderr_path, PDLaunchType launch_type, + uint32_t flags, lldb_private::Error &launch_err); static lldb::pid_t @@ -283,6 +285,7 @@ protected: const char *stdout_path, const char *stderr_path, ProcessMacOSX* process, + int disable_aslr, lldb_private::Error &launch_err); #if defined (__arm__) diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 2a07ee97617..e8d596a413a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -375,6 +375,7 @@ ProcessGDBRemote::DoLaunch Module* module, char const *argv[], char const *envp[], + uint32_t launch_flags, const char *stdin_path, const char *stdout_path, const char *stderr_path @@ -404,6 +405,7 @@ ProcessGDBRemote::DoLaunch NULL, //stdin_path, LLDB_INVALID_PROCESS_ID, NULL, false, + launch_flags & eLaunchFlagDisableASLR != 0, inferior_arch); if (error.Fail()) return error; @@ -422,6 +424,7 @@ ProcessGDBRemote::DoLaunch NULL, //stdin_path, LLDB_INVALID_PROCESS_ID, NULL, false, + launch_flags & eLaunchFlagDisableASLR != 0, inferior_arch); if (error.Fail()) return error; @@ -639,12 +642,14 @@ ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid) SetPrivateState (eStateAttaching); char host_port[128]; snprintf (host_port, sizeof(host_port), "localhost:%u", get_random_port ()); - error = StartDebugserverProcess (host_port, - NULL, - NULL, - NULL, - LLDB_INVALID_PROCESS_ID, - NULL, false, + error = StartDebugserverProcess (host_port, // debugserver_url + NULL, // inferior_argv + NULL, // inferior_envp + NULL, // stdin_path + LLDB_INVALID_PROCESS_ID, // attach_pid + NULL, // attach_pid_name + false, // wait_for_launch + false, // disable_aslr arch_spec); if (error.Fail()) @@ -740,12 +745,14 @@ ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait char host_port[128]; ArchSpec arch_spec = GetTarget().GetArchitecture(); snprintf (host_port, sizeof(host_port), "localhost:%u", get_random_port ()); - error = StartDebugserverProcess (host_port, - NULL, - NULL, - NULL, - LLDB_INVALID_PROCESS_ID, - NULL, false, + error = StartDebugserverProcess (host_port, // debugserver_url + NULL, // inferior_argv + NULL, // inferior_envp + NULL, // stdin_path + LLDB_INVALID_PROCESS_ID, // attach_pid + NULL, // attach_pid_name + false, // wait_for_launch + false, // disable_aslr arch_spec); if (error.Fail()) { @@ -1644,6 +1651,7 @@ ProcessGDBRemote::StartDebugserverProcess lldb::pid_t attach_pid, // If inferior inferior_argv == NULL, and attach_pid != LLDB_INVALID_PROCESS_ID then attach to this attach_pid const char *attach_name, // Wait for the next process to launch whose basename matches "attach_name" bool wait_for_launch, // Wait for the process named "attach_name" to launch + bool disable_aslr, // Disable ASLR ArchSpec& inferior_arch // The arch of the inferior that we will launch ) { @@ -1771,6 +1779,9 @@ ProcessGDBRemote::StartDebugserverProcess // signals generated by special terminal key // sequences (^C) don't affect debugserver + if (disable_aslr) + debugserver_args.AppendArguments("--disable-aslr"); + // Only set the inferior if (launch_process) { diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h index 88c495a652a..62473f9ae38 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -81,6 +81,7 @@ public: DoLaunch (lldb_private::Module* module, char const *argv[], // Can be NULL char const *envp[], // Can be NULL + uint32_t flags, const char *stdin_path, // Can be NULL const char *stdout_path, // Can be NULL const char *stderr_path); // Can be NULL @@ -292,6 +293,7 @@ protected: lldb::pid_t attach_pid, // If inferior inferior_argv == NULL, then attach to this pid const char *attach_pid_name, // Wait for the next process to launch whose basename matches "attach_wait_name" bool wait_for_launch, // Wait for the process named "attach_wait_name" to launch + bool disable_aslr, // Disable ASLR lldb_private::ArchSpec& arch_spec); void diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 20bd1cc794f..986e44dba74 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -946,6 +946,7 @@ Process::Launch ( char const *argv[], char const *envp[], + uint32_t launch_flags, const char *stdin_path, const char *stdout_path, const char *stderr_path @@ -994,6 +995,7 @@ Process::Launch error = DoLaunch (exe_module, exec_path_plus_argv.empty() ? NULL : &exec_path_plus_argv.front(), envp, + launch_flags, stdin_path, stdout_path, stderr_path); diff --git a/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj b/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj index a2c774888e0..03653d36b9f 100644 --- a/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj +++ b/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj @@ -499,6 +499,7 @@ CURRENT_PROJECT_VERSION = 112; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_PREPROCESSOR_DEFINITIONS = LLDB_DEBUGSERVER; + HEADER_SEARCH_PATHS = /System/Library/Frameworks/System.framework/PrivateHeaders; INSTALL_PATH = /Developer/usr/bin; LLDB_DEBUGSERVER = 1; OTHER_CFLAGS = "-Wparentheses"; @@ -531,6 +532,7 @@ GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = LLDB_DEBUGSERVER; + HEADER_SEARCH_PATHS = /System/Library/Frameworks/System.framework/PrivateHeaders; INSTALL_PATH = /Developer/usr/bin; LLDB_DEBUGSERVER = 1; OTHER_CFLAGS = "-Wparentheses"; @@ -561,6 +563,7 @@ CURRENT_PROJECT_VERSION = 112; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_PREPROCESSOR_DEFINITIONS = LLDB_DEBUGSERVER; + HEADER_SEARCH_PATHS = /System/Library/Frameworks/System.framework/PrivateHeaders; INSTALL_PATH = /Developer/usr/bin; LLDB_DEBUGSERVER = 1; OTHER_CFLAGS = "-Wparentheses"; diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp index 72a111bab2c..ce7670cb209 100644 --- a/lldb/tools/debugserver/source/DNB.cpp +++ b/lldb/tools/debugserver/source/DNB.cpp @@ -177,10 +177,11 @@ DNBProcessLaunch (const char *path, const char *envp[], const char *stdio_path, nub_launch_flavor_t launch_flavor, + int disable_aslr, char *err_str, size_t err_len) { - DNBLogThreadedIf(LOG_PROCESS, "%s ( path='%s', argv = %p, envp = %p, launch_flavor = %u, err = %p, err_len = %zu) called...", __FUNCTION__, path, argv, envp, launch_flavor, err_str, err_len); + DNBLogThreadedIf(LOG_PROCESS, "%s ( path='%s', argv = %p, envp = %p, launch_flavor = %u, disable_aslr = %d, err = %p, err_len = %zu) called...", __FUNCTION__, path, argv, envp, launch_flavor, disable_aslr, err_str, err_len); if (err_str && err_len > 0) err_str[0] = '\0'; @@ -197,7 +198,7 @@ DNBProcessLaunch (const char *path, if (processSP.get()) { DNBError launch_err; - pid_t pid = processSP->LaunchForDebug(path, argv, envp, stdio_path, launch_flavor, launch_err); + pid_t pid = processSP->LaunchForDebug(path, argv, envp, stdio_path, launch_flavor, disable_aslr, launch_err); if (err_str) { *err_str = '\0'; diff --git a/lldb/tools/debugserver/source/DNB.h b/lldb/tools/debugserver/source/DNB.h index 55a039e2699..4dadff2473b 100644 --- a/lldb/tools/debugserver/source/DNB.h +++ b/lldb/tools/debugserver/source/DNB.h @@ -28,7 +28,7 @@ typedef bool (*DNBShouldCancelCallback) (void *); //---------------------------------------------------------------------- // Process control //---------------------------------------------------------------------- -nub_process_t DNBProcessLaunch (const char *path, char const *argv[], const char *envp[], const char *stdio_path, nub_launch_flavor_t launch_flavor, char *err_str, size_t err_len) DNB_EXPORT; +nub_process_t DNBProcessLaunch (const char *path, char const *argv[], const char *envp[], const char *stdio_path, nub_launch_flavor_t launch_flavor, int disable_aslr, char *err_str, size_t err_len) DNB_EXPORT; nub_process_t DNBProcessAttach (nub_process_t pid, struct timespec *timeout, char *err_str, size_t err_len) DNB_EXPORT; nub_process_t DNBProcessAttachByName (const char *name, struct timespec *timeout, char *err_str, size_t err_len) DNB_EXPORT; nub_process_t DNBProcessAttachWait (const char *wait_name, nub_launch_flavor_t launch_flavor, struct timespec *timeout, useconds_t interval, char *err_str, size_t err_len, DNBShouldCancelCallback should_cancel = NULL, void *callback_data = NULL) DNB_EXPORT; diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp index a0d7d35dd65..2eb371faa77 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp @@ -85,6 +85,9 @@ IsSBProcess (nub_process_t pid) #define MACH_PROCESS_USE_POSIX_SPAWN 1 #endif +#ifndef _POSIX_SPAWN_DISABLE_ASLR +#define _POSIX_SPAWN_DISABLE_ASLR 0x0100 +#endif MachProcess::MachProcess() : m_pid (0), @@ -1457,13 +1460,14 @@ MachProcess::LaunchForDebug char const *envp[], const char *stdio_path, nub_launch_flavor_t launch_flavor, + int disable_aslr, DNBError &launch_err ) { // Clear out and clean up from any current state Clear(); - DNBLogThreadedIf(LOG_PROCESS, "%s( path = '%s', argv = %p, envp = %p, launch_flavor = %u )", __FUNCTION__, path, argv, envp, launch_flavor); + DNBLogThreadedIf(LOG_PROCESS, "%s( path = '%s', argv = %p, envp = %p, launch_flavor = %u, disable_aslr = %d )", __FUNCTION__, path, argv, envp, launch_flavor, disable_aslr); // Fork a child process for debugging SetState(eStateLaunching); @@ -1475,7 +1479,7 @@ MachProcess::LaunchForDebug break; case eLaunchFlavorPosixSpawn: - m_pid = MachProcess::PosixSpawnChildForPTraceDebugging (path, argv, envp, stdio_path, this, launch_err); + m_pid = MachProcess::PosixSpawnChildForPTraceDebugging (path, argv, envp, stdio_path, this, disable_aslr, launch_err); break; #if defined (__arm__) @@ -1562,10 +1566,12 @@ MachProcess::PosixSpawnChildForPTraceDebugging char const *envp[], const char *stdio_path, MachProcess* process, + int disable_aslr, DNBError& err ) { posix_spawnattr_t attr; + short flags; DNBLogThreadedIf(LOG_PROCESS, "%s ( path='%s', argv=%p, envp=%p, process )", __FUNCTION__, path, argv, envp); err.SetError( ::posix_spawnattr_init (&attr), DNBError::POSIX); @@ -1574,9 +1580,13 @@ MachProcess::PosixSpawnChildForPTraceDebugging if (err.Fail()) return INVALID_NUB_PROCESS; - err.SetError( ::posix_spawnattr_setflags (&attr, POSIX_SPAWN_START_SUSPENDED), DNBError::POSIX); + flags = POSIX_SPAWN_START_SUSPENDED; + if (disable_aslr) + flags |= _POSIX_SPAWN_DISABLE_ASLR; + + err.SetError( ::posix_spawnattr_setflags (&attr, flags), DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) - err.LogThreaded("::posix_spawnattr_setflags ( &attr, POSIX_SPAWN_START_SUSPENDED )"); + err.LogThreaded("::posix_spawnattr_setflags ( &attr, POSIX_SPAWN_START_SUSPENDED%s )", flags & _POSIX_SPAWN_DISABLE_ASLR ? " | _POSIX_SPAWN_DISABLE_ASLR" : ""); if (err.Fail()) return INVALID_NUB_PROCESS; @@ -1585,13 +1595,6 @@ MachProcess::PosixSpawnChildForPTraceDebugging // On SnowLeopard we should set "DYLD_NO_PIE" in the inferior environment.... -//#ifndef _POSIX_SPAWN_DISABLE_ASLR -//#define _POSIX_SPAWN_DISABLE_ASLR 0x0100 -//#endif -// err.SetError( ::posix_spawnattr_setflags (&attr, _POSIX_SPAWN_DISABLE_ASLR), DNBError::POSIX); -// if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) -// err.LogThreaded("::posix_spawnattr_setflags ( &attr, _POSIX_SPAWN_DISABLE_ASLR )"); - #if !defined(__arm__) // We don't need to do this for ARM, and we really shouldn't now that we diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.h b/lldb/tools/debugserver/source/MacOSX/MachProcess.h index ddab00e60cc..533cb2ebda7 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.h +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.h @@ -46,9 +46,9 @@ public: // Child process control //---------------------------------------------------------------------- pid_t AttachForDebug (pid_t pid, char *err_str, size_t err_len); - pid_t LaunchForDebug (const char *path, char const *argv[], char const *envp[], const char *stdio_path, nub_launch_flavor_t launch_flavor, DNBError &err); + pid_t LaunchForDebug (const char *path, char const *argv[], char const *envp[], const char *stdio_path, nub_launch_flavor_t launch_flavor, int disable_aslr, DNBError &err); static pid_t ForkChildForPTraceDebugging (const char *path, char const *argv[], char const *envp[], MachProcess* process, DNBError &err); - static pid_t PosixSpawnChildForPTraceDebugging (const char *path, char const *argv[], char const *envp[], const char *stdio_path, MachProcess* process, DNBError& err); + static pid_t PosixSpawnChildForPTraceDebugging (const char *path, char const *argv[], char const *envp[], const char *stdio_path, MachProcess* process, int disable_aslr, DNBError& err); nub_addr_t GetDYLDAllImageInfosAddress (); 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); diff --git a/lldb/tools/debugserver/source/debugserver.cpp b/lldb/tools/debugserver/source/debugserver.cpp index 680a988de52..17918da2290 100644 --- a/lldb/tools/debugserver/source/debugserver.cpp +++ b/lldb/tools/debugserver/source/debugserver.cpp @@ -53,6 +53,7 @@ RNBRemoteSP g_remoteSP; static int g_lockdown_opt = 0; static int g_applist_opt = 0; static nub_launch_flavor_t g_launch_flavor = eLaunchFlavorDefault; +static int g_disable_aslr = 0; int g_isatty = 0; @@ -209,6 +210,7 @@ RNBRunLoopLaunchInferior (RNBRemoteSP &remote, const char *stdio_path) &inferior_envp[0], stdio_path, launch_flavor, + g_disable_aslr, launch_err_str, sizeof(launch_err_str)); @@ -655,6 +657,7 @@ static struct option g_long_options[] = { "native-regs", no_argument, NULL, 'r' }, // Specify to use the native registers instead of the gdb defaults for the architecture. { "stdio-path", required_argument, NULL, 's' }, // Set the STDIO path to be used when launching applications { "setsid", no_argument, NULL, 'S' }, // call setsid() to make debugserver run in its own sessions + { "disable-aslr", no_argument, NULL, 'D' }, // Use _POSIX_SPAWN_DISABLE_ASLR to avoid shared library randomization { NULL, 0, NULL, 0 } }; @@ -861,6 +864,9 @@ main (int argc, char *argv[]) // signals sent to the session (i.e. dying when anyone hits ^C). setsid(); break; + case 'D': + g_disable_aslr = 1; + break; } } |