Add support for character option types.
This will allow, in a subsequent patch, the addition of a global
setting that allows the user to specify a single character that
LLDB will recognize as an escape character when processing arg
strings to accomodate differences in Windows/non-Windows path
handling.
Differential Revision: http://reviews.llvm.org/D6887
Reviewed by: Jim Ingham
llvm-svn: 225694
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp
index 75c77d4..9393380 100644
--- a/lldb/source/Interpreter/Args.cpp
+++ b/lldb/source/Interpreter/Args.cpp
@@ -969,6 +969,26 @@
return fail_value;
}
+char
+Args::StringToChar(const char *s, char fail_value, bool *success_ptr)
+{
+ bool success = false;
+ char result = fail_value;
+
+ if (s)
+ {
+ size_t length = strlen(s);
+ if (length == 1)
+ {
+ success = true;
+ result = s[0];
+ }
+ }
+ if (success_ptr)
+ *success_ptr = success;
+ return result;
+}
+
const char *
Args::StringToVersion (const char *s, uint32_t &major, uint32_t &minor, uint32_t &update)
{
diff --git a/lldb/source/Interpreter/CMakeLists.txt b/lldb/source/Interpreter/CMakeLists.txt
index 52f89bb..fd8267d 100644
--- a/lldb/source/Interpreter/CMakeLists.txt
+++ b/lldb/source/Interpreter/CMakeLists.txt
@@ -24,6 +24,7 @@
OptionValueArgs.cpp
OptionValueArray.cpp
OptionValueBoolean.cpp
+ OptionValueChar.cpp
OptionValueDictionary.cpp
OptionValueEnumeration.cpp
OptionValueFileSpec.cpp
diff --git a/lldb/source/Interpreter/OptionValue.cpp b/lldb/source/Interpreter/OptionValue.cpp
index bc1e1c4..a08a612 100644
--- a/lldb/source/Interpreter/OptionValue.cpp
+++ b/lldb/source/Interpreter/OptionValue.cpp
@@ -71,6 +71,21 @@
return nullptr;
}
+const OptionValueChar *
+OptionValue::GetAsChar () const
+{
+ if (GetType () == OptionValue::eTypeChar)
+ return static_cast<const OptionValueChar *>(this);
+ return nullptr;
+}
+
+OptionValueChar *
+OptionValue::GetAsChar ()
+{
+ if (GetType () == OptionValue::eTypeChar)
+ return static_cast<OptionValueChar *>(this);
+ return nullptr;
+}
OptionValueFileSpec *
OptionValue::GetAsFileSpec ()
@@ -342,6 +357,27 @@
return false;
}
+char
+OptionValue::GetCharValue(char fail_value) const
+{
+ const OptionValueChar *option_value = GetAsChar();
+ if (option_value)
+ return option_value->GetCurrentValue();
+ return fail_value;
+}
+
+char
+OptionValue::SetCharValue(char new_value)
+{
+ OptionValueChar *option_value = GetAsChar();
+ if (option_value)
+ {
+ option_value->SetCurrentValue(new_value);
+ return true;
+ }
+ return false;
+}
+
int64_t
OptionValue::GetEnumerationValue (int64_t fail_value) const
{
@@ -520,6 +556,8 @@
case eTypeArgs: return "arguments";
case eTypeArray: return "array";
case eTypeBoolean: return "boolean";
+ case eTypeChar:
+ return "char";
case eTypeDictionary: return "dictionary";
case eTypeEnum: return "enum";
case eTypeFileSpec: return "file";
@@ -547,6 +585,7 @@
{
case 1u << eTypeArch: value_sp.reset(new OptionValueArch()); break;
case 1u << eTypeBoolean: value_sp.reset(new OptionValueBoolean(false)); break;
+ case 1u << eTypeChar: value_sp.reset(new OptionValueChar('\0')); break;
case 1u << eTypeFileSpec: value_sp.reset(new OptionValueFileSpec()); break;
case 1u << eTypeFormat: value_sp.reset(new OptionValueFormat(eFormatInvalid)); break;
case 1u << eTypeSInt64: value_sp.reset(new OptionValueSInt64()); break;
diff --git a/lldb/source/Interpreter/OptionValueArray.cpp b/lldb/source/Interpreter/OptionValueArray.cpp
index 769aadd..82ac745 100644
--- a/lldb/source/Interpreter/OptionValueArray.cpp
+++ b/lldb/source/Interpreter/OptionValueArray.cpp
@@ -53,6 +53,7 @@
break;
case eTypeBoolean:
+ case eTypeChar:
case eTypeEnum:
case eTypeFileSpec:
case eTypeFormat:
diff --git a/lldb/source/Interpreter/OptionValueChar.cpp b/lldb/source/Interpreter/OptionValueChar.cpp
new file mode 100644
index 0000000..7a01353
--- /dev/null
+++ b/lldb/source/Interpreter/OptionValueChar.cpp
@@ -0,0 +1,80 @@
+//===-- OptionValueChar.cpp -------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Interpreter/OptionValueChar.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/Stream.h"
+#include "lldb/Core/StringList.h"
+#include "lldb/Interpreter/Args.h"
+#include "llvm/ADT/STLExtras.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+void
+OptionValueChar::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask)
+{
+ if (dump_mask & eDumpOptionType)
+ strm.Printf ("(%s)", GetTypeAsCString ());
+
+ if (dump_mask & eDumpOptionValue)
+ {
+ if (dump_mask & eDumpOptionType)
+ strm.PutCString (" = ");
+ if (m_current_value != '\0')
+ strm.PutChar(m_current_value);
+ else
+ strm.PutCString("(null)");
+ }
+}
+
+Error
+OptionValueChar::SetValueFromCString (const char *value_cstr,
+ VarSetOperationType op)
+{
+ Error error;
+ switch (op)
+ {
+ case eVarSetOperationClear:
+ Clear();
+ break;
+
+ case eVarSetOperationReplace:
+ case eVarSetOperationAssign:
+ {
+ bool success = false;
+ char char_value = Args::StringToChar(value_cstr, '\0', &success);
+ if (success)
+ {
+ m_current_value = char_value;
+ m_value_was_set = true;
+ }
+ else
+ error.SetErrorStringWithFormat("'%s' cannot be longer than 1 character", value_cstr);
+ }
+ break;
+
+ default:
+ error = OptionValue::SetValueFromCString (value_cstr, op);
+ break;
+ }
+ return error;
+}
+
+lldb::OptionValueSP
+OptionValueChar::DeepCopy () const
+{
+ return OptionValueSP(new OptionValueChar(*this));
+}
+
+
diff --git a/lldb/source/Interpreter/OptionValueDictionary.cpp b/lldb/source/Interpreter/OptionValueDictionary.cpp
index b560937..3357cd4 100644
--- a/lldb/source/Interpreter/OptionValueDictionary.cpp
+++ b/lldb/source/Interpreter/OptionValueDictionary.cpp
@@ -64,6 +64,7 @@
break;
case eTypeBoolean:
+ case eTypeChar:
case eTypeEnum:
case eTypeFileSpec:
case eTypeFormat:
diff --git a/lldb/source/Interpreter/Property.cpp b/lldb/source/Interpreter/Property.cpp
index 4937626..4d4d75a 100644
--- a/lldb/source/Interpreter/Property.cpp
+++ b/lldb/source/Interpreter/Property.cpp
@@ -60,7 +60,11 @@
else
m_value_sp.reset (new OptionValueBoolean(definition.default_uint_value != 0));
break;
-
+
+ case OptionValue::eTypeChar:
+ m_value_sp.reset(new OptionValueChar(Args::StringToChar(definition.default_cstr_value, '\0', nullptr)));
+ break;
+
case OptionValue::eTypeDictionary:
// "definition.default_uint_value" is always a OptionValue::Type
m_value_sp.reset (new OptionValueDictionary(OptionValue::ConvertTypeToMask((OptionValue::Type)definition.default_uint_value)));