LLDB  mainline
FormattersHelpers.cpp
Go to the documentation of this file.
1 //===-- FormattersHelpers.cpp ---------------------------------------------===//
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 
10 
11 
13 
14 #include "lldb/Target/StackFrame.h"
15 #include "lldb/Target/Target.h"
16 #include "lldb/Target/Thread.h"
19 
20 using namespace lldb;
21 using namespace lldb_private;
22 using namespace lldb_private::formatters;
23 
26  ConstString type_name, TypeFormatImpl::Flags flags, bool regex) {
27  lldb::TypeFormatImplSP format_sp(new TypeFormatImpl_Format(format, flags));
28 
29  if (regex)
30  category_sp->GetRegexTypeFormatsContainer()->Add(
31  RegularExpression(type_name.GetStringRef()), format_sp);
32  else
33  category_sp->GetTypeFormatsContainer()->Add(std::move(type_name),
34  format_sp);
35 }
36 
38  TypeCategoryImpl::SharedPointer category_sp, TypeSummaryImplSP summary_sp,
39  ConstString type_name, bool regex) {
40  if (regex)
41  category_sp->GetRegexTypeSummariesContainer()->Add(
42  RegularExpression(type_name.GetStringRef()), summary_sp);
43  else
44  category_sp->GetTypeSummariesContainer()->Add(std::move(type_name),
45  summary_sp);
46 }
47 
49  TypeCategoryImpl::SharedPointer category_sp, const char *string,
50  ConstString type_name, TypeSummaryImpl::Flags flags, bool regex) {
51  lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, string));
52 
53  if (regex)
54  category_sp->GetRegexTypeSummariesContainer()->Add(
55  RegularExpression(type_name.GetStringRef()), summary_sp);
56  else
57  category_sp->GetTypeSummariesContainer()->Add(std::move(type_name),
58  summary_sp);
59 }
60 
62  TypeCategoryImpl::SharedPointer category_sp, ConstString type_name,
63  TypeSummaryImpl::Flags flags, bool regex) {
64  flags.SetShowMembersOneLiner(true);
65  lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, ""));
66 
67  if (regex)
68  category_sp->GetRegexTypeSummariesContainer()->Add(
69  RegularExpression(type_name.GetStringRef()), summary_sp);
70  else
71  category_sp->GetTypeSummariesContainer()->Add(std::move(type_name),
72  summary_sp);
73 }
74 
77  CXXFunctionSummaryFormat::Callback funct, const char *description,
78  ConstString type_name, TypeSummaryImpl::Flags flags, bool regex) {
79  lldb::TypeSummaryImplSP summary_sp(
80  new CXXFunctionSummaryFormat(flags, funct, description));
81  if (regex)
82  category_sp->GetRegexTypeSummariesContainer()->Add(
83  RegularExpression(type_name.GetStringRef()), summary_sp);
84  else
85  category_sp->GetTypeSummariesContainer()->Add(std::move(type_name),
86  summary_sp);
87 }
88 
92  const char *description, ConstString type_name,
93  ScriptedSyntheticChildren::Flags flags, bool regex) {
94  lldb::SyntheticChildrenSP synth_sp(
95  new CXXSyntheticChildren(flags, description, generator));
96  if (regex)
97  category_sp->GetRegexTypeSyntheticsContainer()->Add(
98  RegularExpression(type_name.GetStringRef()), synth_sp);
99  else
100  category_sp->GetTypeSyntheticsContainer()->Add(std::move(type_name),
101  synth_sp);
102 }
103 
106  std::vector<std::string> children, const char *description,
107  ConstString type_name, ScriptedSyntheticChildren::Flags flags, bool regex) {
108  TypeFilterImplSP filter_sp(new TypeFilterImpl(flags));
109  for (auto child : children)
110  filter_sp->AddExpressionPath(child);
111  if (regex)
112  category_sp->GetRegexTypeFiltersContainer()->Add(
113  RegularExpression(type_name.GetStringRef()), filter_sp);
114  else
115  category_sp->GetTypeFiltersContainer()->Add(std::move(type_name),
116  filter_sp);
117 }
118 
120  if (!item_name || !*item_name)
121  return UINT32_MAX;
122  if (*item_name != '[')
123  return UINT32_MAX;
124  item_name++;
125  char *endptr = nullptr;
126  unsigned long int idx = ::strtoul(item_name, &endptr, 0);
127  if (idx == 0 && endptr == item_name)
128  return UINT32_MAX;
129  if (idx == ULONG_MAX)
130  return UINT32_MAX;
131  return idx;
132 }
133 
137 
138  if (valobj.IsPointerType())
139  data_addr = valobj.GetValueAsUnsigned(0);
140  else if (valobj.IsArrayType())
141  data_addr = valobj.GetAddressOf();
142 
143  return data_addr;
144 }
145 
146 lldb::ValueObjectSP
148  ValueObjectSP value =
149  pair.GetChildMemberWithName(ConstString("__value_"), true);
150  if (!value) {
151  // pre-r300140 member name
152  value = pair.GetChildMemberWithName(ConstString("__first_"), true);
153  }
154  return value;
155 }
A class that represents a running process on the host machine.
lldb::addr_t GetArrayAddressOrPointerValue(ValueObject &valobj)
virtual lldb::ValueObjectSP GetChildMemberWithName(ConstString name, bool can_create)
std::function< bool(ValueObject &, Stream &, const TypeSummaryOptions &)> Callback
Definition: TypeSummary.h:311
void AddOneLineSummary(TypeCategoryImpl::SharedPointer category_sp, ConstString type_name, TypeSummaryImpl::Flags flags, bool regex=false)
std::shared_ptr< TypeCategoryImpl > SharedPointer
Definition: TypeCategory.h:318
virtual bool IsPointerType()
Format
Display format definitions.
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
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
lldb::ValueObjectSP GetValueOfLibCXXCompressedPair(ValueObject &pair)
virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr)
void AddFilter(TypeCategoryImpl::SharedPointer category_sp, std::vector< std::string > children, const char *description, ConstString type_name, ScriptedSyntheticChildren::Flags flags, bool regex=false)
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:232
void AddCXXSummary(TypeCategoryImpl::SharedPointer category_sp, CXXFunctionSummaryFormat::Callback funct, const char *description, ConstString type_name, TypeSummaryImpl::Flags flags, bool regex=false)
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)
A uniqued constant string class.
Definition: ConstString.h:40
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
Definition: SBAddress.h:15
Flags & SetShowMembersOneLiner(bool value=true)
Definition: TypeSummary.h:160
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)