2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBFileSpec.cpp ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-04-19 11:09:28 +08:00
|
|
|
#include <inttypes.h> // PRIu64
|
2011-04-08 21:36:44 +08:00
|
|
|
#include <limits.h>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/API/SBFileSpec.h"
|
2010-09-20 13:20:02 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2010-10-26 11:11:13 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2011-11-13 14:57:31 +08:00
|
|
|
#include "lldb/Core/Stream.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Host/FileSpec.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-08-08 01:33:36 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec::SBFileSpec() : m_opaque_ap(new lldb_private::FileSpec()) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec::SBFileSpec(const SBFileSpec &rhs)
|
|
|
|
: m_opaque_ap(new lldb_private::FileSpec(*rhs.m_opaque_ap)) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec::SBFileSpec(const lldb_private::FileSpec &fspec)
|
|
|
|
: m_opaque_ap(new lldb_private::FileSpec(fspec)) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2014-07-02 05:22:11 +08:00
|
|
|
// Deprecated!!!
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec::SBFileSpec(const char *path)
|
|
|
|
: m_opaque_ap(new FileSpec(path, true)) {}
|
2010-10-21 04:54:39 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec::SBFileSpec(const char *path, bool resolve)
|
|
|
|
: m_opaque_ap(new FileSpec(path, resolve)) {}
|
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) {
|
|
|
|
if (this != &rhs)
|
|
|
|
*m_opaque_ap = *rhs.m_opaque_ap;
|
|
|
|
return *this;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBFileSpec::IsValid() const { return m_opaque_ap->operator bool(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBFileSpec::Exists() const {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool result = m_opaque_ap->Exists();
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("SBFileSpec(%p)::Exists () => %s",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()),
|
|
|
|
(result ? "true" : "false"));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return result;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBFileSpec::ResolveExecutableLocation() {
|
|
|
|
return m_opaque_ap->ResolveExecutableLocation();
|
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) {
|
|
|
|
llvm::SmallString<64> result(src_path);
|
|
|
|
lldb_private::FileSpec::Resolve(result);
|
|
|
|
::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 {
|
|
|
|
const char *s = m_opaque_ap->GetFilename().AsCString();
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
|
|
|
if (log) {
|
|
|
|
if (s)
|
|
|
|
log->Printf("SBFileSpec(%p)::GetFilename () => \"%s\"",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()), s);
|
|
|
|
else
|
|
|
|
log->Printf("SBFileSpec(%p)::GetFilename () => NULL",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *SBFileSpec::GetDirectory() const {
|
|
|
|
FileSpec directory{*m_opaque_ap};
|
|
|
|
directory.GetFilename().Clear();
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
|
|
|
if (log) {
|
|
|
|
if (directory)
|
|
|
|
log->Printf("SBFileSpec(%p)::GetDirectory () => \"%s\"",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()),
|
|
|
|
directory.GetCString());
|
|
|
|
else
|
|
|
|
log->Printf("SBFileSpec(%p)::GetDirectory () => NULL",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()));
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
if (filename && filename[0])
|
|
|
|
m_opaque_ap->GetFilename().SetCString(filename);
|
|
|
|
else
|
|
|
|
m_opaque_ap->GetFilename().Clear();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBFileSpec::SetDirectory(const char *directory) {
|
|
|
|
if (directory && directory[0])
|
|
|
|
m_opaque_ap->GetDirectory().SetCString(directory);
|
|
|
|
else
|
|
|
|
m_opaque_ap->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 {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t result = m_opaque_ap->GetPath(dst_path, dst_len);
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("SBFileSpec(%p)::GetPath (dst_path=\"%.*s\", dst_len=%" PRIu64
|
|
|
|
") => %u",
|
|
|
|
static_cast<void *>(m_opaque_ap.get()), result, dst_path,
|
|
|
|
static_cast<uint64_t>(dst_len), result);
|
2010-06-09 00:52:24 +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 {
|
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const lldb_private::FileSpec *SBFileSpec::get() const {
|
|
|
|
return m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const lldb_private::FileSpec &SBFileSpec::operator*() const {
|
|
|
|
return *m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const lldb_private::FileSpec &SBFileSpec::ref() const {
|
|
|
|
return *m_opaque_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SBFileSpec::SetFileSpec(const lldb_private::FileSpec &fs) {
|
|
|
|
*m_opaque_ap = fs;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBFileSpec::GetDescription(SBStream &description) const {
|
|
|
|
Stream &strm = description.ref();
|
|
|
|
char path[PATH_MAX];
|
|
|
|
if (m_opaque_ap->GetPath(path, sizeof(path)))
|
|
|
|
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) {
|
|
|
|
m_opaque_ap->AppendPathComponent(fn);
|
2016-02-19 08:05:17 +08:00
|
|
|
}
|