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 15 namespace lldb { 16 17 class SBStructuredData { 18 public: 19 SBStructuredData(); 20 21 SBStructuredData(const lldb::SBStructuredData &rhs); 22 23 SBStructuredData(const lldb::EventSP &event_sp); 24 25 SBStructuredData(const lldb_private::StructuredDataImpl &impl); 26 27 ~SBStructuredData(); 28 29 lldb::SBStructuredData &operator=(const lldb::SBStructuredData &rhs); 30 31 explicit operator bool() const; 32 33 bool IsValid() const; 34 35 lldb::SBError SetFromJSON(lldb::SBStream &stream); 36 37 lldb::SBError SetFromJSON(const char *json); 38 39 void Clear(); 40 41 lldb::SBError GetAsJSON(lldb::SBStream &stream) const; 42 43 lldb::SBError GetDescription(lldb::SBStream &stream) const; 44 45 /// Return the type of data in this data structure 46 lldb::StructuredDataType GetType() const; 47 48 /// Return the size (i.e. number of elements) in this data structure 49 /// if it is an array or dictionary type. For other types, 0 will be 50 // returned. 51 size_t GetSize() const; 52 53 /// Fill keys with the keys in this object and return true if this data 54 /// structure is a dictionary. Returns false otherwise. 55 bool GetKeys(lldb::SBStringList &keys) const; 56 57 /// Return the value corresponding to a key if this data structure 58 /// is a dictionary type. 59 lldb::SBStructuredData GetValueForKey(const char *key) const; 60 61 /// Return the value corresponding to an index if this data structure 62 /// is array. 63 lldb::SBStructuredData GetItemAtIndex(size_t idx) const; 64 65 /// Return the integer value if this data structure is an integer type. 66 uint64_t GetIntegerValue(uint64_t fail_value = 0) const; 67 68 /// Return the floating point value if this data structure is a floating 69 /// type. 70 double GetFloatValue(double fail_value = 0.0) const; 71 72 /// Return the boolean value if this data structure is a boolean type. 73 bool GetBooleanValue(bool fail_value = false) const; 74 75 /// Provides the string value if this data structure is a string type. 76 /// 77 /// \param[out] dst 78 /// pointer where the string value will be written. In case it is null, 79 /// nothing will be written at \a dst. 80 /// 81 /// \param[in] dst_len 82 /// max number of characters that can be written at \a dst. In case it is 83 /// zero, nothing will be written at \a dst. If this length is not enough 84 /// to write the complete string value, (\a dst_len - 1) bytes of the 85 /// string value will be written at \a dst followed by a null character. 86 /// 87 /// \return 88 /// Returns the byte size needed to completely write the string value at 89 /// \a dst in all cases. 90 size_t GetStringValue(char *dst, size_t dst_len) const; 91 92 protected: 93 friend class SBLaunchInfo; 94 friend class SBDebugger; 95 friend class SBTarget; 96 friend class SBProcess; 97 friend class SBThread; 98 friend class SBThreadPlan; 99 friend class SBBreakpoint; 100 friend class SBBreakpointLocation; 101 friend class SBBreakpointName; 102 friend class SBTrace; 103 104 StructuredDataImplUP m_impl_up; 105 }; 106 } // namespace lldb 107 108 #endif // LLDB_API_SBSTRUCTUREDDATA_H 109