Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/DataFormatters/FormattersHelpers.h
Line
Count
Source (jump to first uncovered line)
1
//===-- FormattersHelpers.h --------------------------------------*- C++
2
//-*-===//
3
//
4
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5
// See https://llvm.org/LICENSE.txt for license information.
6
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H
11
#define LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H
12
13
#include "lldb/lldb-enumerations.h"
14
#include "lldb/lldb-forward.h"
15
16
#include "lldb/DataFormatters/TypeCategory.h"
17
#include "lldb/DataFormatters/TypeFormat.h"
18
#include "lldb/DataFormatters/TypeSummary.h"
19
#include "lldb/DataFormatters/TypeSynthetic.h"
20
21
namespace lldb_private {
22
namespace formatters {
23
void AddFormat(TypeCategoryImpl::SharedPointer category_sp, lldb::Format format,
24
               ConstString type_name, TypeFormatImpl::Flags flags,
25
               bool regex = false);
26
27
void AddSummary(TypeCategoryImpl::SharedPointer category_sp,
28
                lldb::TypeSummaryImplSP summary_sp, ConstString type_name,
29
                bool regex = false);
30
31
void AddStringSummary(TypeCategoryImpl::SharedPointer category_sp,
32
                      const char *string, ConstString type_name,
33
                      TypeSummaryImpl::Flags flags, bool regex = false);
34
35
void AddOneLineSummary(TypeCategoryImpl::SharedPointer category_sp,
36
                       ConstString type_name, TypeSummaryImpl::Flags flags,
37
                       bool regex = false);
38
39
/// Add a summary that is implemented by a C++ callback.
40
void AddCXXSummary(TypeCategoryImpl::SharedPointer category_sp,
41
                   CXXFunctionSummaryFormat::Callback funct,
42
                   const char *description, ConstString type_name,
43
                   TypeSummaryImpl::Flags flags, bool regex = false);
44
45
/// Add a synthetic that is implemented by a C++ callback.
46
void AddCXXSynthetic(TypeCategoryImpl::SharedPointer category_sp,
47
                     CXXSyntheticChildren::CreateFrontEndCallback generator,
48
                     const char *description, ConstString type_name,
49
                     ScriptedSyntheticChildren::Flags flags,
50
                     bool regex = false);
51
52
void AddFilter(TypeCategoryImpl::SharedPointer category_sp,
53
               std::vector<std::string> children, const char *description,
54
               ConstString type_name, ScriptedSyntheticChildren::Flags flags,
55
               bool regex = false);
56
57
size_t ExtractIndexFromString(const char *item_name);
58
59
Address GetArrayAddressOrPointerValue(ValueObject &valobj);
60
61
lldb::ValueObjectSP GetValueOfLibCXXCompressedPair(ValueObject &pair);
62
63
time_t GetOSXEpoch();
64
65
struct InferiorSizedWord {
66
67
0
  InferiorSizedWord(const InferiorSizedWord &word) : ptr_size(word.ptr_size) {
68
0
    if (ptr_size == 4)
69
0
      thirty_two = word.thirty_two;
70
0
    else
71
0
      sixty_four = word.sixty_four;
72
0
  }
73
74
0
  InferiorSizedWord operator=(const InferiorSizedWord &word) {
75
0
    ptr_size = word.ptr_size;
76
0
    if (ptr_size == 4)
77
0
      thirty_two = word.thirty_two;
78
0
    else
79
0
      sixty_four = word.sixty_four;
80
0
    return *this;
81
0
  }
82
83
  InferiorSizedWord(uint64_t val, Process &process)
84
677
      : ptr_size(process.GetAddressByteSize()) {
85
677
    if (ptr_size == 4)
86
0
      thirty_two = (uint32_t)val;
87
677
    else if (ptr_size == 8)
88
677
      sixty_four = val;
89
0
    else
90
0
      assert(false && "new pointer size is unknown");
91
677
  }
92
93
0
  bool IsNegative() const {
94
0
    if (ptr_size == 4)
95
0
      return ((int32_t)thirty_two) < 0;
96
0
    else
97
0
      return ((int64_t)sixty_four) < 0;
98
0
  }
99
100
0
  bool IsZero() const {
101
0
    if (ptr_size == 4)
102
0
      return thirty_two == 0;
103
0
    else
104
0
      return sixty_four == 0;
105
0
  }
106
107
0
  static InferiorSizedWord GetMaximum(Process &process) {
108
0
    if (process.GetAddressByteSize() == 4)
109
0
      return InferiorSizedWord(UINT32_MAX, 4);
110
0
    else
111
0
      return InferiorSizedWord(UINT64_MAX, 8);
112
0
  }
113
114
0
  InferiorSizedWord operator>>(int rhs) const {
115
0
    if (ptr_size == 4)
116
0
      return InferiorSizedWord(thirty_two >> rhs, 4);
117
0
    return InferiorSizedWord(sixty_four >> rhs, 8);
118
0
  }
119
120
0
  InferiorSizedWord operator<<(int rhs) const {
121
0
    if (ptr_size == 4)
122
0
      return InferiorSizedWord(thirty_two << rhs, 4);
123
0
    return InferiorSizedWord(sixty_four << rhs, 8);
124
0
  }
125
126
0
  InferiorSizedWord operator&(const InferiorSizedWord &word) const {
127
0
    if (ptr_size != word.ptr_size)
128
0
      return InferiorSizedWord(0, ptr_size);
129
0
    if (ptr_size == 4)
130
0
      return InferiorSizedWord(thirty_two & word.thirty_two, 4);
131
0
    return InferiorSizedWord(sixty_four & word.sixty_four, 8);
132
0
  }
133
134
0
  InferiorSizedWord operator&(int x) const {
135
0
    if (ptr_size == 4)
136
0
      return InferiorSizedWord(thirty_two & x, 4);
137
0
    return InferiorSizedWord(sixty_four & x, 8);
138
0
  }
139
140
0
  size_t GetBitSize() const { return ptr_size << 3; }
141
142
0
  size_t GetByteSize() const { return ptr_size; }
143
144
0
  uint64_t GetValue() const {
145
0
    if (ptr_size == 4)
146
0
      return (uint64_t)thirty_two;
147
0
    return sixty_four;
148
0
  }
149
150
0
  InferiorSizedWord SignExtend() const {
151
0
    if (ptr_size == 4)
152
0
      return InferiorSizedWord((int32_t)thirty_two, 4);
153
0
    return InferiorSizedWord((int64_t)sixty_four, 8);
154
0
  }
155
156
0
  uint8_t *CopyToBuffer(uint8_t *buffer) const {
157
0
    if (ptr_size == 4) {
158
0
      memcpy(buffer, &thirty_two, 4);
159
0
      return buffer + 4;
160
0
    } else {
161
0
      memcpy(buffer, &sixty_four, 8);
162
0
      return buffer + 8;
163
0
    }
164
0
  }
165
166
  DataExtractor
167
479
  GetAsData(lldb::ByteOrder byte_order = lldb::eByteOrderInvalid) const {
168
479
    if (ptr_size == 4)
169
0
      return DataExtractor(&thirty_two, 4, byte_order, 4);
170
479
    else
171
479
      return DataExtractor(&sixty_four, 8, byte_order, 8);
172
479
  }
173
174
private:
175
0
  InferiorSizedWord(uint64_t val, size_t psz) : ptr_size(psz) {
176
0
    if (ptr_size == 4)
177
0
      thirty_two = (uint32_t)val;
178
0
    else
179
0
      sixty_four = val;
180
0
  }
181
182
  size_t ptr_size;
183
  union {
184
    uint32_t thirty_two;
185
    uint64_t sixty_four;
186
  };
187
};
188
} // namespace formatters
189
} // namespace lldb_private
190
191
#endif // LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H