blob: 8b2a6600e41906a84a571ec068fe3e1894ebe7f8 [file] [log] [blame]
Zachary Turner97a14e62014-08-19 17:18:29 +00001//===-- 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
16using namespace lldb_private;
17
Zachary Turnera21fee02014-08-21 21:49:24 +000018FileSpec HostInfoWindows::m_program_filespec;
19
Zachary Turner97a14e62014-08-19 17:18:29 +000020size_t
21HostInfoWindows::GetPageSize()
22{
23 SYSTEM_INFO systemInfo;
24 GetNativeSystemInfo(&systemInfo);
25 return systemInfo.dwPageSize;
26}
27
28bool
29HostInfoWindows::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
53bool
54HostInfoWindows::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
66bool
67HostInfoWindows::GetOSKernelDescription(std::string &s)
68{
69 return GetOSBuildString(s);
70}
71
72bool
73HostInfoWindows::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 Turner42ff0ad2014-08-21 17:29:12 +000083
Zachary Turnera21fee02014-08-21 21:49:24 +000084FileSpec
85HostInfoWindows::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 Turner42ff0ad2014-08-21 17:29:12 +000099bool
100HostInfoWindows::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 Clayton0d8400c2014-08-25 18:21:06 +0000110 file_spec.GetDirectory().SetCString(raw_path);
Zachary Turner42ff0ad2014-08-21 17:29:12 +0000111 return true;
112}