[Lldb-commits] [PATCH] Adjust process launch --disable-aslr to take true/false value.

Todd Fiala tfiala at google.com
Mon Aug 18 16:14:50 PDT 2014


Adjust process launch --disable-aslr to take true/false value.

This change modifies the 'process launch' --disable-aslr option to take a
boolean argument.  If the user directly specifies --disable-aslr
{true,false}, that setting will control whether the process is launched
with ASLR disabled accordingly.  In the event that the setting is not
explicitly made on the process launch command line, then the value is
retrieved from the target.disable-aslr setting (i.e. settings show
target.disable-aslr).
-- 
Todd Fiala | Software Engineer | tfiala at google.com | 650-943-3180
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140818/9ecdb063/attachment.html>
-------------- next part --------------
Index: include/lldb/Target/Process.h
===================================================================
--- include/lldb/Target/Process.h	(revision 215945)
+++ include/lldb/Target/Process.h	(working copy)
@@ -392,6 +392,7 @@
     OptionParsingStarting ()
     {
         launch_info.Clear();
+        disable_aslr = eLazyBoolCalculate;
     }
     
     const OptionDefinition*
@@ -407,6 +408,7 @@
     // Instance variables to hold the values for command options.
     
     ProcessLaunchInfo launch_info;
+    lldb_private::LazyBool disable_aslr;
 };
 
 //----------------------------------------------------------------------
Index: source/Commands/CommandObjectProcess.cpp
===================================================================
--- source/Commands/CommandObjectProcess.cpp	(revision 215945)
+++ source/Commands/CommandObjectProcess.cpp	(working copy)
@@ -205,8 +205,25 @@
         
         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);
Index: source/Target/Process.cpp
===================================================================
--- source/Target/Process.cpp	(revision 215945)
+++ source/Target/Process.cpp	(working copy)
@@ -454,11 +454,18 @@
                 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 @@
 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."},


More information about the lldb-commits mailing list