Path: blob/main/contrib/llvm-project/lldb/source/API/SBCompileUnit.cpp
39587 views
//===-- SBCompileUnit.cpp -------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/API/SBCompileUnit.h"9#include "lldb/API/SBLineEntry.h"10#include "lldb/API/SBStream.h"11#include "lldb/Core/Module.h"12#include "lldb/Symbol/CompileUnit.h"13#include "lldb/Symbol/LineEntry.h"14#include "lldb/Symbol/LineTable.h"15#include "lldb/Symbol/SymbolFile.h"16#include "lldb/Symbol/Type.h"17#include "lldb/Symbol/TypeList.h"18#include "lldb/Utility/Instrumentation.h"1920using namespace lldb;21using namespace lldb_private;2223SBCompileUnit::SBCompileUnit() { LLDB_INSTRUMENT_VA(this); }2425SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr)26: m_opaque_ptr(lldb_object_ptr) {}2728SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs)29: m_opaque_ptr(rhs.m_opaque_ptr) {30LLDB_INSTRUMENT_VA(this, rhs);31}3233const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) {34LLDB_INSTRUMENT_VA(this, rhs);3536m_opaque_ptr = rhs.m_opaque_ptr;37return *this;38}3940SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = nullptr; }4142SBFileSpec SBCompileUnit::GetFileSpec() const {43LLDB_INSTRUMENT_VA(this);4445SBFileSpec file_spec;46if (m_opaque_ptr)47file_spec.SetFileSpec(m_opaque_ptr->GetPrimaryFile());48return file_spec;49}5051uint32_t SBCompileUnit::GetNumLineEntries() const {52LLDB_INSTRUMENT_VA(this);5354if (m_opaque_ptr) {55LineTable *line_table = m_opaque_ptr->GetLineTable();56if (line_table) {57return line_table->GetSize();58}59}60return 0;61}6263SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const {64LLDB_INSTRUMENT_VA(this, idx);6566SBLineEntry sb_line_entry;67if (m_opaque_ptr) {68LineTable *line_table = m_opaque_ptr->GetLineTable();69if (line_table) {70LineEntry line_entry;71if (line_table->GetLineEntryAtIndex(idx, line_entry))72sb_line_entry.SetLineEntry(line_entry);73}74}7576return sb_line_entry;77}7879uint32_t SBCompileUnit::FindLineEntryIndex(lldb::SBLineEntry &line_entry,80bool exact) const {81LLDB_INSTRUMENT_VA(this, line_entry, exact);8283if (!m_opaque_ptr || !line_entry.IsValid())84return UINT32_MAX;8586LineEntry found_line_entry;8788return m_opaque_ptr->FindLineEntry(0, line_entry.GetLine(),89line_entry.GetFileSpec().get(), exact,90&line_entry.ref());91}9293uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,94SBFileSpec *inline_file_spec) const {95LLDB_INSTRUMENT_VA(this, start_idx, line, inline_file_spec);9697const bool exact = true;98return FindLineEntryIndex(start_idx, line, inline_file_spec, exact);99}100101uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line,102SBFileSpec *inline_file_spec,103bool exact) const {104LLDB_INSTRUMENT_VA(this, start_idx, line, inline_file_spec, exact);105106uint32_t index = UINT32_MAX;107if (m_opaque_ptr) {108FileSpec file_spec;109if (inline_file_spec && inline_file_spec->IsValid())110file_spec = inline_file_spec->ref();111else112file_spec = m_opaque_ptr->GetPrimaryFile();113114LineEntry line_entry;115index = m_opaque_ptr->FindLineEntry(116start_idx, line, inline_file_spec ? inline_file_spec->get() : nullptr,117exact, &line_entry);118}119120return index;121}122123uint32_t SBCompileUnit::GetNumSupportFiles() const {124LLDB_INSTRUMENT_VA(this);125126if (m_opaque_ptr)127return m_opaque_ptr->GetSupportFiles().GetSize();128129return 0;130}131132lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) {133LLDB_INSTRUMENT_VA(this, type_mask);134135SBTypeList sb_type_list;136137if (!m_opaque_ptr)138return sb_type_list;139140ModuleSP module_sp(m_opaque_ptr->GetModule());141if (!module_sp)142return sb_type_list;143144SymbolFile *symfile = module_sp->GetSymbolFile();145if (!symfile)146return sb_type_list;147148TypeClass type_class = static_cast<TypeClass>(type_mask);149TypeList type_list;150symfile->GetTypes(m_opaque_ptr, type_class, type_list);151sb_type_list.m_opaque_up->Append(type_list);152return sb_type_list;153}154155SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const {156LLDB_INSTRUMENT_VA(this, idx);157158SBFileSpec sb_file_spec;159if (m_opaque_ptr) {160FileSpec spec = m_opaque_ptr->GetSupportFiles().GetFileSpecAtIndex(idx);161sb_file_spec.SetFileSpec(spec);162}163164return sb_file_spec;165}166167uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx,168const SBFileSpec &sb_file,169bool full) {170LLDB_INSTRUMENT_VA(this, start_idx, sb_file, full);171172if (m_opaque_ptr) {173const SupportFileList &support_files = m_opaque_ptr->GetSupportFiles();174return support_files.FindFileIndex(start_idx, sb_file.ref(), full);175}176return 0;177}178179lldb::LanguageType SBCompileUnit::GetLanguage() {180LLDB_INSTRUMENT_VA(this);181182if (m_opaque_ptr)183return m_opaque_ptr->GetLanguage();184return lldb::eLanguageTypeUnknown;185}186187bool SBCompileUnit::IsValid() const {188LLDB_INSTRUMENT_VA(this);189return this->operator bool();190}191SBCompileUnit::operator bool() const {192LLDB_INSTRUMENT_VA(this);193194return m_opaque_ptr != nullptr;195}196197bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const {198LLDB_INSTRUMENT_VA(this, rhs);199200return m_opaque_ptr == rhs.m_opaque_ptr;201}202203bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const {204LLDB_INSTRUMENT_VA(this, rhs);205206return m_opaque_ptr != rhs.m_opaque_ptr;207}208209const lldb_private::CompileUnit *SBCompileUnit::operator->() const {210return m_opaque_ptr;211}212213const lldb_private::CompileUnit &SBCompileUnit::operator*() const {214return *m_opaque_ptr;215}216217lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; }218219void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) {220m_opaque_ptr = lldb_object_ptr;221}222223bool SBCompileUnit::GetDescription(SBStream &description) {224LLDB_INSTRUMENT_VA(this, description);225226Stream &strm = description.ref();227228if (m_opaque_ptr) {229m_opaque_ptr->Dump(&strm, false);230} else231strm.PutCString("No value");232233return true;234}235236237