2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBFileSpec.cpp ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
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
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBFileSpec.h"
|
2019-03-06 08:06:00 +08:00
|
|
|
#include "SBReproducerPrivate.h"
|
|
|
|
#include "Utils.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2018-11-02 01:09:22 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2017-03-23 01:33:23 +08:00
|
|
|
#include "lldb/Host/PosixApi.h"
|
2017-03-23 02:40:07 +08:00
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-08-08 01:33:36 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
SBFileSpec::SBFileSpec() : m_opaque_up(new lldb_private::FileSpec()) {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBFileSpec);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2019-03-06 08:05:55 +08:00
|
|
|
SBFileSpec::SBFileSpec(const SBFileSpec &rhs) : m_opaque_up() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBFileSpec, (const lldb::SBFileSpec &), rhs);
|
|
|
|
|
2019-03-06 08:05:55 +08:00
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec::SBFileSpec(const lldb_private::FileSpec &fspec)
|
2019-02-13 14:25:41 +08:00
|
|
|
: m_opaque_up(new lldb_private::FileSpec(fspec)) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-07-02 05:22:11 +08:00
|
|
|
// Deprecated!!!
|
2019-02-13 14:25:41 +08:00
|
|
|
SBFileSpec::SBFileSpec(const char *path) : m_opaque_up(new FileSpec(path)) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBFileSpec, (const char *), path);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
FileSystem::Instance().Resolve(*m_opaque_up);
|
2018-11-02 05:05:36 +08:00
|
|
|
}
|
2010-10-21 04:54:39 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec::SBFileSpec(const char *path, bool resolve)
|
2019-02-13 14:25:41 +08:00
|
|
|
: m_opaque_up(new FileSpec(path)) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBFileSpec, (const char *, bool), path, resolve);
|
|
|
|
|
2018-11-02 05:05:36 +08:00
|
|
|
if (resolve)
|
2019-02-13 14:25:41 +08:00
|
|
|
FileSystem::Instance().Resolve(*m_opaque_up);
|
2018-11-02 05:05:36 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec::~SBFileSpec() {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const SBFileSpec &SBFileSpec::operator=(const SBFileSpec &rhs) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(const lldb::SBFileSpec &,
|
|
|
|
SBFileSpec, operator=,(const lldb::SBFileSpec &), rhs);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (this != &rhs)
|
2019-03-06 08:05:55 +08:00
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2019-04-04 05:31:22 +08:00
|
|
|
return LLDB_RECORD_RESULT(*this);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
Make operator==s consistent between c++ and python APIs
Summary:
modify-python-lldb.py had code to insert python equality operators to
some classes. Some of those classes already had c++ equality operators,
and some didn't.
This makes the situation more consistent, by removing all equality
handilng from modify-python-lldb. Instead, I add c++ operators to
classes where they were missing, and expose them in the swig interface
files so that they are available to python too.
The only tricky case was the SBAddress class, which had an operator==
defined as a free function, which is not handled by swig. This function
cannot be removed without breaking ABI, and we cannot add an extra
operator== member, as that would make equality comparisons ambiguous.
For this class, I define a python __eq__ function by hand and have it
delegate to the operator!=, which I have defined as a member function.
This isn't fully NFC, as the semantics of some equality functions in
python changes slightly, but I believe it changes for the better (e.g.,
previously SBBreakpoint.__eq__ would consider two breakpoints with the
same ID as equal, even if they belonged to different targets; now they
are only equal if they belong to the same target).
Reviewers: jingham, clayborg, zturner
Subscribers: jdoerfert, JDevlieghere, lldb-commits
Differential Revision: https://reviews.llvm.org/D59819
llvm-svn: 357463
2019-04-02 18:18:46 +08:00
|
|
|
bool SBFileSpec::operator==(const SBFileSpec &rhs) const {
|
|
|
|
LLDB_RECORD_METHOD_CONST(bool, SBFileSpec, operator==,(const SBFileSpec &rhs),
|
|
|
|
rhs);
|
|
|
|
|
|
|
|
return ref() == rhs.ref();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBFileSpec::operator!=(const SBFileSpec &rhs) const {
|
|
|
|
LLDB_RECORD_METHOD_CONST(bool, SBFileSpec, operator!=,(const SBFileSpec &rhs),
|
|
|
|
rhs);
|
|
|
|
|
|
|
|
return !(*this == rhs);
|
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
bool SBFileSpec::IsValid() const {
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFileSpec, IsValid);
|
Add "operator bool" to SB APIs
Summary:
Our python version of the SB API has (the python equivalent of)
operator bool, but the C++ version doesn't.
This is because our python operators are added by modify-python-lldb.py,
which performs postprocessing on the swig-generated interface files.
In this patch, I add the "operator bool" to all SB classes which have an
IsValid method (which is the same logic used by modify-python-lldb.py).
This way, we make the two interfaces more constent, and it allows us to
rely on swig's automatic syntesis of python __nonzero__ methods instead
of doing manual fixups.
Reviewers: zturner, jingham, clayborg, jfb, serge-sans-paille
Subscribers: jdoerfert, lldb-commits
Differential Revision: https://reviews.llvm.org/D58792
llvm-svn: 355824
2019-03-11 21:58:46 +08:00
|
|
|
return this->operator bool();
|
|
|
|
}
|
|
|
|
SBFileSpec::operator bool() const {
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFileSpec, operator bool);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
|
|
|
return m_opaque_up->operator bool();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBFileSpec::Exists() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFileSpec, Exists);
|
|
|
|
|
2019-03-08 06:47:13 +08:00
|
|
|
return FileSystem::Instance().Exists(*m_opaque_up);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBFileSpec::ResolveExecutableLocation() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBFileSpec, ResolveExecutableLocation);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
return FileSystem::Instance().ResolveExecutableLocation(*m_opaque_up);
|
2010-09-10 12:48:55 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
int SBFileSpec::ResolvePath(const char *src_path, char *dst_path,
|
|
|
|
size_t dst_len) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_STATIC_METHOD(int, SBFileSpec, ResolvePath,
|
|
|
|
(const char *, char *, size_t), src_path, dst_path,
|
|
|
|
dst_len);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
llvm::SmallString<64> result(src_path);
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSystem::Instance().Resolve(result);
|
2016-09-07 04:57:50 +08:00
|
|
|
::snprintf(dst_path, dst_len, "%s", result.c_str());
|
|
|
|
return std::min(dst_len - 1, result.size());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *SBFileSpec::GetFilename() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBFileSpec, GetFilename);
|
|
|
|
|
2019-03-08 06:47:13 +08:00
|
|
|
return m_opaque_up->GetFilename().AsCString();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBFileSpec::GetDirectory() const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBFileSpec, GetDirectory);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
FileSpec directory{*m_opaque_up};
|
2016-09-07 04:57:50 +08:00
|
|
|
directory.GetFilename().Clear();
|
|
|
|
return directory.GetCString();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBFileSpec::SetFilename(const char *filename) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBFileSpec, SetFilename, (const char *), filename);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (filename && filename[0])
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->GetFilename().SetCString(filename);
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->GetFilename().Clear();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBFileSpec::SetDirectory(const char *directory) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBFileSpec, SetDirectory, (const char *), directory);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (directory && directory[0])
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->GetDirectory().SetCString(directory);
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->GetDirectory().Clear();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t SBFileSpec::GetPath(char *dst_path, size_t dst_len) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(uint32_t, SBFileSpec, GetPath, (char *, size_t),
|
|
|
|
dst_path, dst_len);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
uint32_t result = m_opaque_up->GetPath(dst_path, dst_len);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (result == 0 && dst_path && dst_len > 0)
|
|
|
|
*dst_path = '\0';
|
|
|
|
return result;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const lldb_private::FileSpec *SBFileSpec::operator->() const {
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const lldb_private::FileSpec *SBFileSpec::get() const {
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_opaque_up.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const lldb_private::FileSpec &SBFileSpec::operator*() const {
|
2019-02-13 14:25:41 +08:00
|
|
|
return *m_opaque_up;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
const lldb_private::FileSpec &SBFileSpec::ref() const { return *m_opaque_up; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBFileSpec::SetFileSpec(const lldb_private::FileSpec &fs) {
|
2019-02-13 14:25:41 +08:00
|
|
|
*m_opaque_up = fs;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBFileSpec::GetDescription(SBStream &description) const {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_CONST(bool, SBFileSpec, GetDescription, (lldb::SBStream &),
|
|
|
|
description);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Stream &strm = description.ref();
|
|
|
|
char path[PATH_MAX];
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up->GetPath(path, sizeof(path)))
|
2016-09-07 04:57:50 +08:00
|
|
|
strm.PutCString(path);
|
|
|
|
return true;
|
2010-10-26 11:11:13 +08:00
|
|
|
}
|
2016-02-19 08:05:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBFileSpec::AppendPathComponent(const char *fn) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(void, SBFileSpec, AppendPathComponent, (const char *), fn);
|
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
m_opaque_up->AppendPathComponent(fn);
|
2016-02-19 08:05:17 +08:00
|
|
|
}
|
2019-03-20 01:13:13 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
namespace repro {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void RegisterMethods<SBFileSpec>(Registry &R) {
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBFileSpec, ());
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBFileSpec, (const lldb::SBFileSpec &));
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBFileSpec, (const char *));
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBFileSpec, (const char *, bool));
|
|
|
|
LLDB_REGISTER_METHOD(const lldb::SBFileSpec &,
|
|
|
|
SBFileSpec, operator=,(const lldb::SBFileSpec &));
|
Make operator==s consistent between c++ and python APIs
Summary:
modify-python-lldb.py had code to insert python equality operators to
some classes. Some of those classes already had c++ equality operators,
and some didn't.
This makes the situation more consistent, by removing all equality
handilng from modify-python-lldb. Instead, I add c++ operators to
classes where they were missing, and expose them in the swig interface
files so that they are available to python too.
The only tricky case was the SBAddress class, which had an operator==
defined as a free function, which is not handled by swig. This function
cannot be removed without breaking ABI, and we cannot add an extra
operator== member, as that would make equality comparisons ambiguous.
For this class, I define a python __eq__ function by hand and have it
delegate to the operator!=, which I have defined as a member function.
This isn't fully NFC, as the semantics of some equality functions in
python changes slightly, but I believe it changes for the better (e.g.,
previously SBBreakpoint.__eq__ would consider two breakpoints with the
same ID as equal, even if they belonged to different targets; now they
are only equal if they belong to the same target).
Reviewers: jingham, clayborg, zturner
Subscribers: jdoerfert, JDevlieghere, lldb-commits
Differential Revision: https://reviews.llvm.org/D59819
llvm-svn: 357463
2019-04-02 18:18:46 +08:00
|
|
|
LLDB_REGISTER_METHOD_CONST(bool,
|
|
|
|
SBFileSpec, operator==,(const lldb::SBFileSpec &));
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool,
|
|
|
|
SBFileSpec, operator!=,(const lldb::SBFileSpec &));
|
2019-03-20 01:13:13 +08:00
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBFileSpec, IsValid, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBFileSpec, operator bool, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBFileSpec, Exists, ());
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBFileSpec, ResolveExecutableLocation, ());
|
|
|
|
LLDB_REGISTER_STATIC_METHOD(int, SBFileSpec, ResolvePath,
|
|
|
|
(const char *, char *, size_t));
|
|
|
|
LLDB_REGISTER_METHOD_CONST(const char *, SBFileSpec, GetFilename, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(const char *, SBFileSpec, GetDirectory, ());
|
|
|
|
LLDB_REGISTER_METHOD(void, SBFileSpec, SetFilename, (const char *));
|
|
|
|
LLDB_REGISTER_METHOD(void, SBFileSpec, SetDirectory, (const char *));
|
|
|
|
LLDB_REGISTER_METHOD_CONST(uint32_t, SBFileSpec, GetPath, (char *, size_t));
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBFileSpec, GetDescription,
|
|
|
|
(lldb::SBStream &));
|
|
|
|
LLDB_REGISTER_METHOD(void, SBFileSpec, AppendPathComponent, (const char *));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|