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