Re-organized the contents of RangeMap.h to be more concise and also allow for a Range, RangeArray, RangeData (range + data), or a RangeDataArray. We have many range implementations in LLDB and I will be converting over to using the classes in RangeMap.h so we can have one set of code that does ranges and searching  of ranges.

Fixed up DWARFDebugAranges to use the new range classes.

Fixed the enumeration parsing to take a lldb_private::Error to avoid a lot of duplicated code. Now when an invalid enumeration is supplied, an error will be returned and that error will contain a list of the valid enumeration values.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@141382 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandObjectBreakpointCommand.cpp b/source/Commands/CommandObjectBreakpointCommand.cpp
index 5130a2f..942d7ff 100644
--- a/source/Commands/CommandObjectBreakpointCommand.cpp
+++ b/source/Commands/CommandObjectBreakpointCommand.cpp
@@ -91,45 +91,42 @@
     char short_option = (char) m_getopt_table[option_idx].val;
 
     switch (short_option)
-      {
-      case 'o':
-          m_use_one_liner = true;
-          m_one_liner = option_arg;
-          break;
-          break;
-      case 's':
-          {
-              bool found_one = false;
-              m_script_language = (lldb::ScriptLanguage) Args::StringToOptionEnum (option_arg, 
-                                                                         g_option_table[option_idx].enum_values, 
-                                                                         eScriptLanguageNone,
-                                                                         &found_one);
-              if (!found_one)
-                  error.SetErrorStringWithFormat("Invalid enumeration value '%s' for option '%c'.\n", 
-                                                 option_arg, 
-                                                 short_option);
+    {
+    case 'o':
+        m_use_one_liner = true;
+        m_one_liner = option_arg;
+        break;
 
-              if (m_script_language == eScriptLanguagePython || m_script_language == eScriptLanguageDefault)
-              {
-                  m_use_commands = false;
-                  m_use_script_language = true;
-              }
-              else
-              {
-                  m_use_commands = true;
-                  m_use_script_language = false;
-              }          
-          }
-      break;
-      case 'e':
-          bool success_ptr;
-          m_stop_on_error = Args::StringToBoolean(option_arg, false, &success_ptr);
-          if (!success_ptr)
-              error.SetErrorStringWithFormat("Invalid value for stop-on-error: \"%s\".\n", option_arg);
-          break;
-      default:
-          break;
-      }
+    case 's':
+        m_script_language = (lldb::ScriptLanguage) Args::StringToOptionEnum (option_arg, 
+                                                                             g_option_table[option_idx].enum_values, 
+                                                                             eScriptLanguageNone,
+                                                                             error);
+
+        if (m_script_language == eScriptLanguagePython || m_script_language == eScriptLanguageDefault)
+        {
+            m_use_commands = false;
+            m_use_script_language = true;
+        }
+        else
+        {
+            m_use_commands = true;
+            m_use_script_language = false;
+        }          
+        break;
+
+    case 'e':
+        {
+            bool success = false;
+            m_stop_on_error = Args::StringToBoolean(option_arg, false, &success);
+            if (!success)
+                error.SetErrorStringWithFormat("Invalid value for stop-on-error: \"%s\".\n", option_arg);
+        }
+        break;
+
+    default:
+        break;
+    }
     return error;
 }
 
diff --git a/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index f948d0f..2be8e8d 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -1876,17 +1876,10 @@
             switch (short_option)
             {
                 case 's':
-                {
-                    bool found_one = false;
                     m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg, 
                                                                          g_option_table[option_idx].enum_values, 
                                                                          eSortOrderNone,
-                                                                         &found_one);
-                    if (!found_one)
-                        error.SetErrorStringWithFormat("Invalid enumeration value '%s' for option '%c'.\n", 
-                                                       option_arg, 
-                                                       short_option);
-                }
+                                                                         error);
                     break;
                     
                 default:
diff --git a/source/Commands/CommandObjectThread.cpp b/source/Commands/CommandObjectThread.cpp
index 8e4ae8d..c7bf276 100644
--- a/source/Commands/CommandObjectThread.cpp
+++ b/source/Commands/CommandObjectThread.cpp
@@ -307,11 +307,8 @@
             
             case 'm':
                 {
-                    bool found_one = false;
                     OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; 
-                    m_run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, &found_one);
-                    if (!found_one)
-                        error.SetErrorStringWithFormat("Invalid enumeration value for option '%c'.\n", short_option);
+                    m_run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, error);
                 }
                 break;
             
@@ -807,17 +804,16 @@
                 break;
                 case 'm':
                 {
-                    bool found_one = false;
                     OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; 
-                    lldb::RunMode run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, &found_one);
+                    lldb::RunMode run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, error);
 
-                    if (!found_one)
-                        error.SetErrorStringWithFormat("Invalid enumeration value for option '%c'.\n", short_option);
-                    else if (run_mode == eAllThreads)
-                        m_stop_others = false;
-                    else
-                        m_stop_others = true;
-        
+                    if (error.Success())
+                    {
+                        if (run_mode == eAllThreads)
+                            m_stop_others = false;
+                        else
+                            m_stop_others = true;
+                    }
                 }
                 break;
                 default:
diff --git a/source/Core/UserSettingsController.cpp b/source/Core/UserSettingsController.cpp
index 332652a..a33b915 100644
--- a/source/Core/UserSettingsController.cpp
+++ b/source/Core/UserSettingsController.cpp
@@ -2381,14 +2381,9 @@
 UserSettingsController::UpdateEnumVariable (OptionEnumValueElement *enum_values,
                                             int *enum_var,
                                             const char *new_value,
-                                            Error &err)
+                                            Error &error)
 {
-    bool found_one;
-    
-    *enum_var = Args::StringToOptionEnum (new_value, enum_values, enum_values[0].value, &found_one);
-
-    if (!found_one)
-        err.SetErrorString ("Invalid enumeration value; cannot update variable.\n");
+    *enum_var = Args::StringToOptionEnum (new_value, enum_values, enum_values[0].value, error);
 }
 
 void
