/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/API/SBFileSpec.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
9 | | #include "lldb/API/SBFileSpec.h" |
10 | | #include "Utils.h" |
11 | | #include "lldb/API/SBStream.h" |
12 | | #include "lldb/Host/FileSystem.h" |
13 | | #include "lldb/Host/PosixApi.h" |
14 | | #include "lldb/Utility/FileSpec.h" |
15 | | #include "lldb/Utility/Instrumentation.h" |
16 | | #include "lldb/Utility/Stream.h" |
17 | | |
18 | | #include "llvm/ADT/SmallString.h" |
19 | | |
20 | | #include <cinttypes> |
21 | | #include <climits> |
22 | | |
23 | | using namespace lldb; |
24 | | using namespace lldb_private; |
25 | | |
26 | 10.2k | SBFileSpec::SBFileSpec() : m_opaque_up(new lldb_private::FileSpec()) { |
27 | 10.2k | LLDB_INSTRUMENT_VA(this); |
28 | 10.2k | } |
29 | | |
30 | 2.45k | SBFileSpec::SBFileSpec(const SBFileSpec &rhs) { |
31 | 2.45k | LLDB_INSTRUMENT_VA(this, rhs); |
32 | | |
33 | 2.45k | m_opaque_up = clone(rhs.m_opaque_up); |
34 | 2.45k | } |
35 | | |
36 | | SBFileSpec::SBFileSpec(const lldb_private::FileSpec &fspec) |
37 | 523 | : m_opaque_up(new lldb_private::FileSpec(fspec)) {} |
38 | | |
39 | | // Deprecated!!! |
40 | 1.45k | SBFileSpec::SBFileSpec(const char *path) : m_opaque_up(new FileSpec(path)) { |
41 | 1.45k | LLDB_INSTRUMENT_VA(this, path); |
42 | | |
43 | 1.45k | FileSystem::Instance().Resolve(*m_opaque_up); |
44 | 1.45k | } |
45 | | |
46 | | SBFileSpec::SBFileSpec(const char *path, bool resolve) |
47 | 818 | : m_opaque_up(new FileSpec(path)) { |
48 | 818 | LLDB_INSTRUMENT_VA(this, path, resolve); |
49 | | |
50 | 818 | if (resolve) |
51 | 1 | FileSystem::Instance().Resolve(*m_opaque_up); |
52 | 818 | } |
53 | | |
54 | 15.4k | SBFileSpec::~SBFileSpec() = default; |
55 | | |
56 | 2.45k | const SBFileSpec &SBFileSpec::operator=(const SBFileSpec &rhs) { |
57 | 2.45k | LLDB_INSTRUMENT_VA(this, rhs); |
58 | | |
59 | 2.45k | if (this != &rhs) |
60 | 2.45k | m_opaque_up = clone(rhs.m_opaque_up); |
61 | 2.45k | return *this; |
62 | 2.45k | } |
63 | | |
64 | 66 | bool SBFileSpec::operator==(const SBFileSpec &rhs) const { |
65 | 66 | LLDB_INSTRUMENT_VA(this, rhs); |
66 | | |
67 | 66 | return ref() == rhs.ref(); |
68 | 66 | } |
69 | | |
70 | 66 | bool SBFileSpec::operator!=(const SBFileSpec &rhs) const { |
71 | 66 | LLDB_INSTRUMENT_VA(this, rhs); |
72 | | |
73 | 66 | return !(*this == rhs); |
74 | 66 | } |
75 | | |
76 | 2.45k | bool SBFileSpec::IsValid() const { |
77 | 2.45k | LLDB_INSTRUMENT_VA(this); |
78 | 2.45k | return this->operator bool(); |
79 | 2.45k | } |
80 | 2.48k | SBFileSpec::operator bool() const { |
81 | 2.48k | LLDB_INSTRUMENT_VA(this); |
82 | | |
83 | 2.48k | return m_opaque_up->operator bool(); |
84 | 2.48k | } |
85 | | |
86 | 628 | bool SBFileSpec::Exists() const { |
87 | 628 | LLDB_INSTRUMENT_VA(this); |
88 | | |
89 | 628 | return FileSystem::Instance().Exists(*m_opaque_up); |
90 | 628 | } |
91 | | |
92 | 2 | bool SBFileSpec::ResolveExecutableLocation() { |
93 | 2 | LLDB_INSTRUMENT_VA(this); |
94 | | |
95 | 2 | return FileSystem::Instance().ResolveExecutableLocation(*m_opaque_up); |
96 | 2 | } |
97 | | |
98 | | int SBFileSpec::ResolvePath(const char *src_path, char *dst_path, |
99 | 0 | size_t dst_len) { |
100 | 0 | LLDB_INSTRUMENT_VA(src_path, dst_path, dst_len); |
101 | |
|
102 | 0 | llvm::SmallString<64> result(src_path); |
103 | 0 | FileSystem::Instance().Resolve(result); |
104 | 0 | ::snprintf(dst_path, dst_len, "%s", result.c_str()); |
105 | 0 | return std::min(dst_len - 1, result.size()); |
106 | 0 | } |
107 | | |
108 | 2.80k | const char *SBFileSpec::GetFilename() const { |
109 | 2.80k | LLDB_INSTRUMENT_VA(this); |
110 | | |
111 | 2.80k | return m_opaque_up->GetFilename().AsCString(); |
112 | 2.80k | } |
113 | | |
114 | 858 | const char *SBFileSpec::GetDirectory() const { |
115 | 858 | LLDB_INSTRUMENT_VA(this); |
116 | | |
117 | 858 | FileSpec directory{*m_opaque_up}; |
118 | 858 | directory.ClearFilename(); |
119 | 858 | return directory.GetPathAsConstString().GetCString(); |
120 | 858 | } |
121 | | |
122 | 18 | void SBFileSpec::SetFilename(const char *filename) { |
123 | 18 | LLDB_INSTRUMENT_VA(this, filename); |
124 | | |
125 | 18 | if (filename && filename[0]) |
126 | 18 | m_opaque_up->SetFilename(filename); |
127 | 0 | else |
128 | 0 | m_opaque_up->ClearFilename(); |
129 | 18 | } |
130 | | |
131 | 18 | void SBFileSpec::SetDirectory(const char *directory) { |
132 | 18 | LLDB_INSTRUMENT_VA(this, directory); |
133 | | |
134 | 18 | if (directory && directory[0]) |
135 | 18 | m_opaque_up->SetDirectory(directory); |
136 | 0 | else |
137 | 0 | m_opaque_up->ClearDirectory(); |
138 | 18 | } |
139 | | |
140 | 5.36k | uint32_t SBFileSpec::GetPath(char *dst_path, size_t dst_len) const { |
141 | 5.36k | LLDB_INSTRUMENT_VA(this, dst_path, dst_len); |
142 | | |
143 | 5.36k | uint32_t result = m_opaque_up->GetPath(dst_path, dst_len); |
144 | | |
145 | 5.36k | if (result == 0 && dst_path205 && dst_len > 0204 ) |
146 | 204 | *dst_path = '\0'; |
147 | 5.36k | return result; |
148 | 5.36k | } |
149 | | |
150 | 0 | const lldb_private::FileSpec *SBFileSpec::operator->() const { |
151 | 0 | return m_opaque_up.get(); |
152 | 0 | } |
153 | | |
154 | 8 | const lldb_private::FileSpec *SBFileSpec::get() const { |
155 | 8 | return m_opaque_up.get(); |
156 | 8 | } |
157 | | |
158 | 734 | const lldb_private::FileSpec &SBFileSpec::operator*() const { |
159 | 734 | return *m_opaque_up; |
160 | 734 | } |
161 | | |
162 | 1.75k | const lldb_private::FileSpec &SBFileSpec::ref() const { return *m_opaque_up; } |
163 | | |
164 | 7.39k | void SBFileSpec::SetFileSpec(const lldb_private::FileSpec &fs) { |
165 | 7.39k | *m_opaque_up = fs; |
166 | 7.39k | } |
167 | | |
168 | 90 | bool SBFileSpec::GetDescription(SBStream &description) const { |
169 | 90 | LLDB_INSTRUMENT_VA(this, description); |
170 | | |
171 | 90 | Stream &strm = description.ref(); |
172 | 90 | char path[PATH_MAX]; |
173 | 90 | if (m_opaque_up->GetPath(path, sizeof(path))) |
174 | 88 | strm.PutCString(path); |
175 | 90 | return true; |
176 | 90 | } |
177 | | |
178 | 1 | void SBFileSpec::AppendPathComponent(const char *fn) { |
179 | 1 | LLDB_INSTRUMENT_VA(this, fn); |
180 | | |
181 | 1 | m_opaque_up->AppendPathComponent(fn); |
182 | 1 | } |