LLDB mainline
SBFileSpec.cpp
Go to the documentation of this file.
1//===-- SBFileSpec.cpp ----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "Utils.h"
11#include "lldb/API/SBStream.h"
13#include "lldb/Host/PosixApi.h"
16#include "lldb/Utility/Stream.h"
17
18#include "llvm/ADT/SmallString.h"
19
20#include <cinttypes>
21#include <climits>
22
23using namespace lldb;
24using namespace lldb_private;
25
28}
29
31 LLDB_INSTRUMENT_VA(this, rhs);
32
34}
35
37 : m_opaque_up(new lldb_private::FileSpec(fspec)) {}
38
39// Deprecated!!!
40SBFileSpec::SBFileSpec(const char *path) : m_opaque_up(new FileSpec(path)) {
41 LLDB_INSTRUMENT_VA(this, path);
42
44}
45
46SBFileSpec::SBFileSpec(const char *path, bool resolve)
47 : m_opaque_up(new FileSpec(path)) {
48 LLDB_INSTRUMENT_VA(this, path, resolve);
49
50 if (resolve)
52}
53
54SBFileSpec::~SBFileSpec() = default;
55
57 LLDB_INSTRUMENT_VA(this, rhs);
58
59 if (this != &rhs)
61 return *this;
62}
63
64bool SBFileSpec::operator==(const SBFileSpec &rhs) const {
65 LLDB_INSTRUMENT_VA(this, rhs);
66
67 return ref() == rhs.ref();
68}
69
70bool SBFileSpec::operator!=(const SBFileSpec &rhs) const {
71 LLDB_INSTRUMENT_VA(this, rhs);
72
73 return !(*this == rhs);
74}
75
76bool SBFileSpec::IsValid() const {
78 return this->operator bool();
79}
80SBFileSpec::operator bool() const {
82
83 return m_opaque_up->operator bool();
84}
85
86bool SBFileSpec::Exists() const {
88
90}
91
94
96}
97
98int SBFileSpec::ResolvePath(const char *src_path, char *dst_path,
99 size_t dst_len) {
100 LLDB_INSTRUMENT_VA(src_path, dst_path, dst_len);
101
102 llvm::SmallString<64> result(src_path);
104 ::snprintf(dst_path, dst_len, "%s", result.c_str());
105 return std::min(dst_len - 1, result.size());
106}
107
108const char *SBFileSpec::GetFilename() const {
109 LLDB_INSTRUMENT_VA(this);
110
111 return m_opaque_up->GetFilename().AsCString();
112}
113
114const char *SBFileSpec::GetDirectory() const {
115 LLDB_INSTRUMENT_VA(this);
116
117 FileSpec directory{*m_opaque_up};
118 directory.ClearFilename();
119 return directory.GetPathAsConstString().GetCString();
120}
121
122void SBFileSpec::SetFilename(const char *filename) {
123 LLDB_INSTRUMENT_VA(this, filename);
124
125 if (filename && filename[0])
126 m_opaque_up->SetFilename(filename);
127 else
128 m_opaque_up->ClearFilename();
129}
130
131void SBFileSpec::SetDirectory(const char *directory) {
132 LLDB_INSTRUMENT_VA(this, directory);
133
134 if (directory && directory[0])
135 m_opaque_up->SetDirectory(directory);
136 else
137 m_opaque_up->ClearDirectory();
138}
139
140uint32_t SBFileSpec::GetPath(char *dst_path, size_t dst_len) const {
141 LLDB_INSTRUMENT_VA(this, dst_path, dst_len);
142
143 uint32_t result = m_opaque_up->GetPath(dst_path, dst_len);
144
145 if (result == 0 && dst_path && dst_len > 0)
146 *dst_path = '\0';
147 return result;
148}
149
151 return m_opaque_up.get();
152}
153
155 return m_opaque_up.get();
156}
157
159 return *m_opaque_up;
160}
161
163
165 *m_opaque_up = fs;
166}
167
168bool SBFileSpec::GetDescription(SBStream &description) const {
169 LLDB_INSTRUMENT_VA(this, description);
170
171 Stream &strm = description.ref();
172 char path[PATH_MAX];
173 if (m_opaque_up->GetPath(path, sizeof(path)))
174 strm.PutCString(path);
175 return true;
176}
177
179 LLDB_INSTRUMENT_VA(this, fn);
180
181 m_opaque_up->AppendPathComponent(fn);
182}
#define LLDB_INSTRUMENT_VA(...)
void SetFilename(const char *filename)
Definition: SBFileSpec.cpp:122
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:164
void AppendPathComponent(const char *file_or_directory)
Definition: SBFileSpec.cpp:178
static int ResolvePath(const char *src_path, char *dst_path, size_t dst_len)
Definition: SBFileSpec.cpp:98
bool IsValid() const
Definition: SBFileSpec.cpp:76
const SBFileSpec & operator=(const lldb::SBFileSpec &rhs)
Definition: SBFileSpec.cpp:56
const lldb_private::FileSpec & operator*() const
Definition: SBFileSpec.cpp:158
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:162
uint32_t GetPath(char *dst_path, size_t dst_len) const
Definition: SBFileSpec.cpp:140
bool Exists() const
Definition: SBFileSpec.cpp:86
const lldb_private::FileSpec * get() const
Definition: SBFileSpec.cpp:154
const char * GetFilename() const
Definition: SBFileSpec.cpp:108
bool GetDescription(lldb::SBStream &description) const
Definition: SBFileSpec.cpp:168
bool ResolveExecutableLocation()
Definition: SBFileSpec.cpp:92
void SetDirectory(const char *directory)
Definition: SBFileSpec.cpp:131
const char * GetDirectory() const
Definition: SBFileSpec.cpp:114
bool operator!=(const SBFileSpec &rhs) const
Definition: SBFileSpec.cpp:70
bool operator==(const SBFileSpec &rhs) const
Definition: SBFileSpec.cpp:64
std::unique_ptr< lldb_private::FileSpec > m_opaque_up
Definition: SBFileSpec.h:95
const lldb_private::FileSpec * operator->() const
Definition: SBFileSpec.cpp:150
lldb_private::Stream & ref()
Definition: SBStream.cpp:177
A file utility class.
Definition: FileSpec.h:56
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
A class that represents a running process on the host machine.
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
Definition: SBAddress.h:15
#define PATH_MAX