2014-08-20 01:18:29 +08:00
|
|
|
//===-- HostInfoWindows.cpp -------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
2015-02-03 10:05:44 +08:00
|
|
|
#include <mutex> // std::once
|
|
|
|
|
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"
|
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"
|
|
|
|
#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;
|
|
|
|
|
2014-08-22 05:49:24 +08:00
|
|
|
FileSpec HostInfoWindows::m_program_filespec;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void HostInfoWindows::Initialize() {
|
|
|
|
::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
|
|
|
HostInfoBase::Initialize();
|
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
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void HostInfoWindows::Terminate() {
|
|
|
|
HostInfoBase::Terminate();
|
|
|
|
::CoUninitialize();
|
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
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t HostInfoWindows::GetPageSize() {
|
|
|
|
SYSTEM_INFO systemInfo;
|
|
|
|
GetNativeSystemInfo(&systemInfo);
|
|
|
|
return systemInfo.dwPageSize;
|
2014-08-20 01:18:29 +08:00
|
|
|
}
|
|
|
|
|
2018-06-18 23:02:23 +08:00
|
|
|
llvm::VersionTuple HostInfoWindows::GetOSVersion() {
|
2016-09-07 04:57:50 +08:00
|
|
|
OSVERSIONINFOEX info;
|
2014-08-20 01:18:29 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
|
|
|
|
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
2014-08-20 01:18:29 +08:00
|
|
|
#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
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool HostInfoWindows::GetOSBuildString(std::string &s) {
|
|
|
|
s.clear();
|
2018-06-18 23:29:42 +08:00
|
|
|
llvm::VersionTuple version = GetOSVersion();
|
|
|
|
if (version.empty())
|
2016-09-07 04:57:50 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
llvm::raw_string_ostream stream(s);
|
2018-06-18 23:29:42 +08:00
|
|
|
stream << "Windows NT " << version.getAsString();
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
2014-08-20 01:18:29 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool HostInfoWindows::GetOSKernelDescription(std::string &s) {
|
|
|
|
return GetOSBuildString(s);
|
2014-08-20 01:18:29 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool HostInfoWindows::GetHostname(std::string &s) {
|
|
|
|
wchar_t buffer[MAX_COMPUTERNAME_LENGTH + 1];
|
|
|
|
DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
|
|
|
|
if (!::GetComputerNameW(buffer, &dwSize))
|
|
|
|
return false;
|
2014-08-20 01:18:29 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return llvm::convertWideToUTF8(buffer, s);
|
2014-08-20 01:18:29 +08:00
|
|
|
}
|
2014-08-22 01:29:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +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-09-07 04:57:50 +08:00
|
|
|
std::vector<wchar_t> buffer(PATH_MAX);
|
|
|
|
::GetModuleFileNameW(NULL, buffer.data(), buffer.size());
|
|
|
|
std::string path;
|
|
|
|
llvm::convertWideToUTF8(buffer.data(), path);
|
2018-06-14 06:23:48 +08:00
|
|
|
m_program_filespec.SetFile(path, false, FileSpec::Style::native);
|
2016-09-07 04:57:50 +08:00
|
|
|
});
|
|
|
|
return m_program_filespec;
|
2014-08-22 05:49:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +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-09-07 04:57:50 +08:00
|
|
|
std::string shell;
|
2018-07-18 23:21:54 +08:00
|
|
|
if (GetEnvironmentVar("ComSpec", shell))
|
|
|
|
return FileSpec(shell, false);
|
|
|
|
|
|
|
|
return FileSpec("C:\\Windows\\system32\\cmd.exe", false);
|
2014-10-21 01:46:43 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool HostInfoWindows::GetEnvironmentVar(const std::string &var_name,
|
|
|
|
std::string &var) {
|
|
|
|
std::wstring wvar_name;
|
|
|
|
if (!llvm::ConvertUTF8toWide(var_name, wvar_name))
|
2016-03-23 01:58:09 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (const wchar_t *wvar = _wgetenv(wvar_name.c_str()))
|
|
|
|
return llvm::convertWideToUTF8(wvar, var);
|
|
|
|
return false;
|
2016-03-23 01:58:09 +08:00
|
|
|
}
|