2020-07-26 15:36:28 -04:00
|
|
|
//===-- SBLineEntry.cpp ---------------------------------------------------===//
|
2013-08-23 13:46:38 -04:00
|
|
|
//
|
2019-08-20 16:51:52 -04:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-08-23 13:46:38 -04:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/API/SBLineEntry.h"
|
2019-08-20 16:51:52 -04:00
|
|
|
#include "Utils.h"
|
2013-08-23 13:46:38 -04:00
|
|
|
#include "lldb/API/SBStream.h"
|
2017-04-16 12:04:10 -04:00
|
|
|
#include "lldb/Host/PosixApi.h"
|
2013-08-23 13:46:38 -04:00
|
|
|
#include "lldb/Symbol/LineEntry.h"
|
2022-01-27 17:06:42 -05:00
|
|
|
#include "lldb/Utility/Instrumentation.h"
|
2017-04-16 12:04:10 -04:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2021-07-29 16:15:26 -04:00
|
|
|
#include <climits>
|
2019-08-20 16:51:52 -04:00
|
|
|
|
2013-08-23 13:46:38 -04:00
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2022-01-27 17:06:42 -05:00
|
|
|
SBLineEntry::SBLineEntry() { LLDB_INSTRUMENT_VA(this); }
|
2019-08-20 16:51:52 -04:00
|
|
|
|
2022-01-27 17:06:42 -05:00
|
|
|
SBLineEntry::SBLineEntry(const SBLineEntry &rhs) {
|
|
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2019-08-20 16:51:52 -04:00
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2022-01-27 17:06:42 -05:00
|
|
|
SBLineEntry::SBLineEntry(const lldb_private::LineEntry *lldb_object_ptr) {
|
2017-01-02 14:26:05 -05:00
|
|
|
if (lldb_object_ptr)
|
2019-10-23 13:53:01 -04:00
|
|
|
m_opaque_up = std::make_unique<LineEntry>(*lldb_object_ptr);
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
const SBLineEntry &SBLineEntry::operator=(const SBLineEntry &rhs) {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2019-08-20 16:51:52 -04:00
|
|
|
|
|
|
|
|
if (this != &rhs)
|
|
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2022-01-27 17:06:42 -05:00
|
|
|
return *this;
|
2017-01-02 14:26:05 -05:00
|
|
|
}
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
void SBLineEntry::SetLineEntry(const lldb_private::LineEntry &lldb_object_ref) {
|
2019-10-23 13:53:01 -04:00
|
|
|
m_opaque_up = std::make_unique<LineEntry>(lldb_object_ref);
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2020-07-26 15:36:28 -04:00
|
|
|
SBLineEntry::~SBLineEntry() = default;
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
SBAddress SBLineEntry::GetStartAddress() const {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-08-20 16:51:52 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
SBAddress sb_address;
|
2019-08-20 16:51:52 -04:00
|
|
|
if (m_opaque_up)
|
2021-02-16 15:13:02 -05:00
|
|
|
sb_address.SetAddress(m_opaque_up->range.GetBaseAddress());
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2022-01-27 17:06:42 -05:00
|
|
|
return sb_address;
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
SBAddress SBLineEntry::GetEndAddress() const {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-08-20 16:51:52 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
SBAddress sb_address;
|
2019-08-20 16:51:52 -04:00
|
|
|
if (m_opaque_up) {
|
2021-02-16 15:13:02 -05:00
|
|
|
sb_address.SetAddress(m_opaque_up->range.GetBaseAddress());
|
2019-08-20 16:51:52 -04:00
|
|
|
sb_address.OffsetAddress(m_opaque_up->range.GetByteSize());
|
2017-01-02 14:26:05 -05:00
|
|
|
}
|
2022-01-27 17:06:42 -05:00
|
|
|
return sb_address;
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
bool SBLineEntry::IsValid() const {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-08-20 16:51:52 -04:00
|
|
|
return this->operator bool();
|
|
|
|
|
}
|
|
|
|
|
SBLineEntry::operator bool() const {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-08-20 16:51:52 -04:00
|
|
|
|
|
|
|
|
return m_opaque_up.get() && m_opaque_up->IsValid();
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
SBFileSpec SBLineEntry::GetFileSpec() const {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
SBFileSpec sb_file_spec;
|
2019-08-20 16:51:52 -04:00
|
|
|
if (m_opaque_up.get() && m_opaque_up->file)
|
|
|
|
|
sb_file_spec.SetFileSpec(m_opaque_up->file);
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2022-01-27 17:06:42 -05:00
|
|
|
return sb_file_spec;
|
2017-01-02 14:26:05 -05:00
|
|
|
}
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
uint32_t SBLineEntry::GetLine() const {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
uint32_t line = 0;
|
2019-08-20 16:51:52 -04:00
|
|
|
if (m_opaque_up)
|
|
|
|
|
line = m_opaque_up->line;
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
return line;
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
uint32_t SBLineEntry::GetColumn() const {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this);
|
2019-08-20 16:51:52 -04:00
|
|
|
|
|
|
|
|
if (m_opaque_up)
|
|
|
|
|
return m_opaque_up->column;
|
2017-01-02 14:26:05 -05:00
|
|
|
return 0;
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
void SBLineEntry::SetFileSpec(lldb::SBFileSpec filespec) {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this, filespec);
|
2019-08-20 16:51:52 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
if (filespec.IsValid())
|
|
|
|
|
ref().file = filespec.ref();
|
|
|
|
|
else
|
|
|
|
|
ref().file.Clear();
|
|
|
|
|
}
|
2019-08-20 16:51:52 -04:00
|
|
|
void SBLineEntry::SetLine(uint32_t line) {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this, line);
|
2019-08-20 16:51:52 -04:00
|
|
|
|
|
|
|
|
ref().line = line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SBLineEntry::SetColumn(uint32_t column) {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this, column);
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2019-08-20 16:51:52 -04:00
|
|
|
ref().line = column;
|
|
|
|
|
}
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
bool SBLineEntry::operator==(const SBLineEntry &rhs) const {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2019-08-20 16:51:52 -04:00
|
|
|
|
|
|
|
|
lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();
|
|
|
|
|
lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
if (lhs_ptr && rhs_ptr)
|
|
|
|
|
return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) == 0;
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
return lhs_ptr == rhs_ptr;
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
bool SBLineEntry::operator!=(const SBLineEntry &rhs) const {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this, rhs);
|
2019-08-20 16:51:52 -04:00
|
|
|
|
|
|
|
|
lldb_private::LineEntry *lhs_ptr = m_opaque_up.get();
|
|
|
|
|
lldb_private::LineEntry *rhs_ptr = rhs.m_opaque_up.get();
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
if (lhs_ptr && rhs_ptr)
|
|
|
|
|
return lldb_private::LineEntry::Compare(*lhs_ptr, *rhs_ptr) != 0;
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
return lhs_ptr != rhs_ptr;
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
const lldb_private::LineEntry *SBLineEntry::operator->() const {
|
2019-08-20 16:51:52 -04:00
|
|
|
return m_opaque_up.get();
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
lldb_private::LineEntry &SBLineEntry::ref() {
|
2019-08-20 16:51:52 -04:00
|
|
|
if (m_opaque_up == nullptr)
|
2020-07-26 15:36:28 -04:00
|
|
|
m_opaque_up = std::make_unique<lldb_private::LineEntry>();
|
2019-08-20 16:51:52 -04:00
|
|
|
return *m_opaque_up;
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-20 16:51:52 -04:00
|
|
|
const lldb_private::LineEntry &SBLineEntry::ref() const { return *m_opaque_up; }
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
bool SBLineEntry::GetDescription(SBStream &description) {
|
2022-01-27 17:06:42 -05:00
|
|
|
LLDB_INSTRUMENT_VA(this, description);
|
2019-08-20 16:51:52 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
Stream &strm = description.ref();
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2019-08-20 16:51:52 -04:00
|
|
|
if (m_opaque_up) {
|
2017-01-02 14:26:05 -05:00
|
|
|
char file_path[PATH_MAX * 2];
|
2019-08-20 16:51:52 -04:00
|
|
|
m_opaque_up->file.GetPath(file_path, sizeof(file_path));
|
2017-01-02 14:26:05 -05:00
|
|
|
strm.Printf("%s:%u", file_path, GetLine());
|
|
|
|
|
if (GetColumn() > 0)
|
|
|
|
|
strm.Printf(":%u", GetColumn());
|
|
|
|
|
} else
|
|
|
|
|
strm.PutCString("No value");
|
2013-08-23 13:46:38 -04:00
|
|
|
|
2017-01-02 14:26:05 -05:00
|
|
|
return true;
|
2013-08-23 13:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2019-08-20 16:51:52 -04:00
|
|
|
lldb_private::LineEntry *SBLineEntry::get() { return m_opaque_up.get(); }
|