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_DATAFORMATTERS_FORMATTERSHELPERS_H
11 #define LLDB_DATAFORMATTERS_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 
39 /// Add a summary that is implemented by a C++ callback.
42  const char *description, ConstString type_name,
43  TypeSummaryImpl::Flags flags, bool regex = false);
44 
45 /// Add a synthetic that is implemented by a C++ callback.
48  const char *description, ConstString type_name,
49  ScriptedSyntheticChildren::Flags flags,
50  bool regex = false);
51 
53  std::vector<std::string> children, const char *description,
54  ConstString type_name, ScriptedSyntheticChildren::Flags flags,
55  bool regex = false);
56 
57 size_t ExtractIndexFromString(const char *item_name);
58 
59 Address GetArrayAddressOrPointerValue(ValueObject &valobj);
60 
61 lldb::ValueObjectSP GetValueOfLibCXXCompressedPair(ValueObject &pair);
62 
63 time_t GetOSXEpoch();
64 
66 
68  if (ptr_size == 4)
69  thirty_two = word.thirty_two;
70  else
71  sixty_four = word.sixty_four;
72  }
73 
75  ptr_size = word.ptr_size;
76  if (ptr_size == 4)
77  thirty_two = word.thirty_two;
78  else
79  sixty_four = word.sixty_four;
80  return *this;
81  }
82 
83  InferiorSizedWord(uint64_t val, Process &process)
84  : ptr_size(process.GetAddressByteSize()) {
85  if (ptr_size == 4)
86  thirty_two = (uint32_t)val;
87  else if (ptr_size == 8)
88  sixty_four = val;
89  else
90  assert(false && "new pointer size is unknown");
91  }
92 
93  bool IsNegative() const {
94  if (ptr_size == 4)
95  return ((int32_t)thirty_two) < 0;
96  else
97  return ((int64_t)sixty_four) < 0;
98  }
99 
100  bool IsZero() const {
101  if (ptr_size == 4)
102  return thirty_two == 0;
103  else
104  return sixty_four == 0;
105  }
106 
108  if (process.GetAddressByteSize() == 4)
109  return InferiorSizedWord(UINT32_MAX, 4);
110  else
111  return InferiorSizedWord(UINT64_MAX, 8);
112  }
113 
114  InferiorSizedWord operator>>(int rhs) const {
115  if (ptr_size == 4)
116  return InferiorSizedWord(thirty_two >> rhs, 4);
117  return InferiorSizedWord(sixty_four >> rhs, 8);
118  }
119 
120  InferiorSizedWord operator<<(int rhs) const {
121  if (ptr_size == 4)
122  return InferiorSizedWord(thirty_two << rhs, 4);
123  return InferiorSizedWord(sixty_four << rhs, 8);
124  }
125 
127  if (ptr_size != word.ptr_size)
128  return InferiorSizedWord(0, ptr_size);
129  if (ptr_size == 4)
130  return InferiorSizedWord(thirty_two & word.thirty_two, 4);
131  return InferiorSizedWord(sixty_four & word.sixty_four, 8);
132  }
133 
135  if (ptr_size == 4)
136  return InferiorSizedWord(thirty_two & x, 4);
137  return InferiorSizedWord(sixty_four & x, 8);
138  }
139 
140  size_t GetBitSize() const { return ptr_size << 3; }
141 
142  size_t GetByteSize() const { return ptr_size; }
143 
144  uint64_t GetValue() const {
145  if (ptr_size == 4)
146  return (uint64_t)thirty_two;
147  return sixty_four;
148  }
149 
151  if (ptr_size == 4)
152  return InferiorSizedWord((int32_t)thirty_two, 4);
153  return InferiorSizedWord((int64_t)sixty_four, 8);
154  }
155 
156  uint8_t *CopyToBuffer(uint8_t *buffer) const {
157  if (ptr_size == 4) {
158  memcpy(buffer, &thirty_two, 4);
159  return buffer + 4;
160  } else {
161  memcpy(buffer, &sixty_four, 8);
162  return buffer + 8;
163  }
164  }
165 
168  if (ptr_size == 4)
169  return DataExtractor(&thirty_two, 4, byte_order, 4);
170  else
171  return DataExtractor(&sixty_four, 8, byte_order, 8);
172  }
173 
174 private:
175  InferiorSizedWord(uint64_t val, size_t psz) : ptr_size(psz) {
176  if (ptr_size == 4)
177  thirty_two = (uint32_t)val;
178  else
179  sixty_four = val;
180  }
181 
182  size_t ptr_size;
183  union {
185  uint64_t sixty_four;
186  };
187 };
188 } // namespace formatters
189 } // namespace lldb_private
190 
191 #endif // LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H
lldb::Format
Format
Display format definitions.
Definition: lldb-enumerations.h:155
lldb_private::formatters::AddOneLineSummary
void AddOneLineSummary(TypeCategoryImpl::SharedPointer category_sp, ConstString type_name, TypeSummaryImpl::Flags flags, bool regex=false)
Definition: FormattersHelpers.cpp:61
lldb_private::CXXSyntheticChildren::CreateFrontEndCallback
std::function< SyntheticChildrenFrontEnd *(CXXSyntheticChildren *, lldb::ValueObjectSP)> CreateFrontEndCallback
Definition: TypeSynthetic.h:362
lldb_private::Process
Definition: Process.h:341
lldb_private::formatters::InferiorSizedWord::GetByteSize
size_t GetByteSize() const
Definition: FormattersHelpers.h:142
lldb_private::formatters::AddFormat
void AddFormat(TypeCategoryImpl::SharedPointer category_sp, lldb::Format format, ConstString type_name, TypeFormatImpl::Flags flags, bool regex=false)
Definition: FormattersHelpers.cpp:24
lldb_private::formatters::InferiorSizedWord::operator<<
InferiorSizedWord operator<<(int rhs) const
Definition: FormattersHelpers.h:120
lldb_private::formatters::InferiorSizedWord::SignExtend
InferiorSizedWord SignExtend() const
Definition: FormattersHelpers.h:150
lldb_private::formatters::InferiorSizedWord::operator=
InferiorSizedWord operator=(const InferiorSizedWord &word)
Definition: FormattersHelpers.h:74
lldb_private::formatters::InferiorSizedWord
Definition: FormattersHelpers.h:65
lldb_private::formatters::InferiorSizedWord::InferiorSizedWord
InferiorSizedWord(uint64_t val, size_t psz)
Definition: FormattersHelpers.h:175
lldb_private::formatters::AddStringSummary
void AddStringSummary(TypeCategoryImpl::SharedPointer category_sp, const char *string, ConstString type_name, TypeSummaryImpl::Flags flags, bool regex=false)
Definition: FormattersHelpers.cpp:48
lldb_private::formatters::InferiorSizedWord::operator&
InferiorSizedWord operator&(int x) const
Definition: FormattersHelpers.h:134
lldb_private::formatters::InferiorSizedWord::GetValue
uint64_t GetValue() const
Definition: FormattersHelpers.h:144
lldb_private::formatters::InferiorSizedWord::GetMaximum
static InferiorSizedWord GetMaximum(Process &process)
Definition: FormattersHelpers.h:107
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::formatters::AddCXXSummary
void AddCXXSummary(TypeCategoryImpl::SharedPointer category_sp, CXXFunctionSummaryFormat::Callback funct, const char *description, ConstString type_name, TypeSummaryImpl::Flags flags, bool regex=false)
Add a summary that is implemented by a C++ callback.
Definition: FormattersHelpers.cpp:75
lldb_private::formatters::InferiorSizedWord::IsZero
bool IsZero() const
Definition: FormattersHelpers.h:100
lldb_private::formatters::InferiorSizedWord::operator&
InferiorSizedWord operator&(const InferiorSizedWord &word) const
Definition: FormattersHelpers.h:126
lldb_private::formatters::GetValueOfLibCXXCompressedPair
lldb::ValueObjectSP GetValueOfLibCXXCompressedPair(ValueObject &pair)
Definition: FormattersHelpers.cpp:150
lldb_private::Process::GetAddressByteSize
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3306
lldb-enumerations.h
lldb_private::formatters::InferiorSizedWord::GetBitSize
size_t GetBitSize() const
Definition: FormattersHelpers.h:140
lldb_private::TypeCategoryImpl::SharedPointer
std::shared_ptr< TypeCategoryImpl > SharedPointer
Definition: TypeCategory.h:316
lldb_private::formatters::InferiorSizedWord::CopyToBuffer
uint8_t * CopyToBuffer(uint8_t *buffer) const
Definition: FormattersHelpers.h:156
lldb_private::formatters::InferiorSizedWord::GetAsData
DataExtractor GetAsData(lldb::ByteOrder byte_order=lldb::eByteOrderInvalid) const
Definition: FormattersHelpers.h:167
TypeSummary.h
lldb_private::formatters::InferiorSizedWord::InferiorSizedWord
InferiorSizedWord(const InferiorSizedWord &word)
Definition: FormattersHelpers.h:67
lldb::eByteOrderInvalid
@ eByteOrderInvalid
Definition: lldb-enumerations.h:139
uint32_t
TypeSynthetic.h
lldb_private::formatters::InferiorSizedWord::ptr_size
size_t ptr_size
Definition: FormattersHelpers.h:182
lldb_private::formatters::GetArrayAddressOrPointerValue
Address GetArrayAddressOrPointerValue(ValueObject &valobj)
Definition: FormattersHelpers.cpp:135
lldb_private::formatters::AddFilter
void AddFilter(TypeCategoryImpl::SharedPointer category_sp, std::vector< std::string > children, const char *description, ConstString type_name, ScriptedSyntheticChildren::Flags flags, bool regex=false)
Definition: FormattersHelpers.cpp:104
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::CXXFunctionSummaryFormat::Callback
std::function< bool(ValueObject &, Stream &, const TypeSummaryOptions &)> Callback
Definition: TypeSummary.h:311
lldb_private::formatters::GetOSXEpoch
time_t GetOSXEpoch()
Definition: Cocoa.cpp:1213
TypeFormat.h
lldb-forward.h
lldb_private::formatters::InferiorSizedWord::InferiorSizedWord
InferiorSizedWord(uint64_t val, Process &process)
Definition: FormattersHelpers.h:83
TypeCategory.h
lldb_private::formatters::InferiorSizedWord::operator>>
InferiorSizedWord operator>>(int rhs) const
Definition: FormattersHelpers.h:114
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::formatters::InferiorSizedWord::IsNegative
bool IsNegative() const
Definition: FormattersHelpers.h:93
lldb_private::formatters::InferiorSizedWord::thirty_two
uint32_t thirty_two
Definition: FormattersHelpers.h:184
lldb_private::formatters::InferiorSizedWord::sixty_four
uint64_t sixty_four
Definition: FormattersHelpers.h:185
lldb_private::formatters::AddCXXSynthetic
void AddCXXSynthetic(TypeCategoryImpl::SharedPointer category_sp, CXXSyntheticChildren::CreateFrontEndCallback generator, const char *description, ConstString type_name, ScriptedSyntheticChildren::Flags flags, bool regex=false)
Add a synthetic that is implemented by a C++ callback.
Definition: FormattersHelpers.cpp:89
lldb_private::formatters::AddSummary
void AddSummary(TypeCategoryImpl::SharedPointer category_sp, lldb::TypeSummaryImplSP summary_sp, ConstString type_name, bool regex=false)
lldb_private::formatters::ExtractIndexFromString
size_t ExtractIndexFromString(const char *item_name)
Definition: FormattersHelpers.cpp:119
UINT64_MAX
#define UINT64_MAX
Definition: lldb-defines.h:35
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138