Coverage Report

Created: 2023-11-11 10:31

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/DataFormatters/FormattersHelpers.cpp
Line
Count
Source (jump to first uncovered line)
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
12
#include "lldb/DataFormatters/FormattersHelpers.h"
13
#include "lldb/Core/Module.h"
14
#include "lldb/Target/StackFrame.h"
15
#include "lldb/Target/Target.h"
16
#include "lldb/Target/Thread.h"
17
#include "lldb/Utility/ConstString.h"
18
#include "lldb/Utility/RegularExpression.h"
19
20
using namespace lldb;
21
using namespace lldb_private;
22
using namespace lldb_private::formatters;
23
24
void lldb_private::formatters::AddFormat(
25
    TypeCategoryImpl::SharedPointer category_sp, lldb::Format format,
26
736
    llvm::StringRef type_name, TypeFormatImpl::Flags flags, bool regex) {
27
736
  lldb::TypeFormatImplSP format_sp(new TypeFormatImpl_Format(format, flags));
28
29
736
  FormatterMatchType match_type =
30
736
      regex ? 
eFormatterMatchRegex0
: eFormatterMatchExact;
31
736
  category_sp->AddTypeFormat(type_name, match_type, format_sp);
32
736
}
33
34
void lldb_private::formatters::AddSummary(
35
    TypeCategoryImpl::SharedPointer category_sp, TypeSummaryImplSP summary_sp,
36
0
    llvm::StringRef type_name, bool regex) {
37
0
  FormatterMatchType match_type =
38
0
      regex ? eFormatterMatchRegex : eFormatterMatchExact;
39
0
  category_sp->AddTypeSummary(type_name, match_type, summary_sp);
40
0
}
41
42
void lldb_private::formatters::AddStringSummary(
43
    TypeCategoryImpl::SharedPointer category_sp, const char *string,
44
19.4k
    llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex) {
45
19.4k
  lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, string));
46
47
19.4k
  FormatterMatchType match_type =
48
19.4k
      regex ? 
eFormatterMatchRegex0
: eFormatterMatchExact;
49
19.4k
  category_sp->AddTypeSummary(type_name, match_type, summary_sp);
50
19.4k
}
51
52
void lldb_private::formatters::AddOneLineSummary(
53
    TypeCategoryImpl::SharedPointer category_sp, llvm::StringRef type_name,
54
4.23k
    TypeSummaryImpl::Flags flags, bool regex) {
55
4.23k
  flags.SetShowMembersOneLiner(true);
56
4.23k
  lldb::TypeSummaryImplSP summary_sp(new StringSummaryFormat(flags, ""));
57
58
4.23k
  FormatterMatchType match_type =
59
4.23k
      regex ? 
eFormatterMatchRegex0
: eFormatterMatchExact;
60
4.23k
  category_sp->AddTypeSummary(type_name, match_type, summary_sp);
61
4.23k
}
62
63
void lldb_private::formatters::AddCXXSummary(
64
    TypeCategoryImpl::SharedPointer category_sp,
65
    CXXFunctionSummaryFormat::Callback funct, const char *description,
66
108k
    llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex) {
67
108k
  lldb::TypeSummaryImplSP summary_sp(
68
108k
      new CXXFunctionSummaryFormat(flags, funct, description));
69
70
108k
  FormatterMatchType match_type =
71
108k
      regex ? 
eFormatterMatchRegex30.1k
:
eFormatterMatchExact78.0k
;
72
108k
  category_sp->AddTypeSummary(type_name, match_type, summary_sp);
73
108k
}
74
75
void lldb_private::formatters::AddCXXSynthetic(
76
    TypeCategoryImpl::SharedPointer category_sp,
77
    CXXSyntheticChildren::CreateFrontEndCallback generator,
78
    const char *description, llvm::StringRef type_name,
79
47.3k
    ScriptedSyntheticChildren::Flags flags, bool regex) {
80
47.3k
  lldb::SyntheticChildrenSP synth_sp(
81
47.3k
      new CXXSyntheticChildren(flags, description, generator));
82
47.3k
  FormatterMatchType match_type =
83
47.3k
      regex ? 
eFormatterMatchRegex22.6k
:
eFormatterMatchExact24.6k
;
84
47.3k
  category_sp->AddTypeSynthetic(type_name, match_type, synth_sp);
85
47.3k
}
86
87
void lldb_private::formatters::AddFilter(
88
    TypeCategoryImpl::SharedPointer category_sp,
89
    std::vector<std::string> children, const char *description,
90
    llvm::StringRef type_name, ScriptedSyntheticChildren::Flags flags,
91
0
    bool regex) {
92
0
  TypeFilterImplSP filter_sp(new TypeFilterImpl(flags));
93
0
  for (auto child : children)
94
0
    filter_sp->AddExpressionPath(child);
95
0
  FormatterMatchType match_type =
96
0
      regex ? eFormatterMatchRegex : eFormatterMatchExact;
97
0
  category_sp->AddTypeFilter(type_name, match_type, filter_sp);
98
0
}
99
100
2
size_t lldb_private::formatters::ExtractIndexFromString(const char *item_name) {
101
2
  if (!item_name || !*item_name)
102
0
    return UINT32_MAX;
103
2
  if (*item_name != '[')
104
0
    return UINT32_MAX;
105
2
  item_name++;
106
2
  char *endptr = nullptr;
107
2
  unsigned long int idx = ::strtoul(item_name, &endptr, 0);
108
2
  if (idx == 0 && endptr == item_name)
109
0
    return UINT32_MAX;
110
2
  if (idx == ULONG_MAX)
111
0
    return UINT32_MAX;
112
2
  return idx;
113
2
}
114
115
Address
116
66
lldb_private::formatters::GetArrayAddressOrPointerValue(ValueObject &valobj) {
117
66
  lldb::addr_t data_addr = LLDB_INVALID_ADDRESS;
118
66
  AddressType type;
119
120
66
  if (valobj.IsPointerType())
121
38
    data_addr = valobj.GetPointerValue(&type);
122
28
  else if (valobj.IsArrayType())
123
28
    data_addr = valobj.GetAddressOf(/*scalar_is_load_address=*/true, &type);
124
66
  if (data_addr != LLDB_INVALID_ADDRESS && type == eAddressTypeFile)
125
0
    return Address(data_addr, valobj.GetModule()->GetSectionList());
126
127
66
  return data_addr;
128
66
}