1 //===-- source/Host/windows/Host.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 // C Includes 11 #include <stdio.h> 12 #include "lldb/Host/windows/windows.h" 13 14 // C++ Includes 15 // Other libraries and framework includes 16 // Project includes 17 #include "lldb/Core/Error.h" 18 #include "lldb/Core/Log.h" 19 #include "lldb/Target/Process.h" 20 21 #include "lldb/Host/Host.h" 22 #include "lldb/Core/DataBufferHeap.h" 23 #include "lldb/Core/DataExtractor.h" 24 25 using namespace lldb; 26 using namespace lldb_private; 27 28 bool 29 Host::GetOSVersion(uint32_t &major, 30 uint32_t &minor, 31 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 return false; 44 } 45 #pragma warning(pop) 46 47 major = (uint32_t) info.dwMajorVersion; 48 minor = (uint32_t) info.dwMinorVersion; 49 update = (uint32_t) info.wServicePackMajor; 50 51 return true; 52 } 53 54 Error 55 Host::LaunchProcess (ProcessLaunchInfo &launch_info) 56 { 57 Error error; 58 assert(!"Not implemented yet!!!"); 59 return error; 60 } 61 62 lldb::DataBufferSP 63 Host::GetAuxvData(lldb_private::Process *process) 64 { 65 return 0; 66 } 67 68 std::string 69 Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid) 70 { 71 return std::string(); 72 } 73 74 lldb::tid_t 75 Host::GetCurrentThreadID() 76 { 77 return lldb::tid_t(::GetCurrentThreadId()); 78 } 79 80 lldb::thread_t 81 Host::GetCurrentThread () 82 { 83 return lldb::thread_t(::GetCurrentThread()); 84 } 85 86 bool 87 Host::ThreadCancel (lldb::thread_t thread, Error *error) 88 { 89 int err = ::TerminateThread((HANDLE)thread, 0); 90 return err == 0; 91 } 92 93 bool 94 Host::ThreadDetach (lldb::thread_t thread, Error *error) 95 { 96 return ThreadCancel(thread, error); 97 } 98 99 bool 100 Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Error *error) 101 { 102 WaitForSingleObject((HANDLE) thread, INFINITE); 103 return true; 104 } 105 106 lldb::thread_key_t 107 Host::ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback) 108 { 109 return TlsAlloc(); 110 } 111 112 void* 113 Host::ThreadLocalStorageGet(lldb::thread_key_t key) 114 { 115 return ::TlsGetValue (key); 116 } 117 118 void 119 Host::ThreadLocalStorageSet(lldb::thread_key_t key, void *value) 120 { 121 ::TlsSetValue (key, value); 122 } 123 124 bool 125 Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name) 126 { 127 return false; 128 } 129 130 bool 131 Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid, 132 const char *thread_name, size_t len) 133 { 134 return false; 135 } 136 137 void 138 Host::Kill(lldb::pid_t pid, int signo) 139 { 140 TerminateProcess((HANDLE) pid, 1); 141 } 142 143 uint32_t 144 Host::GetNumberCPUS() 145 { 146 static uint32_t g_num_cores = UINT32_MAX; 147 if (g_num_cores == UINT32_MAX) 148 { 149 SYSTEM_INFO system_info; 150 ::GetSystemInfo(&system_info); 151 g_num_cores = system_info.dwNumberOfProcessors; 152 } 153 return g_num_cores; 154 } 155 156 size_t 157 Host::GetPageSize() 158 { 159 static long g_pagesize = 0; 160 if (!g_pagesize) 161 { 162 SYSTEM_INFO systemInfo; 163 GetNativeSystemInfo(&systemInfo); 164 g_pagesize = systemInfo.dwPageSize; 165 } 166 return g_pagesize; 167 } 168 169 const char * 170 Host::GetSignalAsCString(int signo) 171 { 172 return NULL; 173 } 174 175 FileSpec 176 Host::GetModuleFileSpecForHostAddress (const void *host_addr) 177 { 178 FileSpec module_filespec; 179 return module_filespec; 180 } 181 182 void * 183 Host::DynamicLibraryOpen(const FileSpec &file_spec, uint32_t options, Error &error) 184 { 185 error.SetErrorString("not implemented"); 186 return NULL; 187 } 188 189 Error 190 Host::DynamicLibraryClose (void *opaque) 191 { 192 Error error; 193 error.SetErrorString("not implemented"); 194 return error; 195 } 196 197 void * 198 Host::DynamicLibraryGetSymbol(void *opaque, const char *symbol_name, Error &error) 199 { 200 error.SetErrorString("not implemented"); 201 return NULL; 202 } 203 204 const char * 205 Host::GetUserName (uint32_t uid, std::string &user_name) 206 { 207 return NULL; 208 } 209 210 const char * 211 Host::GetGroupName (uint32_t gid, std::string &group_name) 212 { 213 return NULL; 214 } 215 216 uint32_t 217 Host::GetUserID () 218 { 219 return 0; 220 } 221 222 uint32_t 223 Host::GetGroupID () 224 { 225 return 0; 226 } 227 228 uint32_t 229 Host::GetEffectiveUserID () 230 { 231 return 0; 232 } 233 234 uint32_t 235 Host::GetEffectiveGroupID () 236 { 237 return 0; 238 } 239 240 lldb::thread_t 241 Host::StartMonitoringChildProcess 242 ( 243 Host::MonitorChildProcessCallback callback, 244 void *callback_baton, 245 lldb::pid_t pid, 246 bool monitor_signals 247 ) 248 { 249 return LLDB_INVALID_HOST_THREAD; 250 }