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 }
lldb_private::SyntheticChildren::Flags
Definition: TypeSynthetic.h:134
RegularExpression.h
lldb_private::ValueObject::GetValueAsUnsigned
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
Definition: ValueObject.cpp:1090
lldb_private::RegularExpression
Definition: RegularExpression.h:18
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::CXXFunctionSummaryFormat
Definition: TypeSummary.h:306
lldb_private::CXXSyntheticChildren::CreateFrontEndCallback
std::function< SyntheticChildrenFrontEnd *(CXXSyntheticChildren *, lldb::ValueObjectSP)> CreateFrontEndCallback
Definition: TypeSynthetic.h:362
lldb_private::TypeSummaryImpl::Flags
Definition: TypeSummary.h:53
lldb_private::formatters::GetArrayAddressOrPointerValue
lldb::addr_t GetArrayAddressOrPointerValue(ValueObject &valobj)
Definition: FormattersHelpers.cpp:135
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::TypeFilterImpl
Definition: TypeSynthetic.h:277
lldb_private::ValueObject::IsPointerType
virtual bool IsPointerType()
Definition: ValueObject.h:382
StackFrame.h
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::ValueObject::IsArrayType
virtual bool IsArrayType()
Definition: ValueObject.h:384
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
Target.h
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::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
lldb_private::ValueObject::GetChildMemberWithName
virtual lldb::ValueObjectSP GetChildMemberWithName(ConstString name, bool can_create)
Definition: ValueObject.cpp:468
lldb_private::TypeSummaryImpl::Flags::SetShowMembersOneLiner
Flags & SetShowMembersOneLiner(bool value=true)
Definition: TypeSummary.h:160
lldb_private::formatters::GetValueOfLibCXXCompressedPair
lldb::ValueObjectSP GetValueOfLibCXXCompressedPair(ValueObject &pair)
Definition: FormattersHelpers.cpp:147
lldb_private::ConstString
Definition: ConstString.h:40
Thread.h
lldb_private::TypeCategoryImpl::SharedPointer
std::shared_ptr< TypeCategoryImpl > SharedPointer
Definition: TypeCategory.h:316
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::TypeFormatImpl::Flags
Definition: TypeFormat.h:26
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_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::formatters
Definition: CXXFunctionPointer.h:15
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::TypeFormatImpl_Format
Definition: TypeFormat.h:159
lldb_private::ValueObject::GetAddressOf
virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr)
Definition: ValueObject.cpp:1399
ConstString.h
lldb_private::StringSummaryFormat
Definition: TypeSummary.h:278
lldb_private::CXXSyntheticChildren
Definition: TypeSynthetic.h:358
FormattersHelpers.h
lldb
Definition: SBAddress.h:15
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