Index: include/lldb/API/SBStructuredData.h =================================================================== --- include/lldb/API/SBStructuredData.h +++ include/lldb/API/SBStructuredData.h @@ -37,11 +37,70 @@ lldb::SBError GetDescription(lldb::SBStream &stream) const; + //------------------------------------------------------------------ + /// Return the type of data in this data structure + //------------------------------------------------------------------ + lldb::StructuredDataType GetType() const; + + //------------------------------------------------------------------ + /// Return the size (i.e. number of elements) in this data structure + /// if it is an array or dictionary type. For other types, 0 will be + // returned. + //------------------------------------------------------------------ + size_t GetSize() const; + + //------------------------------------------------------------------ + /// Return the value corresponding to a key if this data structure + /// is a dictionary type. + //------------------------------------------------------------------ + lldb::SBStructuredData GetValueForKey(const char *key) const; + + //------------------------------------------------------------------ + /// Return the value corresponding to an index if this data structure + /// is array. + //------------------------------------------------------------------ + lldb::SBStructuredData GetItemAtIndex(size_t idx) const; + + //------------------------------------------------------------------ + /// Return the integer value if this data structure is an integer type. + //------------------------------------------------------------------ + uint64_t GetIntegerValue(uint64_t fail_value = 0) const; + + //------------------------------------------------------------------ + /// Return the floating point value if this data structure is a floating + /// type. + //------------------------------------------------------------------ + double GetFloatValue(double fail_value = 0.0) const; + + //------------------------------------------------------------------ + /// Return the boolean value if this data structure is a boolean type. + //------------------------------------------------------------------ + bool GetBooleanValue(bool fail_value = false) const; + + //------------------------------------------------------------------ + /// Provides the string value if this data structure is a string type. + /// + /// @param[out] dst + /// pointer where the string value will be written. In case it is null, + /// nothing will be written at @dst. + /// + /// @param[in] dst_len + /// max number of characters that can be written at @dst. In case it is + /// zero, nothing will be written at @dst. If this length is not enough + /// to write the complete string value, (dst_len-1) bytes of the string + /// value will be written at @dst followed by a null character. + /// + /// @return + /// Returns the byte size needed to completely write the string value at + /// @dst in all cases. + //------------------------------------------------------------------ + size_t GetStringValue(char *dst, size_t dst_len) const; + protected: friend class SBTraceOptions; StructuredDataImplUP m_impl_up; }; -} +} // namespace lldb #endif /* SBStructuredData_h */ Index: include/lldb/Core/StructuredData.h =================================================================== --- include/lldb/Core/StructuredData.h +++ include/lldb/Core/StructuredData.h @@ -13,7 +13,8 @@ #include "llvm/ADT/StringRef.h" #include "lldb/Utility/ConstString.h" -#include "lldb/Utility/FileSpec.h" // for FileSpec +#include "lldb/Utility/FileSpec.h" // for FileSpec +#include "lldb/lldb-enumerations.h" // for StructuredDataType #include #include @@ -71,46 +72,41 @@ typedef std::shared_ptr DictionarySP; typedef std::shared_ptr GenericSP; - enum class Type { - eTypeInvalid = -1, - eTypeNull = 0, - eTypeGeneric, - eTypeArray, - eTypeInteger, - eTypeFloat, - eTypeBoolean, - eTypeString, - eTypeDictionary - }; - class Object : public std::enable_shared_from_this { public: - Object(Type t = Type::eTypeInvalid) : m_type(t) {} + Object(lldb::StructuredDataType t = + lldb::StructuredDataType::eStructuredDataTypeInvalid) + : m_type(t) {} virtual ~Object() = default; virtual bool IsValid() const { return true; } - virtual void Clear() { m_type = Type::eTypeInvalid; } + virtual void Clear() { + m_type = lldb::StructuredDataType::eStructuredDataTypeInvalid; + } - Type GetType() const { return m_type; } + lldb::StructuredDataType GetType() const { return m_type; } - void SetType(Type t) { m_type = t; } + void SetType(lldb::StructuredDataType t) { m_type = t; } Array *GetAsArray() { - return ((m_type == Type::eTypeArray) ? static_cast(this) - : nullptr); + return ((m_type == lldb::StructuredDataType::eStructuredDataTypeArray) + ? static_cast(this) + : nullptr); } Dictionary *GetAsDictionary() { - return ((m_type == Type::eTypeDictionary) - ? static_cast(this) - : nullptr); + return ( + (m_type == lldb::StructuredDataType::eStructuredDataTypeDictionary) + ? static_cast(this) + : nullptr); } Integer *GetAsInteger() { - return ((m_type == Type::eTypeInteger) ? static_cast(this) - : nullptr); + return ((m_type == lldb::StructuredDataType::eStructuredDataTypeInteger) + ? static_cast(this) + : nullptr); } uint64_t GetIntegerValue(uint64_t fail_value = 0) { @@ -119,8 +115,9 @@ } Float *GetAsFloat() { - return ((m_type == Type::eTypeFloat) ? static_cast(this) - : nullptr); + return ((m_type == lldb::StructuredDataType::eStructuredDataTypeFloat) + ? static_cast(this) + : nullptr); } double GetFloatValue(double fail_value = 0.0) { @@ -129,8 +126,9 @@ } Boolean *GetAsBoolean() { - return ((m_type == Type::eTypeBoolean) ? static_cast(this) - : nullptr); + return ((m_type == lldb::StructuredDataType::eStructuredDataTypeBoolean) + ? static_cast(this) + : nullptr); } bool GetBooleanValue(bool fail_value = false) { @@ -139,8 +137,9 @@ } String *GetAsString() { - return ((m_type == Type::eTypeString) ? static_cast(this) - : nullptr); + return ((m_type == lldb::StructuredDataType::eStructuredDataTypeString) + ? static_cast(this) + : nullptr); } llvm::StringRef GetStringValue(const char *fail_value = nullptr) { @@ -152,8 +151,9 @@ } Generic *GetAsGeneric() { - return ((m_type == Type::eTypeGeneric) ? static_cast(this) - : nullptr); + return ((m_type == lldb::StructuredDataType::eStructuredDataTypeGeneric) + ? static_cast(this) + : nullptr); } ObjectSP GetObjectForDotSeparatedPath(llvm::StringRef path); @@ -163,12 +163,12 @@ virtual void Dump(Stream &s, bool pretty_print = true) const = 0; private: - Type m_type; + lldb::StructuredDataType m_type; }; class Array : public Object { public: - Array() : Object(Type::eTypeArray) {} + Array() : Object(lldb::StructuredDataType::eStructuredDataTypeArray) {} ~Array() override = default; @@ -288,7 +288,9 @@ class Integer : public Object { public: - Integer(uint64_t i = 0) : Object(Type::eTypeInteger), m_value(i) {} + Integer(uint64_t i = 0) + : Object(lldb::StructuredDataType::eStructuredDataTypeInteger), + m_value(i) {} ~Integer() override = default; @@ -304,7 +306,9 @@ class Float : public Object { public: - Float(double d = 0.0) : Object(Type::eTypeFloat), m_value(d) {} + Float(double d = 0.0) + : Object(lldb::StructuredDataType::eStructuredDataTypeFloat), + m_value(d) {} ~Float() override = default; @@ -320,7 +324,9 @@ class Boolean : public Object { public: - Boolean(bool b = false) : Object(Type::eTypeBoolean), m_value(b) {} + Boolean(bool b = false) + : Object(lldb::StructuredDataType::eStructuredDataTypeBoolean), + m_value(b) {} ~Boolean() override = default; @@ -336,9 +342,10 @@ class String : public Object { public: - String() : Object(Type::eTypeString) {} + String() : Object(lldb::StructuredDataType::eStructuredDataTypeString) {} explicit String(llvm::StringRef S) - : Object(Type::eTypeString), m_value(S) {} + : Object(lldb::StructuredDataType::eStructuredDataTypeString), + m_value(S) {} void SetValue(llvm::StringRef S) { m_value = S; } @@ -352,7 +359,9 @@ class Dictionary : public Object { public: - Dictionary() : Object(Type::eTypeDictionary), m_dict() {} + Dictionary() + : Object(lldb::StructuredDataType::eStructuredDataTypeDictionary), + m_dict() {} ~Dictionary() override = default; @@ -522,7 +531,7 @@ class Null : public Object { public: - Null() : Object(Type::eTypeNull) {} + Null() : Object(lldb::StructuredDataType::eStructuredDataTypeNull) {} ~Null() override = default; @@ -534,7 +543,8 @@ class Generic : public Object { public: explicit Generic(void *object = nullptr) - : Object(Type::eTypeGeneric), m_object(object) {} + : Object(lldb::StructuredDataType::eStructuredDataTypeGeneric), + m_object(object) {} void SetValue(void *value) { m_object = value; } Index: include/lldb/Core/StructuredDataImpl.h =================================================================== --- include/lldb/Core/StructuredDataImpl.h +++ include/lldb/Core/StructuredDataImpl.h @@ -15,7 +15,9 @@ #include "lldb/Target/StructuredDataPlugin.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/Stream.h" +#include "lldb/lldb-enumerations.h" #include "lldb/lldb-forward.h" +#include "llvm/ADT/StringRef.h" #pragma mark-- #pragma mark StructuredDataImpl @@ -78,18 +80,79 @@ return plugin_sp->GetDescription(m_data_sp, stream); } - StructuredData::ObjectSP GetObjectSP() { - return m_data_sp; + StructuredData::ObjectSP GetObjectSP() { return m_data_sp; } + + void SetObjectSP(const StructuredData::ObjectSP &obj) { m_data_sp = obj; } + + lldb::StructuredDataType GetType() const { + return (m_data_sp ? m_data_sp->GetType() + : lldb::StructuredDataType::eStructuredDataTypeInvalid); } - void SetObjectSP(const StructuredData::ObjectSP &obj) { - m_data_sp = obj; + size_t GetSize() const { + if (!m_data_sp) + return 0; + + if (m_data_sp->GetType() == + lldb::StructuredDataType::eStructuredDataTypeDictionary) { + auto dict = m_data_sp->GetAsDictionary(); + return (dict->GetSize()); + } else if (m_data_sp->GetType() == + lldb::StructuredDataType::eStructuredDataTypeArray) { + auto array = m_data_sp->GetAsArray(); + return (array->GetSize()); + } else + return 0; } -private: + StructuredData::ObjectSP GetValueForKey(const char *key) const { + if (m_data_sp) { + auto dict = m_data_sp->GetAsDictionary(); + if (dict) + return dict->GetValueForKey(llvm::StringRef(key)); + } + return StructuredData::ObjectSP(); + } + + StructuredData::ObjectSP GetItemAtIndex(size_t idx) const { + if (m_data_sp) { + auto array = m_data_sp->GetAsArray(); + if (array) + return array->GetItemAtIndex(idx); + } + return StructuredData::ObjectSP(); + } + + uint64_t GetIntegerValue(uint64_t fail_value = 0) const { + return (m_data_sp ? m_data_sp->GetIntegerValue(fail_value) : fail_value); + } + double GetFloatValue(double fail_value = 0.0) const { + return (m_data_sp ? m_data_sp->GetFloatValue(fail_value) : fail_value); + } + + bool GetBooleanValue(bool fail_value = false) const { + return (m_data_sp ? m_data_sp->GetBooleanValue(fail_value) : fail_value); + } + + size_t GetStringValue(char *dst, size_t dst_len) const { + if (!m_data_sp) + return 0; + + std::string result = m_data_sp->GetStringValue(); + if (result.empty()) + return 0; + + if (!dst || !dst_len) { + char s[1]; + return (::snprintf(s, 1, "%s", result.c_str())); + } + return (::snprintf(dst, dst_len, "%s", result.c_str())); + } + +private: lldb::StructuredDataPluginWP m_plugin_wp; StructuredData::ObjectSP m_data_sp; }; -} +} // namespace lldb_private #endif Index: include/lldb/lldb-enumerations.h =================================================================== --- include/lldb/lldb-enumerations.h +++ include/lldb/lldb-enumerations.h @@ -725,6 +725,18 @@ eTraceTypeProcessorTrace }; +enum StructuredDataType { + eStructuredDataTypeInvalid = -1, + eStructuredDataTypeNull = 0, + eStructuredDataTypeGeneric, + eStructuredDataTypeArray, + eStructuredDataTypeInteger, + eStructuredDataTypeFloat, + eStructuredDataTypeBoolean, + eStructuredDataTypeString, + eStructuredDataTypeDictionary +}; + FLAGS_ENUM(TypeClass){ eTypeClassInvalid = (0u), eTypeClassArray = (1u << 0), eTypeClassBlockPointer = (1u << 1), eTypeClassBuiltin = (1u << 2), Index: packages/Python/lldbsuite/test/python_api/sbstructureddata/Makefile =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/python_api/sbstructureddata/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Index: packages/Python/lldbsuite/test/python_api/sbstructureddata/TestStructuredDataAPI.py =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/python_api/sbstructureddata/TestStructuredDataAPI.py @@ -0,0 +1,222 @@ +""" +Test some SBStructuredData API. +""" + +from __future__ import print_function + +import os +import re +import time + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestStructuredDataAPI(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test(self): + self.build() + self.structured_data_api_test() + + def setUp(self): + TestBase.setUp(self) + self.line = line_number( + 'main.c', '// Set break point at this line') + + @add_test_categories(['pyapi']) + def structured_data_api_test(self): + exe = os.path.join(os.getcwd(), "a.out") + + # Create a target by the debugger. + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + # Create the breakpoint inside function 'main'. + breakpoint = target.BreakpointCreateByLocation("main.c", self.line) + self.assertTrue(breakpoint, VALID_BREAKPOINT) + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple( + None, None, self.get_process_working_directory()) + + error = lldb.SBError() + s = lldb.SBStream() + s.Print( + "{\"key_dict\":{\"key_string\":\"STRING\",\"key_int\":3,\"key_float\":2.99,\"key_bool\":true,\"key_array\":[\"23\",\"arr\"]}}") + example = lldb.SBStructuredData() + + # Check SetFromJSON API for dictionaries, integers, floating point + # values, strings and arrays + error = example.SetFromJSON(s) + if not error.Success(): + self.fail("FAILED: " + error.GetCString()) + + # Tests for invalid data type + self.invalid_struct_test(example) + + dict_struct = lldb.SBStructuredData() + dict_struct = example.GetValueForKey("key_dict") + + # Tests for dictionary data type + self.dictionary_struct_test(example) + + # Tests for string data type + self.string_struct_test(dict_struct) + + # Tests for integer data type + self.int_struct_test(dict_struct) + + # Tests for floating point data type + self.double_struct_test(dict_struct) + + # Tests for boolean data type + self.bool_struct_test(dict_struct) + + # Tests for array data type + self.array_struct_test(dict_struct) + + def invalid_struct_test(self, example): + invalid_struct = lldb.SBStructuredData() + invalid_struct = example.GetValueForKey("invalid_key") + if invalid_struct.IsValid(): + self.fail("An invalid object should have been returned") + + # Check Type API + if not invalid_struct.GetType() == lldb.eStructuredDataTypeInvalid: + self.fail("Wrong type returned: " + str(invalid_struct.GetType())) + + def dictionary_struct_test(self, example): + # Check API returning a valid SBStructuredData of 'dictionary' type + dict_struct = lldb.SBStructuredData() + dict_struct = example.GetValueForKey("key_dict") + if not dict_struct.IsValid(): + self.fail("A valid object should have been returned") + + # Check Type API + if not dict_struct.GetType() == lldb.eStructuredDataTypeDictionary: + self.fail("Wrong type returned: " + str(dict_struct.GetType())) + + # Check Size API for 'dictionary' type + if not dict_struct.GetSize() == 5: + self.fail("Wrong no of elements returned: " + + str(dict_struct.GetSize())) + + def string_struct_test(self, dict_struct): + string_struct = lldb.SBStructuredData() + string_struct = dict_struct.GetValueForKey("key_string") + if not string_struct.IsValid(): + self.fail("A valid object should have been returned") + + # Check Type API + if not string_struct.GetType() == lldb.eStructuredDataTypeString: + self.fail("Wrong type returned: " + str(string_struct.GetType())) + + # Check API returning 'string' value + output = string_struct.GetStringValue(25) + if not "STRING" in output: + self.fail("wrong output: " + output) + + # Calling wrong API on a SBStructuredData + # (e.g. getting an integer from a string type structure) + output = string_struct.GetIntegerValue() + if output: + self.fail( + "Valid integer value " + + str(output) + + " returned for a string object") + + def int_struct_test(self, dict_struct): + # Check a valid SBStructuredData containing an 'integer' by + int_struct = lldb.SBStructuredData() + int_struct = dict_struct.GetValueForKey("key_int") + if not int_struct.IsValid(): + self.fail("A valid object should have been returned") + + # Check Type API + if not int_struct.GetType() == lldb.eStructuredDataTypeInteger: + self.fail("Wrong type returned: " + str(int_struct.GetType())) + + # Check API returning 'integer' value + output = int_struct.GetIntegerValue() + if not output == 3: + self.fail("wrong output: " + str(output)) + + # Calling wrong API on a SBStructuredData + # (e.g. getting a string value from an integer type structure) + output = int_struct.GetStringValue(25) + if output: + self.fail( + "Valid string " + + output + + " returned for an integer object") + + def double_struct_test(self, dict_struct): + floating_point_struct = lldb.SBStructuredData() + floating_point_struct = dict_struct.GetValueForKey("key_float") + if not floating_point_struct.IsValid(): + self.fail("A valid object should have been returned") + + # Check Type API + if not floating_point_struct.GetType() == lldb.eStructuredDataTypeFloat: + self.fail("Wrong type returned: " + + str(floating_point_struct.GetType())) + + # Check API returning 'double' value + output = floating_point_struct.GetFloatValue() + if not output == 2.99: + self.fail("wrong output: " + str(output)) + + def bool_struct_test(self, dict_struct): + bool_struct = lldb.SBStructuredData() + bool_struct = dict_struct.GetValueForKey("key_bool") + if not bool_struct.IsValid(): + self.fail("A valid object should have been returned") + + # Check Type API + if not bool_struct.GetType() == lldb.eStructuredDataTypeBoolean: + self.fail("Wrong type returned: " + str(bool_struct.GetType())) + + # Check API returning 'bool' value + output = bool_struct.GetBooleanValue() + if not output: + self.fail("wrong output: " + str(output)) + + def array_struct_test(self, dict_struct): + # Check API returning a valid SBStructuredData of 'array' type + array_struct = lldb.SBStructuredData() + array_struct = dict_struct.GetValueForKey("key_array") + if not array_struct.IsValid(): + self.fail("A valid object should have been returned") + + # Check Type API + if not array_struct.GetType() == lldb.eStructuredDataTypeArray: + self.fail("Wrong type returned: " + str(array_struct.GetType())) + + # Check Size API for 'array' type + if not array_struct.GetSize() == 2: + self.fail("Wrong no of elements returned: " + + str(array_struct.GetSize())) + + # Check API returning a valid SBStructuredData for different 'array' + # indices + string_struct = array_struct.GetItemAtIndex(0) + if not string_struct.IsValid(): + self.fail("A valid object should have been returned") + if not string_struct.GetType() == lldb.eStructuredDataTypeString: + self.fail("Wrong type returned: " + str(string_struct.GetType())) + output = string_struct.GetStringValue(5) + if not output == "23": + self.fail("wrong output: " + str(output)) + + string_struct = array_struct.GetItemAtIndex(1) + if not string_struct.IsValid(): + self.fail("A valid object should have been returned") + if not string_struct.GetType() == lldb.eStructuredDataTypeString: + self.fail("Wrong type returned: " + str(string_struct.GetType())) + output = string_struct.GetStringValue(5) + if not output == "arr": + self.fail("wrong output: " + str(output)) Index: packages/Python/lldbsuite/test/python_api/sbstructureddata/main.c =================================================================== --- /dev/null +++ packages/Python/lldbsuite/test/python_api/sbstructureddata/main.c @@ -0,0 +1,15 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include + +int main (int argc, char const *argv[]) +{ + uint32_t a = 0xE0A35F10; // Set break point at this line. + return 0; +} Index: scripts/interface/SBStructuredData.i =================================================================== --- scripts/interface/SBStructuredData.i +++ scripts/interface/SBStructuredData.i @@ -18,21 +18,38 @@ class SBStructuredData { public: - SBStructuredData(); - + SBStructuredData(const lldb::SBStructuredData &rhs); SBStructuredData(const lldb::EventSP &event_sp); ~SBStructuredData(); - + bool IsValid() const; - + void Clear(); + lldb::SBStructuredData &operator=(const lldb::SBStructuredData &rhs); + + lldb::StructuredDataType GetType() const; + + size_t GetSize() const; + + lldb::SBStructuredData GetValueForKey(const char *key) const; + + lldb::SBStructuredData GetItemAtIndex(size_t idx) const; + + uint64_t GetIntegerValue(uint64_t fail_value = 0) const; + + double GetFloatValue(double fail_value = 0.0) const; + + bool GetBooleanValue(bool fail_value = false) const; + + size_t GetStringValue(char *dst, size_t dst_len) const; + lldb::SBError GetAsJSON(lldb::SBStream &stream) const; Index: source/API/SBStructuredData.cpp =================================================================== --- source/API/SBStructuredData.cpp +++ source/API/SBStructuredData.cpp @@ -46,7 +46,8 @@ StructuredData::ObjectSP json_obj = StructuredData::ParseJSON(json_str); m_impl_up->SetObjectSP(json_obj); - if (!json_obj || json_obj->GetType() != StructuredData::Type::eTypeDictionary) + if (!json_obj || + json_obj->GetType() != StructuredDataType::eStructuredDataTypeDictionary) error.SetErrorString("Invalid Syntax"); return error; } @@ -67,3 +68,46 @@ sb_error.SetError(error); return sb_error; } + +StructuredDataType SBStructuredData::GetType() const { + return (m_impl_up ? m_impl_up->GetType() + : StructuredDataType::eStructuredDataTypeInvalid); +} + +size_t SBStructuredData::GetSize() const { + return (m_impl_up ? m_impl_up->GetSize() : 0); +} + +lldb::SBStructuredData SBStructuredData::GetValueForKey(const char *key) const { + if (!m_impl_up) + return SBStructuredData(); + + SBStructuredData result; + result.m_impl_up->SetObjectSP(m_impl_up->GetValueForKey(key)); + return result; +} + +lldb::SBStructuredData SBStructuredData::GetItemAtIndex(size_t idx) const { + if (!m_impl_up) + return SBStructuredData(); + + SBStructuredData result; + result.m_impl_up->SetObjectSP(m_impl_up->GetItemAtIndex(idx)); + return result; +} + +uint64_t SBStructuredData::GetIntegerValue(uint64_t fail_value) const { + return (m_impl_up ? m_impl_up->GetIntegerValue(fail_value) : fail_value); +} + +double SBStructuredData::GetFloatValue(double fail_value) const { + return (m_impl_up ? m_impl_up->GetFloatValue(fail_value) : fail_value); +} + +bool SBStructuredData::GetBooleanValue(bool fail_value) const { + return (m_impl_up ? m_impl_up->GetBooleanValue(fail_value) : fail_value); +} + +size_t SBStructuredData::GetStringValue(char *dst, size_t dst_len) const { + return (m_impl_up ? m_impl_up->GetStringValue(dst, dst_len) : 0); +} Index: source/API/SBThread.cpp =================================================================== --- source/API/SBThread.cpp +++ source/API/SBThread.cpp @@ -43,6 +43,7 @@ #include "lldb/API/SBThreadCollection.h" #include "lldb/API/SBThreadPlan.h" #include "lldb/API/SBValue.h" +#include "lldb/lldb-enumerations.h" using namespace lldb; using namespace lldb_private; @@ -561,26 +562,29 @@ StructuredData::ObjectSP node = info_root_sp->GetObjectForDotSeparatedPath(path); if (node) { - if (node->GetType() == StructuredData::Type::eTypeString) { + if (node->GetType() == + StructuredDataType::eStructuredDataTypeString) { strm.Printf("%s", node->GetAsString()->GetValue().str().c_str()); success = true; } - if (node->GetType() == StructuredData::Type::eTypeInteger) { + if (node->GetType() == + StructuredDataType::eStructuredDataTypeInteger) { strm.Printf("0x%" PRIx64, node->GetAsInteger()->GetValue()); success = true; } - if (node->GetType() == StructuredData::Type::eTypeFloat) { + if (node->GetType() == StructuredDataType::eStructuredDataTypeFloat) { strm.Printf("0x%f", node->GetAsFloat()->GetValue()); success = true; } - if (node->GetType() == StructuredData::Type::eTypeBoolean) { + if (node->GetType() == + StructuredDataType::eStructuredDataTypeBoolean) { if (node->GetAsBoolean()->GetValue() == true) strm.Printf("true"); else strm.Printf("false"); success = true; } - if (node->GetType() == StructuredData::Type::eTypeNull) { + if (node->GetType() == StructuredDataType::eStructuredDataTypeNull) { strm.Printf("null"); success = true; } Index: source/Core/FormatEntity.cpp =================================================================== --- source/Core/FormatEntity.cpp +++ source/Core/FormatEntity.cpp @@ -1040,24 +1040,28 @@ thread_info_dictionary->GetObjectForDotSeparatedPath(path); if (value) { - if (value->GetType() == StructuredData::Type::eTypeInteger) { + if (value->GetType() == StructuredDataType::eStructuredDataTypeInteger) { const char *token_format = "0x%4.4" PRIx64; if (!entry.printf_format.empty()) token_format = entry.printf_format.c_str(); s.Printf(token_format, value->GetAsInteger()->GetValue()); return true; - } else if (value->GetType() == StructuredData::Type::eTypeFloat) { + } else if (value->GetType() == + StructuredDataType::eStructuredDataTypeFloat) { s.Printf("%f", value->GetAsFloat()->GetValue()); return true; - } else if (value->GetType() == StructuredData::Type::eTypeString) { + } else if (value->GetType() == + StructuredDataType::eStructuredDataTypeString) { s.Format("{0}", value->GetAsString()->GetValue()); return true; - } else if (value->GetType() == StructuredData::Type::eTypeArray) { + } else if (value->GetType() == + StructuredDataType::eStructuredDataTypeArray) { if (value->GetAsArray()->GetSize() > 0) { s.Printf("%zu", value->GetAsArray()->GetSize()); return true; } - } else if (value->GetType() == StructuredData::Type::eTypeDictionary) { + } else if (value->GetType() == + StructuredDataType::eStructuredDataTypeDictionary) { s.Printf("%zu", value->GetAsDictionary()->GetKeys()->GetAsArray()->GetSize()); return true; @@ -1346,7 +1350,8 @@ if (thread) { StructuredData::ObjectSP object_sp = thread->GetExtendedInfo(); if (object_sp && - object_sp->GetType() == StructuredData::Type::eTypeDictionary) { + object_sp->GetType() == + StructuredDataType::eStructuredDataTypeDictionary) { if (FormatThreadExtendedInfoRecurse(entry, object_sp, sc, exe_ctx, s)) return true; } Index: source/Core/StructuredData.cpp =================================================================== --- source/Core/StructuredData.cpp +++ source/Core/StructuredData.cpp @@ -184,7 +184,8 @@ StructuredData::ObjectSP StructuredData::Object::GetObjectForDotSeparatedPath(llvm::StringRef path) { - if (this->GetType() == Type::eTypeDictionary) { + if (this->GetType() == + lldb::StructuredDataType::eStructuredDataTypeDictionary) { std::pair match = path.split('.'); std::string key = match.first.str(); ObjectSP value = this->GetAsDictionary()->GetValueForKey(key); @@ -200,7 +201,7 @@ return ObjectSP(); } - if (this->GetType() == Type::eTypeArray) { + if (this->GetType() == lldb::StructuredDataType::eStructuredDataTypeArray) { std::pair match = path.split('['); if (match.second.size() == 0) { return this->shared_from_this(); Index: source/Target/Thread.cpp =================================================================== --- source/Target/Thread.cpp +++ source/Target/Thread.cpp @@ -51,6 +51,7 @@ #include "lldb/Utility/RegularExpression.h" #include "lldb/Utility/Stream.h" #include "lldb/Utility/StreamString.h" +#include "lldb/lldb-enumerations.h" using namespace lldb; using namespace lldb_private; @@ -397,7 +398,7 @@ bool plan_overrides_trace = have_valid_stop_info && have_valid_completed_plan && (m_stop_info_sp->GetStopReason() == eStopReasonTrace); - + if (have_valid_stop_info && !plan_overrides_trace) { return m_stop_info_sp; } else if (have_valid_completed_plan) { @@ -541,7 +542,7 @@ saved_state.orig_stop_id = process_sp->GetStopID(); saved_state.current_inlined_depth = GetCurrentInlinedDepth(); saved_state.m_completed_plan_stack = m_completed_plan_stack; - + return true; } @@ -1994,13 +1995,15 @@ thread_info->GetObjectForDotSeparatedPath("trace_messages"); bool printed_activity = false; - if (activity && - activity->GetType() == StructuredData::Type::eTypeDictionary) { + if (activity && activity->GetType() == + StructuredDataType::eStructuredDataTypeDictionary) { StructuredData::Dictionary *activity_dict = activity->GetAsDictionary(); StructuredData::ObjectSP id = activity_dict->GetValueForKey("id"); StructuredData::ObjectSP name = activity_dict->GetValueForKey("name"); - if (name && name->GetType() == StructuredData::Type::eTypeString && id && - id->GetType() == StructuredData::Type::eTypeInteger) { + if (name && + name->GetType() == StructuredDataType::eStructuredDataTypeString && + id && + id->GetType() == StructuredDataType::eStructuredDataTypeInteger) { strm.Format(" Activity '{0}', {1:x}\n", name->GetAsString()->GetValue(), id->GetAsInteger()->GetValue()); @@ -2008,8 +2011,8 @@ printed_activity = true; } bool printed_breadcrumb = false; - if (breadcrumb && - breadcrumb->GetType() == StructuredData::Type::eTypeDictionary) { + if (breadcrumb && breadcrumb->GetType() == + StructuredDataType::eStructuredDataTypeDictionary) { if (printed_activity) strm.Printf("\n"); StructuredData::Dictionary *breadcrumb_dict = @@ -2017,13 +2020,15 @@ StructuredData::ObjectSP breadcrumb_text = breadcrumb_dict->GetValueForKey("name"); if (breadcrumb_text && - breadcrumb_text->GetType() == StructuredData::Type::eTypeString) { + breadcrumb_text->GetType() == + StructuredDataType::eStructuredDataTypeString) { strm.Format(" Current Breadcrumb: {0}\n", breadcrumb_text->GetAsString()->GetValue()); } printed_breadcrumb = true; } - if (messages && messages->GetType() == StructuredData::Type::eTypeArray) { + if (messages && + messages->GetType() == StructuredDataType::eStructuredDataTypeArray) { if (printed_breadcrumb) strm.Printf("\n"); StructuredData::Array *messages_array = messages->GetAsArray(); @@ -2033,13 +2038,15 @@ for (size_t i = 0; i < msg_count; i++) { StructuredData::ObjectSP message = messages_array->GetItemAtIndex(i); if (message && - message->GetType() == StructuredData::Type::eTypeDictionary) { + message->GetType() == + StructuredDataType::eStructuredDataTypeDictionary) { StructuredData::Dictionary *message_dict = message->GetAsDictionary(); StructuredData::ObjectSP message_text = message_dict->GetValueForKey("message"); if (message_text && - message_text->GetType() == StructuredData::Type::eTypeString) { + message_text->GetType() == + StructuredDataType::eStructuredDataTypeString) { strm.Format(" {0}\n", message_text->GetAsString()->GetValue()); } } Index: unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp =================================================================== --- unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp +++ unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp @@ -15,6 +15,7 @@ #include "lldb/Host/File.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" +#include "lldb/lldb-enumerations.h" #include "PythonTestSuite.h" @@ -355,9 +356,9 @@ list.AppendItem(PythonString(string_value1)); auto array_sp = list.CreateStructuredArray(); - EXPECT_EQ(StructuredData::Type::eTypeInteger, + EXPECT_EQ(lldb::StructuredDataType::eStructuredDataTypeInteger, array_sp->GetItemAtIndex(0)->GetType()); - EXPECT_EQ(StructuredData::Type::eTypeString, + EXPECT_EQ(lldb::StructuredDataType::eStructuredDataTypeString, array_sp->GetItemAtIndex(1)->GetType()); auto int_sp = array_sp->GetItemAtIndex(0)->GetAsInteger(); @@ -424,9 +425,9 @@ auto array_sp = tuple.CreateStructuredArray(); EXPECT_EQ(tuple.GetSize(), array_sp->GetSize()); - EXPECT_EQ(StructuredData::Type::eTypeInteger, + EXPECT_EQ(lldb::StructuredDataType::eStructuredDataTypeInteger, array_sp->GetItemAtIndex(0)->GetType()); - EXPECT_EQ(StructuredData::Type::eTypeString, + EXPECT_EQ(lldb::StructuredDataType::eStructuredDataTypeString, array_sp->GetItemAtIndex(1)->GetType()); }