Coverage Report

Created: 2023-11-11 10:31

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/API/SBSymbol.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- SBSymbol.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
#include "lldb/API/SBSymbol.h"
10
#include "lldb/API/SBStream.h"
11
#include "lldb/Core/Disassembler.h"
12
#include "lldb/Core/Module.h"
13
#include "lldb/Symbol/Symbol.h"
14
#include "lldb/Target/ExecutionContext.h"
15
#include "lldb/Target/Target.h"
16
#include "lldb/Utility/Instrumentation.h"
17
18
using namespace lldb;
19
using namespace lldb_private;
20
21
4.22k
SBSymbol::SBSymbol() { LLDB_INSTRUMENT_VA(this); }
22
23
SBSymbol::SBSymbol(lldb_private::Symbol *lldb_object_ptr)
24
89
    : m_opaque_ptr(lldb_object_ptr) {}
25
26
2.15k
SBSymbol::SBSymbol(const lldb::SBSymbol &rhs) : m_opaque_ptr(rhs.m_opaque_ptr) {
27
2.15k
  LLDB_INSTRUMENT_VA(this, rhs);
28
2.15k
}
29
30
2.15k
const SBSymbol &SBSymbol::operator=(const SBSymbol &rhs) {
31
2.15k
  LLDB_INSTRUMENT_VA(this, rhs);
32
33
2.15k
  m_opaque_ptr = rhs.m_opaque_ptr;
34
2.15k
  return *this;
35
2.15k
}
36
37
6.46k
SBSymbol::~SBSymbol() { m_opaque_ptr = nullptr; }
38
39
898
void SBSymbol::SetSymbol(lldb_private::Symbol *lldb_object_ptr) {
40
898
  m_opaque_ptr = lldb_object_ptr;
41
898
}
42
43
360
bool SBSymbol::IsValid() const {
44
360
  LLDB_INSTRUMENT_VA(this);
45
360
  return this->operator bool();
46
360
}
47
654
SBSymbol::operator bool() const {
48
654
  LLDB_INSTRUMENT_VA(this);
49
50
654
  return m_opaque_ptr != nullptr;
51
654
}
52
53
1.20k
const char *SBSymbol::GetName() const {
54
1.20k
  LLDB_INSTRUMENT_VA(this);
55
56
1.20k
  const char *name = nullptr;
57
1.20k
  if (m_opaque_ptr)
58
1.20k
    name = m_opaque_ptr->GetName().AsCString();
59
60
1.20k
  return name;
61
1.20k
}
62
63
0
const char *SBSymbol::GetDisplayName() const {
64
0
  LLDB_INSTRUMENT_VA(this);
65
66
0
  const char *name = nullptr;
67
0
  if (m_opaque_ptr)
68
0
    name = m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString();
69
70
0
  return name;
71
0
}
72
73
21
const char *SBSymbol::GetMangledName() const {
74
21
  LLDB_INSTRUMENT_VA(this);
75
76
21
  const char *name = nullptr;
77
21
  if (m_opaque_ptr)
78
20
    name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
79
21
  return name;
80
21
}
81
82
0
bool SBSymbol::operator==(const SBSymbol &rhs) const {
83
0
  LLDB_INSTRUMENT_VA(this, rhs);
84
85
0
  return m_opaque_ptr == rhs.m_opaque_ptr;
86
0
}
87
88
0
bool SBSymbol::operator!=(const SBSymbol &rhs) const {
89
0
  LLDB_INSTRUMENT_VA(this, rhs);
90
91
0
  return m_opaque_ptr != rhs.m_opaque_ptr;
92
0
}
93
94
158
bool SBSymbol::GetDescription(SBStream &description) {
95
158
  LLDB_INSTRUMENT_VA(this, description);
96
97
158
  Stream &strm = description.ref();
98
99
158
  if (m_opaque_ptr) {
100
156
    m_opaque_ptr->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
101
156
  } else
102
2
    strm.PutCString("No value");
103
104
158
  return true;
105
158
}
106
107
5
SBInstructionList SBSymbol::GetInstructions(SBTarget target) {
108
5
  LLDB_INSTRUMENT_VA(this, target);
109
110
5
  return GetInstructions(target, nullptr);
111
5
}
112
113
SBInstructionList SBSymbol::GetInstructions(SBTarget target,
114
5
                                            const char *flavor_string) {
115
5
  LLDB_INSTRUMENT_VA(this, target, flavor_string);
116
117
5
  SBInstructionList sb_instructions;
118
5
  if (m_opaque_ptr) {
119
4
    TargetSP target_sp(target.GetSP());
120
4
    std::unique_lock<std::recursive_mutex> lock;
121
4
    if (target_sp && m_opaque_ptr->ValueIsAddress()) {
122
4
      lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
123
4
      const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
124
4
      ModuleSP module_sp = symbol_addr.GetModule();
125
4
      if (module_sp) {
126
4
        AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
127
4
        const bool force_live_memory = true;
128
4
        sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
129
4
            module_sp->GetArchitecture(), nullptr, flavor_string, *target_sp,
130
4
            symbol_range, force_live_memory));
131
4
      }
132
4
    }
