LLDB  mainline
SBCompileUnit.cpp
Go to the documentation of this file.
1 //===-- SBCompileUnit.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 
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBLineEntry.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Core/Module.h"
15 #include "lldb/Symbol/LineEntry.h"
16 #include "lldb/Symbol/LineTable.h"
17 #include "lldb/Symbol/SymbolFile.h"
18 #include "lldb/Symbol/Type.h"
19 #include "lldb/Symbol/TypeList.h"
20 
21 using namespace lldb;
22 using namespace lldb_private;
23 
26 }
27 
29  : m_opaque_ptr(lldb_object_ptr) {}
30 
32  : m_opaque_ptr(rhs.m_opaque_ptr) {
34 }
35 
38  SBCompileUnit, operator=,(const lldb::SBCompileUnit &),
39  rhs);
40 
42  return LLDB_RECORD_RESULT(*this);
43 }
44 
46 
49  GetFileSpec);
50 
51  SBFileSpec file_spec;
52  if (m_opaque_ptr)
54  return LLDB_RECORD_RESULT(file_spec);
55 }
56 
59 
60  if (m_opaque_ptr) {
61  LineTable *line_table = m_opaque_ptr->GetLineTable();
62  if (line_table) {
63  return line_table->GetSize();
64  }
65  }
66  return 0;
67 }
68 
72 
73  SBLineEntry sb_line_entry;
74  if (m_opaque_ptr) {
75  LineTable *line_table = m_opaque_ptr->GetLineTable();
76  if (line_table) {
77  LineEntry line_entry;
78  if (line_table->GetLineEntryAtIndex(idx, line_entry))
79  sb_line_entry.SetLineEntry(line_entry);
80  }
81  }
82 
83  return LLDB_RECORD_RESULT(sb_line_entry);
84 }
85 
87  SBFileSpec *inline_file_spec) const {
89  (uint32_t, uint32_t, lldb::SBFileSpec *), start_idx,
90  line, inline_file_spec);
91 
92  const bool exact = true;
93  return FindLineEntryIndex(start_idx, line, inline_file_spec, exact);
94 }
95 
97  SBFileSpec *inline_file_spec,
98  bool exact) const {
100  (uint32_t, uint32_t, lldb::SBFileSpec *, bool),
101  start_idx, line, inline_file_spec, exact);
102 
103  uint32_t index = UINT32_MAX;
104  if (m_opaque_ptr) {
105  FileSpec file_spec;
106  if (inline_file_spec && inline_file_spec->IsValid())
107  file_spec = inline_file_spec->ref();
108  else
109  file_spec = m_opaque_ptr->GetPrimaryFile();
110 
111  LineEntry line_entry;
112  index = m_opaque_ptr->FindLineEntry(
113  start_idx, line, inline_file_spec ? inline_file_spec->get() : nullptr,
114  exact, &line_entry);
115  }
116 
117  return index;
118 }
119 
122 
123  if (m_opaque_ptr)
124  return m_opaque_ptr->GetSupportFiles().GetSize();
125 
126  return 0;
127 }
128 
131  type_mask);
132 
133  SBTypeList sb_type_list;
134 
135  if (!m_opaque_ptr)
136  return LLDB_RECORD_RESULT(sb_type_list);
137 
138  ModuleSP module_sp(m_opaque_ptr->GetModule());
139  if (!module_sp)
140  return LLDB_RECORD_RESULT(sb_type_list);
141 
142  SymbolFile *symfile = module_sp->GetSymbolFile();
143  if (!symfile)
144  return LLDB_RECORD_RESULT(sb_type_list);
145 
146  TypeClass type_class = static_cast<TypeClass>(type_mask);
147  TypeList type_list;
148  symfile->GetTypes(m_opaque_ptr, type_class, type_list);
149  sb_type_list.m_opaque_up->Append(type_list);
150  return LLDB_RECORD_RESULT(sb_type_list);
151 }
152 
156 
157  SBFileSpec sb_file_spec;
158  if (m_opaque_ptr) {
159  FileSpec spec = m_opaque_ptr->GetSupportFiles().GetFileSpecAtIndex(idx);
160  sb_file_spec.SetFileSpec(spec);
161  }
162 
163 
164  return LLDB_RECORD_RESULT(sb_file_spec);
165 }
166 
168  const SBFileSpec &sb_file,
169  bool full) {
171  (uint32_t, const lldb::SBFileSpec &, bool), start_idx,
172  sb_file, full);
173 
174  if (m_opaque_ptr) {
175  const FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
176  return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
177  }
178  return 0;
179 }
180 
183 
184  if (m_opaque_ptr)
185  return m_opaque_ptr->GetLanguage();
187 }
188 
191  return this->operator bool();
192 }
193 SBCompileUnit::operator bool() const {
194  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBCompileUnit, operator bool);
195 
196  return m_opaque_ptr != nullptr;
197 }
198 
199 bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
201  bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &), rhs);
202 
203  return m_opaque_ptr == rhs.m_opaque_ptr;
204 }
205 
206 bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
208  bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &), rhs);
209 
210  return m_opaque_ptr != rhs.m_opaque_ptr;
211 }
212 
214  return m_opaque_ptr;
215 }
216 
218  return *m_opaque_ptr;
219 }
220 
222 
224  m_opaque_ptr = lldb_object_ptr;
225 }
226 
229  description);
230 
231  Stream &strm = description.ref();
232 
233  if (m_opaque_ptr) {
234  m_opaque_ptr->Dump(&strm, false);
235  } else
236  strm.PutCString("No value");
237 
238  return true;
239 }
240 
241 namespace lldb_private {
242 namespace repro {
243 
244 template <>
249  const lldb::SBCompileUnit &,
250  SBCompileUnit, operator=,(const lldb::SBCompileUnit &));
252  ());
253  LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, GetNumLineEntries, ());
255  GetLineEntryAtIndex, (uint32_t));
259  (uint32_t, uint32_t, lldb::SBFileSpec *, bool));
260  LLDB_REGISTER_METHOD_CONST(uint32_t, SBCompileUnit, GetNumSupportFiles, ());
263  GetSupportFileAtIndex, (uint32_t));
264  LLDB_REGISTER_METHOD(uint32_t, SBCompileUnit, FindSupportFileIndex,
265  (uint32_t, const lldb::SBFileSpec &, bool));
267  LLDB_REGISTER_METHOD_CONST(bool, SBCompileUnit, IsValid, ());
268  LLDB_REGISTER_METHOD_CONST(bool, SBCompileUnit, operator bool, ());
270  bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &));
272  bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &));
273  LLDB_REGISTER_METHOD(bool, SBCompileUnit, GetDescription,
274  (lldb::SBStream &));
275 }
276 
277 }
278 }
SBLineEntry.h
lldb_private::SymbolFile
Definition: SymbolFile.h:37
lldb_private::CompileUnit::GetSupportFiles
const FileSpecList & GetSupportFiles()
Get the compile unit's support file list.
Definition: CompileUnit.cpp:387
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:178
lldb::SBCompileUnit::GetNumLineEntries
uint32_t GetNumLineEntries() const
Definition: SBCompileUnit.cpp:57
CompileUnit.h
lldb::SBCompileUnit::GetLineEntryAtIndex
lldb::SBLineEntry GetLineEntryAtIndex(uint32_t idx) const
Definition: SBCompileUnit.cpp:69
lldb::SBCompileUnit
Definition: SBCompileUnit.h:17
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
LLDB_RECORD_METHOD_CONST_NO_ARGS
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:168
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:165
lldb_private::LineTable::GetLineEntryAtIndex
bool GetLineEntryAtIndex(uint32_t idx, LineEntry &line_entry)
Get the line entry from the line table at index idx.
Definition: LineTable.cpp:179
Module.h
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
LLDB_RECORD_CONSTRUCTOR_NO_ARGS
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
Definition: ReproducerInstrumentation.h:136
lldb::SBCompileUnit::operator->
const lldb_private::CompileUnit * operator->() const
Definition: SBCompileUnit.cpp:213
LLDB_REGISTER_METHOD_CONST
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:98
lldb_private::Stream
Definition: Stream.h:28
SBReproducerPrivate.h
lldb::SBCompileUnit::FindLineEntryIndex
uint32_t FindLineEntryIndex(uint32_t start_idx, uint32_t line, lldb::SBFileSpec *inline_file_spec) const
Definition: SBCompileUnit.cpp:86
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
lldb::SBFileSpec::SetFileSpec
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:170
lldb::SBCompileUnit::m_opaque_ptr
lldb_private::CompileUnit * m_opaque_ptr
Definition: SBCompileUnit.h:90
lldb_private::CompileUnit
Definition: CompileUnit.h:38
lldb::SBCompileUnit::operator=
const lldb::SBCompileUnit & operator=(const lldb::SBCompileUnit &rhs)
Definition: SBCompileUnit.cpp:36
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::repro::RegisterMethods< SBCompileUnit >
void RegisterMethods< SBCompileUnit >(Registry &R)
Definition: SBCompileUnit.cpp:245
SBStream.h
lldb_private::LineTable
Definition: LineTable.h:40
SBCompileUnit.h
lldb::SBCompileUnit::IsValid
bool IsValid() const
Definition: SBCompileUnit.cpp:189
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
LineEntry.h
Type.h
lldb::SBCompileUnit::GetFileSpec
lldb::SBFileSpec GetFileSpec() const
Definition: SBCompileUnit.cpp:47
lldb::SBFileSpec::ref
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:168
lldb_private::CompileUnit::GetPrimaryFile
const FileSpec & GetPrimaryFile() const
Return the primary source file associated with this compile unit.
Definition: CompileUnit.h:227
lldb::SBCompileUnit::operator==
bool operator==(const lldb::SBCompileUnit &rhs) const
Definition: SBCompileUnit.cpp:199
lldb_private::LineTable::GetSize
uint32_t GetSize() const
Gets the size of the line table in number of line table entries.
Definition: LineTable.cpp:177
lldb_private::CompileUnit::GetLineTable
LineTable * GetLineTable()
Get the line table for the compile unit.
Definition: CompileUnit.cpp:161
lldb_private::CompileUnit::GetLanguage
lldb::LanguageType GetLanguage()
Definition: CompileUnit.cpp:150
lldb::SBTypeList::m_opaque_up
std::unique_ptr< lldb_private::TypeListImpl > m_opaque_up
Definition: SBType.h:262
lldb::SBCompileUnit::GetLanguage
lldb::LanguageType GetLanguage()
Definition: SBCompileUnit.cpp:181
lldb::SBTypeList
Definition: SBType.h:241
TypeList.h
LLDB_RECORD_CONSTRUCTOR
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
Definition: ReproducerInstrumentation.h:133
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
lldb_private::CompileUnit::FindLineEntry
uint32_t FindLineEntry(uint32_t start_idx, uint32_t line, const FileSpec *file_spec_ptr, bool exact, LineEntry *line_entry)
Find the line entry by line and optional inlined file spec.
Definition: CompileUnit.cpp:228
lldb::eLanguageTypeUnknown
@ eLanguageTypeUnknown
Unknown or invalid language value.
Definition: lldb-enumerations.h:437
uint32_t
lldb::SBCompileUnit::GetSupportFileAtIndex
SBFileSpec GetSupportFileAtIndex(uint32_t idx) const
Definition: SBCompileUnit.cpp:153
LineTable.h
lldb::SBCompileUnit::operator!=
bool operator!=(const lldb::SBCompileUnit &rhs) const
Definition: SBCompileUnit.cpp:206
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb::SBCompileUnit::reset
void reset(lldb_private::CompileUnit *lldb_object_ptr)
Definition: SBCompileUnit.cpp:223
lldb_private::ModuleChild::GetModule
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
lldb::SBCompileUnit::get
lldb_private::CompileUnit * get()
Definition: SBCompileUnit.cpp:221
lldb::SBFileSpec
Definition: SBFileSpec.h:16
lldb::SBLineEntry
Definition: SBLineEntry.h:18
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBCompileUnit::FindSupportFileIndex
uint32_t FindSupportFileIndex(uint32_t start_idx, const SBFileSpec &sb_file, bool full)
Definition: SBCompileUnit.cpp:167
lldb_private::TypeList
Definition: TypeList.h:20
lldb::SBCompileUnit::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBCompileUnit.cpp:227
lldb::SBCompileUnit::SBCompileUnit
SBCompileUnit()
Definition: SBCompileUnit.cpp:24
lldb::SBLineEntry::SetLineEntry
void SetLineEntry(const lldb_private::LineEntry &lldb_object_ref)
Definition: SBLineEntry.cpp:47
lldb_private::SymbolFile::GetTypes
virtual void GetTypes(lldb_private::SymbolContextScope *sc_scope, lldb::TypeClass type_mask, lldb_private::TypeList &type_list)=0
lldb_private::CompileUnit::Dump
void Dump(Stream *s, bool show_context) const
Dump the compile unit contents to the stream s.
Definition: CompileUnit.cpp:110
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb::SBStream
Definition: SBStream.h:18
LLDB_RECORD_METHOD_CONST
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:161
lldb
Definition: SBAddress.h:15
lldb::SBCompileUnit::GetNumSupportFiles
uint32_t GetNumSupportFiles() const
Definition: SBCompileUnit.cpp:120
SymbolFile.h
lldb_private::LineEntry
Definition: LineEntry.h:20
lldb::SBCompileUnit::operator*
const lldb_private::CompileUnit & operator*() const
Definition: SBCompileUnit.cpp:217
lldb::SBCompileUnit::~SBCompileUnit
~SBCompileUnit()
Definition: SBCompileUnit.cpp:45
lldb::SBCompileUnit::GetTypes
lldb::SBTypeList GetTypes(uint32_t type_mask=lldb::eTypeClassAny)
Get all types matching type_mask from debug info in this compile unit.
Definition: SBCompileUnit.cpp:129
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93