diff options
| -rw-r--r-- | lldb/include/lldb/Target/Process.h | 2 | ||||
| -rw-r--r-- | lldb/source/Commands/CommandObjectProcess.cpp | 19 | ||||
| -rw-r--r-- | lldb/source/Target/Process.cpp | 17 |
3 files changed, 32 insertions, 6 deletions
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 95ebf26c559..1486484d6fe 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -392,6 +392,7 @@ public: OptionParsingStarting () { launch_info.Clear(); + disable_aslr = eLazyBoolCalculate; } const OptionDefinition* @@ -407,6 +408,7 @@ public: // Instance variables to hold the values for command options. ProcessLaunchInfo launch_info; + lldb_private::LazyBool disable_aslr; }; //---------------------------------------------------------------------- diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 5678ae40464..6536c6ef169 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -205,8 +205,25 @@ protected: const char *target_settings_argv0 = target->GetArg0(); - if (target->GetDisableASLR()) + // Determine whether we will disable ASLR or leave it in the default state (i.e. enabled if the platform supports it). + // First check if the process launch options explicitly turn on/off disabling ASLR. If so, use that setting; + // otherwise, use the 'settings target.disable-aslr' setting. + bool disable_aslr = false; + if (m_options.disable_aslr != eLazyBoolCalculate) + { + // The user specified an explicit setting on the process launch line. Use it. + disable_aslr = (m_options.disable_aslr == eLazyBoolYes); + } + else + { + // The user did not explicitly specify whether to disable ASLR. Fall back to the target.disable-aslr setting. + disable_aslr = target->GetDisableASLR (); + } + + if (disable_aslr) m_options.launch_info.GetFlags().Set (eLaunchFlagDisableASLR); + else + m_options.launch_info.GetFlags().Clear (eLaunchFlagDisableASLR); if (target->GetDetachOnError()) m_options.launch_info.GetFlags().Set (eLaunchFlagDetachOnError); diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 3d44b240735..4092aa7f80b 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -454,11 +454,18 @@ ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *op launch_info.GetArchitecture().SetTriple (option_arg); break; - case 'A': - launch_info.GetFlags().Set (eLaunchFlagDisableASLR); + case 'A': // Disable ASLR. + { + bool success; + const bool disable_aslr_arg = Args::StringToBoolean (option_arg, true, &success); + if (success) + disable_aslr = disable_aslr_arg ? eLazyBoolYes : eLazyBoolNo; + else + error.SetErrorStringWithFormat ("Invalid boolean value for disable-aslr option: '%s'", option_arg ? option_arg : "<null>"); break; - - case 'c': + } + + case 'c': if (option_arg && option_arg[0]) launch_info.SetShell (option_arg); else @@ -480,7 +487,7 @@ OptionDefinition ProcessLaunchCommandOptions::g_option_table[] = { { LLDB_OPT_SET_ALL, false, "stop-at-entry", 's', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Stop at the entry point of the program when launching a process."}, -{ LLDB_OPT_SET_ALL, false, "disable-aslr", 'A', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Disable address space layout randomization when launching a process."}, +{ LLDB_OPT_SET_ALL, false, "disable-aslr", 'A', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "Set whether to disable address space layout randomization when launching a process."}, { LLDB_OPT_SET_ALL, false, "plugin", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, { LLDB_OPT_SET_ALL, false, "working-dir", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeDirectoryName, "Set the current working directory to <path> when running the inferior."}, { LLDB_OPT_SET_ALL, false, "arch", 'a', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeArchitecture, "Set the architecture for the process to launch when ambiguous."}, |