diff --git a/source/Interpreter/Args.cpp b/source/Interpreter/Args.cpp
index 101a1c2..7205cb6 100644
--- a/source/Interpreter/Args.cpp
+++ b/source/Interpreter/Args.cpp
@@ -834,21 +834,36 @@
 
 
 int32_t
-Args::StringToOptionEnum (const char *s, OptionEnumValueElement *enum_values, int32_t fail_value, bool *success_ptr)
+Args::StringToOptionEnum (const char *s, OptionEnumValueElement *enum_values, int32_t fail_value, Error &error)
 {    
-    if (enum_values && s && s[0])
+    if (enum_values)
     {
-        for (int i = 0; enum_values[i].string_value != NULL ; i++) 
+        if (s && s[0])
         {
-            if (strstr(enum_values[i].string_value, s) == enum_values[i].string_value)
+            for (int i = 0; enum_values[i].string_value != NULL ; i++) 
             {
-                if (success_ptr) *success_ptr = true;
-                return enum_values[i].value;
+                if (strstr(enum_values[i].string_value, s) == enum_values[i].string_value)
+                {
+                    error.Clear();
+                    return enum_values[i].value;
+                }
             }
         }
+
+        StreamString strm;
+        strm.PutCString ("invalid enumeration value, valid values are: ");
+        for (int i = 0; enum_values[i].string_value != NULL; i++) 
+        {
+            strm.Printf ("%s\"%s\"", 
+                         i > 0 ? ", " : "",
+                         enum_values[i].string_value);
+        }
+        error.SetErrorString(strm.GetData());
     }
-    if (success_ptr) *success_ptr = false;
-    
+    else
+    {
+        error.SetErrorString ("invalid enumeration argument");
+    }
     return fail_value;
 }
 
diff --git a/source/Interpreter/OptionGroupValueObjectDisplay.cpp b/source/Interpreter/OptionGroupValueObjectDisplay.cpp
index e4c2b66..bda9b68 100644
--- a/source/Interpreter/OptionGroupValueObjectDisplay.cpp
+++ b/source/Interpreter/OptionGroupValueObjectDisplay.cpp
@@ -72,12 +72,9 @@
     {
         case 'd':
             {
-                bool success;
                 int32_t result;
-                result = Args::StringToOptionEnum (option_arg, TargetInstanceSettings::g_dynamic_value_types, 2, &success);
-                if (!success)
-                    error.SetErrorStringWithFormat("Invalid dynamic value setting: \"%s\".\n", option_arg);
-                else
+                result = Args::StringToOptionEnum (option_arg, TargetInstanceSettings::g_dynamic_value_types, 2, error);
+                if (error.Success())
                     use_dynamic = (lldb::DynamicValueType) result;
             }
             break;
diff --git a/source/Interpreter/OptionGroupWatchpoint.cpp b/source/Interpreter/OptionGroupWatchpoint.cpp
index 076d010..c1f2182 100644
--- a/source/Interpreter/OptionGroupWatchpoint.cpp
+++ b/source/Interpreter/OptionGroupWatchpoint.cpp
@@ -64,21 +64,16 @@
     char short_option = (char) g_option_table[option_idx].short_option;
     switch (short_option)
     {
-        case 'w': {
-            OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values;
-            watch_type = (WatchType) Args::StringToOptionEnum(option_arg, enum_values, 0, &watch_variable);
-            if (!watch_variable)
-                error.SetErrorStringWithFormat("Invalid option arg for '-w': '%s'.\n", option_arg);
+        case 'w':
+            watch_type = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
+            if (error.Success())
+                watch_variable = true;
             break;
-        }
-        case 'x': {
-            bool success = false;
-            OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values;
-            watch_size = (WatchType) Args::StringToOptionEnum(option_arg, enum_values, 0, &success);
-            if (!success)
-                error.SetErrorStringWithFormat("Invalid option arg for '-x': '%s'.\n", option_arg);
+
+        case 'x':
+            watch_size = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
             break;
-        }
+
         default:
             error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
             break;
@@ -91,8 +86,8 @@
 OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter)
 {
     watch_variable = false;
-    watch_type     = eWatchInvalid;
-    watch_size     = 0;
+    watch_type = eWatchInvalid;
+    watch_size = 0;
 }
 
 
diff --git a/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp b/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
index d52b2f0..8c269b9 100644
--- a/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
+++ b/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.cpp
@@ -119,8 +119,8 @@
         const RangeToDIE::Entry *entry = m_aranges.GetEntryAtIndex(i);
         log->Printf ("0x%8.8x: [0x%llx - 0x%llx)", 
                      entry->data,
-                     entry->range.GetBase(),
-                     entry->range.GetEnd());
+                     entry->GetRangeBase(),
+                     entry->GetRangeEnd());
     }
 }
 
diff --git a/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h b/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h
index c02ea61..90dc4fc 100644
--- a/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h
+++ b/source/Plugins/SymbolFile/DWARF/DWARFDebugAranges.h
@@ -20,7 +20,7 @@
 class DWARFDebugAranges
 {
 protected:
-    typedef lldb_private::RangeMap<dw_addr_t, uint32_t, dw_offset_t> RangeToDIE;
+    typedef lldb_private::RangeDataArray<dw_addr_t, uint32_t, dw_offset_t> RangeToDIE;
 
 public:
     typedef RangeToDIE::Entry Range;