10#include "lldb/Host/Config.h"
15#include "llvm/Support/Threading.h"
20#include <sys/utsname.h>
30struct HostInfoLinuxFields {
31 llvm::once_flag m_distribution_once_flag;
32 std::string m_distribution_id;
33 llvm::once_flag m_os_version_once_flag;
34 llvm::VersionTuple m_os_version;
43 g_fields =
new HostInfoLinuxFields();
47 assert(
g_fields &&
"Missing call to Initialize?");
54 assert(
g_fields &&
"Missing call to Initialize?");
55 llvm::call_once(
g_fields->m_os_version_once_flag, []() {
60 llvm::StringRef release = un.release;
63 release = release.substr(0, release.find_first_not_of(
"0123456789."));
64 g_fields->m_os_version.tryParse(release);
72 ::memset(&un, 0,
sizeof(utsname));
77 return std::string(un.release);
81 assert(
g_fields &&
"Missing call to Initialize?");
84 llvm::call_once(
g_fields->m_distribution_once_flag, []() {
85 Log *log = GetLog(LLDBLog::Host);
86 LLDB_LOGF(log,
"attempting to determine Linux distribution...");
89 const char *const exe_paths[] = {
"/bin/lsb_release",
90 "/usr/bin/lsb_release"};
92 for (
size_t exe_index = 0;
93 exe_index <
sizeof(exe_paths) /
sizeof(exe_paths[0]); ++exe_index) {
94 const char *
const get_distribution_info_exe = exe_paths[exe_index];
95 if (access(get_distribution_info_exe, F_OK)) {
97 LLDB_LOGF(log,
"executable doesn't exist: %s",
98 get_distribution_info_exe);
103 std::string get_distribution_id_command(get_distribution_info_exe);
104 get_distribution_id_command +=
" -i";
106 FILE *file = popen(get_distribution_id_command.c_str(),
"r");
109 "failed to run command: \"%s\", cannot retrieve "
110 "platform information",
111 get_distribution_id_command.c_str());
116 char distribution_id[256] = {
'\0'};
117 if (fgets(distribution_id,
sizeof(distribution_id) - 1, file) !=
119 LLDB_LOGF(log,
"distribution id command returned \"%s\"",
122 const char *
const distributor_id_key =
"Distributor ID:\t";
123 if (strstr(distribution_id, distributor_id_key)) {
125 std::string id_string(distribution_id + strlen(distributor_id_key));
126 llvm::erase(id_string,
'\n');
130 id_string.begin(), id_string.end(), id_string.begin(),
131 [](
char ch) { return tolower(isspace(ch) ?
'_' : ch); });
133 g_fields->m_distribution_id = id_string;
134 LLDB_LOGF(log,
"distribution id set to \"%s\"",
135 g_fields->m_distribution_id.c_str());
137 LLDB_LOGF(log,
"failed to find \"%s\" field in \"%s\"",
138 distributor_id_key, distribution_id);
142 "failed to retrieve distribution id, \"%s\" returned no"
144 get_distribution_id_command.c_str());
158 if (!g_program_filespec) {
160 ssize_t len = readlink(
"/proc/self/exe", exe_path,
sizeof(exe_path) - 1);
163 g_program_filespec.
SetFile(exe_path, FileSpec::Style::native);
167 return g_program_filespec;
179 FileSpec temp_file(
"/usr/" LLDB_INSTALL_LIBDIR_BASENAME
"/lldb/plugins");
189 const char *xdg_data_home = getenv(
"XDG_DATA_HOME");
190 if (xdg_data_home && xdg_data_home[0]) {
191 std::string user_plugin_dir(xdg_data_home);
192 user_plugin_dir +=
"/lldb";
206 if (arch_32.
GetTriple().getVendor() == llvm::Triple::UnknownVendor)
207 arch_32.
GetTriple().setVendorName(llvm::StringRef());
210 if (arch_64.
GetTriple().getVendor() == llvm::Triple::UnknownVendor)
211 arch_64.
GetTriple().setVendorName(llvm::StringRef());
static HostInfoBaseFields * g_fields
static HostInfoLinuxFields * g_fields
#define LLDB_LOGF(log,...)
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool IsEmpty() const
Test for empty string.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
void SetDirectory(ConstString directory)
Directory string set accessor.
const ConstString & GetDirectory() const
Directory string const get accessor.
bool IsAbsolute() const
Returns true if the filespec represents an absolute path.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64)
void(FileSpec &this_file) SharedLibraryDirectoryHelper
A helper function for determining the liblldb location.
static void Initialize(SharedLibraryDirectoryHelper *helper=nullptr)
static FileSpec GetProgramFileSpec()
static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64)
static void Initialize(SharedLibraryDirectoryHelper *helper=nullptr)
static bool ComputeSupportExeDirectory(FileSpec &file_spec)
static std::optional< std::string > GetOSBuildString()
static bool ComputeSystemPluginsDirectory(FileSpec &file_spec)
static llvm::VersionTuple GetOSVersion()
static bool ComputeUserPluginsDirectory(FileSpec &file_spec)
static llvm::StringRef GetDistributionId()
static bool ComputeSupportExeDirectory(FileSpec &file_spec)
A class that represents a running process on the host machine.