LLDB  mainline
SBCompileUnit.cpp
Go to the documentation of this file.
1 //===-- SBCompileUnit.cpp ---------------------------------------*- C++ -*-===//
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"
18 #include "lldb/Symbol/Type.h"
19 
20 using namespace lldb;
21 using namespace lldb_private;
22 
23 SBCompileUnit::SBCompileUnit() : m_opaque_ptr(NULL) {
25 }
26 
28  : m_opaque_ptr(lldb_object_ptr) {}
29 
31  : m_opaque_ptr(rhs.m_opaque_ptr) {
33 }
34 
37  SBCompileUnit, operator=,(const lldb::SBCompileUnit &),
38  rhs);
39 
40  m_opaque_ptr = rhs.m_opaque_ptr;
41  return LLDB_RECORD_RESULT(*this);
42 }
43 
44 SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = NULL; }
45 
48  GetFileSpec);
49 
50  SBFileSpec file_spec;
51  if (m_opaque_ptr)
52  file_spec.SetFileSpec(*m_opaque_ptr);
53  return LLDB_RECORD_RESULT(file_spec);
54 }
55 
58 
59  if (m_opaque_ptr) {
60  LineTable *line_table = m_opaque_ptr->GetLineTable();
61  if (line_table) {
62  return line_table->GetSize();
63  }
64  }
65  return 0;
66 }
67 
71 
72  SBLineEntry sb_line_entry;
73  if (m_opaque_ptr) {
74  LineTable *line_table = m_opaque_ptr->GetLineTable();
75  if (line_table) {
76  LineEntry line_entry;
77  if (line_table->GetLineEntryAtIndex(idx, line_entry))
78  sb_line_entry.SetLineEntry(line_entry);
79  }
80  }
81 
82  return LLDB_RECORD_RESULT(sb_line_entry);
83 }
84 
86  SBFileSpec *inline_file_spec) const {
88  (uint32_t, uint32_t, lldb::SBFileSpec *), start_idx,
89  line, inline_file_spec);
90 
91  const bool exact = true;
92  return FindLineEntryIndex(start_idx, line, inline_file_spec, exact);
93 }
94 
96  SBFileSpec *inline_file_spec,
97  bool exact) const {
100  start_idx, line, inline_file_spec, exact);
101 
102  uint32_t index = UINT32_MAX;
103  if (m_opaque_ptr) {
104  FileSpec file_spec;
105  if (inline_file_spec && inline_file_spec->IsValid())
106  file_spec = inline_file_spec->ref();
107  else
108  file_spec = *m_opaque_ptr;
109 
110  index = m_opaque_ptr->FindLineEntry(
111  start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL,
112  exact, NULL);
113  }
114 
115  return index;
116 }
117 
120 
121  if (m_opaque_ptr) {
122  FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
123  return support_files.GetSize();
124  }
125  return 0;
126 }
127 
130  type_mask);
131 
132  SBTypeList sb_type_list;
133 
134  if (!m_opaque_ptr)
135  return LLDB_RECORD_RESULT(sb_type_list);
136 
137  ModuleSP module_sp(m_opaque_ptr->GetModule());
138  if (!module_sp)
139  return LLDB_RECORD_RESULT(sb_type_list);
140 
141  SymbolVendor *vendor = module_sp->GetSymbolVendor();
142  if (!vendor)
143  return LLDB_RECORD_RESULT(sb_type_list);
144 
145  TypeClass type_class = static_cast<TypeClass>(type_mask);
146  TypeList type_list;
147  vendor->GetTypes(m_opaque_ptr, type_class, type_list);
148  sb_type_list.m_opaque_up->Append(type_list);
149  return LLDB_RECORD_RESULT(sb_type_list);
150 }
151 
155 
156  SBFileSpec sb_file_spec;
157  if (m_opaque_ptr) {
158  FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
159  FileSpec file_spec = support_files.GetFileSpecAtIndex(idx);
160  sb_file_spec.SetFileSpec(file_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  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 != NULL;
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 
213 const lldb_private::CompileUnit *SBCompileUnit::operator->() const {
214  return m_opaque_ptr;
215 }
216 
217 const lldb_private::CompileUnit &SBCompileUnit::operator*() const {
218  return *m_opaque_ptr;
219 }
220 
221 lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }
222 
223 void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {
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  ());
259  (uint32_t, uint32_t, lldb::SBFileSpec *, bool));
265  (uint32_t, const lldb::SBFileSpec &, bool));
268  LLDB_REGISTER_METHOD_CONST(bool, SBCompileUnit, operator bool, ());
270  bool, SBCompileUnit, operator==,(const lldb::SBCompileUnit &));
272  bool, SBCompileUnit, operator!=,(const lldb::SBCompileUnit &));
274  (lldb::SBStream &));
275 }
276 
277 }
278 }
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.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
A line table entry class.
Definition: LineEntry.h:20
The registry contains a unique mapping between functions and their ID.
lldb::SBTypeList GetTypes(uint32_t type_mask=lldb::eTypeClassAny)
Get all types matching type_mask from debug info in this compile unit.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
bool GetLineEntryAtIndex(uint32_t idx, LineEntry &line_entry)
Get the line entry from the line table at index idx.
Definition: LineTable.cpp:161
A file utility class.
Definition: FileSpec.h:55
uint32_t GetSize() const
Gets the size of the line table in number of line table entries.
Definition: LineTable.cpp:159
const lldb::SBCompileUnit & operator=(const lldb::SBCompileUnit &rhs)
lldb::LanguageType GetLanguage()
bool operator==(const lldb::SBCompileUnit &rhs) const
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:27
A class that describes a compilation unit.
Definition: CompileUnit.h:35
lldb::SBLineEntry GetLineEntryAtIndex(uint32_t idx) const
#define UINT32_MAX
Definition: lldb-defines.h:31
uint32_t GetNumLineEntries() const
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
LanguageType
Programming language type.
uint32_t FindSupportFileIndex(uint32_t start_idx, const SBFileSpec &sb_file, bool full)
bool GetDescription(lldb::SBStream &description)
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
A line table class.
Definition: LineTable.h:37
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
void RegisterMethods< SBCompileUnit >(Registry &R)
FileSpecList & GetSupportFiles()
Get the compile unit&#39;s support file list.
lldb::LanguageType GetLanguage()
uint32_t FindLineEntryIndex(uint32_t start_idx, uint32_t line, lldb::SBFileSpec *inline_file_spec) const
LineTable * GetLineTable()
Get the line table for the compile unit.
lldb_private::Stream & ref()
Definition: SBStream.cpp:162
void Dump(Stream *s, bool show_context) const
Dump the compile unit contents to the stream s.
Definition: CompileUnit.cpp:88
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
SBFileSpec GetSupportFileAtIndex(uint32_t idx) const
Unknown or invalid language value.
virtual size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, TypeList &type_list)
Definition: SBAddress.h:15
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
lldb::SBFileSpec GetFileSpec() const
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
uint32_t GetNumSupportFiles() const
#define LLDB_RECORD_RESULT(Result)
bool operator!=(const lldb::SBCompileUnit &rhs) const
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)