LLDB  mainline
FormattersHelpers.cpp
Go to the documentation of this file.
1 //===-- FormattersHelpers.cpp -------------------------------------*- 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 
11 
12 
14 
15 #include "lldb/Target/StackFrame.h"
16 #include "lldb/Target/Target.h"
17 #include "lldb/Target/Thread.h"
20 
21 using namespace lldb;
22 using namespace lldb_private;
23 using namespace lldb_private::formatters;
24 
27  ConstString type_name, TypeFormatImpl::Flags flags, bool regex) {
28  lldb::TypeFormatImplSP format_sp(new TypeFormatImpl_Format(format, flags));
29 
30  if (regex)
31  category_sp->GetRegexTypeFormatsContainer()->Add(
32  RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
33  format_sp);
34  else
35  category_sp->GetTypeFormatsContainer()->Add(type_name, format_sp);
36 }
37 
39  TypeCategoryImpl::SharedPointer category_sp, TypeSummaryImplSP summary_sp,
40  ConstString type_name, bool regex) {
41  if (regex)
42  category_sp->GetRegexTypeSummariesContainer()->Add(
43  RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
44  summary_sp);
45  else
46  category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
47 }
48 
50  TypeCategoryImpl::SharedPointer category_sp, const char *string,
51  ConstString type_name, TypeSummaryImpl::Flags flags, bool regex) {
52  lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, string));
53 
54  if (regex)
55  category_sp->GetRegexTypeSummariesContainer()->Add(
56  RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
57  summary_sp);
58  else
59  category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
60 }
61 
63  TypeCategoryImpl::SharedPointer category_sp, ConstString type_name,
64  TypeSummaryImpl::Flags flags, bool regex) {
65  flags.SetShowMembersOneLiner(true);
66  lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, ""));
67 
68  if (regex)
69  category_sp->GetRegexTypeSummariesContainer()->Add(
70  RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
71  summary_sp);
72  else
73  category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
74 }
75 
78  CXXFunctionSummaryFormat::Callback funct, const char *description,
79  ConstString type_name, TypeSummaryImpl::Flags flags, bool regex) {
80  lldb::TypeSummaryImplSP summary_sp(
81  new CXXFunctionSummaryFormat(flags, funct, description));
82  if (regex)
83  category_sp->GetRegexTypeSummariesContainer()->Add(
84  RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
85  summary_sp);
86  else
87  category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
88 }
89 
93  const char *description, ConstString type_name,
94  ScriptedSyntheticChildren::Flags flags, bool regex) {
95  lldb::SyntheticChildrenSP synth_sp(
96  new CXXSyntheticChildren(flags, description, generator));
97  if (regex)
98  category_sp->GetRegexTypeSyntheticsContainer()->Add(
99  RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
100  synth_sp);
101  else
102  category_sp->GetTypeSyntheticsContainer()->Add(type_name, synth_sp);
103 }
104 
107  std::vector<std::string> children, const char *description,
108  ConstString type_name, ScriptedSyntheticChildren::Flags flags, bool regex) {
109  TypeFilterImplSP filter_sp(new TypeFilterImpl(flags));
110  for (auto child : children)
111  filter_sp->AddExpressionPath(child);
112  if (regex)
113  category_sp->GetRegexTypeFiltersContainer()->Add(
114  RegularExpressionSP(new RegularExpression(type_name.GetStringRef())),
115  filter_sp);
116  else
117  category_sp->GetTypeFiltersContainer()->Add(type_name, filter_sp);
118 }
119 
121  if (!item_name || !*item_name)
122  return UINT32_MAX;
123  if (*item_name != '[')
124  return UINT32_MAX;
125  item_name++;
126  char *endptr = NULL;
127  unsigned long int idx = ::strtoul(item_name, &endptr, 0);
128  if (idx == 0 && endptr == item_name)
129  return UINT32_MAX;
130  if (idx == ULONG_MAX)
131  return UINT32_MAX;
132  return idx;
133 }
134 
138 
139  if (valobj.IsPointerType())
140  data_addr = valobj.GetValueAsUnsigned(0);
141  else if (valobj.IsArrayType())
142  data_addr = valobj.GetAddressOf();
143 
144  return data_addr;
145 }
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
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
void AddOneLineSummary(TypeCategoryImpl::SharedPointer category_sp, ConstString type_name, TypeSummaryImpl::Flags flags, bool regex=false)
std::shared_ptr< TypeCategoryImpl > SharedPointer
Definition: TypeCategory.h:372
virtual bool IsPointerType()
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
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:233
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:38
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
Definition: SBAddress.h:15
Flags & SetShowMembersOneLiner(bool value=true)
Definition: TypeSummary.h:163
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)