Skip to content

Commit 8c0178b

Browse files
Removed GetProgramFileSpec
1 parent b8807f8 commit 8c0178b

File tree

4 files changed

+19
-37
lines changed

4 files changed

+19
-37
lines changed

lldb/include/lldb/Host/linux/HostInfoLinux.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class HostInfoLinux : public HostInfoPosix {
2626
static void Terminate();
2727

2828
static llvm::StringRef GetDistributionId();
29+
static FileSpec GetProgramFileSpec();
2930

3031
protected:
3132
static void ComputeHostArchitectureSupport(ArchSpec &arch_32,

lldb/include/lldb/Host/posix/HostInfoPosix.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class HostInfoPosix : public HostInfoBase {
3232
static uint32_t GetEffectiveGroupID();
3333

3434
static FileSpec GetDefaultShell();
35-
static FileSpec GetProgramFileSpec();
3635

3736
static bool GetEnvironmentVar(const std::string &var_name, std::string &var);
3837

lldb/source/Host/linux/HostInfoLinux.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ namespace {
3030
struct HostInfoLinuxFields {
3131
llvm::once_flag m_distribution_once_flag;
3232
std::string m_distribution_id;
33-
// llvm::once_flag m_os_version_once_flag;
34-
// llvm::VersionTuple m_os_version;
3533
};
3634
} // namespace
3735

@@ -50,23 +48,6 @@ void HostInfoLinux::Terminate() {
5048
HostInfoBase::Terminate();
5149
}
5250

53-
/*llvm::VersionTuple HostInfoPosix::GetOSVersion() {
54-
assert(g_fields && "Missing call to Initialize?");
55-
llvm::call_once(g_fields->m_os_version_once_flag, []() {
56-
struct utsname un;
57-
if (uname(&un) != 0)
58-
return;
59-
60-
llvm::StringRef release = un.release;
61-
// The kernel release string can include a lot of stuff (e.g.
62-
// 4.9.0-6-amd64). We're only interested in the numbered prefix.
63-
release = release.substr(0, release.find_first_not_of("0123456789."));
64-
g_fields->m_os_version.tryParse(release);
65-
});
66-
67-
return g_fields->m_os_version;
68-
}
69-
*/
7051
llvm::StringRef HostInfoLinux::GetDistributionId() {
7152
assert(g_fields && "Missing call to Initialize?");
7253
// Try to run 'lbs_release -i', and use that response for the distribution
@@ -142,6 +123,21 @@ llvm::StringRef HostInfoLinux::GetDistributionId() {
142123
return g_fields->m_distribution_id;
143124
}
144125

126+
FileSpec HostInfoLinux::GetProgramFileSpec() {
127+
static FileSpec g_program_filespec;
128+
129+
if (!g_program_filespec) {
130+
char exe_path[PATH_MAX];
131+
ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
132+
if (len > 0) {
133+
exe_path[len] = 0;
134+
g_program_filespec.SetFile(exe_path, FileSpec::Style::native);
135+
}
136+
}
137+
138+
return g_program_filespec;
139+
}
140+
145141
void HostInfoLinux::ComputeHostArchitectureSupport(ArchSpec &arch_32,
146142
ArchSpec &arch_64) {
147143
HostInfoPosix::ComputeHostArchitectureSupport(arch_32, arch_64);

lldb/source/Host/posix/HostInfoPosix.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "lldb/Host/posix/HostInfoPosix.h"
1010
#include "lldb/Host/Config.h"
1111
#include "lldb/Host/FileSystem.h"
12+
#include "lldb/Host/HostInfo.h"
1213
#include "lldb/Utility/Log.h"
1314
#include "lldb/Utility/UserIDResolver.h"
1415
#include "llvm/ADT/SmallString.h"
@@ -46,7 +47,7 @@ llvm::VersionTuple HostInfoPosix::GetOSVersion() {
4647
return;
4748

4849
llvm::StringRef release = un.release;
49-
// The kernel release string can include a lot of stuff (e.g.
50+
// The Linux kernel release string can include a lot of stuff (e.g.
5051
// 4.9.0-6-amd64). We're only interested in the numbered prefix.
5152
release = release.substr(0, release.find_first_not_of("0123456789."));
5253
g_fields->m_os_version.tryParse(release);
@@ -177,21 +178,6 @@ FileSpec HostInfoPosix::GetDefaultShell() {
177178
return FileSpec("/bin/sh");
178179
}
179180

180-
FileSpec HostInfoPosix::GetProgramFileSpec() {
181-
static FileSpec g_program_filespec;
182-
183-
if (!g_program_filespec) {
184-
char exe_path[PATH_MAX];
185-
ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
186-
if (len > 0) {
187-
exe_path[len] = 0;
188-
g_program_filespec.SetFile(exe_path, FileSpec::Style::native);
189-
}
190-
}
191-
192-
return g_program_filespec;
193-
}
194-
195181
// Keeping the original one for reference
196182
// bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
197183
// return ComputePathRelativeToLibrary(file_spec, "/bin");
@@ -201,7 +187,7 @@ bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) {
201187
if (ComputePathRelativeToLibrary(file_spec, "/bin") &&
202188
file_spec.IsAbsolute() && FileSystem::Instance().Exists(file_spec))
203189
return true;
204-
file_spec.SetDirectory(GetProgramFileSpec().GetDirectory());
190+
file_spec.SetDirectory(HostInfo::GetProgramFileSpec().GetDirectory());
205191
return !file_spec.GetDirectory().IsEmpty();
206192
}
207193

0 commit comments

Comments
 (0)