[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 08:23:27 +01:00
|
|
|
//===-- HostInfoLinux.cpp -------------------------------------------------===//
|
2014-08-19 17:18:29 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-08-19 17:18:29 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/Host/linux/HostInfoLinux.h"
|
2018-11-01 17:35:31 +00:00
|
|
|
#include "lldb/Host/Config.h"
|
|
|
|
|
#include "lldb/Host/FileSystem.h"
|
2022-02-03 13:26:10 +01:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2017-03-03 20:56:28 +00:00
|
|
|
#include "lldb/Utility/Log.h"
|
2014-08-19 17:18:29 +00:00
|
|
|
|
2017-02-06 17:55:02 +00:00
|
|
|
#include "llvm/Support/Threading.h"
|
|
|
|
|
|
2021-05-26 12:19:37 +02:00
|
|
|
#include <climits>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstring>
|
2014-08-19 17:18:29 +00:00
|
|
|
#include <sys/utsname.h>
|
2017-07-18 13:14:01 +00:00
|
|
|
#include <unistd.h>
|
2014-08-19 17:18:29 +00:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
2018-11-11 23:16:43 +00:00
|
|
|
#include <mutex>
|
2023-01-07 13:43:00 -08:00
|
|
|
#include <optional>
|
2014-08-19 17:18:29 +00:00
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2014-08-21 17:57:03 +00:00
|
|
|
namespace {
|
|
|
|
|
struct HostInfoLinuxFields {
|
2021-06-11 08:51:04 +02:00
|
|
|
llvm::once_flag m_distribution_once_flag;
|
2014-08-21 17:57:03 +00:00
|
|
|
std::string m_distribution_id;
|
|
|
|
|
};
|
2021-10-05 08:29:16 +02:00
|
|
|
} // namespace
|
2014-08-21 17:57:03 +00:00
|
|
|
|
2021-10-05 08:29:16 +02:00
|
|
|
static HostInfoLinuxFields *g_fields = nullptr;
|
2014-08-21 17:57:03 +00:00
|
|
|
|
[lldb] Fix shared library directory computation on windows
Our code for locating the shared library directory works via dladdr (or
the windows equivalent) to locate the path of an address known to reside
in liblldb. This works great for C++ programs, but there's a catch.
When (lib)lldb is used from python (like in our test suite), this dladdr
call will return a path to the _lldb.so (or such) file in the python
directory. To compensate for this, we have code which attempts to
resolve this symlink, to ensure we get the canonical location. However,
here's the second catch.
On windows, this file is not a symlink (but a copy), so this logic
fails. Since most of our other paths are derived from the liblldb
location, all of these paths will be wrong, when running the test suite.
One effect of this was the failure to find lldb-server in D96202.
To fix this issue, I add some windows-specific code to locate the
liblldb directory. Since it cannot rely on symlinks, it works by
manually walking the directory tree -- essentially doing the opposite of
what we do when computing the python directory.
To avoid python leaking back into the host code, I implement this with
the help of a callback which can be passed to HostInfo::Initialize in
order to assist with the directory location. The callback lives inside
the python plugin.
I also strenghten the existing path test to ensure the returned path is
the right one.
Differential Revision: https://reviews.llvm.org/D96779
2021-02-15 21:51:32 +01:00
|
|
|
void HostInfoLinux::Initialize(SharedLibraryDirectoryHelper *helper) {
|
|
|
|
|
HostInfoPosix::Initialize(helper);
|
2014-08-21 17:57:03 +00:00
|
|
|
|
|
|
|
|
g_fields = new HostInfoLinuxFields();
|
|
|
|
|
}
|
2014-08-19 17:18:29 +00:00
|
|
|
|
2021-06-10 18:43:35 -07:00
|
|
|
void HostInfoLinux::Terminate() {
|
|
|
|
|
assert(g_fields && "Missing call to Initialize?");
|
|
|
|
|
delete g_fields;
|
|
|
|
|
g_fields = nullptr;
|
|
|
|
|
HostInfoBase::Terminate();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-19 17:18:29 +00:00
|
|
|
llvm::StringRef HostInfoLinux::GetDistributionId() {
|
2021-06-11 08:51:04 +02:00
|
|
|
assert(g_fields && "Missing call to Initialize?");
|
2018-04-30 16:49:04 +00:00
|
|
|
// Try to run 'lbs_release -i', and use that response for the distribution
|
|
|
|
|
// id.
|
2021-06-11 08:51:04 +02:00
|
|
|
llvm::call_once(g_fields->m_distribution_once_flag, []() {
|
2022-01-31 15:57:48 +01:00
|
|
|
Log *log = GetLog(LLDBLog::Host);
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "attempting to determine Linux distribution...");
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// check if the lsb_release command exists at one of the following paths
|
2014-08-19 17:18:29 +00:00
|
|
|
const char *const exe_paths[] = {"/bin/lsb_release",
|
|
|
|
|
"/usr/bin/lsb_release"};
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-08-19 17:18:29 +00:00
|
|
|
for (size_t exe_index = 0;
|
|
|
|
|
exe_index < sizeof(exe_paths) / sizeof(exe_paths[0]); ++exe_index) {
|
|
|
|
|
const char *const get_distribution_info_exe = exe_paths[exe_index];
|
|
|
|
|
if (access(get_distribution_info_exe, F_OK)) {
|
|
|
|
|
// this exe doesn't exist, move on to next exe
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "executable doesn't exist: %s",
|
|
|
|
|
get_distribution_info_exe);
|
2014-08-19 17:18:29 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-21 17:57:03 +00:00
|
|
|
// execute the distribution-retrieval command, read output
|
|
|
|
|
std::string get_distribution_id_command(get_distribution_info_exe);
|
2014-08-19 17:18:29 +00:00
|
|
|
get_distribution_id_command += " -i";
|
2014-08-20 16:42:51 +00:00
|
|
|
|
2014-08-21 21:49:24 +00:00
|
|
|
FILE *file = popen(get_distribution_id_command.c_str(), "r");
|
|
|
|
|
if (!file) {
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
|
"failed to run command: \"%s\", cannot retrieve "
|
|
|
|
|
"platform information",
|
|
|
|
|
get_distribution_id_command.c_str());
|
2014-08-21 21:49:24 +00:00
|
|
|
break;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-21 21:49:24 +00:00
|
|
|
// retrieve the distribution id string.
|
|
|
|
|
char distribution_id[256] = {'\0'};
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 11:14:47 +00:00
|
|
|
if (fgets(distribution_id, sizeof(distribution_id) - 1, file) !=
|
|
|
|
|
nullptr) {
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "distribution id command returned \"%s\"",
|
|
|
|
|
distribution_id);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-08-19 17:18:29 +00:00
|
|
|
const char *const distributor_id_key = "Distributor ID:\t";
|
|
|
|
|
if (strstr(distribution_id, distributor_id_key)) {
|
2014-08-21 21:49:24 +00:00
|
|
|
// strip newlines
|
|
|
|
|
std::string id_string(distribution_id + strlen(distributor_id_key));
|
2023-12-22 12:11:05 -05:00
|
|
|
llvm::erase(id_string, '\n');
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-08-21 21:49:24 +00:00
|
|
|
// lower case it and convert whitespace to underscores
|
2014-08-19 17:18:29 +00:00
|
|
|
std::transform(
|
|
|
|
|
id_string.begin(), id_string.end(), id_string.begin(),
|
2014-08-21 21:49:24 +00:00
|
|
|
[](char ch) { return tolower(isspace(ch) ? '_' : ch); });
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-08-21 21:49:24 +00:00
|
|
|
g_fields->m_distribution_id = id_string;
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "distribution id set to \"%s\"",
|
|
|
|
|
g_fields->m_distribution_id.c_str());
|
2014-08-21 21:49:24 +00:00
|
|
|
} else {
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "failed to find \"%s\" field in \"%s\"",
|
|
|
|
|
distributor_id_key, distribution_id);
|
2014-08-21 21:49:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
|
"failed to retrieve distribution id, \"%s\" returned no"
|
|
|
|
|
" lines",
|
|
|
|
|
get_distribution_id_command.c_str());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-19 17:18:29 +00:00
|
|
|
// clean up the file
|
|
|
|
|
pclose(file);
|
2014-08-21 21:49:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
});
|
2014-08-21 21:49:24 +00:00
|
|
|
|
2016-11-02 20:34:10 +00:00
|
|
|
return g_fields->m_distribution_id;
|
2014-08-21 21:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-24 23:07:02 +00:00
|
|
|
FileSpec HostInfoLinux::GetProgramFileSpec() {
|
2015-02-10 18:30:34 +00:00
|
|
|
static FileSpec g_program_filespec;
|
|
|
|
|
|
2014-08-21 17:29:12 +00:00
|
|
|
if (!g_program_filespec) {
|
|
|
|
|
char exe_path[PATH_MAX];
|
2016-04-27 17:49:51 +00:00
|
|
|
ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
|
|
|
|
|
if (len > 0) {
|
2014-08-21 21:49:24 +00:00
|
|
|
exe_path[len] = 0;
|
2018-11-01 21:05:36 +00:00
|
|
|
g_program_filespec.SetFile(exe_path, FileSpec::Style::native);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-21 17:29:12 +00:00
|
|
|
return g_program_filespec;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 16:42:51 +00:00
|
|
|
void HostInfoLinux::ComputeHostArchitectureSupport(ArchSpec &arch_32,
|
|
|
|
|
ArchSpec &arch_64) {
|
|
|
|
|
HostInfoPosix::ComputeHostArchitectureSupport(arch_32, arch_64);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-08-20 16:42:51 +00:00
|
|
|
// On Linux, "unknown" in the vendor slot isn't what we want for the default
|
|
|
|
|
// triple. It's probably an artifact of config.guess.
|
|
|
|
|
if (arch_32.IsValid()) {
|
|
|
|
|
if (arch_32.GetTriple().getVendor() == llvm::Triple::UnknownVendor)
|
2015-10-13 23:41:19 +00:00
|
|
|
arch_32.GetTriple().setVendorName(llvm::StringRef());
|
2014-08-20 16:42:51 +00:00
|
|
|
}
|
|
|
|
|
if (arch_64.IsValid()) {
|
|
|
|
|
if (arch_64.GetTriple().getVendor() == llvm::Triple::UnknownVendor)
|
2015-10-13 23:41:19 +00:00
|
|
|
arch_64.GetTriple().setVendorName(llvm::StringRef());
|
2014-08-20 16:42:51 +00:00
|
|
|
}
|
|
|
|
|
}
|