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