LLDB  mainline
StructuredData.h
Go to the documentation of this file.
1 //===-- StructuredData.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_UTILITY_STRUCTUREDDATA_H
10 #define LLDB_UTILITY_STRUCTUREDDATA_H
11 
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/Support/JSON.h"
14 
16 #include "lldb/Utility/FileSpec.h"
17 #include "lldb/Utility/Stream.h"
18 #include "lldb/lldb-enumerations.h"
19 
20 #include <cassert>
21 #include <cstddef>
22 #include <cstdint>
23 #include <functional>
24 #include <map>
25 #include <memory>
26 #include <string>
27 #include <type_traits>
28 #include <utility>
29 #include <vector>
30 
31 namespace lldb_private {
32 class Status;
33 }
34 
35 namespace lldb_private {
36 
37 /// \class StructuredData StructuredData.h "lldb/Utility/StructuredData.h"
38 /// A class which can hold structured data
39 ///
40 /// The StructuredData class is designed to hold the data from a JSON or plist
41 /// style file -- a serialized data structure with dictionaries (maps,
42 /// hashes), arrays, and concrete values like integers, floating point
43 /// numbers, strings, booleans.
44 ///
45 /// StructuredData does not presuppose any knowledge of the schema for the
46 /// data it is holding; it can parse JSON data, for instance, and other parts
47 /// of lldb can iterate through the parsed data set to find keys and values
48 /// that may be present.
49 
51 public:
52  class Object;
53  class Array;
54  class Integer;
55  class Float;
56  class Boolean;
57  class String;
58  class Dictionary;
59  class Generic;
60 
61  typedef std::shared_ptr<Object> ObjectSP;
62  typedef std::shared_ptr<Array> ArraySP;
63  typedef std::shared_ptr<Integer> IntegerSP;
64  typedef std::shared_ptr<Float> FloatSP;
65  typedef std::shared_ptr<Boolean> BooleanSP;
66  typedef std::shared_ptr<String> StringSP;
67  typedef std::shared_ptr<Dictionary> DictionarySP;
68  typedef std::shared_ptr<Generic> GenericSP;
69 
70  class Object : public std::enable_shared_from_this<Object> {
71  public:
73  : m_type(t) {}
74 
75  virtual ~Object() = default;
76 
77  virtual bool IsValid() const { return true; }
78 
80 
82 
84 
87  ? static_cast<Array *>(this)
88  : nullptr);
89  }
90 
93  ? static_cast<Dictionary *>(this)
94  : nullptr);
95  }
96 
99  ? static_cast<Integer *>(this)
100  : nullptr);
101  }
102 
103  uint64_t GetIntegerValue(uint64_t fail_value = 0) {
105  return ((integer != nullptr) ? integer->GetValue() : fail_value);
106  }
107 
110  ? static_cast<Float *>(this)
111  : nullptr);
112  }
113 
114  double GetFloatValue(double fail_value = 0.0) {
115  Float *f = GetAsFloat();
116  return ((f != nullptr) ? f->GetValue() : fail_value);
117  }
118 
121  ? static_cast<Boolean *>(this)
122  : nullptr);
123  }
124 
125  bool GetBooleanValue(bool fail_value = false) {
126  Boolean *b = GetAsBoolean();
127  return ((b != nullptr) ? b->GetValue() : fail_value);
128  }
129 
132  ? static_cast<String *>(this)
133  : nullptr);
134  }
135 
136  llvm::StringRef GetStringValue(const char *fail_value = nullptr) {
137  String *s = GetAsString();
138  if (s)
139  return s->GetValue();
140 
141  return fail_value;
142  }
143 
146  ? static_cast<Generic *>(this)
147  : nullptr);
148  }
149 
150  ObjectSP GetObjectForDotSeparatedPath(llvm::StringRef path);
151 
152  void DumpToStdout(bool pretty_print = true) const;
153 
154  virtual void Serialize(llvm::json::OStream &s) const = 0;
155 
156  void Dump(lldb_private::Stream &s, bool pretty_print = true) const {
157  llvm::json::OStream jso(s.AsRawOstream(), pretty_print ? 2 : 0);
158  Serialize(jso);
159  }
160 
161  virtual void GetDescription(lldb_private::Stream &s) const {
162  s.IndentMore();
163  Dump(s, false);
164  s.IndentLess();
165  }
166 
167  private:
169  };
170 
171  class Array : public Object {
172  public:
174 
175  ~Array() override = default;
176 
177  bool
178  ForEach(std::function<bool(Object *object)> const &foreach_callback) const {
179  for (const auto &object_sp : m_items) {
180  if (!foreach_callback(object_sp.get()))
181  return false;
182  }
183  return true;
184  }
185 
186  size_t GetSize() const { return m_items.size(); }
187 
188  ObjectSP operator[](size_t idx) {
189  if (idx < m_items.size())
190  return m_items[idx];
191  return ObjectSP();
192  }
193 
194  ObjectSP GetItemAtIndex(size_t idx) const {
195  assert(idx < GetSize());
196  if (idx < m_items.size())
197  return m_items[idx];
198  return ObjectSP();
199  }
200 
201  template <class IntType>
202  bool GetItemAtIndexAsInteger(size_t idx, IntType &result) const {
203  ObjectSP value_sp = GetItemAtIndex(idx);
204  if (value_sp.get()) {
205  if (auto int_value = value_sp->GetAsInteger()) {
206  result = static_cast<IntType>(int_value->GetValue());
207  return true;
208  }
209  }
210  return false;
211  }
212 
213  template <class IntType>
214  bool GetItemAtIndexAsInteger(size_t idx, IntType &result,
215  IntType default_val) const {
216  bool success = GetItemAtIndexAsInteger(idx, result);
217  if (!success)
218  result = default_val;
219  return success;
220  }
221 
222  bool GetItemAtIndexAsString(size_t idx, llvm::StringRef &result) const {
223  ObjectSP value_sp = GetItemAtIndex(idx);
224  if (value_sp.get()) {
225  if (auto string_value = value_sp->GetAsString()) {
226  result = string_value->GetValue();
227  return true;
228  }
229  }
230  return false;
231  }
232 
233  bool GetItemAtIndexAsString(size_t idx, llvm::StringRef &result,
234  llvm::StringRef default_val) const {
235  bool success = GetItemAtIndexAsString(idx, result);
236  if (!success)
237  result = default_val;
238  return success;
239  }
240 
241  bool GetItemAtIndexAsString(size_t idx, ConstString &result) const {
242  ObjectSP value_sp = GetItemAtIndex(idx);
243  if (value_sp.get()) {
244  if (auto string_value = value_sp->GetAsString()) {
245  result = ConstString(string_value->GetValue());
246  return true;
247  }
248  }
249  return false;
250  }
251 
252  bool GetItemAtIndexAsString(size_t idx, ConstString &result,
253  const char *default_val) const {
254  bool success = GetItemAtIndexAsString(idx, result);
255  if (!success)
256  result.SetCString(default_val);
257  return success;
258  }
259 
260  bool GetItemAtIndexAsDictionary(size_t idx, Dictionary *&result) const {
261  result = nullptr;
262  ObjectSP value_sp = GetItemAtIndex(idx);
263  if (value_sp.get()) {
264  result = value_sp->GetAsDictionary();
265  return (result != nullptr);
266  }
267  return false;
268  }
269 
270  bool GetItemAtIndexAsArray(size_t idx, Array *&result) const {
271  result = nullptr;
272  ObjectSP value_sp = GetItemAtIndex(idx);
273  if (value_sp.get()) {
274  result = value_sp->GetAsArray();
275  return (result != nullptr);
276  }
277  return false;
278  }
279 
280  void Push(const ObjectSP &item) { m_items.push_back(item); }
281 
282  void AddItem(const ObjectSP &item) { m_items.push_back(item); }
283 
284  void Serialize(llvm::json::OStream &s) const override;
285 
286  void GetDescription(lldb_private::Stream &s) const override;
287 
288  protected:
289  typedef std::vector<ObjectSP> collection;
291  };
292 
293  class Integer : public Object {
294  public:
295  Integer(uint64_t i = 0)
297 
298  ~Integer() override = default;
299 
300  void SetValue(uint64_t value) { m_value = value; }
301 
302  uint64_t GetValue() { return m_value; }
303 
304  void Serialize(llvm::json::OStream &s) const override;
305 
306  void GetDescription(lldb_private::Stream &s) const override;
307 
308  protected:
309  uint64_t m_value;
310  };
311 
312  class Float : public Object {
313  public:
314  Float(double d = 0.0)
316 
317  ~Float() override = default;
318 
319  void SetValue(double value) { m_value = value; }
320 
321  double GetValue() { return m_value; }
322 
323  void Serialize(llvm::json::OStream &s) const override;
324 
325  void GetDescription(lldb_private::Stream &s) const override;
326 
327  protected:
328  double m_value;
329  };
330 
331  class Boolean : public Object {
332  public:
333  Boolean(bool b = false)
335 
336  ~Boolean() override = default;
337 
338  void SetValue(bool value) { m_value = value; }
339 
340  bool GetValue() { return m_value; }
341 
342  void Serialize(llvm::json::OStream &s) const override;
343 
344  void GetDescription(lldb_private::Stream &s) const override;
345 
346  protected:
347  bool m_value;
348  };
349 
350  class String : public Object {
351  public:
353  explicit String(llvm::StringRef S)
355 
356  void SetValue(llvm::StringRef S) { m_value = std::string(S); }
357 
358  llvm::StringRef GetValue() { return m_value; }
359 
360  void Serialize(llvm::json::OStream &s) const override;
361 
362  void GetDescription(lldb_private::Stream &s) const override;
363 
364  protected:
366  };
367 
368  class Dictionary : public Object {
369  public:
371 
373  if (!obj_sp || obj_sp->GetType() != lldb::eStructuredDataTypeDictionary) {
375  return;
376  }
377 
378  Dictionary *dict = obj_sp->GetAsDictionary();
379  m_dict = dict->m_dict;
380  }
381 
382  ~Dictionary() override = default;
383 
384  size_t GetSize() const { return m_dict.size(); }
385 
386  void ForEach(std::function<bool(ConstString key, Object *object)> const
387  &callback) const {
388  for (const auto &pair : m_dict) {
389  if (!callback(pair.first, pair.second.get()))
390  break;
391  }
392  }
393 
394  ArraySP GetKeys() const {
395  auto array_sp = std::make_shared<Array>();
396  collection::const_iterator iter;
397  for (iter = m_dict.begin(); iter != m_dict.end(); ++iter) {
398  auto key_object_sp = std::make_shared<String>();
399  key_object_sp->SetValue(iter->first.AsCString());
400  array_sp->Push(key_object_sp);
401  }
402  return array_sp;
403  }
404 
405  ObjectSP GetValueForKey(llvm::StringRef key) const {
406  ObjectSP value_sp;
407  if (!key.empty()) {
408  ConstString key_cs(key);
409  collection::const_iterator iter = m_dict.find(key_cs);
410  if (iter != m_dict.end())
411  value_sp = iter->second;
412  }
413  return value_sp;
414  }
415 
416  bool GetValueForKeyAsBoolean(llvm::StringRef key, bool &result) const {
417  bool success = false;
418  ObjectSP value_sp = GetValueForKey(key);
419  if (value_sp.get()) {
420  Boolean *result_ptr = value_sp->GetAsBoolean();
421  if (result_ptr) {
422  result = result_ptr->GetValue();
423  success = true;
424  }
425  }
426  return success;
427  }
428  template <class IntType>
429  bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const {
430  ObjectSP value_sp = GetValueForKey(key);
431  if (value_sp) {
432  if (auto int_value = value_sp->GetAsInteger()) {
433  result = static_cast<IntType>(int_value->GetValue());
434  return true;
435  }
436  }
437  return false;
438  }
439 
440  template <class IntType>
441  bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result,
442  IntType default_val) const {
443  bool success = GetValueForKeyAsInteger<IntType>(key, result);
444  if (!success)
445  result = default_val;
446  return success;
447  }
448 
449  bool GetValueForKeyAsString(llvm::StringRef key,
450  llvm::StringRef &result) const {
451  ObjectSP value_sp = GetValueForKey(key);
452  if (value_sp.get()) {
453  if (auto string_value = value_sp->GetAsString()) {
454  result = string_value->GetValue();
455  return true;
456  }
457  }
458  return false;
459  }
460 
461  bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result,
462  const char *default_val) const {
463  bool success = GetValueForKeyAsString(key, result);
464  if (!success) {
465  if (default_val)
466  result = default_val;
467  else
468  result = llvm::StringRef();
469  }
470  return success;
471  }
472 
473  bool GetValueForKeyAsString(llvm::StringRef key,
474  ConstString &result) const {
475  ObjectSP value_sp = GetValueForKey(key);
476  if (value_sp.get()) {
477  if (auto string_value = value_sp->GetAsString()) {
478  result = ConstString(string_value->GetValue());
479  return true;
480  }
481  }
482  return false;
483  }
484 
485  bool GetValueForKeyAsString(llvm::StringRef key, ConstString &result,
486  const char *default_val) const {
487  bool success = GetValueForKeyAsString(key, result);
488  if (!success)
489  result.SetCString(default_val);
490  return success;
491  }
492 
493  bool GetValueForKeyAsDictionary(llvm::StringRef key,
494  Dictionary *&result) const {
495  result = nullptr;
496  ObjectSP value_sp = GetValueForKey(key);
497  if (value_sp.get()) {
498  result = value_sp->GetAsDictionary();
499  return (result != nullptr);
500  }
501  return false;
502  }
503 
504  bool GetValueForKeyAsArray(llvm::StringRef key, Array *&result) const {
505  result = nullptr;
506  ObjectSP value_sp = GetValueForKey(key);
507  if (value_sp.get()) {
508  result = value_sp->GetAsArray();
509  return (result != nullptr);
510  }
511  return false;
512  }
513 
514  bool HasKey(llvm::StringRef key) const {
515  ConstString key_cs(key);
516  collection::const_iterator search = m_dict.find(key_cs);
517  return search != m_dict.end();
518  }
519 
520  void AddItem(llvm::StringRef key, ObjectSP value_sp) {
521  ConstString key_cs(key);
522  m_dict[key_cs] = std::move(value_sp);
523  }
524 
525  void AddIntegerItem(llvm::StringRef key, uint64_t value) {
526  AddItem(key, std::make_shared<Integer>(value));
527  }
528 
529  void AddFloatItem(llvm::StringRef key, double value) {
530  AddItem(key, std::make_shared<Float>(value));
531  }
532 
533  void AddStringItem(llvm::StringRef key, llvm::StringRef value) {
534  AddItem(key, std::make_shared<String>(std::move(value)));
535  }
536 
537  void AddBooleanItem(llvm::StringRef key, bool value) {
538  AddItem(key, std::make_shared<Boolean>(value));
539  }
540 
541  void Serialize(llvm::json::OStream &s) const override;
542 
543  void GetDescription(lldb_private::Stream &s) const override;
544 
545  protected:
546  typedef std::map<ConstString, ObjectSP> collection;
548  };
549 
550  class Null : public Object {
551  public:
553 
554  ~Null() override = default;
555 
556  bool IsValid() const override { return false; }
557 
558  void Serialize(llvm::json::OStream &s) const override;
559 
560  void GetDescription(lldb_private::Stream &s) const override;
561  };
562 
563  class Generic : public Object {
564  public:
565  explicit Generic(void *object = nullptr)
567 
568  void SetValue(void *value) { m_object = value; }
569 
570  void *GetValue() const { return m_object; }
571 
572  bool IsValid() const override { return m_object != nullptr; }
573 
574  void Serialize(llvm::json::OStream &s) const override;
575 
576  void GetDescription(lldb_private::Stream &s) const override;
577 
578  private:
579  void *m_object;
580  };
581 
582  static ObjectSP ParseJSON(const std::string &json_text);
583  static ObjectSP ParseJSONFromFile(const FileSpec &file, Status &error);
584  static bool IsRecordType(const ObjectSP object_sp);
585 };
586 
587 } // namespace lldb_private
588 
589 #endif // LLDB_UTILITY_STRUCTUREDDATA_H
lldb_private::StructuredData::Float::~Float
~Float() override=default
lldb::eStructuredDataTypeBoolean
@ eStructuredDataTypeBoolean
Definition: lldb-enumerations.h:800
lldb_private::Stream::IndentLess
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition: Stream.cpp:171
lldb_private::StructuredData::Boolean::m_value
bool m_value
Definition: StructuredData.h:347
lldb::StructuredDataType
StructuredDataType
Definition: lldb-enumerations.h:793
lldb_private::StructuredData::Dictionary
Definition: StructuredData.h:368
lldb_private::StructuredData::Object::IsValid
virtual bool IsValid() const
Definition: StructuredData.h:77
lldb_private::StructuredData::Array
Definition: StructuredData.h:171
lldb_private::StructuredData::Dictionary::GetValueForKey
ObjectSP GetValueForKey(llvm::StringRef key) const
Definition: StructuredData.h:405
lldb_private::StructuredData::GenericSP
std::shared_ptr< Generic > GenericSP
Definition: StructuredData.h:68
lldb::eStructuredDataTypeString
@ eStructuredDataTypeString
Definition: lldb-enumerations.h:801
lldb_private::StructuredData::Array::Serialize
void Serialize(llvm::json::OStream &s) const override
Definition: StructuredData.cpp:142
lldb::eStructuredDataTypeDictionary
@ eStructuredDataTypeDictionary
Definition: lldb-enumerations.h:802
lldb_private::StructuredData::Integer
Definition: StructuredData.h:293
lldb_private::StructuredData::Object::GetAsGeneric
Generic * GetAsGeneric()
Definition: StructuredData.h:144
lldb_private::StructuredData::Dictionary::m_dict
collection m_dict
Definition: StructuredData.h:547
lldb_private::StructuredData::Array::GetItemAtIndexAsDictionary
bool GetItemAtIndexAsDictionary(size_t idx, Dictionary *&result) const
Definition: StructuredData.h:260
lldb_private::StructuredData::Boolean::~Boolean
~Boolean() override=default
lldb_private::StructuredData::Object::GetType
lldb::StructuredDataType GetType() const
Definition: StructuredData.h:81
lldb_private::StructuredData::String::String
String(llvm::StringRef S)
Definition: StructuredData.h:353
lldb_private::StructuredData::Object::DumpToStdout
void DumpToStdout(bool pretty_print=true) const
Definition: StructuredData.cpp:137
lldb_private::StructuredData::Object::GetFloatValue
double GetFloatValue(double fail_value=0.0)
Definition: StructuredData.h:114
lldb_private::StructuredData::Array::GetItemAtIndexAsInteger
bool GetItemAtIndexAsInteger(size_t idx, IntType &result, IntType default_val) const
Definition: StructuredData.h:214
lldb_private::StructuredData::Object::GetDescription
virtual void GetDescription(lldb_private::Stream &s) const
Definition: StructuredData.h:161
lldb_private::StructuredData::Boolean::GetDescription
void GetDescription(lldb_private::Stream &s) const override
Definition: StructuredData.cpp:192
lldb_private::StructuredData::Array::Array
Array()
Definition: StructuredData.h:173
lldb_private::ConstString::SetCString
void SetCString(const char *cstr)
Set the C string value.
Definition: ConstString.cpp:301
lldb_private::StructuredData::Dictionary::Serialize
void Serialize(llvm::json::OStream &s) const override
Definition: StructuredData.cpp:166
lldb_private::StructuredData::Dictionary::Dictionary
Dictionary()
Definition: StructuredData.h:370
lldb_private::Stream
Definition: Stream.h:28
lldb_private::StructuredData::Integer::Serialize
void Serialize(llvm::json::OStream &s) const override
Definition: StructuredData.cpp:150
lldb_private::StructuredData::Array::collection
std::vector< ObjectSP > collection
Definition: StructuredData.h:289
lldb_private::StructuredData::Object::GetAsInteger
Integer * GetAsInteger()
Definition: StructuredData.h:97
lldb_private::StructuredData::Dictionary::Dictionary
Dictionary(ObjectSP obj_sp)
Definition: StructuredData.h:372
lldb_private::StructuredData::Array::GetItemAtIndexAsString
bool GetItemAtIndexAsString(size_t idx, ConstString &result) const
Definition: StructuredData.h:241
lldb_private::StructuredData::String::GetDescription
void GetDescription(lldb_private::Stream &s) const override
Definition: StructuredData.cpp:196
lldb_private::StructuredData::Object::GetAsString
String * GetAsString()
Definition: StructuredData.h:130
lldb_private::StructuredData::Null::Serialize
void Serialize(llvm::json::OStream &s) const override
Definition: StructuredData.cpp:176
lldb::eStructuredDataTypeInvalid
@ eStructuredDataTypeInvalid
Definition: lldb-enumerations.h:794
lldb_private::StructuredData::Boolean
Definition: StructuredData.h:331
lldb_private::StructuredData::Dictionary::GetValueForKeyAsInteger
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const
Definition: StructuredData.h:429
lldb_private::StructuredData::Dictionary::AddBooleanItem
void AddBooleanItem(llvm::StringRef key, bool value)
Definition: StructuredData.h:537
lldb_private::StructuredData::Dictionary::~Dictionary
~Dictionary() override=default
lldb_private::StructuredData::Object::Clear
virtual void Clear()
Definition: StructuredData.h:79
lldb::eStructuredDataTypeGeneric
@ eStructuredDataTypeGeneric
Definition: lldb-enumerations.h:796
lldb_private::StructuredData::Integer::GetValue
uint64_t GetValue()
Definition: StructuredData.h:302
lldb_private::StructuredData::String::String
String()
Definition: StructuredData.h:352
lldb_private::FileSpec
Definition: FileSpec.h:55
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::StructuredData::StringSP
std::shared_ptr< String > StringSP
Definition: StructuredData.h:66
lldb_private::StructuredData::String
Definition: StructuredData.h:350
lldb_private::StructuredData::ParseJSONFromFile
static ObjectSP ParseJSONFromFile(const FileSpec &file, Status &error)
Definition: StructuredData.cpp:35
lldb_private::StructuredData::Null
Definition: StructuredData.h:550
lldb_private::StructuredData::Object::Dump
void Dump(lldb_private::Stream &s, bool pretty_print=true) const
Definition: StructuredData.h:156
lldb_private::StructuredData::Object::GetStringValue
llvm::StringRef GetStringValue(const char *fail_value=nullptr)
Definition: StructuredData.h:136
lldb_private::StructuredData::Dictionary::GetValueForKeyAsString
bool GetValueForKeyAsString(llvm::StringRef key, ConstString &result, const char *default_val) const
Definition: StructuredData.h:485
lldb_private::StructuredData::IsRecordType
static bool IsRecordType(const ObjectSP object_sp)
Definition: StructuredData.cpp:53
lldb_private::StructuredData::Integer::Integer
Integer(uint64_t i=0)
Definition: StructuredData.h:295
lldb_private::StructuredData::Float::SetValue
void SetValue(double value)
Definition: StructuredData.h:319
lldb_private::StructuredData::Object::GetAsFloat
Float * GetAsFloat()
Definition: StructuredData.h:108
lldb_private::StructuredData::ObjectSP
std::shared_ptr< Object > ObjectSP
Definition: StructuredData.h:59
lldb_private::StructuredData::Float::m_value
double m_value
Definition: StructuredData.h:328
lldb_private::StructuredData::Array::GetItemAtIndexAsString
bool GetItemAtIndexAsString(size_t idx, ConstString &result, const char *default_val) const
Definition: StructuredData.h:252
lldb_private::StructuredData::Dictionary::GetDescription
void GetDescription(lldb_private::Stream &s) const override
Definition: StructuredData.cpp:236
lldb_private::ConstString
Definition: ConstString.h:39
lldb_private::StructuredData::Boolean::SetValue
void SetValue(bool value)
Definition: StructuredData.h:338
lldb_private::StructuredData::Array::GetDescription
void GetDescription(lldb_private::Stream &s) const override
Definition: StructuredData.cpp:200
lldb_private::StructuredData::Dictionary::GetValueForKeyAsInteger
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result, IntType default_val) const
Definition: StructuredData.h:441
lldb-enumerations.h
lldb_private::StructuredData::Array::GetItemAtIndexAsArray
bool GetItemAtIndexAsArray(size_t idx, Array *&result) const
Definition: StructuredData.h:270
lldb_private::StructuredData::Boolean::Serialize
void Serialize(llvm::json::OStream &s) const override
Definition: StructuredData.cpp:158
lldb_private::StructuredData::Array::AddItem
void AddItem(const ObjectSP &item)
Definition: StructuredData.h:282
lldb_private::StructuredData::Null::~Null
~Null() override=default
lldb_private::StructuredData::Float::GetDescription
void GetDescription(lldb_private::Stream &s) const override
Definition: StructuredData.cpp:188
lldb_private::StructuredData::Object::GetIntegerValue
uint64_t GetIntegerValue(uint64_t fail_value=0)
Definition: StructuredData.h:103
lldb_private::StructuredData::DictionarySP
std::shared_ptr< Dictionary > DictionarySP
Definition: StructuredData.h:67
lldb_private::StructuredData::Array::Push
void Push(const ObjectSP &item)
Definition: StructuredData.h:280
lldb_private::StructuredData::Dictionary::GetSize
size_t GetSize() const
Definition: StructuredData.h:384
lldb_private::StructuredData::Null::GetDescription
void GetDescription(lldb_private::Stream &s) const override
Definition: StructuredData.cpp:271
lldb_private::StructuredData::Generic::Generic
Generic(void *object=nullptr)
Definition: StructuredData.h:565
lldb_private::StructuredData::String::m_value
std::string m_value
Definition: StructuredData.h:365
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::StructuredData::String::GetValue
llvm::StringRef GetValue()
Definition: StructuredData.h:358
lldb_private::StructuredData::Null::IsValid
bool IsValid() const override
Definition: StructuredData.h:556
lldb_private::StructuredData::Generic
Definition: StructuredData.h:563
lldb_private::StructuredData
Definition: StructuredData.h:50
lldb_private::StructuredData::Dictionary::AddItem
void AddItem(llvm::StringRef key, ObjectSP value_sp)
Definition: StructuredData.h:520
lldb_private::StructuredData::Dictionary::GetKeys
ArraySP GetKeys() const
Definition: StructuredData.h:394
lldb_private::StructuredData::Object::Object
Object(lldb::StructuredDataType t=lldb::eStructuredDataTypeInvalid)
Definition: StructuredData.h:72
lldb_private::StructuredData::Null::Null
Null()
Definition: StructuredData.h:552
lldb_private::StructuredData::Array::operator[]
ObjectSP operator[](size_t idx)
Definition: StructuredData.h:188
lldb_private::StructuredData::Object::GetAsArray
Array * GetAsArray()
Definition: StructuredData.h:85
lldb_private::StructuredData::Object::~Object
virtual ~Object()=default
lldb_private::StructuredData::Object::GetBooleanValue
bool GetBooleanValue(bool fail_value=false)
Definition: StructuredData.h:125
lldb_private::StructuredData::Float
Definition: StructuredData.h:312
lldb_private::StructuredData::FloatSP
std::shared_ptr< Float > FloatSP
Definition: StructuredData.h:64
lldb_private::Status
Definition: Status.h:44
lldb_private::StructuredData::Boolean::GetValue
bool GetValue()
Definition: StructuredData.h:340
lldb_private::StructuredData::Integer::m_value
uint64_t m_value
Definition: StructuredData.h:309
lldb_private::StructuredData::Float::GetValue
double GetValue()
Definition: StructuredData.h:321
lldb_private::StructuredData::Dictionary::AddFloatItem
void AddFloatItem(llvm::StringRef key, double value)
Definition: StructuredData.h:529
lldb_private::Stream::IndentMore
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition: Stream.cpp:168
lldb_private::StructuredData::Dictionary::ForEach
void ForEach(std::function< bool(ConstString key, Object *object)> const &callback) const
Definition: StructuredData.h:386
lldb_private::StructuredData::Dictionary::GetValueForKeyAsString
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result, const char *default_val) const
Definition: StructuredData.h:461
lldb_private::StructuredData::Object::SetType
void SetType(lldb::StructuredDataType t)
Definition: StructuredData.h:83
lldb_private::StructuredData::Object::GetAsDictionary
Dictionary * GetAsDictionary()
Definition: StructuredData.h:91
lldb_private::StructuredData::String::Serialize
void Serialize(llvm::json::OStream &s) const override
Definition: StructuredData.cpp:162
lldb_private::StructuredData::Array::m_items
collection m_items
Definition: StructuredData.h:290
lldb_private::StructuredData::Array::GetItemAtIndexAsInteger
bool GetItemAtIndexAsInteger(size_t idx, IntType &result) const
Definition: StructuredData.h:202
lldb_private::StructuredData::Object::Serialize
virtual void Serialize(llvm::json::OStream &s) const =0
lldb_private::Stream::AsRawOstream
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:357
lldb_private::StructuredData::Dictionary::HasKey
bool HasKey(llvm::StringRef key) const
Definition: StructuredData.h:514
lldb_private::StructuredData::BooleanSP
std::shared_ptr< Boolean > BooleanSP
Definition: StructuredData.h:65
lldb_private::StructuredData::Float::Float
Float(double d=0.0)
Definition: StructuredData.h:314
lldb::eStructuredDataTypeInteger
@ eStructuredDataTypeInteger
Definition: lldb-enumerations.h:798
lldb::eStructuredDataTypeFloat
@ eStructuredDataTypeFloat
Definition: lldb-enumerations.h:799
lldb_private::StructuredData::Dictionary::AddStringItem
void AddStringItem(llvm::StringRef key, llvm::StringRef value)
Definition: StructuredData.h:533
lldb_private::StructuredData::String::SetValue
void SetValue(llvm::StringRef S)
Definition: StructuredData.h:356
lldb_private::StructuredData::Array::GetItemAtIndexAsString
bool GetItemAtIndexAsString(size_t idx, llvm::StringRef &result, llvm::StringRef default_val) const
Definition: StructuredData.h:233
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::StructuredData::Object::GetObjectForDotSeparatedPath
ObjectSP GetObjectForDotSeparatedPath(llvm::StringRef path)
Definition: StructuredData.cpp:104
lldb_private::StructuredData::Dictionary::GetValueForKeyAsDictionary
bool GetValueForKeyAsDictionary(llvm::StringRef key, Dictionary *&result) const
Definition: StructuredData.h:493
lldb_private::StructuredData::Dictionary::AddIntegerItem
void AddIntegerItem(llvm::StringRef key, uint64_t value)
Definition: StructuredData.h:525
FileSpec.h
lldb_private::StructuredData::Dictionary::collection
std::map< ConstString, ObjectSP > collection
Definition: StructuredData.h:546
lldb_private::StructuredData::Object::GetAsBoolean
Boolean * GetAsBoolean()
Definition: StructuredData.h:119
lldb::eStructuredDataTypeArray
@ eStructuredDataTypeArray
Definition: lldb-enumerations.h:797
ConstString.h
lldb_private::StructuredData::Generic::m_object
void * m_object
Definition: StructuredData.h:579
lldb_private::StructuredData::Generic::GetValue
void * GetValue() const
Definition: StructuredData.h:570
lldb_private::StructuredData::Array::GetItemAtIndexAsString
bool GetItemAtIndexAsString(size_t idx, llvm::StringRef &result) const
Definition: StructuredData.h:222
Stream.h
lldb_private::StructuredData::ParseJSON
static ObjectSP ParseJSON(const std::string &json_text)
Definition: StructuredData.cpp:25
lldb_private::StructuredData::ArraySP
std::shared_ptr< Array > ArraySP
Definition: StructuredData.h:62
lldb_private::StructuredData::Integer::~Integer
~Integer() override=default
lldb_private::StructuredData::Dictionary::GetValueForKeyAsString
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
Definition: StructuredData.h:449
lldb_private::StructuredData::Dictionary::GetValueForKeyAsArray
bool GetValueForKeyAsArray(llvm::StringRef key, Array *&result) const
Definition: StructuredData.h:504
lldb_private::StructuredData::Array::GetItemAtIndex
ObjectSP GetItemAtIndex(size_t idx) const
Definition: StructuredData.h:194
lldb_private::StructuredData::Boolean::Boolean
Boolean(bool b=false)
Definition: StructuredData.h:333
lldb_private::StructuredData::Generic::SetValue
void SetValue(void *value)
Definition: StructuredData.h:568
lldb_private::StructuredData::Array::GetSize
size_t GetSize() const
Definition: StructuredData.h:186
integer
#define integer
Definition: EmulateInstructionARM64.cpp:74
lldb_private::StructuredData::Generic::Serialize
void Serialize(llvm::json::OStream &s) const override
Definition: StructuredData.cpp:180
lldb_private::StructuredData::Dictionary::GetValueForKeyAsString
bool GetValueForKeyAsString(llvm::StringRef key, ConstString &result) const
Definition: StructuredData.h:473
lldb_private::StructuredData::Generic::IsValid
bool IsValid() const override
Definition: StructuredData.h:572
lldb_private::StructuredData::Generic::GetDescription
void GetDescription(lldb_private::Stream &s) const override
Definition: StructuredData.cpp:275
lldb::eStructuredDataTypeNull
@ eStructuredDataTypeNull
Definition: lldb-enumerations.h:795
lldb_private::StructuredData::Dictionary::GetValueForKeyAsBoolean
bool GetValueForKeyAsBoolean(llvm::StringRef key, bool &result) const
Definition: StructuredData.h:416
lldb_private::StructuredData::Object::m_type
lldb::StructuredDataType m_type
Definition: StructuredData.h:168
lldb_private::LineStatus::Status
@ Status
lldb_private::StructuredData::IntegerSP
std::shared_ptr< Integer > IntegerSP
Definition: StructuredData.h:63
lldb_private::StructuredData::Object
Definition: StructuredData.h:70
lldb
Definition: SBAddress.h:15
lldb_private::StructuredData::Integer::GetDescription
void GetDescription(lldb_private::Stream &s) const override
Definition: StructuredData.cpp:184
lldb_private::StructuredData::Array::~Array
~Array() override=default
lldb_private::StructuredData::Array::ForEach
bool ForEach(std::function< bool(Object *object)> const &foreach_callback) const
Definition: StructuredData.h:178
lldb_private::StructuredData::Float::Serialize
void Serialize(llvm::json::OStream &s) const override
Definition: StructuredData.cpp:154
lldb_private::StructuredData::Integer::SetValue
void SetValue(uint64_t value)
Definition: StructuredData.h:300