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 "lldb/API/SBLineEntry.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Module.h"
14 #include "lldb/Symbol/LineEntry.h"
15 #include "lldb/Symbol/LineTable.h"
16 #include "lldb/Symbol/SymbolFile.h"
17 #include "lldb/Symbol/Type.h"
18 #include "lldb/Symbol/TypeList.h"
20 
21 using namespace lldb;
22 using namespace lldb_private;
23 
25 
27  : m_opaque_ptr(lldb_object_ptr) {}
28 
30  : m_opaque_ptr(rhs.m_opaque_ptr) {
31  LLDB_INSTRUMENT_VA(this, rhs);
32 }
33 
35  LLDB_INSTRUMENT_VA(this, rhs);
36 
38  return *this;
39 }
40 
42 
44  LLDB_INSTRUMENT_VA(this);
45 
46  SBFileSpec file_spec;
47  if (m_opaque_ptr)
49  return file_spec;
50 }
51 
53  LLDB_INSTRUMENT_VA(this);
54 
55  if (m_opaque_ptr) {
56  LineTable *line_table = m_opaque_ptr->GetLineTable();
57  if (line_table) {
58  return line_table->GetSize();
59  }
60  }
61  return 0;
62 }
63 
65  LLDB_INSTRUMENT_VA(this, idx);
66 
67  SBLineEntry sb_line_entry;
68  if (m_opaque_ptr) {
69  LineTable *line_table = m_opaque_ptr->GetLineTable();
70  if (line_table) {
71  LineEntry line_entry;
72  if (line_table->GetLineEntryAtIndex(idx, line_entry))
73  sb_line_entry.SetLineEntry(line_entry);
74  }
75  }
76 
77  return sb_line_entry;
78 }
79 
81  bool exact) const {
82  LLDB_INSTRUMENT_VA(this, line_entry, exact);
83 
84  if (!m_opaque_ptr || !line_entry.IsValid())
85  return UINT32_MAX;
86 
87  LineEntry found_line_entry;
88 
89  return m_opaque_ptr->FindLineEntry(0, line_entry.GetLine(),
90  line_entry.GetFileSpec().get(), exact,
91  &line_entry.ref());
92 }
93 
95  SBFileSpec *inline_file_spec) const {
96  LLDB_INSTRUMENT_VA(this, start_idx, line, inline_file_spec);
97 
98  const bool exact = true;
99  return FindLineEntryIndex(start_idx, line, inline_file_spec, exact);
100 }
101 
103  SBFileSpec *inline_file_spec,
104  bool exact) const {
105  LLDB_INSTRUMENT_VA(this, start_idx, line, inline_file_spec, exact);
106 
107  uint32_t index = UINT32_MAX;
108  if (m_opaque_ptr) {
109  FileSpec file_spec;
110  if (inline_file_spec && inline_file_spec->IsValid())
111  file_spec = inline_file_spec->ref();
112  else
113  file_spec = m_opaque_ptr->GetPrimaryFile();
114 
115  LineEntry line_entry;
116  index = m_opaque_ptr->FindLineEntry(
117  start_idx, line, inline_file_spec ? inline_file_spec->get() : nullptr,
118  exact, &line_entry);
119  }
120 
121  return index;
122 }
123 
125  LLDB_INSTRUMENT_VA(this);
126 
127  if (m_opaque_ptr)
128  return m_opaque_ptr->GetSupportFiles().GetSize();
129 
130  return 0;
131 }
132 
134  LLDB_INSTRUMENT_VA(this, type_mask);
135 
136  SBTypeList sb_type_list;
137 
138  if (!m_opaque_ptr)
139  return sb_type_list;
140 
141  ModuleSP module_sp(m_opaque_ptr->GetModule());
142  if (!module_sp)
143  return sb_type_list;
144 
145  SymbolFile *symfile = module_sp->GetSymbolFile();
146  if (!symfile)
147  return sb_type_list;
148 
149  TypeClass type_class = static_cast<TypeClass>(type_mask);
150  TypeList type_list;
151  symfile->GetTypes(m_opaque_ptr, type_class, type_list);
152  sb_type_list.m_opaque_up->Append(type_list);
153  return sb_type_list;
154 }
155 
157  LLDB_INSTRUMENT_VA(this, idx);
158 
159  SBFileSpec sb_file_spec;
160  if (m_opaque_ptr) {
161  FileSpec spec = m_opaque_ptr->GetSupportFiles().GetFileSpecAtIndex(idx);
162  sb_file_spec.SetFileSpec(spec);
163  }
164 
165  return sb_file_spec;
166 }
167 
169  const SBFileSpec &sb_file,
170  bool full) {
171  LLDB_INSTRUMENT_VA(this, start_idx, sb_file, full);
172 
173  if (m_opaque_ptr) {
174  const FileSpecList &support_files = m_opaque_ptr->GetSupportFiles();
175  return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
176  }
177  return 0;
178 }
179 
181  LLDB_INSTRUMENT_VA(this);
182 
183  if (m_opaque_ptr)
184  return m_opaque_ptr->GetLanguage();
186 }
187 
189  LLDB_INSTRUMENT_VA(this);
190  return this->operator bool();
191 }
192 SBCompileUnit::operator bool() const {
193  LLDB_INSTRUMENT_VA(this);
194 
195  return m_opaque_ptr != nullptr;
196 }
197 
198 bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {
199  LLDB_INSTRUMENT_VA(this, rhs);
200 
201  return m_opaque_ptr == rhs.m_opaque_ptr;
202 }
203 
204 bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {
205  LLDB_INSTRUMENT_VA(this, rhs);
206 
207  return m_opaque_ptr != rhs.m_opaque_ptr;
208 }
209 
211  return m_opaque_ptr;
212 }
213 
215  return *m_opaque_ptr;
216 }
217 
219 
221  m_opaque_ptr = lldb_object_ptr;
222 }
223 
225  LLDB_INSTRUMENT_VA(this, description);
226 
227  Stream &strm = description.ref();
228 
229  if (m_opaque_ptr) {
230  m_opaque_ptr->Dump(&strm, false);
231  } else
232  strm.PutCString("No value");
233 
234  return true;
235 }
lldb::SBFileSpec::get
const lldb_private::FileSpec * get() const
Definition: SBFileSpec.cpp:154
Instrumentation.h
SBLineEntry.h
lldb_private::SymbolFile
Provides public interface for all SymbolFiles.
Definition: SymbolFile.h:45
lldb_private::CompileUnit::GetSupportFiles
const FileSpecList & GetSupportFiles()
Get the compile unit's support file list.
Definition: CompileUnit.cpp:390
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:176
lldb::SBCompileUnit::GetNumLineEntries
uint32_t GetNumLineEntries() const
Definition: SBCompileUnit.cpp:52
CompileUnit.h
lldb::SBCompileUnit::GetLineEntryAtIndex
lldb::SBLineEntry GetLineEntryAtIndex(uint32_t idx) const
Definition: SBCompileUnit.cpp:64
lldb::SBCompileUnit
Definition: SBCompileUnit.h:17
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::SBCompileUnit::operator->
const lldb_private::CompileUnit * operator->() const
Definition: SBCompileUnit.cpp:210
lldb_private::Stream
Definition: Stream.h:28
lldb::SBLineEntry::GetLine
uint32_t GetLine() const
Definition: SBLineEntry.cpp:90
lldb::SBFileSpec::SetFileSpec
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:164
lldb::SBCompileUnit::FindLineEntryIndex
uint32_t FindLineEntryIndex(lldb::SBLineEntry &line_entry, bool exact=false) const
Definition: SBCompileUnit.cpp:80
lldb::SBCompileUnit::m_opaque_ptr
lldb_private::CompileUnit * m_opaque_ptr
Definition: SBCompileUnit.h:93
lldb_private::CompileUnit
Definition: CompileUnit.h:38
lldb::SBCompileUnit::operator=
const lldb::SBCompileUnit & operator=(const lldb::SBCompileUnit &rhs)
Definition: SBCompileUnit.cpp:34
lldb_private::FileSpec
Definition: FileSpec.h:56
SBStream.h
lldb_private::LineTable
Definition: LineTable.h:40
SBCompileUnit.h
lldb::SBCompileUnit::IsValid
bool IsValid() const
Definition: SBCompileUnit.cpp:188
lldb::SBLineEntry::ref
lldb_private::LineEntry & ref()
Definition: SBLineEntry.cpp:156
LineEntry.h
lldb::SBLineEntry::GetFileSpec
lldb::SBFileSpec GetFileSpec() const
Definition: SBLineEntry.cpp:80
Type.h
lldb::SBCompileUnit::GetFileSpec
lldb::SBFileSpec GetFileSpec() const
Definition: SBCompileUnit.cpp:43
lldb::SBLineEntry::IsValid
bool IsValid() const
Definition: SBLineEntry.cpp:70
lldb::SBFileSpec::ref
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:162
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:198
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:264
lldb::SBCompileUnit::GetLanguage
lldb::LanguageType GetLanguage()
Definition: SBCompileUnit.cpp:180
lldb::SBTypeList
Definition: SBType.h:243
TypeList.h
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:156
LineTable.h
lldb::SBCompileUnit::operator!=
bool operator!=(const lldb::SBCompileUnit &rhs) const
Definition: SBCompileUnit.cpp:204
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:19
lldb::SBCompileUnit::reset
void reset(lldb_private::CompileUnit *lldb_object_ptr)
Definition: SBCompileUnit.cpp:220
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:218
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:168
lldb_private::TypeList
Definition: TypeList.h:20
lldb::SBCompileUnit::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBCompileUnit.cpp:224
lldb::SBCompileUnit::SBCompileUnit
SBCompileUnit()
Definition: SBCompileUnit.cpp:24
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBLineEntry::SetLineEntry
void SetLineEntry(const lldb_private::LineEntry &lldb_object_ref)
Definition: SBLineEntry.cpp:43
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
Definition: SBAddress.h:15
lldb::SBCompileUnit::GetNumSupportFiles
uint32_t GetNumSupportFiles() const
Definition: SBCompileUnit.cpp:124
SymbolFile.h
lldb_private::LineEntry
Definition: LineEntry.h:20
lldb::SBCompileUnit::operator*
const lldb_private::CompileUnit & operator*() const
Definition: SBCompileUnit.cpp:214
lldb::SBCompileUnit::~SBCompileUnit
~SBCompileUnit()
Definition: SBCompileUnit.cpp:41
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:133