Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 1 | //===-- HostInfoWindows.cpp -------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Host/windows/windows.h" |
| 11 | |
Greg Clayton | ff48e4b | 2015-02-03 02:05:44 +0000 | [diff] [blame] | 12 | #include <mutex> // std::once |
| 13 | |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 14 | #include "lldb/Host/windows/HostInfoWindows.h" |
| 15 | #include "llvm/ADT/SmallString.h" |
| 16 | #include "llvm/Support/raw_ostream.h" |
| 17 | |
| 18 | using namespace lldb_private; |
| 19 | |
Zachary Turner | a21fee0 | 2014-08-21 21:49:24 +0000 | [diff] [blame] | 20 | FileSpec HostInfoWindows::m_program_filespec; |
| 21 | |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 22 | size_t |
| 23 | HostInfoWindows::GetPageSize() |
| 24 | { |
| 25 | SYSTEM_INFO systemInfo; |
| 26 | GetNativeSystemInfo(&systemInfo); |
| 27 | return systemInfo.dwPageSize; |
| 28 | } |
| 29 | |
| 30 | bool |
| 31 | HostInfoWindows::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update) |
| 32 | { |
| 33 | OSVERSIONINFOEX info; |
| 34 | |
| 35 | ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); |
| 36 | info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
| 37 | #pragma warning(push) |
| 38 | #pragma warning(disable : 4996) |
| 39 | // Starting with Microsoft SDK for Windows 8.1, this function is deprecated in favor of the |
| 40 | // new Windows Version Helper APIs. Since we don't specify a minimum SDK version, it's easier |
| 41 | // to simply disable the warning rather than try to support both APIs. |
| 42 | if (GetVersionEx((LPOSVERSIONINFO)&info) == 0) |
| 43 | { |
| 44 | return false; |
| 45 | } |
| 46 | #pragma warning(pop) |
| 47 | |
| 48 | major = info.dwMajorVersion; |
| 49 | minor = info.dwMinorVersion; |
| 50 | update = info.wServicePackMajor; |
| 51 | |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | bool |
| 56 | HostInfoWindows::GetOSBuildString(std::string &s) |
| 57 | { |
| 58 | s.clear(); |
| 59 | uint32_t major, minor, update; |
| 60 | if (!GetOSVersion(major, minor, update)) |
| 61 | return false; |
| 62 | |
| 63 | llvm::raw_string_ostream stream(s); |
| 64 | stream << "Windows NT " << major << "." << minor << "." << update; |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | bool |
| 69 | HostInfoWindows::GetOSKernelDescription(std::string &s) |
| 70 | { |
| 71 | return GetOSBuildString(s); |
| 72 | } |
| 73 | |
| 74 | bool |
| 75 | HostInfoWindows::GetHostname(std::string &s) |
| 76 | { |
| 77 | char buffer[MAX_COMPUTERNAME_LENGTH + 1]; |
| 78 | DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1; |
| 79 | if (!::GetComputerName(buffer, &dwSize)) |
| 80 | return false; |
| 81 | |
| 82 | s.assign(buffer, buffer + dwSize); |
| 83 | return true; |
| 84 | } |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 85 | |
Zachary Turner | a21fee0 | 2014-08-21 21:49:24 +0000 | [diff] [blame] | 86 | FileSpec |
| 87 | HostInfoWindows::GetProgramFileSpec() |
| 88 | { |
Greg Clayton | ff48e4b | 2015-02-03 02:05:44 +0000 | [diff] [blame] | 89 | static std::once_flag g_once_flag; |
| 90 | std::call_once(g_once_flag, []() { |
| 91 | char buffer[PATH_MAX]; |
| 92 | ::GetModuleFileName(NULL, buffer, sizeof(buffer)); |
| 93 | m_program_filespec.SetFile(buffer, false); |
Zachary Turner | a21fee0 | 2014-08-21 21:49:24 +0000 | [diff] [blame] | 94 | } |
| 95 | return m_program_filespec; |
| 96 | } |
| 97 | |
Zachary Turner | 10687b0 | 2014-10-20 17:46:43 +0000 | [diff] [blame] | 98 | FileSpec |
| 99 | HostInfoWindows::GetDefaultShell() |
| 100 | { |
| 101 | return FileSpec(::getenv("ComSpec"), false); |
| 102 | } |
| 103 | |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 104 | bool |
| 105 | HostInfoWindows::ComputePythonDirectory(FileSpec &file_spec) |
| 106 | { |
| 107 | FileSpec lldb_file_spec; |
| 108 | if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec)) |
| 109 | return false; |
| 110 | |
| 111 | char raw_path[PATH_MAX]; |
| 112 | lldb_file_spec.AppendPathComponent("../lib/site-packages"); |
| 113 | lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); |
| 114 | |
Greg Clayton | 0d8400c | 2014-08-25 18:21:06 +0000 | [diff] [blame] | 115 | file_spec.GetDirectory().SetCString(raw_path); |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 116 | return true; |
| 117 | } |