[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 15:23:27 +08:00
|
|
|
//===-- HostInfoWindows.cpp -----------------------------------------------===//
|
2014-08-20 01:18:29 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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-20 01:18:29 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Host/windows/windows.h"
|
|
|
|
|
Add support for reading line tables from PDB files.
PDB is Microsoft's debug information format, and although we
cannot yet generate it, we still must be able to consume it.
Reason for this is that debug information for system libraries
(e.g. kernel32, C Runtime Library, etc) only have debug info
in PDB format, so in order to be able to support debugging
of system code, we must support it.
Currently this code should compile on every platform, but on
non-Windows platforms the PDB plugin will return 0 capabilities,
meaning that for now PDB is only supported on Windows. This
may change in the future, but the API is designed in such a way
that this will require few (if any) changes on the LLDB side.
In the future we can just flip a switch and everything will
work.
This patch only adds support for line tables. It does not return
information about functions, types, global variables, or anything
else. This functionality will be added in a followup patch.
Differential Revision: http://reviews.llvm.org/D17363
Reviewed by: Greg Clayton
llvm-svn: 262528
2016-03-03 06:05:52 +08:00
|
|
|
#include <objbase.h>
|
|
|
|
|
2018-11-12 07:16:43 +08:00
|
|
|
#include <mutex>
|
2015-02-03 10:05:44 +08:00
|
|
|
|
2014-08-20 01:18:29 +08:00
|
|
|
#include "lldb/Host/windows/HostInfoWindows.h"
|
2017-03-23 01:33:23 +08:00
|
|
|
#include "lldb/Host/windows/PosixApi.h"
|
2019-03-05 03:57:04 +08:00
|
|
|
#include "lldb/Utility/UserIDResolver.h"
|
2014-08-20 01:18:29 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2016-03-23 01:58:09 +08:00
|
|
|
#include "llvm/Support/ConvertUTF.h"
|
2015-04-10 02:08:50 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2019-03-05 03:57:04 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2015-04-10 02:08:50 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2017-02-07 01:55:02 +08:00
|
|
|
#include "llvm/Support/Threading.h"
|
2016-03-23 01:58:09 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2014-08-20 01:18:29 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-03-05 03:57:04 +08:00
|
|
|
namespace {
|
|
|
|
class WindowsUserIDResolver : public UserIDResolver {
|
|
|
|
protected:
|
|
|
|
llvm::Optional<std::string> DoGetUserName(id_t uid) override {
|
|
|
|
return llvm::None;
|
|
|
|
}
|
|
|
|
llvm::Optional<std::string> DoGetGroupName(id_t gid) override {
|
|
|
|
return llvm::None;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2014-08-22 05:49:24 +08:00
|
|
|
FileSpec HostInfoWindows::m_program_filespec;
|
|
|
|
|
[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-16 04:51:32 +08:00
|
|
|
void HostInfoWindows::Initialize(SharedLibraryDirectoryHelper *helper) {
|
Add support for reading line tables from PDB files.
PDB is Microsoft's debug information format, and although we
cannot yet generate it, we still must be able to consume it.
Reason for this is that debug information for system libraries
(e.g. kernel32, C Runtime Library, etc) only have debug info
in PDB format, so in order to be able to support debugging
of system code, we must support it.
Currently this code should compile on every platform, but on
non-Windows platforms the PDB plugin will return 0 capabilities,
meaning that for now PDB is only supported on Windows. This
may change in the future, but the API is designed in such a way
that this will require few (if any) changes on the LLDB side.
In the future we can just flip a switch and everything will
work.
This patch only adds support for line tables. It does not return
information about functions, types, global variables, or anything
else. This functionality will be added in a followup patch.
Differential Revision: http://reviews.llvm.org/D17363
Reviewed by: Greg Clayton
llvm-svn: 262528
2016-03-03 06:05:52 +08:00
|
|
|
::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
[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-16 04:51:32 +08:00
|
|
|
HostInfoBase::Initialize(helper);
|
Add support for reading line tables from PDB files.
PDB is Microsoft's debug information format, and although we
cannot yet generate it, we still must be able to consume it.
Reason for this is that debug information for system libraries
(e.g. kernel32, C Runtime Library, etc) only have debug info
in PDB format, so in order to be able to support debugging
of system code, we must support it.
Currently this code should compile on every platform, but on
non-Windows platforms the PDB plugin will return 0 capabilities,
meaning that for now PDB is only supported on Windows. This
may change in the future, but the API is designed in such a way
that this will require few (if any) changes on the LLDB side.
In the future we can just flip a switch and everything will
work.
This patch only adds support for line tables. It does not return
information about functions, types, global variables, or anything
else. This functionality will be added in a followup patch.
Differential Revision: http://reviews.llvm.org/D17363
Reviewed by: Greg Clayton
llvm-svn: 262528
2016-03-03 06:05:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void HostInfoWindows::Terminate() {
|
|
|
|
HostInfoBase::Terminate();
|
|
|
|
::CoUninitialize();
|
|
|
|
}
|
|
|
|
|
2014-08-20 01:18:29 +08:00
|
|
|
size_t HostInfoWindows::GetPageSize() {
|
|
|
|
SYSTEM_INFO systemInfo;
|
|
|
|
GetNativeSystemInfo(&systemInfo);
|
|
|
|
return systemInfo.dwPageSize;
|
|
|
|
}
|
|
|
|
|
2018-06-18 23:02:23 +08:00
|
|
|
llvm::VersionTuple HostInfoWindows::GetOSVersion() {
|
2014-08-20 01:18:29 +08:00
|
|
|
OSVERSIONINFOEX info;
|
|
|
|
|
|
|
|
ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
|
|
|
|
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4996)
|
2018-05-01 00:49:04 +08:00
|
|
|
// Starting with Microsoft SDK for Windows 8.1, this function is deprecated
|
|
|
|
// in favor of the new Windows Version Helper APIs. Since we don't specify a
|
|
|
|
// minimum SDK version, it's easier to simply disable the warning rather than
|
|
|
|
// try to support both APIs.
|
2018-06-18 23:02:23 +08:00
|
|
|
if (GetVersionEx((LPOSVERSIONINFO)&info) == 0)
|
|
|
|
return llvm::VersionTuple();
|
2014-08-20 01:18:29 +08:00
|
|
|
#pragma warning(pop)
|
|
|
|
|
2018-06-18 23:02:23 +08:00
|
|
|
return llvm::VersionTuple(info.dwMajorVersion, info.dwMinorVersion,
|
|
|
|
info.wServicePackMajor);
|
2014-08-20 01:18:29 +08:00
|
|
|
}
|
|
|
|
|
2021-10-22 20:28:52 +08:00
|
|
|
llvm::Optional<std::string> HostInfoWindows::GetOSBuildString() {
|
2018-06-18 23:29:42 +08:00
|
|
|
llvm::VersionTuple version = GetOSVersion();
|
|
|
|
if (version.empty())
|
2021-10-22 20:28:52 +08:00
|
|
|
return llvm::None;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2021-10-22 20:28:52 +08:00
|
|
|
return "Windows NT " + version.getAsString();
|
2014-08-20 01:18:29 +08:00
|
|
|
}
|
|
|
|
|
2021-10-25 22:44:12 +08:00
|
|
|
llvm::Optional<std::string> HostInfoWindows::GetOSKernelDescription() {
|
|
|
|
return GetOSBuildString();
|
2014-08-20 01:18:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HostInfoWindows::GetHostname(std::string &s) {
|
2016-03-23 01:58:09 +08:00
|
|
|
wchar_t buffer[MAX_COMPUTERNAME_LENGTH + 1];
|
2014-08-20 01:18:29 +08:00
|
|
|
DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
|
2016-03-23 01:58:09 +08:00
|
|
|
if (!::GetComputerNameW(buffer, &dwSize))
|
2014-08-20 01:18:29 +08:00
|
|
|
return false;
|
|
|
|
|
2019-04-17 11:13:06 +08:00
|
|
|
// The conversion requires an empty string.
|
|
|
|
s.clear();
|
2016-03-23 01:58:09 +08:00
|
|
|
return llvm::convertWideToUTF8(buffer, s);
|
2014-08-20 01:18:29 +08:00
|
|
|
}
|
2014-08-22 01:29:12 +08:00
|
|
|
|
2014-08-22 05:49:24 +08:00
|
|
|
FileSpec HostInfoWindows::GetProgramFileSpec() {
|
2017-02-07 01:55:02 +08:00
|
|
|
static llvm::once_flag g_once_flag;
|
|
|
|
llvm::call_once(g_once_flag, []() {
|
2016-03-23 01:58:09 +08:00
|
|
|
std::vector<wchar_t> buffer(PATH_MAX);
|
|
|
|
::GetModuleFileNameW(NULL, buffer.data(), buffer.size());
|
|
|
|
std::string path;
|
|
|
|
llvm::convertWideToUTF8(buffer.data(), path);
|
2018-11-02 16:47:33 +08:00
|
|
|
m_program_filespec.SetFile(path, FileSpec::Style::native);
|
2015-02-04 02:26:00 +08:00
|
|
|
});
|
2014-08-22 05:49:24 +08:00
|
|
|
return m_program_filespec;
|
|
|
|
}
|
|
|
|
|
2014-10-21 01:46:43 +08:00
|
|
|
FileSpec HostInfoWindows::GetDefaultShell() {
|
2018-07-18 23:21:54 +08:00
|
|
|
// Try to retrieve ComSpec from the environment. On the rare occasion
|
|
|
|
// that it fails, try a well-known path for ComSpec instead.
|
|
|
|
|
2016-03-23 01:58:09 +08:00
|
|
|
std::string shell;
|
2018-07-18 23:21:54 +08:00
|
|
|
if (GetEnvironmentVar("ComSpec", shell))
|
2018-11-02 16:47:33 +08:00
|
|
|
return FileSpec(shell);
|
2018-07-18 23:21:54 +08:00
|
|
|
|
2018-11-02 16:47:33 +08:00
|
|
|
return FileSpec("C:\\Windows\\system32\\cmd.exe");
|
2014-10-21 01:46:43 +08:00
|
|
|
}
|
|
|
|
|
2016-03-23 01:58:09 +08:00
|
|
|
bool HostInfoWindows::GetEnvironmentVar(const std::string &var_name,
|
|
|
|
std::string &var) {
|
|
|
|
std::wstring wvar_name;
|
|
|
|
if (!llvm::ConvertUTF8toWide(var_name, wvar_name))
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-23 01:58:09 +08:00
|
|
|
if (const wchar_t *wvar = _wgetenv(wvar_name.c_str()))
|
|
|
|
return llvm::convertWideToUTF8(wvar, var);
|
|
|
|
return false;
|
|
|
|
}
|
2019-03-05 03:57:04 +08:00
|
|
|
|
|
|
|
static llvm::ManagedStatic<WindowsUserIDResolver> g_user_id_resolver;
|
|
|
|
|
|
|
|
UserIDResolver &HostInfoWindows::GetUserIDResolver() {
|
|
|
|
return *g_user_id_resolver;
|
|
|
|
}
|