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#include "lldb/Core/Module.h"
15#include "lldb/Target/Target.h"
16#include "lldb/Target/Thread.h"
19
20using namespace lldb;
21using namespace lldb_private;
22using namespace lldb_private::formatters;
23
26 llvm::StringRef type_name, TypeFormatImpl::Flags flags, bool regex) {
27 lldb::TypeFormatImplSP format_sp(new TypeFormatImpl_Format(format, flags));
28
29 FormatterMatchType match_type =
31 category_sp->AddTypeFormat(type_name, match_type, format_sp);
32}
33
36 llvm::StringRef type_name, bool regex) {
37 FormatterMatchType match_type =
39 category_sp->AddTypeSummary(type_name, match_type, summary_sp);
40}
41
43 TypeCategoryImpl::SharedPointer category_sp, const char *string,
44 llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex) {
45 lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, string));
46
47 FormatterMatchType match_type =
49 category_sp->AddTypeSummary(type_name, match_type, summary_sp);
50}
51
53 TypeCategoryImpl::SharedPointer category_sp, llvm::StringRef type_name,
54 TypeSummaryImpl::Flags flags, bool regex) {
55 flags.SetShowMembersOneLiner(true);
56 lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, ""));
57
58 FormatterMatchType match_type =
60 category_sp->AddTypeSummary(type_name, match_type, summary_sp);
61}
62
65 CXXFunctionSummaryFormat::Callback funct, const char *description,
66 llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex) {
67 lldb::TypeSummaryImplSP summary_sp(
68 new CXXFunctionSummaryFormat(flags, funct, description));
69
70 FormatterMatchType match_type =
72 category_sp->AddTypeSummary(type_name, match_type, summary_sp);
73}
74
78 const char *description, llvm::StringRef type_name,
79 ScriptedSyntheticChildren::Flags flags, bool regex) {
81 new CXXSyntheticChildren(flags, description, generator));
82 FormatterMatchType match_type =
84 category_sp->AddTypeSynthetic(type_name, match_type, synth_sp);
85}
86
89 std::vector<std::string> children, const char *description,
90 llvm::StringRef type_name, ScriptedSyntheticChildren::Flags flags,
91 bool regex) {
92 TypeFilterImplSP filter_sp(new TypeFilterImpl(flags));
93 for (auto child : children)
94 filter_sp->AddExpressionPath(child);
95 FormatterMatchType match_type =
97 category_sp->AddTypeFilter(type_name, match_type, filter_sp);
98}
99
100std::optional<size_t>
102 if (!item_name || !*item_name)
103 return std::nullopt;
104 if (*item_name != '[')
105 return std::nullopt;
106 item_name++;
107 char *endptr = nullptr;
108 unsigned long int idx = ::strtoul(item_name, &endptr, 0);
109 if ((idx == 0 && endptr == item_name) || idx == ULONG_MAX)
110 return std::nullopt;
111 return idx;
112}
113
116 ValueObject::AddrAndType data_addr;
117
118 if (valobj.IsPointerType())
119 data_addr = valobj.GetPointerValue();
120 else if (valobj.IsArrayType())
121 data_addr = valobj.GetAddressOf(/*scalar_is_load_address=*/true);
122
123 if (data_addr.address != LLDB_INVALID_ADDRESS &&
124 data_addr.type == eAddressTypeFile)
125 return Address(data_addr.address, valobj.GetModule()->GetSectionList());
126
127 return data_addr.address;
128}
129
131 Stream &stream, ValueObject &ptr, const TypeSummaryOptions &options) {
132 if (ptr.GetValueAsUnsigned(0) == 0) {
133 stream.Printf("nullptr");
134 return;
135 }
136
138 ValueObjectSP pointee_sp = ptr.Dereference(error);
139 if (!pointee_sp || !error.Success())
140 return;
141
142 if (!pointee_sp->DumpPrintableRepresentation(
146 stream.Printf("ptr = 0x%" PRIx64, ptr.GetValueAsUnsigned(0));
147}
148
150 ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
151 return FormatEntity::FormatStringRef("size=${svar%#}", stream, nullptr,
152 nullptr, nullptr, &valobj, false, false);
153}
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition Address.h:62
std::function< SyntheticChildrenFrontEnd *(CXXSyntheticChildren *, lldb::ValueObjectSP)> CreateFrontEndCallback
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
bool FormatStringRef(const llvm::StringRef &format, Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const Address *addr, ValueObject *valobj, bool function_changed, bool initial_function)
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