[Lldb-commits] [lldb] r112616 - in /lldb/trunk: include/lldb/ include/lldb/API/ include/lldb/Interpreter/ include/lldb/Target/ lldb.xcodeproj/ source/API/ source/Commands/ source/Host/macosx/ source/Interpreter/ source/Plugins/Process/MacOSX-User/source/ source/Plugins/Process/gdb-remote/ source/Target/ tools/debugserver/debugserver.xcodeproj/ tools/debugserver/source/ tools/debugserver/source/MacOSX/
Greg Clayton
gclayton at apple.com
Tue Aug 31 11:35:14 PDT 2010
Author: gclayton
Date: Tue Aug 31 13:35:14 2010
New Revision: 112616
URL: http://llvm.org/viewvc/llvm-project?rev=112616&view=rev
Log:
Added the ability to disable ASLR (Address Space Layout Randomization). ASLR
is disabled by default, and can be enabled using:
(lldb) set disable-aslr 0
Modified:
lldb/trunk/include/lldb/API/SBTarget.h
lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
lldb/trunk/include/lldb/Target/Process.h
lldb/trunk/include/lldb/lldb-enumerations.h
lldb/trunk/lldb.xcodeproj/project.pbxproj
lldb/trunk/source/API/SBTarget.cpp
lldb/trunk/source/Commands/CommandObjectProcess.cpp
lldb/trunk/source/Host/macosx/Host.mm
lldb/trunk/source/Interpreter/CommandInterpreter.cpp
lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp
lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
lldb/trunk/source/Target/Process.cpp
lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj
lldb/trunk/tools/debugserver/source/DNB.cpp
lldb/trunk/tools/debugserver/source/DNB.h
lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
lldb/trunk/tools/debugserver/source/debugserver.cpp
Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Tue Aug 31 13:35:14 2010
@@ -59,6 +59,7 @@
LaunchProcess (char const **argv,
char const **envp,
const char *tty,
+ uint32_t launch_flags, // See lldb::LaunchFlags
bool stop_at_entry);
lldb::SBFileSpec
Modified: lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandInterpreter.h Tue Aug 31 13:35:14 2010
@@ -166,6 +166,9 @@
const Args *
GetEnvironmentVariables ();
+ int
+ GetDisableASLR ();
+
const char *
ProcessEmbeddedScriptCommands (const char *arg);
Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Tue Aug 31 13:35:14 2010
@@ -251,6 +251,9 @@
/// @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 @@
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 @@
/// @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 @@
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;
Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Tue Aug 31 13:35:14 2010
@@ -50,6 +50,15 @@
} StepType;
//----------------------------------------------------------------------
+// Launch Flags
+//----------------------------------------------------------------------
+typedef enum LaunchFlags
+{
+ eLaunchFlagNone = 0u,
+ eLaunchFlagDisableASLR = (1u << 0) ///< Disable Address Space Layout Randomization
+} LaunchFlags;
+
+//----------------------------------------------------------------------
// Thread Run Modes
//----------------------------------------------------------------------
typedef enum RunMode {
Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Aug 31 13:35:14 2010
@@ -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";
Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Tue Aug 31 13:35:14 2010
@@ -121,6 +121,7 @@
char const **argv,
char const **envp,
const char *tty,
+ uint32_t launch_flags,
bool stop_at_entry
)
{
@@ -129,7 +130,7 @@
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)
Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Tue Aug 31 13:35:14 2010
@@ -163,6 +163,9 @@
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 @@
Error error (process->Launch (launch_args.GetConstArgumentVector(),
environment ? environment->GetConstArgumentVector() : NULL,
+ launch_flags,
stdin_path,
stdout_path,
stderr_path));
Modified: lldb/trunk/source/Host/macosx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Host.mm (original)
+++ lldb/trunk/source/Host/macosx/Host.mm Tue Aug 31 13:35:14 2010
@@ -834,17 +834,17 @@
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 @@
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 @@
}
}
-
- 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(),
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Tue Aug 31 13:35:14 2010
@@ -161,6 +161,11 @@
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 @@
return NULL;
}
+int
+CommandInterpreter::GetDisableASLR ()
+{
+ StateVariable *var = GetStateVariable ("disable-aslr");
+ int disable_aslr = var->GetIntValue();
+
+ return disable_aslr;
+}
CommandInterpreter::~CommandInterpreter ()
{
Modified: lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp Tue Aug 31 13:35:14 2010
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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;
Modified: lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h Tue Aug 31 13:35:14 2010
@@ -93,6 +93,7 @@
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 @@
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 @@
const char *stdout_path,
const char *stderr_path,
ProcessMacOSX* process,
+ int disable_aslr,
lldb_private::Error &launch_err);
#if defined (__arm__)
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Tue Aug 31 13:35:14 2010
@@ -375,6 +375,7 @@
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 @@
NULL, //stdin_path,
LLDB_INVALID_PROCESS_ID,
NULL, false,
+ launch_flags & eLaunchFlagDisableASLR != 0,
inferior_arch);
if (error.Fail())
return error;
@@ -422,6 +424,7 @@
NULL, //stdin_path,
LLDB_INVALID_PROCESS_ID,
NULL, false,
+ launch_flags & eLaunchFlagDisableASLR != 0,
inferior_arch);
if (error.Fail())
return error;
@@ -639,12 +642,14 @@
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 @@
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 @@
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 @@
// 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)
{
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h Tue Aug 31 13:35:14 2010
@@ -81,6 +81,7 @@
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 @@
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
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Tue Aug 31 13:35:14 2010
@@ -946,6 +946,7 @@
(
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 @@
error = DoLaunch (exe_module,
exec_path_plus_argv.empty() ? NULL : &exec_path_plus_argv.front(),
envp,
+ launch_flags,
stdin_path,
stdout_path,
stderr_path);
Modified: lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj Tue Aug 31 13:35:14 2010
@@ -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";
Modified: lldb/trunk/tools/debugserver/source/DNB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.cpp?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/DNB.cpp (original)
+++ lldb/trunk/tools/debugserver/source/DNB.cpp Tue Aug 31 13:35:14 2010
@@ -177,10 +177,11 @@
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 @@
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';
Modified: lldb/trunk/tools/debugserver/source/DNB.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.h?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/DNB.h (original)
+++ lldb/trunk/tools/debugserver/source/DNB.h Tue Aug 31 13:35:14 2010
@@ -28,7 +28,7 @@
//----------------------------------------------------------------------
// 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;
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Tue Aug 31 13:35:14 2010
@@ -85,6 +85,9 @@
#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 @@
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 @@
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 @@
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 @@
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 @@
// 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
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h Tue Aug 31 13:35:14 2010
@@ -46,9 +46,9 @@
// 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);
Modified: lldb/trunk/tools/debugserver/source/debugserver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/debugserver.cpp?rev=112616&r1=112615&r2=112616&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/debugserver.cpp (original)
+++ lldb/trunk/tools/debugserver/source/debugserver.cpp Tue Aug 31 13:35:14 2010
@@ -53,6 +53,7 @@
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 @@
&inferior_envp[0],
stdio_path,
launch_flavor,
+ g_disable_aslr,
launch_err_str,
sizeof(launch_err_str));
@@ -655,6 +657,7 @@
{ "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 @@
// signals sent to the session (i.e. dying when anyone hits ^C).
setsid();
break;
+ case 'D':
+ g_disable_aslr = 1;
+ break;
}
}
More information about the lldb-commits
mailing list