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 ConstString 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.GetStringRef(), match_type, format_sp);
32}
33
35 TypeCategoryImpl::SharedPointer category_sp, TypeSummaryImplSP summary_sp,
36 ConstString type_name, bool regex) {
37 FormatterMatchType match_type =
39 category_sp->AddTypeSummary(type_name.GetStringRef(), match_type, summary_sp);
40}
41
43 TypeCategoryImpl::SharedPointer category_sp, const char *string,
44 ConstString 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.GetStringRef(), match_type, summary_sp);
50}
51
53 TypeCategoryImpl::SharedPointer category_sp, ConstString 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.GetStringRef(), match_type, summary_sp);
61}
62
65 CXXFunctionSummaryFormat::Callback funct, const char *description,
66 ConstString 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.GetStringRef(), match_type, summary_sp);
73}
74
78 const char *description, ConstString type_name,
79 ScriptedSyntheticChildren::Flags flags, bool regex) {
80 lldb::SyntheticChildrenSP synth_sp(
81 new CXXSyntheticChildren(flags, description, generator));
82 FormatterMatchType match_type =
84 category_sp->AddTypeSynthetic(type_name.GetStringRef(), match_type, synth_sp);
85}
86
89 std::vector<std::string> children, const char *description,
90 ConstString type_name, ScriptedSyntheticChildren::Flags flags, bool regex) {
91 TypeFilterImplSP filter_sp(new TypeFilterImpl(flags));
92 for (auto child : children)
93 filter_sp->AddExpressionPath(child);
94 FormatterMatchType match_type =
96 category_sp->AddTypeFilter(type_name.GetStringRef(), match_type, filter_sp);
97}
98
100 if (!item_name || !*item_name)
101 return UINT32_MAX;
102 if (*item_name != '[')
103 return UINT32_MAX;
104 item_name++;
105 char *endptr = nullptr;
106 unsigned long int idx = ::strtoul(item_name, &endptr, 0);
107 if (idx == 0 && endptr == item_name)
108 return UINT32_MAX;
109 if (idx == ULONG_MAX)
110 return UINT32_MAX;
111 return idx;
112}
113
117 AddressType type;
118
119 if (valobj.IsPointerType())
120 data_addr = valobj.GetPointerValue(&type);
121 else if (valobj.IsArrayType())
122 data_addr = valobj.GetAddressOf(/*scalar_is_load_address=*/true, &type);
123 if (data_addr != LLDB_INVALID_ADDRESS && type == eAddressTypeFile)
124 return Address(data_addr, valobj.GetModule()->GetSectionList());
125
126 return data_addr;
127}
128
129lldb::ValueObjectSP
131 ValueObjectSP value =
132 pair.GetChildMemberWithName(ConstString("__value_"), true);
133 if (!value) {
134 // pre-r300140 member name
135 value = pair.GetChildMemberWithName(ConstString("__first_"), true);
136 }
137 return value;
138}
A section + offset based address class.
Definition: Address.h:59
std::function< SyntheticChildrenFrontEnd *(CXXSyntheticChildren *, lldb::ValueObjectSP)> CreateFrontEndCallback
A uniqued constant string class.
Definition: ConstString.h:39
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:201
std::shared_ptr< TypeCategoryImpl > SharedPointer
Definition: TypeCategory.h:357
Flags & SetShowMembersOneLiner(bool value=true)
Definition: TypeSummary.h:160
lldb::addr_t GetPointerValue(AddressType *address_type=nullptr)
virtual bool IsArrayType()
Definition: ValueObject.h:384
virtual lldb::ModuleSP GetModule()
Return the module associated with this value object in case the value is from an executable file and ...
virtual lldb::addr_t GetAddressOf(bool scalar_is_load_address=true, AddressType *address_type=nullptr)
virtual bool IsPointerType()
Definition: ValueObject.h:382
virtual lldb::ValueObjectSP GetChildMemberWithName(ConstString name, bool can_create)
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
#define UINT32_MAX
Definition: lldb-defines.h:19
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.
void AddStringSummary(TypeCategoryImpl::SharedPointer category_sp, const char *string, ConstString type_name, TypeSummaryImpl::Flags flags, bool regex=false)
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.
size_t ExtractIndexFromString(const char *item_name)
void AddFilter(TypeCategoryImpl::SharedPointer category_sp, std::vector< std::string > children, const char *description, ConstString type_name, ScriptedSyntheticChildren::Flags flags, bool regex=false)
void AddFormat(TypeCategoryImpl::SharedPointer category_sp, lldb::Format format, ConstString type_name, TypeFormatImpl::Flags flags, bool regex=false)
lldb::ValueObjectSP GetValueOfLibCXXCompressedPair(ValueObject &pair)
Address GetArrayAddressOrPointerValue(ValueObject &valobj)
void AddSummary(TypeCategoryImpl::SharedPointer category_sp, lldb::TypeSummaryImplSP summary_sp, ConstString type_name, bool regex=false)
void AddOneLineSummary(TypeCategoryImpl::SharedPointer category_sp, ConstString type_name, TypeSummaryImpl::Flags flags, bool regex=false)
A class that represents a running process on the host machine.
@ eAddressTypeFile
Address is an address as found in an object or symbol file.
Definition: SBAddress.h:15
Format
Display format definitions.
FormatterMatchType
Type of match to be performed when looking for a formatter for a data type.
@ eFormatterMatchExact
@ eFormatterMatchRegex
uint64_t addr_t
Definition: lldb-types.h:83
std::function< bool(ValueObject &, Stream &, const TypeSummaryOptions &)> Callback
Definition: TypeSummary.h:311