Added a --force option to "memory read,"
disallowing reads over 1KiB in total size
unless the user explicitly allows them.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@155750 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandObjectMemory.cpp b/source/Commands/CommandObjectMemory.cpp
index 558f840..c312816 100644
--- a/source/Commands/CommandObjectMemory.cpp
+++ b/source/Commands/CommandObjectMemory.cpp
@@ -37,7 +37,8 @@
 {
     { LLDB_OPT_SET_1, false, "num-per-line" ,'l', required_argument, NULL, 0, eArgTypeNumberPerLine ,"The number of items per line to display."},
     { LLDB_OPT_SET_2, false, "binary"       ,'b', no_argument      , NULL, 0, eArgTypeNone          ,"If true, memory will be saved as binary. If false, the memory is saved save as an ASCII dump that uses the format, size, count and number per line settings."},
-    { LLDB_OPT_SET_3, true , "view-as"      ,'t', required_argument, NULL, 0, eArgTypeNone          ,"The name of a type to view memory as."},
+    { LLDB_OPT_SET_3, true , "view-as"      ,'t', required_argument, NULL, 0, eArgTypeNone          ,"The name of a type to view memory as."}, 
+    { LLDB_OPT_SET_4, false, "force"        ,'r', no_argument,       NULL, 0, eArgTypeNone          ,"Necessary if reading over 1024 bytes of memory."},
 };
 
 
@@ -94,6 +95,10 @@
             case 't':
                 error = m_view_as_type.SetValueFromCString (option_arg);
                 break;
+            
+            case 'r':
+                m_force = true;
+                break;
                 
             default:
                 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
@@ -270,6 +275,7 @@
     OptionValueUInt64 m_num_per_line;
     bool m_output_as_binary;
     OptionValueString m_view_as_type;
+    bool m_force;
 };
 
 
@@ -591,6 +597,13 @@
             item_count = total_byte_size / item_byte_size;
         }
         
+        if (total_byte_size > 1024 && !m_memory_options.m_force)
+        {
+            result.AppendErrorWithFormat("Normally, \'memory read\' will not read over 1Kbyte of data.\n");
+            result.AppendErrorWithFormat("Please use --force to override this restriction.\n");
+            return false;
+        }
+        
         DataBufferSP data_sp;
         size_t bytes_read = 0;
         if (!clang_ast_type.GetOpaqueQualType())