LLDB  mainline
FormattersHelpers.h
Go to the documentation of this file.
1 //===-- FormattersHelpers.h --------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef lldb_FormattersHelpers_h_
11 #define lldb_FormattersHelpers_h_
12 
13 #include "lldb/lldb-enumerations.h"
14 #include "lldb/lldb-forward.h"
15 
20 
21 namespace lldb_private {
22 namespace formatters {
24  ConstString type_name, TypeFormatImpl::Flags flags,
25  bool regex = false);
26 
28  lldb::TypeSummaryImplSP summary_sp, ConstString type_name,
29  bool regex = false);
30 
32  const char *string, ConstString type_name,
33  TypeSummaryImpl::Flags flags, bool regex = false);
34 
36  ConstString type_name, TypeSummaryImpl::Flags flags,
37  bool regex = false);
38 
41  const char *description, ConstString type_name,
42  TypeSummaryImpl::Flags flags, bool regex = false);
43 
46  const char *description, ConstString type_name,
47  ScriptedSyntheticChildren::Flags flags,
48  bool regex = false);
49 
51  std::vector<std::string> children, const char *description,
52  ConstString type_name, ScriptedSyntheticChildren::Flags flags,
53  bool regex = false);
54 
55 size_t ExtractIndexFromString(const char *item_name);
56 
57 lldb::addr_t GetArrayAddressOrPointerValue(ValueObject &valobj);
58 
59 time_t GetOSXEpoch();
60 
62 
63  InferiorSizedWord(const InferiorSizedWord &word) : ptr_size(word.ptr_size) {
64  if (ptr_size == 4)
65  thirty_two = word.thirty_two;
66  else
67  sixty_four = word.sixty_four;
68  }
69 
71  ptr_size = word.ptr_size;
72  if (ptr_size == 4)
73  thirty_two = word.thirty_two;
74  else
75  sixty_four = word.sixty_four;
76  return *this;
77  }
78 
79  InferiorSizedWord(uint64_t val, Process &process)
80  : ptr_size(process.GetAddressByteSize()) {
81  if (ptr_size == 4)
82  thirty_two = (uint32_t)val;
83  else if (ptr_size == 8)
84  sixty_four = val;
85  else
86  assert(false && "new pointer size is unknown");
87  }
88 
89  bool IsNegative() const {
90  if (ptr_size == 4)
91  return ((int32_t)thirty_two) < 0;
92  else
93  return ((int64_t)sixty_four) < 0;
94  }
95 
96  bool IsZero() const {
97  if (ptr_size == 4)
98  return thirty_two == 0;
99  else
100  return sixty_four == 0;
101  }
102 
104  if (process.GetAddressByteSize() == 4)
105  return InferiorSizedWord(UINT32_MAX, 4);
106  else
107  return InferiorSizedWord(UINT64_MAX, 8);
108  }
109 
110  InferiorSizedWord operator>>(int rhs) const {
111  if (ptr_size == 4)
112  return InferiorSizedWord(thirty_two >> rhs, 4);
113  return InferiorSizedWord(sixty_four >> rhs, 8);
114  }
115 
116  InferiorSizedWord operator<<(int rhs) const {
117  if (ptr_size == 4)
118  return InferiorSizedWord(thirty_two << rhs, 4);
119  return InferiorSizedWord(sixty_four << rhs, 8);
120  }
121 
123  if (ptr_size != word.ptr_size)
124  return InferiorSizedWord(0, ptr_size);
125  if (ptr_size == 4)
126  return InferiorSizedWord(thirty_two & word.thirty_two, 4);
127  return InferiorSizedWord(sixty_four & word.sixty_four, 8);
128  }
129 
131  if (ptr_size == 4)
132  return InferiorSizedWord(thirty_two & x, 4);
133  return InferiorSizedWord(sixty_four & x, 8);
134  }
135 
136  size_t GetBitSize() const { return ptr_size << 3; }
137 
138  size_t GetByteSize() const { return ptr_size; }
139 
140  uint64_t GetValue() const {
141  if (ptr_size == 4)
142  return (uint64_t)thirty_two;
143  return sixty_four;
144  }
145 
147  if (ptr_size == 4)
148  return InferiorSizedWord((int32_t)thirty_two, 4);
149  return InferiorSizedWord((int64_t)sixty_four, 8);
150  }
151 
152  uint8_t *CopyToBuffer(uint8_t *buffer) const {
153  if (ptr_size == 4) {
154  memcpy(buffer, &thirty_two, 4);
155  return buffer + 4;
156  } else {
157  memcpy(buffer, &sixty_four, 8);
158  return buffer + 8;
159  }
160  }
161 
164  if (ptr_size == 4)
165  return DataExtractor(&thirty_two, 4, byte_order, 4);
166  else
167  return DataExtractor(&sixty_four, 8, byte_order, 8);
168  }
169 
170 private:
171  InferiorSizedWord(uint64_t val, size_t psz) : ptr_size(psz) {
172  if (ptr_size == 4)
173  thirty_two = (uint32_t)val;
174  else
175  sixty_four = val;
176  }
177 
178  size_t ptr_size;
179  union {
181  uint64_t sixty_four;
182  };
183 };
184 } // namespace formatters
185 } // namespace lldb_private
186 
187 #endif // lldb_FormattersHelpers_h_
An data extractor class.
Definition: DataExtractor.h:47
InferiorSizedWord(uint64_t val, Process &process)
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
lldb::addr_t GetArrayAddressOrPointerValue(ValueObject &valobj)
std::function< bool(ValueObject &, Stream &, const TypeSummaryOptions &)> Callback
Definition: TypeSummary.h:312
uint8_t * CopyToBuffer(uint8_t *buffer) const
InferiorSizedWord operator=(const InferiorSizedWord &word)
void AddOneLineSummary(TypeCategoryImpl::SharedPointer category_sp, ConstString type_name, TypeSummaryImpl::Flags flags, bool regex=false)
InferiorSizedWord operator>>(int rhs) const
std::shared_ptr< TypeCategoryImpl > SharedPointer
Definition: TypeCategory.h:372
size_t ExtractIndexFromString(const char *item_name)
void AddStringSummary(TypeCategoryImpl::SharedPointer category_sp, const char *string, ConstString type_name, TypeSummaryImpl::Flags flags, bool regex=false)
#define UINT32_MAX
Definition: lldb-defines.h:31
InferiorSizedWord(const InferiorSizedWord &word)
void AddFilter(TypeCategoryImpl::SharedPointer category_sp, std::vector< std::string > children, const char *description, ConstString type_name, ScriptedSyntheticChildren::Flags flags, bool regex=false)
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3370
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
void AddCXXSummary(TypeCategoryImpl::SharedPointer category_sp, CXXFunctionSummaryFormat::Callback funct, const char *description, ConstString type_name, TypeSummaryImpl::Flags flags, bool regex=false)
DataExtractor GetAsData(lldb::ByteOrder byte_order=lldb::eByteOrderInvalid) const
uint64_t addr_t
Definition: lldb-types.h:83
void AddSummary(TypeCategoryImpl::SharedPointer category_sp, lldb::TypeSummaryImplSP summary_sp, ConstString type_name, bool regex=false)
InferiorSizedWord operator &(const InferiorSizedWord &word) const
static InferiorSizedWord GetMaximum(Process &process)
InferiorSizedWord operator<<(int rhs) const
#define UINT64_MAX
Definition: lldb-defines.h:35
void AddFormat(TypeCategoryImpl::SharedPointer category_sp, lldb::Format format, ConstString type_name, TypeFormatImpl::Flags flags, bool regex=false)
std::function< SyntheticChildrenFrontEnd *(CXXSyntheticChildren *, lldb::ValueObjectSP)> CreateFrontEndCallback
void AddCXXSynthetic(TypeCategoryImpl::SharedPointer category_sp, CXXSyntheticChildren::CreateFrontEndCallback generator, const char *description, ConstString type_name, ScriptedSyntheticChildren::Flags flags, bool regex=false)