1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
//===-- FormattersHelpers.cpp ---------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/DataFormatters/FormattersHelpers.h"
#include "lldb/Core/Module.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/RegularExpression.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::formatters;
void lldb_private::formatters::AddFormat(
TypeCategoryImpl::SharedPointer category_sp, lldb::Format format,
ConstString type_name, TypeFormatImpl::Flags flags, bool regex) {
lldb::TypeFormatImplSP format_sp(new TypeFormatImpl_Format(format, flags));
FormatterMatchType match_type =
regex ? eFormatterMatchRegex : eFormatterMatchExact;
category_sp->AddTypeFormat(type_name.GetStringRef(), match_type, format_sp);
}
void lldb_private::formatters::AddSummary(
TypeCategoryImpl::SharedPointer category_sp, TypeSummaryImplSP summary_sp,
ConstString type_name, bool regex) {
FormatterMatchType match_type =
regex ? eFormatterMatchRegex : eFormatterMatchExact;
category_sp->AddTypeSummary(type_name.GetStringRef(), match_type, summary_sp);
}
void lldb_private::formatters::AddStringSummary(
TypeCategoryImpl::SharedPointer category_sp, const char *string,
ConstString type_name, TypeSummaryImpl::Flags flags, bool regex) {
lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, string));
FormatterMatchType match_type =
regex ? eFormatterMatchRegex : eFormatterMatchExact;
category_sp->AddTypeSummary(type_name.GetStringRef(), match_type, summary_sp);
}
void lldb_private::formatters::AddOneLineSummary(
TypeCategoryImpl::SharedPointer category_sp, ConstString type_name,
TypeSummaryImpl::Flags flags, bool regex) {
flags.SetShowMembersOneLiner(true);
lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, ""));
FormatterMatchType match_type =
regex ? eFormatterMatchRegex : eFormatterMatchExact;
category_sp->AddTypeSummary(type_name.GetStringRef(), match_type, summary_sp);
}
void lldb_private::formatters::AddCXXSummary(
TypeCategoryImpl::SharedPointer category_sp,
CXXFunctionSummaryFormat::Callback funct, const char *description,
ConstString type_name, TypeSummaryImpl::Flags flags, bool regex) {
lldb::TypeSummaryImplSP summary_sp(
new CXXFunctionSummaryFormat(flags, funct, description));
FormatterMatchType match_type =
regex ? eFormatterMatchRegex : eFormatterMatchExact;
category_sp->AddTypeSummary(type_name.GetStringRef(), match_type, summary_sp);
}
void lldb_private::formatters::AddCXXSynthetic(
TypeCategoryImpl::SharedPointer category_sp,
CXXSyntheticChildren::CreateFrontEndCallback generator,
const char *description, ConstString type_name,
ScriptedSyntheticChildren::Flags flags, bool regex) {
lldb::SyntheticChildrenSP synth_sp(
new CXXSyntheticChildren(flags, description, generator));
FormatterMatchType match_type =
regex ? eFormatterMatchRegex : eFormatterMatchExact;
category_sp->AddTypeSynthetic(type_name.GetStringRef(), match_type, synth_sp);
}
void lldb_private::formatters::AddFilter(
TypeCategoryImpl::SharedPointer category_sp,
std::vector<std::string> children, const char *description,
ConstString type_name, ScriptedSyntheticChildren::Flags flags, bool regex) {
TypeFilterImplSP filter_sp(new TypeFilterImpl(flags));
for (auto child : children)
filter_sp->AddExpressionPath(child);
FormatterMatchType match_type =
regex ? eFormatterMatchRegex : eFormatterMatchExact;
category_sp->AddTypeFilter(type_name.GetStringRef(), match_type, filter_sp);
}
size_t lldb_private::formatters::ExtractIndexFromString(const char *item_name) {
if (!item_name || !*item_name)
return UINT32_MAX;
if (*item_name != '[')
return UINT32_MAX;
item_name++;
char *endptr = nullptr;
unsigned long int idx = ::strtoul(item_name, &endptr, 0);
if (idx == 0 && endptr == item_name)
return UINT32_MAX;
if (idx == ULONG_MAX)
return UINT32_MAX;
return idx;
}
Address
lldb_private::formatters::GetArrayAddressOrPointerValue(ValueObject &valobj) {
lldb::addr_t data_addr = LLDB_INVALID_ADDRESS;
AddressType type;
if (valobj.IsPointerType())
data_addr = valobj.GetPointerValue(&type);
else if (valobj.IsArrayType())
data_addr = valobj.GetAddressOf(/*scalar_is_load_address=*/true, &type);
if (data_addr != LLDB_INVALID_ADDRESS && type == eAddressTypeFile)
return Address(data_addr, valobj.GetModule()->GetSectionList());
return data_addr;
}
lldb::ValueObjectSP
lldb_private::formatters::GetValueOfLibCXXCompressedPair(ValueObject &pair) {
ValueObjectSP value =
pair.GetChildMemberWithName(ConstString("__value_"), true);
if (!value) {
// pre-r300140 member name
value = pair.GetChildMemberWithName(ConstString("__first_"), true);
}
return value;
}
|