Path: blob/main/contrib/llvm-project/lldb/source/API/SBLineEntry.cpp
39587 views
//===-- SBLineEntry.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/SBLineEntry.h"9#include "Utils.h"10#include "lldb/API/SBStream.h"11#include "lldb/Host/PosixApi.h"12#include "lldb/Symbol/LineEntry.h"13#include "lldb/Utility/Instrumentation.h"14#include "lldb/Utility/StreamString.h"1516#include <climits>1718using namespace lldb;19using namespace lldb_private;2021SBLineEntry::SBLineEntry() { LLDB_INSTRUMENT_VA(this); }2223SBLineEntry::SBLineEntry(const SBLineEntry &rhs) {24LLDB_INSTRUMENT_VA(this, rhs);2526m_opaque_up = clone(rhs.m_opaque_up);27}2829SBLineEntry::SBLineEntry(const lldb_private::LineEntry *lldb_object_ptr) {30if (lldb_object_ptr)31m_opaque_up = std::make_unique<LineEntry>(*lldb_object_ptr);32}3334const SBLineEntry &SBLineEntry::operator=(const SBLineEntry &rhs) {35LLDB_INSTRUMENT_VA(this, rhs);3637if (this != &rhs)38m_opaque_up = clone(rhs.m_opaque_up);39return *this;40}4142void SBLineEntry::SetLineEntry(const lldb_private::LineEntry &lldb_object_ref) {43m_opaque_up = std::make_unique<LineEntry>(lldb_object_ref);44}4546SBLineEntry::~SBLineEntry() = default;4748SBAddress SBLineEntry::GetStartAddress() const {49LLDB_INSTRUMENT_VA(this);5051SBAddress sb_address;52if (m_opaque_up)53sb_address.SetAddress(m_opaque_up->range.GetBaseAddress());5455return sb_address;56}5758SBAddress SBLineEntry::GetEndAddress() const {59LLDB_INSTRUMENT_VA(this);6061SBAddress sb_address;62if (m_opaque_up) {63sb_address.SetAddress(m_opaque_up->range.GetBaseAddress());64sb_address.OffsetAddress(m_opaque_up->range.GetByteSize());65}66return sb_address;67}6869SBAddress SBLineEntry::GetSameLineContiguousAddressRangeEnd(70bool include_inlined_functions) const {71LLDB_INSTRUMENT_VA(this);7273SBAddress sb_address;74if (m_opaque_up) {75AddressRange line_range = m_opaque_up->GetSameLineContiguousAddressRange(76include_inlined_functions);7778sb_address.SetAddress(line_range.GetBaseAddress());79sb_address.OffsetAddress(line_range.GetByteSize());80}81return sb_address;82}8384bool SBLineEntry::IsValid() const {85LLDB_INSTRUMENT_VA(this);86return this->operator bool();87}88SBLineEntry::operator bool() const {89LLDB_INSTRUMENT_VA(this);9091return m_opaque_up.get() && m_opaque_up->IsValid();92}9394SBFileSpec SBLineEntry::GetFileSpec() const {95LLDB_INSTRUMENT_VA(this);9697SBFileSpec sb_file_spec;98if (m_opaque_up.get() && m_opaque_up->GetFile())99sb_file_spec.SetFileSpec(m_opaque_up->GetFile());100101return sb_file_spec;102}103104uint32_t SBLineEntry::GetLine() const {105LLDB_INSTRUMENT_VA(this);106107uint32_t line = 0;108if (m_opaque_up)109line = m_opaque_up->line;110111return line;112}113114uint32_t SBLineEntry::GetColumn() const {115LLDB_INSTRUMENT_VA(this);116117if (m_opaque_up)118return m_opaque_up->column;119return 0;120}121122void SBLineEntry::SetFileSpec(lldb::SBFileSpec filespec) {123LLDB_INSTRUMENT_VA(this, filespec);124125if (filespec.IsValid())126ref().file_sp = std::make_shared<SupportFile>(filespec.ref());127else128ref().file_sp = std::make_shared<SupportFile>();129}130void SBLineEntry::SetLine(uint32_t line) {131LLDB_INSTRUMENT_VA(this, line);132133ref().line = line;134}135136void SBLineEntry::SetColumn(uint32_t column) {137LLDB_INSTRUMENT_VA(this, column);138139ref().line = column;140}141142bool SBLineEntry::operator==(const SBLineEntry &rhs) const {143LLDB_INSTRUMENT_VA(this, rhs);144145lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();146lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();147148if (lhs_ptr && rhs_ptr)149return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) == 0;150151return lhs_ptr == rhs_ptr;152}153154bool SBLineEntry::operator!=(const SBLineEntry &rhs) const {155LLDB_INSTRUMENT_VA(this, rhs);156157lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();158lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();159160if (lhs_ptr && rhs_ptr)161return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) != 0;162163return lhs_ptr != rhs_ptr;164}165166const lldb_private::LineEntry *SBLineEntry::operator->() const {167return m_opaque_up.get();168}169170lldb_private::LineEntry &SBLineEntry::ref() {171if (m_opaque_up == nullptr)172m_opaque_up = std::make_unique<lldb_private::LineEntry>();173return *m_opaque_up;174}175176const lldb_private::LineEntry &SBLineEntry::ref() const { return *m_opaque_up; }177178bool SBLineEntry::GetDescription(SBStream &description) {179LLDB_INSTRUMENT_VA(this, description);180181Stream &strm = description.ref();182183if (m_opaque_up) {184char file_path[PATH_MAX * 2];185m_opaque_up->GetFile().GetPath(file_path, sizeof(file_path));186strm.Printf("%s:%u", file_path, GetLine());187if (GetColumn() > 0)188strm.Printf(":%u", GetColumn());189} else190strm.PutCString("No value");191192return true;193}194195lldb_private::LineEntry *SBLineEntry::get() { return m_opaque_up.get(); }196197198