[Lldb-commits] [lldb] r225694 - Add support for character option types.
Zachary Turner
zturner at google.com
Mon Jan 12 12:44:02 PST 2015
Author: zturner
Date: Mon Jan 12 14:44:02 2015
New Revision: 225694
URL: http://llvm.org/viewvc/llvm-project?rev=225694&view=rev
Log:
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
Added:
lldb/trunk/include/lldb/Interpreter/OptionValueChar.h
lldb/trunk/source/Interpreter/OptionValueChar.cpp
Modified:
lldb/trunk/include/lldb/Interpreter/Args.h
lldb/trunk/include/lldb/Interpreter/OptionValue.h
lldb/trunk/include/lldb/Interpreter/OptionValues.h
lldb/trunk/include/lldb/lldb-forward.h
lldb/trunk/source/Interpreter/Args.cpp
lldb/trunk/source/Interpreter/CMakeLists.txt
lldb/trunk/source/Interpreter/OptionValue.cpp
lldb/trunk/source/Interpreter/OptionValueArray.cpp
lldb/trunk/source/Interpreter/OptionValueDictionary.cpp
lldb/trunk/source/Interpreter/Property.cpp
Modified: lldb/trunk/include/lldb/Interpreter/Args.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Args.h?rev=225694&r1=225693&r2=225694&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/Args.h (original)
+++ lldb/trunk/include/lldb/Interpreter/Args.h Mon Jan 12 14:44:02 2015
@@ -394,7 +394,9 @@ public:
static bool
StringToBoolean (const char *s, bool fail_value, bool *success_ptr);
-
+
+ static char StringToChar(const char *s, char fail_value, bool *success_ptr);
+
static int64_t
StringToOptionEnum (const char *s, OptionEnumValueElement *enum_values, int32_t fail_value, Error &error);
Modified: lldb/trunk/include/lldb/Interpreter/OptionValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionValue.h?rev=225694&r1=225693&r2=225694&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionValue.h (original)
+++ lldb/trunk/include/lldb/Interpreter/OptionValue.h Mon Jan 12 14:44:02 2015
@@ -26,12 +26,14 @@ namespace lldb_private {
class OptionValue
{
public:
- typedef enum {
+ typedef enum
+ {
eTypeInvalid = 0,
eTypeArch,
eTypeArgs,
eTypeArray,
eTypeBoolean,
+ eTypeChar,
eTypeDictionary,
eTypeEnum,
eTypeFileSpec,
@@ -41,11 +43,11 @@ namespace lldb_private {
eTypeProperties,
eTypeRegex,
eTypeSInt64,
- eTypeString,
+ eTypeString,
eTypeUInt64,
eTypeUUID
} Type;
-
+
enum {
eDumpOptionName = (1u << 0),
eDumpOptionType = (1u << 1),
@@ -173,6 +175,7 @@ namespace lldb_private {
case 1u << eTypeArgs: return eTypeArgs;
case 1u << eTypeArray: return eTypeArray;
case 1u << eTypeBoolean: return eTypeBoolean;
+ case 1u << eTypeChar: return eTypeChar;
case 1u << eTypeDictionary: return eTypeDictionary;
case 1u << eTypeEnum: return eTypeEnum;
case 1u << eTypeFileSpec: return eTypeFileSpec;
@@ -221,10 +224,16 @@ namespace lldb_private {
OptionValueBoolean *
GetAsBoolean ();
-
+
+ OptionValueChar *
+ GetAsChar ();
+
const OptionValueBoolean *
GetAsBoolean () const;
-
+
+ const OptionValueChar *
+ GetAsChar () const;
+
OptionValueDictionary *
GetAsDictionary ();
@@ -302,7 +311,11 @@ namespace lldb_private {
bool
SetBooleanValue (bool new_value);
-
+
+ char GetCharValue(char fail_value) const;
+
+ char SetCharValue(char new_value);
+
int64_t
GetEnumerationValue (int64_t fail_value = -1) const;
Added: lldb/trunk/include/lldb/Interpreter/OptionValueChar.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionValueChar.h?rev=225694&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionValueChar.h (added)
+++ lldb/trunk/include/lldb/Interpreter/OptionValueChar.h Mon Jan 12 14:44:02 2015
@@ -0,0 +1,113 @@
+//===-- OptionValueBoolean.h ------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_OptionValueChar_h_
+#define liblldb_OptionValueChar_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Interpreter/OptionValue.h"
+
+namespace lldb_private {
+
+class OptionValueChar : public OptionValue
+{
+public:
+ OptionValueChar (char value) :
+ OptionValue(),
+ m_current_value (value),
+ m_default_value (value)
+ {
+ }
+ OptionValueChar (char current_value,
+ char default_value) :
+ OptionValue(),
+ m_current_value (current_value),
+ m_default_value (default_value)
+ {
+ }
+
+ virtual
+ ~OptionValueChar()
+ {
+ }
+
+ //---------------------------------------------------------------------
+ // Virtual subclass pure virtual overrides
+ //---------------------------------------------------------------------
+
+ virtual OptionValue::Type
+ GetType () const
+ {
+ return eTypeChar;
+ }
+
+ virtual void
+ DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask);
+
+ virtual Error
+ SetValueFromCString (const char *value,
+ VarSetOperationType op = eVarSetOperationAssign);
+
+ virtual bool
+ Clear ()
+ {
+ m_current_value = m_default_value;
+ m_value_was_set = false;
+ return true;
+ }
+
+ //---------------------------------------------------------------------
+ // Subclass specific functions
+ //---------------------------------------------------------------------
+
+ const char &
+ operator = (char c)
+ {
+ m_current_value = c;
+ return m_current_value;
+ }
+
+ char
+ GetCurrentValue() const
+ {
+ return m_current_value;
+ }
+
+ char
+ GetDefaultValue() const
+ {
+ return m_default_value;
+ }
+
+ void
+ SetCurrentValue (char value)
+ {
+ m_current_value = value;
+ }
+
+ void
+ SetDefaultValue (char value)
+ {
+ m_default_value = value;
+ }
+
+ virtual lldb::OptionValueSP
+ DeepCopy () const;
+
+protected:
+ char m_current_value;
+ char m_default_value;
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_OptionValueChar_h_
Modified: lldb/trunk/include/lldb/Interpreter/OptionValues.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionValues.h?rev=225694&r1=225693&r2=225694&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionValues.h (original)
+++ lldb/trunk/include/lldb/Interpreter/OptionValues.h Mon Jan 12 14:44:02 2015
@@ -15,6 +15,7 @@
#include "lldb/Interpreter/OptionValueArgs.h"
#include "lldb/Interpreter/OptionValueArray.h"
#include "lldb/Interpreter/OptionValueBoolean.h"
+#include "lldb/Interpreter/OptionValueChar.h"
#include "lldb/Interpreter/OptionValueDictionary.h"
#include "lldb/Interpreter/OptionValueEnumeration.h"
#include "lldb/Interpreter/OptionValueFileSpec.h"
Modified: lldb/trunk/include/lldb/lldb-forward.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=225694&r1=225693&r2=225694&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-forward.h (original)
+++ lldb/trunk/include/lldb/lldb-forward.h Mon Jan 12 14:44:02 2015
@@ -140,6 +140,7 @@ class OptionValueArch;
class OptionValueArgs;
class OptionValueArray;
class OptionValueBoolean;
+class OptionValueChar;
class OptionValueDictionary;
class OptionValueEnumeration;
class OptionValueFileSpec;
Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=225694&r1=225693&r2=225694&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Mon Jan 12 14:44:02 2015
@@ -969,6 +969,26 @@ Args::StringToBoolean (const char *s, bo
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)
{
Modified: lldb/trunk/source/Interpreter/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CMakeLists.txt?rev=225694&r1=225693&r2=225694&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CMakeLists.txt (original)
+++ lldb/trunk/source/Interpreter/CMakeLists.txt Mon Jan 12 14:44:02 2015
@@ -24,6 +24,7 @@ add_lldb_library(lldbInterpreter
OptionValueArgs.cpp
OptionValueArray.cpp
OptionValueBoolean.cpp
+ OptionValueChar.cpp
OptionValueDictionary.cpp
OptionValueEnumeration.cpp
OptionValueFileSpec.cpp
Modified: lldb/trunk/source/Interpreter/OptionValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValue.cpp?rev=225694&r1=225693&r2=225694&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValue.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValue.cpp Mon Jan 12 14:44:02 2015
@@ -71,6 +71,21 @@ OptionValue::GetAsBoolean () const
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 @@ OptionValue::SetBooleanValue (bool new_v
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 @@ OptionValue::GetBuiltinTypeAsCString (Ty
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 @@ OptionValue::CreateValueFromCStringForTy
{
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;
Modified: lldb/trunk/source/Interpreter/OptionValueArray.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueArray.cpp?rev=225694&r1=225693&r2=225694&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueArray.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueArray.cpp Mon Jan 12 14:44:02 2015
@@ -53,6 +53,7 @@ OptionValueArray::DumpValue (const Execu
break;
case eTypeBoolean:
+ case eTypeChar:
case eTypeEnum:
case eTypeFileSpec:
case eTypeFormat:
Added: lldb/trunk/source/Interpreter/OptionValueChar.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueChar.cpp?rev=225694&view=auto
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueChar.cpp (added)
+++ lldb/trunk/source/Interpreter/OptionValueChar.cpp Mon Jan 12 14:44:02 2015
@@ -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));
+}
+
+
Modified: lldb/trunk/source/Interpreter/OptionValueDictionary.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueDictionary.cpp?rev=225694&r1=225693&r2=225694&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueDictionary.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueDictionary.cpp Mon Jan 12 14:44:02 2015
@@ -64,6 +64,7 @@ OptionValueDictionary::DumpValue (const
break;
case eTypeBoolean:
+ case eTypeChar:
case eTypeEnum:
case eTypeFileSpec:
case eTypeFormat:
Modified: lldb/trunk/source/Interpreter/Property.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Property.cpp?rev=225694&r1=225693&r2=225694&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Property.cpp (original)
+++ lldb/trunk/source/Interpreter/Property.cpp Mon Jan 12 14:44:02 2015
@@ -60,7 +60,11 @@ Property::Property (const PropertyDefini
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)));
More information about the lldb-commits
mailing list