133
4
  }
134
5
  return sb_instructions;
135
5
}
136
137
0
lldb_private::Symbol *SBSymbol::get() { return m_opaque_ptr; }
138
139
1.16k
void SBSymbol::reset(lldb_private::Symbol *symbol) { m_opaque_ptr = symbol; }
140
141
603
SBAddress SBSymbol::GetStartAddress() {
142
603
  LLDB_INSTRUMENT_VA(this);
143
144
603
  SBAddress addr;
145
603
  if (m_opaque_ptr && 
m_opaque_ptr->ValueIsAddress()602
) {
146
398
    addr.SetAddress(m_opaque_ptr->GetAddressRef());
147
398
  }
148
603
  return addr;
149
603
}
150
151
382
SBAddress SBSymbol::GetEndAddress() {
152
382
  LLDB_INSTRUMENT_VA(this);
153
154
382
  SBAddress addr;
155
382
  if (m_opaque_ptr && 
m_opaque_ptr->ValueIsAddress()381
) {
156
177
    lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
157
177
    if (range_size > 0) {
158
177
      addr.SetAddress(m_opaque_ptr->GetAddressRef());
159
177
      addr->Slide(m_opaque_ptr->GetByteSize());
160
177
    }
161
177
  }
162
382
  return addr;
163
382
}
164
165
3
uint64_t SBSymbol::GetValue() {
166
3
  LLDB_INSTRUMENT_VA(this);
167
3
  if (m_opaque_ptr)
168
3
    return m_opaque_ptr->GetRawValue();
169
0
  return 0;
170
3
}
171
172
9
uint64_t SBSymbol::GetSize() {
173
9
  LLDB_INSTRUMENT_VA(this);
174
9
  if (m_opaque_ptr && m_opaque_ptr->GetByteSizeIsValid())
175
9
    return m_opaque_ptr->GetByteSize();
176
0
  return 0;
177
9
}
178
179
1
uint32_t SBSymbol::GetPrologueByteSize() {
180
1
  LLDB_INSTRUMENT_VA(this);
181
182
1
  if (m_opaque_ptr)
183
0
    return m_opaque_ptr->GetPrologueByteSize();
184
1
  return 0;
185
1
}
186
187
23
SymbolType SBSymbol::GetType() {
188
23
  LLDB_INSTRUMENT_VA(this);
189
190
23
  if (m_opaque_ptr)
191
22
    return m_opaque_ptr->GetType();
192
1
  return eSymbolTypeInvalid;
193
23
}
194
195
0
bool SBSymbol::IsExternal() {
196
0
  LLDB_INSTRUMENT_VA(this);
197
198
0
  if (m_opaque_ptr)
199
0
    return m_opaque_ptr->IsExternal();
200
0
  return false;
201
0
}
202
203
0
bool SBSymbol::IsSynthetic() {
204
0
  LLDB_INSTRUMENT_VA(this);
205
206
0
  if (m_opaque_ptr)
207
0
    return m_opaque_ptr->IsSynthetic();
208
0
  return false;
209
0
}