2017-03-23 01:33:23 +08:00
|
|
|
//===-- SBDeclaration.cpp ----------------------------------------*- C++-*-===//
|
2012-10-11 06:54:17 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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
|
2012-10-11 06:54:17 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBDeclaration.h"
|
2019-03-06 08:05:55 +08:00
|
|
|
#include "Utils.h"
|
2012-10-11 06:54:17 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2017-03-23 01:33:23 +08:00
|
|
|
#include "lldb/Host/PosixApi.h"
|
2012-10-11 06:54:17 +08:00
|
|
|
#include "lldb/Symbol/Declaration.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2012-10-13 00:23:23 +08:00
|
|
|
#include <limits.h>
|
|
|
|
|
2012-10-11 06:54:17 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
SBDeclaration::SBDeclaration() : m_opaque_up() {}
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
SBDeclaration::SBDeclaration(const SBDeclaration &rhs) : m_opaque_up() {
|
2019-03-06 08:05:55 +08:00
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBDeclaration::SBDeclaration(const lldb_private::Declaration *lldb_object_ptr)
|
2019-02-13 14:25:41 +08:00
|
|
|
: m_opaque_up() {
|
2016-09-07 04:57:50 +08:00
|
|
|
if (lldb_object_ptr)
|
2019-03-06 08:05:55 +08:00
|
|
|
m_opaque_up = llvm::make_unique<Declaration>(*lldb_object_ptr);
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const SBDeclaration &SBDeclaration::operator=(const SBDeclaration &rhs) {
|
2019-03-06 08:05:55 +08:00
|
|
|
if (this != &rhs)
|
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2016-09-07 04:57:50 +08:00
|
|
|
return *this;
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBDeclaration::SetDeclaration(
|
|
|
|
const lldb_private::Declaration &lldb_object_ref) {
|
|
|
|
ref() = lldb_object_ref;
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBDeclaration::~SBDeclaration() {}
|
|
|
|
|
|
|
|
bool SBDeclaration::IsValid() const {
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up.get() && m_opaque_up->IsValid();
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec SBDeclaration::GetFileSpec() const {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec sb_file_spec;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up.get() && m_opaque_up->GetFile())
|
|
|
|
sb_file_spec.SetFileSpec(m_opaque_up->GetFile());
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log) {
|
|
|
|
SBStream sstr;
|
|
|
|
sb_file_spec.GetDescription(sstr);
|
|
|
|
log->Printf("SBLineEntry(%p)::GetFileSpec () => SBFileSpec(%p): %s",
|
2019-02-13 14:25:41 +08:00
|
|
|
static_cast<void *>(m_opaque_up.get()),
|
2016-09-07 04:57:50 +08:00
|
|
|
static_cast<const void *>(sb_file_spec.get()), sstr.GetData());
|
|
|
|
}
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return sb_file_spec;
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t SBDeclaration::GetLine() const {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t line = 0;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up)
|
|
|
|
line = m_opaque_up->GetLine();
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("SBLineEntry(%p)::GetLine () => %u",
|
2019-02-13 14:25:41 +08:00
|
|
|
static_cast<void *>(m_opaque_up.get()), line);
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return line;
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t SBDeclaration::GetColumn() const {
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up)
|
|
|
|
return m_opaque_up->GetColumn();
|
2016-09-07 04:57:50 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBDeclaration::SetFileSpec(lldb::SBFileSpec filespec) {
|
|
|
|
if (filespec.IsValid())
|
|
|
|
ref().SetFile(filespec.ref());
|
|
|
|
else
|
|
|
|
ref().SetFile(FileSpec());
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBDeclaration::SetLine(uint32_t line) { ref().SetLine(line); }
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBDeclaration::SetColumn(uint32_t column) { ref().SetColumn(column); }
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBDeclaration::operator==(const SBDeclaration &rhs) const {
|
2019-02-13 14:25:41 +08:00
|
|
|
lldb_private::Declaration *lhs_ptr = m_opaque_up.get();
|
|
|
|
lldb_private::Declaration *rhs_ptr = rhs.m_opaque_up.get();
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (lhs_ptr && rhs_ptr)
|
|
|
|
return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) == 0;
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return lhs_ptr == rhs_ptr;
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBDeclaration::operator!=(const SBDeclaration &rhs) const {
|
2019-02-13 14:25:41 +08:00
|
|
|
lldb_private::Declaration *lhs_ptr = m_opaque_up.get();
|
|
|
|
lldb_private::Declaration *rhs_ptr = rhs.m_opaque_up.get();
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (lhs_ptr && rhs_ptr)
|
|
|
|
return lldb_private::Declaration::Compare(*lhs_ptr, *rhs_ptr) != 0;
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return lhs_ptr != rhs_ptr;
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const lldb_private::Declaration *SBDeclaration::operator->() const {
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up.get();
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb_private::Declaration &SBDeclaration::ref() {
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up == NULL)
|
|
|
|
m_opaque_up.reset(new lldb_private::Declaration());
|
|
|
|
return *m_opaque_up;
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const lldb_private::Declaration &SBDeclaration::ref() const {
|
2019-02-13 14:25:41 +08:00
|
|
|
return *m_opaque_up;
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBDeclaration::GetDescription(SBStream &description) {
|
|
|
|
Stream &strm = description.ref();
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
2016-09-07 04:57:50 +08:00
|
|
|
char file_path[PATH_MAX * 2];
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->GetFile().GetPath(file_path, sizeof(file_path));
|
2016-09-07 04:57:50 +08:00
|
|
|
strm.Printf("%s:%u", file_path, GetLine());
|
|
|
|
if (GetColumn() > 0)
|
|
|
|
strm.Printf(":%u", GetColumn());
|
|
|
|
} else
|
|
|
|
strm.PutCString("No value");
|
2012-10-11 06:54:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
2012-10-11 06:54:17 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
lldb_private::Declaration *SBDeclaration::get() { return m_opaque_up.get(); }
|