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;
41 g_fields =
new HostInfoLinuxFields();
45 assert(
g_fields &&
"Missing call to Initialize?");
52 assert(
g_fields &&
"Missing call to Initialize?");
55 llvm::call_once(
g_fields->m_distribution_once_flag, []() {
56 Log *log = GetLog(LLDBLog::Host);
57 LLDB_LOGF(log,
"attempting to determine Linux distribution...");
60 const char *const exe_paths[] = {
"/bin/lsb_release",
61 "/usr/bin/lsb_release"};
63 for (
size_t exe_index = 0;
64 exe_index <
sizeof(exe_paths) /
sizeof(exe_paths[0]); ++exe_index) {
65 const char *
const get_distribution_info_exe = exe_paths[exe_index];
66 if (access(get_distribution_info_exe, F_OK)) {
68 LLDB_LOGF(log,
"executable doesn't exist: %s",
69 get_distribution_info_exe);
74 std::string get_distribution_id_command(get_distribution_info_exe);
75 get_distribution_id_command +=
" -i";
77 FILE *file = popen(get_distribution_id_command.c_str(),
"r");
80 "failed to run command: \"%s\", cannot retrieve "
81 "platform information",
82 get_distribution_id_command.c_str());
87 char distribution_id[256] = {
'\0'};
88 if (fgets(distribution_id,
sizeof(distribution_id) - 1, file) !=
90 LLDB_LOGF(log,
"distribution id command returned \"%s\"",
93 const char *
const distributor_id_key =
"Distributor ID:\t";
94 if (strstr(distribution_id, distributor_id_key)) {
96 std::string id_string(distribution_id + strlen(distributor_id_key));
97 llvm::erase(id_string,
'\n');
101 id_string.begin(), id_string.end(), id_string.begin(),
102 [](
char ch) { return tolower(isspace(ch) ?
'_' : ch); });
104 g_fields->m_distribution_id = id_string;
105 LLDB_LOGF(log,
"distribution id set to \"%s\"",
106 g_fields->m_distribution_id.c_str());
108 LLDB_LOGF(log,
"failed to find \"%s\" field in \"%s\"",
109 distributor_id_key, distribution_id);
113 "failed to retrieve distribution id, \"%s\" returned no"
115 get_distribution_id_command.c_str());
129 if (!g_program_filespec) {
131 ssize_t len = readlink(
"/proc/self/exe", exe_path,
sizeof(exe_path) - 1);
134 g_program_filespec.
SetFile(exe_path, FileSpec::Style::native);
138 return g_program_filespec;
148 if (arch_32.
GetTriple().getVendor() == llvm::Triple::UnknownVendor)
149 arch_32.
GetTriple().setVendorName(llvm::StringRef());
152 if (arch_64.
GetTriple().getVendor() == llvm::Triple::UnknownVendor)
153 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.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
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 llvm::StringRef GetDistributionId()
A class that represents a running process on the host machine.