LaunchProcess (char const **argv,
char const **envp,
const char *tty,
+ uint32_t launch_flags, // See lldb::LaunchFlags
bool stop_at_entry);
lldb::SBFileSpec
const Args *
GetEnvironmentVariables ();
+ int
+ GetDisableASLR ();
+
const char *
ProcessEmbeddedScriptCommands (const char *arg);
/// @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
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);
/// @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
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;
eStepTypeOut ///< Single step out a specified context.
} StepType;
+//----------------------------------------------------------------------
+// Launch Flags
+//----------------------------------------------------------------------
+typedef enum LaunchFlags
+{
+ eLaunchFlagNone = 0u,
+ eLaunchFlagDisableASLR = (1u << 0) ///< Disable Address Space Layout Randomization
+} LaunchFlags;
+
//----------------------------------------------------------------------
// Thread Run Modes
//----------------------------------------------------------------------
isa = PBXProject;
buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "lldb" */;
compatibilityVersion = "Xcode 3.1";
+ developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
en,
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";
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";
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";
char const **argv,
char const **envp,
const char *tty,
+ uint32_t launch_flags,
bool stop_at_entry
)
{
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)
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).
Error error (process->Launch (launch_args.GetConstArgumentVector(),
environment ? environment->GetConstArgumentVector() : NULL,
+ launch_flags,
stdin_path,
stdout_path,
stderr_path));
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)
log->Printf("Looking for external editor \"%s\".\n", external_editor);
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);
}
}
-
- 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(),
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 *
return NULL;
}
+int
+CommandInterpreter::GetDisableASLR ()
+{
+ StateVariable *var = GetStateVariable ("disable-aslr");
+ int disable_aslr = var->GetIntValue();
+
+ return disable_aslr;
+}
CommandInterpreter::~CommandInterpreter ()
{
#define MACH_PROCESS_USE_POSIX_SPAWN 1
#endif
+#ifndef _POSIX_SPAWN_DISABLE_ASLR
+#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
+#endif
#if defined (__arm__)
Module* module,
char const *argv[],
char const *envp[],
+ uint32_t flags,
const char *stdin_path,
const char *stdout_path,
const char *stderr_path
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
{
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
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);
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__)
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.
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;
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
const char *stdout_path,
const char *stderr_path,
PDLaunchType launch_type,
+ uint32_t flags,
lldb_private::Error &launch_err);
static lldb::pid_t
const char *stdout_path,
const char *stderr_path,
ProcessMacOSX* process,
+ int disable_aslr,
lldb_private::Error &launch_err);
#if defined (__arm__)
Module* module,
char const *argv[],
char const *envp[],
+ uint32_t launch_flags,
const char *stdin_path,
const char *stdout_path,
const char *stderr_path
NULL, //stdin_path,
LLDB_INVALID_PROCESS_ID,
NULL, false,
+ launch_flags & eLaunchFlagDisableASLR != 0,
inferior_arch);
if (error.Fail())
return error;
NULL, //stdin_path,
LLDB_INVALID_PROCESS_ID,
NULL, false,
+ launch_flags & eLaunchFlagDisableASLR != 0,
inferior_arch);
if (error.Fail())
return error;
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())
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())
{
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
)
{
// 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)
{
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
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
(
char const *argv[],
char const *envp[],
+ uint32_t launch_flags,
const char *stdin_path,
const char *stdout_path,
const char *stderr_path
error = DoLaunch (exe_module,
exec_path_plus_argv.empty() ? NULL : &exec_path_plus_argv.front(),
envp,
+ launch_flags,
stdin_path,
stdout_path,
stderr_path);
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";
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";
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";
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';
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';
//----------------------------------------------------------------------
// 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;
#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),
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);
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__)
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);
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;
// 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
// 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);
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;
&inferior_envp[0],
stdio_path,
launch_flavor,
+ g_disable_aslr,
launch_err_str,
sizeof(launch_err_str));
{ "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 }
};
// signals sent to the session (i.e. dying when anyone hits ^C).
setsid();
break;
+ case 'D':
+ g_disable_aslr = 1;
+ break;
}
}