1 //===-- SBStructuredData.h --------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_API_SBSTRUCTUREDDATA_H 10 #define LLDB_API_SBSTRUCTUREDDATA_H 11 12 #include "lldb/API/SBDefines.h" 13 #include "lldb/API/SBModule.h" 14 #include "lldb/API/SBScriptObject.h" 15 16 namespace lldb_private { 17 namespace python { 18 class SWIGBridge; 19 } 20 namespace lua { 21 class SWIGBridge; 22 } 23 } // namespace lldb_private 24 25 namespace lldb { 26 27 class SBStructuredData { 28 public: 29 SBStructuredData(); 30 31 SBStructuredData(const lldb::SBStructuredData &rhs); 32 33 SBStructuredData(const lldb::SBScriptObject obj, 34 const lldb::SBDebugger &debugger); 35 36 ~SBStructuredData(); 37 38 lldb::SBStructuredData &operator=(const lldb::SBStructuredData &rhs); 39 40 explicit operator bool() const; 41 42 bool IsValid() const; 43 44 lldb::SBError SetFromJSON(lldb::SBStream &stream); 45 46 lldb::SBError SetFromJSON(const char *json); 47 48 void Clear(); 49 50 lldb::SBError GetAsJSON(lldb::SBStream &stream) const; 51 52 lldb::SBError GetDescription(lldb::SBStream &stream) const; 53 54 /// Return the type of data in this data structure 55 lldb::StructuredDataType GetType() const; 56 57 /// Return the size (i.e. number of elements) in this data structure 58 /// if it is an array or dictionary type. For other types, 0 will be 59 // returned. 60 size_t GetSize() const; 61 62 /// Fill keys with the keys in this object and return true if this data 63 /// structure is a dictionary. Returns false otherwise. 64 bool GetKeys(lldb::SBStringList &keys) const; 65 66 /// Return the value corresponding to a key if this data structure 67 /// is a dictionary type. 68 lldb::SBStructuredData GetValueForKey(const char *key) const; 69 70 /// Return the value corresponding to an index if this data structure 71 /// is array. 72 lldb::SBStructuredData GetItemAtIndex(size_t idx) const; 73 74 /// Return the integer value if this data structure is an integer type. 75 uint64_t GetUnsignedIntegerValue(uint64_t fail_value = 0) const; 76 /// Return the integer value if this data structure is an integer type. 77 int64_t GetSignedIntegerValue(int64_t fail_value = 0) const; 78 79 LLDB_DEPRECATED_FIXME( 80 "Specify if the value is signed or unsigned", 81 "uint64_t GetUnsignedIntegerValue(uint64_t fail_value = 0)") 82 uint64_t GetIntegerValue(uint64_t fail_value = 0) const; 83 84 /// Return the floating point value if this data structure is a floating 85 /// type. 86 double GetFloatValue(double fail_value = 0.0) const; 87 88 /// Return the boolean value if this data structure is a boolean type. 89 bool GetBooleanValue(bool fail_value = false) const; 90 91 /// Provides the string value if this data structure is a string type. 92 /// 93 /// \param[out] dst 94 /// pointer where the string value will be written. In case it is null, 95 /// nothing will be written at \a dst. 96 /// 97 /// \param[in] dst_len 98 /// max number of characters that can be written at \a dst. In case it is 99 /// zero, nothing will be written at \a dst. If this length is not enough 100 /// to write the complete string value, (\a dst_len - 1) bytes of the 101 /// string value will be written at \a dst followed by a null character. 102 /// 103 /// \return 104 /// Returns the byte size needed to completely write the string value at 105 /// \a dst in all cases. 106 size_t GetStringValue(char *dst, size_t dst_len) const; 107 108 /// Return the generic pointer if this data structure is a generic type. 109 lldb::SBScriptObject GetGenericValue() const; 110 111 protected: 112 friend class SBAttachInfo; 113 friend class SBLaunchInfo; 114 friend class SBDebugger; 115 friend class SBTarget; 116 friend class SBProcess; 117 friend class SBThread; 118 friend class SBThreadPlan; 119 friend class SBBreakpoint; 120 friend class SBBreakpointLocation; 121 friend class SBBreakpointName; 122 friend class SBTrace; 123 friend class lldb_private::python::SWIGBridge; 124 friend class lldb_private::lua::SWIGBridge; 125 friend class SBCommandInterpreter; 126 127 SBStructuredData(const lldb_private::StructuredDataImpl &impl); 128 129 SBStructuredData(const lldb::EventSP &event_sp); 130 131 StructuredDataImplUP m_impl_up; 132 }; 133 } // namespace lldb 134 135 #endif // LLDB_API_SBSTRUCTUREDDATA_H 136