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
14#include "lldb/Core/Module.h"
16#include "lldb/Target/Target.h"
17#include "lldb/Target/Thread.h"
20
21using namespace lldb;
22using namespace lldb_private;
23using namespace lldb_private::formatters;
24
27 llvm::StringRef type_name, TypeFormatImpl::Flags flags, bool regex) {
28 lldb::TypeFormatImplSP format_sp(new TypeFormatImpl_Format(format, flags));
29
30 FormatterMatchType match_type =
32 category_sp->AddTypeFormat(type_name, match_type, format_sp);
33}
34
37 llvm::StringRef type_name, bool regex) {
38 FormatterMatchType match_type =
40 category_sp->AddTypeSummary(type_name, match_type, summary_sp);
41}
42
44 TypeCategoryImpl::SharedPointer category_sp, const char *string,
45 llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex) {
46 lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, string));
47
48 FormatterMatchType match_type =
50 category_sp->AddTypeSummary(type_name, match_type, summary_sp);
51}
52
54 TypeCategoryImpl::SharedPointer category_sp, llvm::StringRef type_name,
55 TypeSummaryImpl::Flags flags, bool regex) {
56 flags.SetShowMembersOneLiner(true);
57 lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, ""));
58
59 FormatterMatchType match_type =
61 category_sp->AddTypeSummary(type_name, match_type, summary_sp);
62}
63
66 CXXFunctionSummaryFormat::Callback funct, const char *description,
67 llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex) {
68 lldb::TypeSummaryImplSP summary_sp(
69 new CXXFunctionSummaryFormat(flags, funct, description));
70
71 FormatterMatchType match_type =
73 category_sp->AddTypeSummary(type_name, match_type, summary_sp);
74}
75
79 const char *description, llvm::StringRef type_name,
80 ScriptedSyntheticChildren::Flags flags, bool regex) {
82 new CXXSyntheticChildren(flags, description, generator));
83 FormatterMatchType match_type =
85 category_sp->AddTypeSynthetic(type_name, match_type, synth_sp);
86}
87
90 std::vector<std::string> children, const char *description,
91 llvm::StringRef type_name, ScriptedSyntheticChildren::Flags flags,
92 bool regex) {
93 TypeFilterImplSP filter_sp(new TypeFilterImpl(flags));
94 for (auto child : children)
95 filter_sp->AddExpressionPath(child);
96 FormatterMatchType match_type =
98 category_sp->AddTypeFilter(type_name, match_type, filter_sp);
99}
100
101std::optional<size_t>
103 if (!item_name || !*item_name)
104 return std::nullopt;
105 if (*item_name != '[')
106 return std::nullopt;
107 item_name++;
108 char *endptr = nullptr;
109 unsigned long int idx = ::strtoul(item_name, &endptr, 0);
110 if ((idx == 0 && endptr == item_name) || idx == ULONG_MAX)
111 return std::nullopt;
112 return idx;
113}
114
117 ValueObject::AddrAndType data_addr;
118
119 if (valobj.IsPointerType())
120 data_addr = valobj.GetPointerValue();
121 else if (valobj.IsArrayType())
122 data_addr = valobj.GetAddressOf(/*scalar_is_load_address=*/true);
123
124 if (data_addr.address != LLDB_INVALID_ADDRESS &&
125 data_addr.type == eAddressTypeFile)
126 return Address(data_addr.address, valobj.GetModule()->GetSectionList());
127
128 return data_addr.address;
129}
130
132 Stream &stream, ValueObject &ptr, const TypeSummaryOptions &options) {
133 if (ptr.GetValueAsUnsigned(0) == 0) {
134 stream.Printf("nullptr");
135 return;
136 }
137
139 ValueObjectSP pointee_sp = ptr.Dereference(error);
140 if (!pointee_sp || !error.Success())
141 return;
142
143 if (!pointee_sp->DumpPrintableRepresentation(
147 stream.Printf("ptr = 0x%" PRIx64, ptr.GetValueAsUnsigned(0));
148}
149
151 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
152 return FormatEntity::Formatter(nullptr, nullptr, nullptr, false, false)
153 .FormatStringRef("size=${svar%#}", stream, &valobj);
154}
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition Address.h:62
std::function< SyntheticChildrenFrontEnd *(CXXSyntheticChildren *, lldb::ValueObjectSP)> CreateFrontEndCallback
bool FormatStringRef(const llvm::StringRef &format, Stream &s, ValueObject *valobj)
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
std::shared_ptr< TypeCategoryImpl > SharedPointer
Flags & SetShowMembersOneLiner(bool value=true)
virtual uint64_t GetValueAsUnsigned(uint64_t fail_value, bool *success=nullptr)
virtual lldb::ModuleSP GetModule()
Return the module associated with this value object in case the value is from an executable file and ...
virtual lldb::ValueObjectSP Dereference(Status &error)
virtual AddrAndType GetAddressOf(bool scalar_is_load_address=true)
#define LLDB_INVALID_ADDRESS
std::optional< size_t > ExtractIndexFromString(const char *item_name)
void AddOneLineSummary(TypeCategoryImpl::SharedPointer category_sp, llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex=false)
void AddCXXSummary(TypeCategoryImpl::SharedPointer category_sp, CXXFunctionSummaryFormat::Callback funct, const char *description, llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex=false)
Add a summary that is implemented by a C++ callback.
void AddStringSummary(TypeCategoryImpl::SharedPointer category_sp, const char *string, llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex=false)
void AddCXXSynthetic(TypeCategoryImpl::SharedPointer category_sp, CXXSyntheticChildren::CreateFrontEndCallback generator, const char *description, llvm::StringRef type_name, ScriptedSyntheticChildren::Flags flags, bool regex=false)
Add a synthetic that is implemented by a C++ callback.
void AddFilter(TypeCategoryImpl::SharedPointer category_sp, std::vector< std::string > children, const char *description, llvm::StringRef type_name, ScriptedSyntheticChildren::Flags flags, bool regex=false)
void AddFormat(TypeCategoryImpl::SharedPointer category_sp, lldb::Format format, llvm::StringRef type_name, TypeFormatImpl::Flags flags, bool regex=false)
bool ContainerSizeSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Address GetArrayAddressOrPointerValue(ValueObject &valobj)
void AddSummary(TypeCategoryImpl::SharedPointer category_sp, lldb::TypeSummaryImplSP summary_sp, llvm::StringRef type_name, bool regex=false)
void DumpCxxSmartPtrPointerSummary(Stream &stream, ValueObject &ptr, const TypeSummaryOptions &options)
Prints the summary for the pointer value of a C++ std::unique_ptr/stdshared_ptr/stdweak_ptr.
A class that represents a running process on the host machine.
@ eAddressTypeFile
Address is an address as found in an object or symbol file.
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Format
Display format definitions.
FormatterMatchType
Type of match to be performed when looking for a formatter for a data type.
@ eFormatterMatchExact
@ eFormatterMatchRegex
std::shared_ptr< lldb_private::SyntheticChildren > SyntheticChildrenSP
std::shared_ptr< lldb_private::TypeFilterImpl > TypeFilterImplSP
std::function< bool(ValueObject &, Stream &, const TypeSummaryOptions &)> Callback