blob: 5aee4ad2094e327ab76375c86e0a99f3412a69bb [file] [log] [blame]
Greg Clayton2bddd342010-09-07 20:11:56 +00001//===-- 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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Greg Claytone3e3fee2013-02-17 20:46:30 +000012// C includes
13#include <dlfcn.h>
14#include <errno.h>
15#include <grp.h>
16#include <limits.h>
17#include <netdb.h>
18#include <pwd.h>
Greg Claytone3e3fee2013-02-17 20:46:30 +000019#include <sys/types.h>
Ed Mastef2b01622013-06-28 12:35:08 +000020#include <sys/sysctl.h>
Greg Claytone3e3fee2013-02-17 20:46:30 +000021#include <unistd.h>
22
23#if defined (__APPLE__)
24
25#include <dispatch/dispatch.h>
26#include <libproc.h>
27#include <mach-o/dyld.h>
28#include <mach/mach_port.h>
29
Ed Maste8b006c62013-06-25 18:58:11 +000030#endif
Greg Claytone3e3fee2013-02-17 20:46:30 +000031
Ed Maste8b006c62013-06-25 18:58:11 +000032#if defined (__linux__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
Greg Claytone3e3fee2013-02-17 20:46:30 +000033#include <sys/wait.h>
Ed Maste8b006c62013-06-25 18:58:11 +000034#endif
Greg Claytone3e3fee2013-02-17 20:46:30 +000035
Ed Maste8b006c62013-06-25 18:58:11 +000036#if defined (__FreeBSD__)
Greg Claytone3e3fee2013-02-17 20:46:30 +000037#include <pthread_np.h>
Greg Claytone3e3fee2013-02-17 20:46:30 +000038#endif
39
Greg Clayton2bddd342010-09-07 20:11:56 +000040#include "lldb/Host/Host.h"
41#include "lldb/Core/ArchSpec.h"
42#include "lldb/Core/ConstString.h"
Sean Callananc0a6e062011-10-27 21:22:25 +000043#include "lldb/Core/Debugger.h"
Greg Clayton2bddd342010-09-07 20:11:56 +000044#include "lldb/Core/Error.h"
Greg Clayton2bddd342010-09-07 20:11:56 +000045#include "lldb/Core/Log.h"
46#include "lldb/Core/StreamString.h"
Jim Inghamc075ecd2012-05-04 19:24:49 +000047#include "lldb/Core/ThreadSafeSTLMap.h"
Greg Clayton45319462011-02-08 00:35:34 +000048#include "lldb/Host/Config.h"
Greg Clayton7fb56d02011-02-01 01:31:41 +000049#include "lldb/Host/Endian.h"
Greg Claytone996fd32011-03-08 22:40:15 +000050#include "lldb/Host/FileSpec.h"
Greg Clayton2bddd342010-09-07 20:11:56 +000051#include "lldb/Host/Mutex.h"
Greg Claytone996fd32011-03-08 22:40:15 +000052#include "lldb/Target/Process.h"
Sean Callananc0a6e062011-10-27 21:22:25 +000053#include "lldb/Target/TargetList.h"
Greg Clayton2bddd342010-09-07 20:11:56 +000054
Stephen Wilsonbd588712011-02-24 19:15:09 +000055#include "llvm/Support/Host.h"
Greg Claytone996fd32011-03-08 22:40:15 +000056#include "llvm/Support/MachO.h"
Daniel Malea53430eb2013-01-04 23:35:13 +000057#include "llvm/ADT/Twine.h"
Stephen Wilsonbd588712011-02-24 19:15:09 +000058
Greg Clayton32e0a752011-03-30 18:16:51 +000059
Greg Clayton2bddd342010-09-07 20:11:56 +000060
Greg Clayton45319462011-02-08 00:35:34 +000061
Greg Clayton2bddd342010-09-07 20:11:56 +000062
63using namespace lldb;
64using namespace lldb_private;
65
Greg Claytone4e45922011-11-16 05:37:56 +000066
Greg Clayton1c4cd072011-11-17 19:41:57 +000067#if !defined (__APPLE__)
Greg Clayton2bddd342010-09-07 20:11:56 +000068struct MonitorInfo
69{
70 lldb::pid_t pid; // The process ID to monitor
71 Host::MonitorChildProcessCallback callback; // The callback function to call when "pid" exits or signals
72 void *callback_baton; // The callback baton for the callback function
73 bool monitor_signals; // If true, call the callback when "pid" gets signaled.
74};
75
76static void *
77MonitorChildProcessThreadFunction (void *arg);
78
79lldb::thread_t
80Host::StartMonitoringChildProcess
81(
82 Host::MonitorChildProcessCallback callback,
83 void *callback_baton,
84 lldb::pid_t pid,
85 bool monitor_signals
86)
87{
88 lldb::thread_t thread = LLDB_INVALID_HOST_THREAD;
Greg Claytone4e45922011-11-16 05:37:56 +000089 MonitorInfo * info_ptr = new MonitorInfo();
Greg Clayton2bddd342010-09-07 20:11:56 +000090
Greg Claytone4e45922011-11-16 05:37:56 +000091 info_ptr->pid = pid;
92 info_ptr->callback = callback;
93 info_ptr->callback_baton = callback_baton;
94 info_ptr->monitor_signals = monitor_signals;
95
96 char thread_name[256];
Daniel Malead01b2952012-11-29 21:49:15 +000097 ::snprintf (thread_name, sizeof(thread_name), "<lldb.host.wait4(pid=%" PRIu64 ")>", pid);
Greg Claytone4e45922011-11-16 05:37:56 +000098 thread = ThreadCreate (thread_name,
99 MonitorChildProcessThreadFunction,
100 info_ptr,
101 NULL);
102
Greg Clayton2bddd342010-09-07 20:11:56 +0000103 return thread;
104}
105
106//------------------------------------------------------------------
107// Scoped class that will disable thread canceling when it is
108// constructed, and exception safely restore the previous value it
109// when it goes out of scope.
110//------------------------------------------------------------------
111class ScopedPThreadCancelDisabler
112{
113public:
114 ScopedPThreadCancelDisabler()
115 {
116 // Disable the ability for this thread to be cancelled
117 int err = ::pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &m_old_state);
118 if (err != 0)
119 m_old_state = -1;
120
121 }
122
123 ~ScopedPThreadCancelDisabler()
124 {
125 // Restore the ability for this thread to be cancelled to what it
126 // previously was.
127 if (m_old_state != -1)
128 ::pthread_setcancelstate (m_old_state, 0);
129 }
130private:
131 int m_old_state; // Save the old cancelability state.
132};
133
134static void *
135MonitorChildProcessThreadFunction (void *arg)
136{
Greg Clayton5160ce52013-03-27 23:08:40 +0000137 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Greg Clayton2bddd342010-09-07 20:11:56 +0000138 const char *function = __FUNCTION__;
139 if (log)
140 log->Printf ("%s (arg = %p) thread starting...", function, arg);
141
142 MonitorInfo *info = (MonitorInfo *)arg;
143
144 const Host::MonitorChildProcessCallback callback = info->callback;
145 void * const callback_baton = info->callback_baton;
146 const lldb::pid_t pid = info->pid;
147 const bool monitor_signals = info->monitor_signals;
148
149 delete info;
150
151 int status = -1;
Sylvestre Ledru59405832013-07-01 08:21:36 +0000152#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
Ashok Thirumurthi0f3b9b82013-05-01 20:38:19 +0000153 #define __WALL 0
154#endif
Matt Kopec650648f2013-01-08 16:30:18 +0000155 const int options = __WALL;
156
Greg Clayton2bddd342010-09-07 20:11:56 +0000157 while (1)
158 {
Caroline Tice20ad3c42010-10-29 21:48:37 +0000159 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Greg Clayton2bddd342010-09-07 20:11:56 +0000160 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000161 log->Printf("%s ::wait_pid (pid = %" PRIu64 ", &status, options = %i)...", function, pid, options);
Greg Clayton2bddd342010-09-07 20:11:56 +0000162
163 // Wait for all child processes
164 ::pthread_testcancel ();
Matt Kopec650648f2013-01-08 16:30:18 +0000165 // Get signals from all children with same process group of pid
166 const lldb::pid_t wait_pid = ::waitpid (-1*pid, &status, options);
Greg Clayton2bddd342010-09-07 20:11:56 +0000167 ::pthread_testcancel ();
168
169 if (wait_pid == -1)
170 {
171 if (errno == EINTR)
172 continue;
173 else
Andrew Kaylor93132f52013-05-28 23:04:25 +0000174 {
175 if (log)
176 log->Printf ("%s (arg = %p) thread exiting because waitpid failed (%s)...", __FUNCTION__, arg, strerror(errno));
Greg Clayton2bddd342010-09-07 20:11:56 +0000177 break;
Andrew Kaylor93132f52013-05-28 23:04:25 +0000178 }
Greg Clayton2bddd342010-09-07 20:11:56 +0000179 }
Matt Kopec650648f2013-01-08 16:30:18 +0000180 else if (wait_pid > 0)
Greg Clayton2bddd342010-09-07 20:11:56 +0000181 {
182 bool exited = false;
183 int signal = 0;
184 int exit_status = 0;
185 const char *status_cstr = NULL;
186 if (WIFSTOPPED(status))
187 {
188 signal = WSTOPSIG(status);
189 status_cstr = "STOPPED";
190 }
191 else if (WIFEXITED(status))
192 {
193 exit_status = WEXITSTATUS(status);
194 status_cstr = "EXITED";
Andrew Kaylor93132f52013-05-28 23:04:25 +0000195 exited = true;
Greg Clayton2bddd342010-09-07 20:11:56 +0000196 }
197 else if (WIFSIGNALED(status))
198 {
199 signal = WTERMSIG(status);
200 status_cstr = "SIGNALED";
Matt Kopec650648f2013-01-08 16:30:18 +0000201 if (wait_pid == pid) {
202 exited = true;
203 exit_status = -1;
204 }
Greg Clayton2bddd342010-09-07 20:11:56 +0000205 }
206 else
207 {
Johnny Chen44805302011-07-19 19:48:13 +0000208 status_cstr = "(\?\?\?)";
Greg Clayton2bddd342010-09-07 20:11:56 +0000209 }
210
211 // Scope for pthread_cancel_disabler
212 {
213 ScopedPThreadCancelDisabler pthread_cancel_disabler;
214
Caroline Tice20ad3c42010-10-29 21:48:37 +0000215 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Greg Clayton2bddd342010-09-07 20:11:56 +0000216 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000217 log->Printf ("%s ::waitpid (pid = %" PRIu64 ", &status, options = %i) => pid = %" PRIu64 ", status = 0x%8.8x (%s), signal = %i, exit_state = %i",
Greg Clayton2bddd342010-09-07 20:11:56 +0000218 function,
219 wait_pid,
220 options,
Greg Clayton2bddd342010-09-07 20:11:56 +0000221 pid,
222 status,
223 status_cstr,
224 signal,
225 exit_status);
226
227 if (exited || (signal != 0 && monitor_signals))
228 {
Greg Claytone4e45922011-11-16 05:37:56 +0000229 bool callback_return = false;
230 if (callback)
Matt Kopec650648f2013-01-08 16:30:18 +0000231 callback_return = callback (callback_baton, wait_pid, exited, signal, exit_status);
Greg Clayton2bddd342010-09-07 20:11:56 +0000232
233 // If our process exited, then this thread should exit
Andrew Kaylor93132f52013-05-28 23:04:25 +0000234 if (exited && wait_pid == pid)
235 {
236 if (log)
237 log->Printf ("%s (arg = %p) thread exiting because pid received exit signal...", __FUNCTION__, arg);
Greg Clayton2bddd342010-09-07 20:11:56 +0000238 break;
Andrew Kaylor93132f52013-05-28 23:04:25 +0000239 }
Greg Clayton2bddd342010-09-07 20:11:56 +0000240 // If the callback returns true, it means this process should
241 // exit
242 if (callback_return)
Andrew Kaylor93132f52013-05-28 23:04:25 +0000243 {
244 if (log)
245 log->Printf ("%s (arg = %p) thread exiting because callback returned true...", __FUNCTION__, arg);
Greg Clayton2bddd342010-09-07 20:11:56 +0000246 break;
Andrew Kaylor93132f52013-05-28 23:04:25 +0000247 }
Greg Clayton2bddd342010-09-07 20:11:56 +0000248 }
249 }
250 }
251 }
252
Caroline Tice20ad3c42010-10-29 21:48:37 +0000253 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Greg Clayton2bddd342010-09-07 20:11:56 +0000254 if (log)
255 log->Printf ("%s (arg = %p) thread exiting...", __FUNCTION__, arg);
256
257 return NULL;
258}
259
Greg Claytone38a5ed2012-01-05 03:57:59 +0000260
261void
262Host::SystemLog (SystemLogType type, const char *format, va_list args)
263{
264 vfprintf (stderr, format, args);
265}
266
Greg Claytone4e45922011-11-16 05:37:56 +0000267#endif // #if !defined (__APPLE__)
268
Greg Claytone38a5ed2012-01-05 03:57:59 +0000269void
270Host::SystemLog (SystemLogType type, const char *format, ...)
271{
272 va_list args;
273 va_start (args, format);
274 SystemLog (type, format, args);
275 va_end (args);
276}
277
Greg Clayton2bddd342010-09-07 20:11:56 +0000278size_t
279Host::GetPageSize()
280{
281 return ::getpagesize();
282}
283
Greg Clayton2bddd342010-09-07 20:11:56 +0000284const ArchSpec &
Greg Clayton514487e2011-02-15 21:59:32 +0000285Host::GetArchitecture (SystemDefaultArchitecture arch_kind)
Greg Clayton2bddd342010-09-07 20:11:56 +0000286{
Greg Clayton514487e2011-02-15 21:59:32 +0000287 static bool g_supports_32 = false;
288 static bool g_supports_64 = false;
289 static ArchSpec g_host_arch_32;
290 static ArchSpec g_host_arch_64;
291
Greg Clayton2bddd342010-09-07 20:11:56 +0000292#if defined (__APPLE__)
Greg Clayton514487e2011-02-15 21:59:32 +0000293
294 // Apple is different in that it can support both 32 and 64 bit executables
295 // in the same operating system running concurrently. Here we detect the
296 // correct host architectures for both 32 and 64 bit including if 64 bit
297 // executables are supported on the system.
298
299 if (g_supports_32 == false && g_supports_64 == false)
300 {
301 // All apple systems support 32 bit execution.
302 g_supports_32 = true;
Greg Clayton2bddd342010-09-07 20:11:56 +0000303 uint32_t cputype, cpusubtype;
Greg Clayton514487e2011-02-15 21:59:32 +0000304 uint32_t is_64_bit_capable = false;
Greg Clayton2bddd342010-09-07 20:11:56 +0000305 size_t len = sizeof(cputype);
Greg Clayton514487e2011-02-15 21:59:32 +0000306 ArchSpec host_arch;
307 // These will tell us about the kernel architecture, which even on a 64
308 // bit machine can be 32 bit...
Greg Clayton2bddd342010-09-07 20:11:56 +0000309 if (::sysctlbyname("hw.cputype", &cputype, &len, NULL, 0) == 0)
310 {
Greg Clayton514487e2011-02-15 21:59:32 +0000311 len = sizeof (cpusubtype);
312 if (::sysctlbyname("hw.cpusubtype", &cpusubtype, &len, NULL, 0) != 0)
313 cpusubtype = CPU_TYPE_ANY;
314
Greg Clayton2bddd342010-09-07 20:11:56 +0000315 len = sizeof (is_64_bit_capable);
316 if (::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0) == 0)
317 {
318 if (is_64_bit_capable)
Greg Clayton514487e2011-02-15 21:59:32 +0000319 g_supports_64 = true;
320 }
321
322 if (is_64_bit_capable)
323 {
Greg Clayton93d3c8332011-02-16 04:46:07 +0000324#if defined (__i386__) || defined (__x86_64__)
325 if (cpusubtype == CPU_SUBTYPE_486)
326 cpusubtype = CPU_SUBTYPE_I386_ALL;
327#endif
Greg Clayton514487e2011-02-15 21:59:32 +0000328 if (cputype & CPU_ARCH_ABI64)
Greg Clayton2bddd342010-09-07 20:11:56 +0000329 {
Greg Clayton514487e2011-02-15 21:59:32 +0000330 // We have a 64 bit kernel on a 64 bit system
Greg Claytone0d378b2011-03-24 21:19:54 +0000331 g_host_arch_32.SetArchitecture (eArchTypeMachO, ~(CPU_ARCH_MASK) & cputype, cpusubtype);
332 g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton514487e2011-02-15 21:59:32 +0000333 }
334 else
335 {
336 // We have a 32 bit kernel on a 64 bit system
Greg Claytone0d378b2011-03-24 21:19:54 +0000337 g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton2bddd342010-09-07 20:11:56 +0000338 cputype |= CPU_ARCH_ABI64;
Greg Claytone0d378b2011-03-24 21:19:54 +0000339 g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton2bddd342010-09-07 20:11:56 +0000340 }
341 }
Greg Clayton514487e2011-02-15 21:59:32 +0000342 else
343 {
Greg Claytone0d378b2011-03-24 21:19:54 +0000344 g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton514487e2011-02-15 21:59:32 +0000345 g_host_arch_64.Clear();
346 }
Greg Clayton2bddd342010-09-07 20:11:56 +0000347 }
Greg Clayton514487e2011-02-15 21:59:32 +0000348 }
349
350#else // #if defined (__APPLE__)
Stephen Wilsonbd588712011-02-24 19:15:09 +0000351
Greg Clayton514487e2011-02-15 21:59:32 +0000352 if (g_supports_32 == false && g_supports_64 == false)
353 {
Peter Collingbourne1f6198d2011-11-05 01:35:31 +0000354 llvm::Triple triple(llvm::sys::getDefaultTargetTriple());
Greg Clayton514487e2011-02-15 21:59:32 +0000355
Stephen Wilsonbd588712011-02-24 19:15:09 +0000356 g_host_arch_32.Clear();
357 g_host_arch_64.Clear();
Greg Clayton514487e2011-02-15 21:59:32 +0000358
Greg Claytonb29e6c62012-10-11 17:38:58 +0000359 // If the OS is Linux, "unknown" in the vendor slot isn't what we want
360 // for the default triple. It's probably an artifact of config.guess.
361 if (triple.getOS() == llvm::Triple::Linux && triple.getVendor() == llvm::Triple::UnknownVendor)
362 triple.setVendorName("");
363
Stephen Wilsonbd588712011-02-24 19:15:09 +0000364 switch (triple.getArch())
365 {
366 default:
367 g_host_arch_32.SetTriple(triple);
368 g_supports_32 = true;
369 break;
Greg Clayton514487e2011-02-15 21:59:32 +0000370
Stephen Wilsonbd588712011-02-24 19:15:09 +0000371 case llvm::Triple::x86_64:
Greg Clayton542e4072012-09-07 17:49:29 +0000372 g_host_arch_64.SetTriple(triple);
373 g_supports_64 = true;
374 g_host_arch_32.SetTriple(triple.get32BitArchVariant());
375 g_supports_32 = true;
376 break;
377
Stephen Wilsonbd588712011-02-24 19:15:09 +0000378 case llvm::Triple::sparcv9:
379 case llvm::Triple::ppc64:
Stephen Wilsonbd588712011-02-24 19:15:09 +0000380 g_host_arch_64.SetTriple(triple);
381 g_supports_64 = true;
382 break;
383 }
Greg Clayton4796c4f2011-02-17 02:05:38 +0000384
385 g_supports_32 = g_host_arch_32.IsValid();
386 g_supports_64 = g_host_arch_64.IsValid();
Greg Clayton2bddd342010-09-07 20:11:56 +0000387 }
Greg Clayton514487e2011-02-15 21:59:32 +0000388
389#endif // #else for #if defined (__APPLE__)
390
391 if (arch_kind == eSystemDefaultArchitecture32)
392 return g_host_arch_32;
393 else if (arch_kind == eSystemDefaultArchitecture64)
394 return g_host_arch_64;
395
396 if (g_supports_64)
397 return g_host_arch_64;
398
399 return g_host_arch_32;
Greg Clayton2bddd342010-09-07 20:11:56 +0000400}
401
402const ConstString &
403Host::GetVendorString()
404{
405 static ConstString g_vendor;
406 if (!g_vendor)
407 {
Greg Clayton950971f2012-05-12 00:01:21 +0000408 const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture);
409 const llvm::StringRef &str_ref = host_arch.GetTriple().getVendorName();
410 g_vendor.SetCStringWithLength(str_ref.data(), str_ref.size());
Greg Clayton2bddd342010-09-07 20:11:56 +0000411 }
412 return g_vendor;
413}
414
415const ConstString &
416Host::GetOSString()
417{
418 static ConstString g_os_string;
419 if (!g_os_string)
420 {
Greg Clayton950971f2012-05-12 00:01:21 +0000421 const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture);
422 const llvm::StringRef &str_ref = host_arch.GetTriple().getOSName();
423 g_os_string.SetCStringWithLength(str_ref.data(), str_ref.size());
Greg Clayton2bddd342010-09-07 20:11:56 +0000424 }
425 return g_os_string;
426}
427
428const ConstString &
429Host::GetTargetTriple()
430{
431 static ConstString g_host_triple;
432 if (!(g_host_triple))
433 {
Greg Clayton950971f2012-05-12 00:01:21 +0000434 const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture);
435 g_host_triple.SetCString(host_arch.GetTriple().getTriple().c_str());
Greg Clayton2bddd342010-09-07 20:11:56 +0000436 }
437 return g_host_triple;
438}
439
440lldb::pid_t
441Host::GetCurrentProcessID()
442{
443 return ::getpid();
444}
445
446lldb::tid_t
447Host::GetCurrentThreadID()
448{
449#if defined (__APPLE__)
Greg Clayton813ddfc2012-09-18 18:19:49 +0000450 // Calling "mach_port_deallocate()" bumps the reference count on the thread
451 // port, so we need to deallocate it. mach_task_self() doesn't bump the ref
452 // count.
453 thread_port_t thread_self = mach_thread_self();
454 mach_port_deallocate(mach_task_self(), thread_self);
455 return thread_self;
Johnny Chen8f3d8382011-08-02 20:52:42 +0000456#elif defined(__FreeBSD__)
457 return lldb::tid_t(pthread_getthreadid_np());
Greg Clayton2bddd342010-09-07 20:11:56 +0000458#else
459 return lldb::tid_t(pthread_self());
460#endif
461}
462
Jim Ingham372787f2012-04-07 00:00:41 +0000463lldb::thread_t
464Host::GetCurrentThread ()
465{
466 return lldb::thread_t(pthread_self());
467}
468
Greg Clayton2bddd342010-09-07 20:11:56 +0000469const char *
470Host::GetSignalAsCString (int signo)
471{
472 switch (signo)
473 {
474 case SIGHUP: return "SIGHUP"; // 1 hangup
475 case SIGINT: return "SIGINT"; // 2 interrupt
476 case SIGQUIT: return "SIGQUIT"; // 3 quit
477 case SIGILL: return "SIGILL"; // 4 illegal instruction (not reset when caught)
478 case SIGTRAP: return "SIGTRAP"; // 5 trace trap (not reset when caught)
479 case SIGABRT: return "SIGABRT"; // 6 abort()
Greg Clayton0ddf6be2011-11-04 03:42:38 +0000480#if (defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE))
Greg Clayton2bddd342010-09-07 20:11:56 +0000481 case SIGPOLL: return "SIGPOLL"; // 7 pollable event ([XSR] generated, not supported)
Benjamin Kramer44030f12011-11-04 16:06:40 +0000482#endif
483#if !defined(_POSIX_C_SOURCE)
Greg Clayton2bddd342010-09-07 20:11:56 +0000484 case SIGEMT: return "SIGEMT"; // 7 EMT instruction
Benjamin Kramer44030f12011-11-04 16:06:40 +0000485#endif
Greg Clayton2bddd342010-09-07 20:11:56 +0000486 case SIGFPE: return "SIGFPE"; // 8 floating point exception
487 case SIGKILL: return "SIGKILL"; // 9 kill (cannot be caught or ignored)
488 case SIGBUS: return "SIGBUS"; // 10 bus error
489 case SIGSEGV: return "SIGSEGV"; // 11 segmentation violation
490 case SIGSYS: return "SIGSYS"; // 12 bad argument to system call
491 case SIGPIPE: return "SIGPIPE"; // 13 write on a pipe with no one to read it
492 case SIGALRM: return "SIGALRM"; // 14 alarm clock
493 case SIGTERM: return "SIGTERM"; // 15 software termination signal from kill
494 case SIGURG: return "SIGURG"; // 16 urgent condition on IO channel
495 case SIGSTOP: return "SIGSTOP"; // 17 sendable stop signal not from tty
496 case SIGTSTP: return "SIGTSTP"; // 18 stop signal from tty
497 case SIGCONT: return "SIGCONT"; // 19 continue a stopped process
498 case SIGCHLD: return "SIGCHLD"; // 20 to parent on child stop or exit
499 case SIGTTIN: return "SIGTTIN"; // 21 to readers pgrp upon background tty read
500 case SIGTTOU: return "SIGTTOU"; // 22 like TTIN for output if (tp->t_local&LTOSTOP)
501#if !defined(_POSIX_C_SOURCE)
502 case SIGIO: return "SIGIO"; // 23 input/output possible signal
503#endif
504 case SIGXCPU: return "SIGXCPU"; // 24 exceeded CPU time limit
505 case SIGXFSZ: return "SIGXFSZ"; // 25 exceeded file size limit
506 case SIGVTALRM: return "SIGVTALRM"; // 26 virtual time alarm
507 case SIGPROF: return "SIGPROF"; // 27 profiling time alarm
508#if !defined(_POSIX_C_SOURCE)
509 case SIGWINCH: return "SIGWINCH"; // 28 window size changes
510 case SIGINFO: return "SIGINFO"; // 29 information request
511#endif
512 case SIGUSR1: return "SIGUSR1"; // 30 user defined signal 1
513 case SIGUSR2: return "SIGUSR2"; // 31 user defined signal 2
514 default:
515 break;
516 }
517 return NULL;
518}
519
520void
521Host::WillTerminate ()
522{
523}
524
Sylvestre Ledru59405832013-07-01 08:21:36 +0000525#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) && !defined (__linux__) // see macosx/Host.mm
Matt Kopec62502c62013-05-13 19:33:58 +0000526
Greg Clayton2bddd342010-09-07 20:11:56 +0000527void
528Host::ThreadCreated (const char *thread_name)
529{
530}
Greg Claytone5219662010-12-03 06:02:24 +0000531
Peter Collingbourne2ced9132011-08-05 00:35:43 +0000532void
Greg Claytone5219662010-12-03 06:02:24 +0000533Host::Backtrace (Stream &strm, uint32_t max_frames)
534{
Michael Sartain3cf443d2013-07-17 00:26:30 +0000535 // TODO: Is there a way to backtrace the current process on other systems?
Greg Claytone5219662010-12-03 06:02:24 +0000536}
537
Greg Clayton85851dd2010-12-04 00:10:17 +0000538size_t
539Host::GetEnvironment (StringList &env)
540{
Michael Sartain3cf443d2013-07-17 00:26:30 +0000541 // TODO: Is there a way to the host environment for this process on other systems?
Greg Clayton85851dd2010-12-04 00:10:17 +0000542 return 0;
543}
544
Sylvestre Ledru59405832013-07-01 08:21:36 +0000545#endif // #if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) && !defined (__linux__)
Greg Clayton2bddd342010-09-07 20:11:56 +0000546
547struct HostThreadCreateInfo
548{
549 std::string thread_name;
550 thread_func_t thread_fptr;
551 thread_arg_t thread_arg;
552
553 HostThreadCreateInfo (const char *name, thread_func_t fptr, thread_arg_t arg) :
554 thread_name (name ? name : ""),
555 thread_fptr (fptr),
556 thread_arg (arg)
557 {
558 }
559};
560
561static thread_result_t
562ThreadCreateTrampoline (thread_arg_t arg)
563{
564 HostThreadCreateInfo *info = (HostThreadCreateInfo *)arg;
565 Host::ThreadCreated (info->thread_name.c_str());
566 thread_func_t thread_fptr = info->thread_fptr;
567 thread_arg_t thread_arg = info->thread_arg;
568
Greg Clayton5160ce52013-03-27 23:08:40 +0000569 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
Greg Clayton2bddd342010-09-07 20:11:56 +0000570 if (log)
571 log->Printf("thread created");
572
573 delete info;
574 return thread_fptr (thread_arg);
575}
576
577lldb::thread_t
578Host::ThreadCreate
579(
580 const char *thread_name,
581 thread_func_t thread_fptr,
582 thread_arg_t thread_arg,
583 Error *error
584)
585{
586 lldb::thread_t thread = LLDB_INVALID_HOST_THREAD;
587
588 // Host::ThreadCreateTrampoline will delete this pointer for us.
589 HostThreadCreateInfo *info_ptr = new HostThreadCreateInfo (thread_name, thread_fptr, thread_arg);
590
591 int err = ::pthread_create (&thread, NULL, ThreadCreateTrampoline, info_ptr);
592 if (err == 0)
593 {
594 if (error)
595 error->Clear();
596 return thread;
597 }
598
599 if (error)
600 error->SetError (err, eErrorTypePOSIX);
601
602 return LLDB_INVALID_HOST_THREAD;
603}
604
605bool
606Host::ThreadCancel (lldb::thread_t thread, Error *error)
607{
608 int err = ::pthread_cancel (thread);
609 if (error)
610 error->SetError(err, eErrorTypePOSIX);
611 return err == 0;
612}
613
614bool
615Host::ThreadDetach (lldb::thread_t thread, Error *error)
616{
617 int err = ::pthread_detach (thread);
618 if (error)
619 error->SetError(err, eErrorTypePOSIX);
620 return err == 0;
621}
622
623bool
624Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Error *error)
625{
626 int err = ::pthread_join (thread, thread_result_ptr);
627 if (error)
628 error->SetError(err, eErrorTypePOSIX);
629 return err == 0;
630}
631
Matt Kopec62502c62013-05-13 19:33:58 +0000632bool
Greg Clayton2bddd342010-09-07 20:11:56 +0000633Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name)
634{
Greg Clayton85719632013-02-27 22:51:58 +0000635#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
Greg Clayton2bddd342010-09-07 20:11:56 +0000636 lldb::pid_t curr_pid = Host::GetCurrentProcessID();
637 lldb::tid_t curr_tid = Host::GetCurrentThreadID();
638 if (pid == LLDB_INVALID_PROCESS_ID)
639 pid = curr_pid;
640
641 if (tid == LLDB_INVALID_THREAD_ID)
642 tid = curr_tid;
643
Greg Clayton2bddd342010-09-07 20:11:56 +0000644 // Set the pthread name if possible
645 if (pid == curr_pid && tid == curr_tid)
646 {
Matt Kopec62502c62013-05-13 19:33:58 +0000647 if (::pthread_setname_np (name) == 0)
648 return true;
Greg Clayton2bddd342010-09-07 20:11:56 +0000649 }
Matt Kopec62502c62013-05-13 19:33:58 +0000650 return false;
Ed Maste02983be2013-07-25 19:10:32 +0000651#elif defined (__FreeBSD__)
652 lldb::pid_t curr_pid = Host::GetCurrentProcessID();
653 lldb::tid_t curr_tid = Host::GetCurrentThreadID();
654 if (pid == LLDB_INVALID_PROCESS_ID)
655 pid = curr_pid;
656
657 if (tid == LLDB_INVALID_THREAD_ID)
658 tid = curr_tid;
659
660 // Set the pthread name if possible
661 if (pid == curr_pid && tid == curr_tid)
662 {
663 ::pthread_set_name_np(::pthread_self(), name);
664 return true;
665 }
666 return false;
Sylvestre Ledru59405832013-07-01 08:21:36 +0000667#elif defined (__linux__) || defined (__GLIBC__)
Matt Kopec62502c62013-05-13 19:33:58 +0000668 void *fn = dlsym (RTLD_DEFAULT, "pthread_setname_np");
669 if (fn)
670 {
671 int (*pthread_setname_np_func)(pthread_t thread, const char *name);
672 *reinterpret_cast<void **> (&pthread_setname_np_func) = fn;
673
674 lldb::pid_t curr_pid = Host::GetCurrentProcessID();
675 lldb::tid_t curr_tid = Host::GetCurrentThreadID();
676
677 if (pid == LLDB_INVALID_PROCESS_ID)
678 pid = curr_pid;
679
680 if (tid == LLDB_INVALID_THREAD_ID)
681 tid = curr_tid;
682
683 if (pid == curr_pid)
684 {
685 if (pthread_setname_np_func (tid, name) == 0)
686 return true;
687 }
688 }
689 return false;
Jim Ingham5c42d8a2013-05-15 18:27:08 +0000690#else
691 return false;
Greg Clayton2bddd342010-09-07 20:11:56 +0000692#endif
Greg Clayton2bddd342010-09-07 20:11:56 +0000693}
694
Ed Maste02983be2013-07-25 19:10:32 +0000695bool
696Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid,
697 const char *thread_name, size_t len)
698{
699 char *namebuf = (char *)::malloc (len + 1);
700
701 // Thread names are coming in like '<lldb.comm.debugger.edit>' and
702 // '<lldb.comm.debugger.editline>'. So just chopping the end of the string
703 // off leads to a lot of similar named threads. Go through the thread name
704 // and search for the last dot and use that.
705 const char *lastdot = ::strrchr (thread_name, '.');
706
707 if (lastdot && lastdot != thread_name)
708 thread_name = lastdot + 1;
709 ::strncpy (namebuf, thread_name, len);
710 namebuf[len] = 0;
711
712 int namebuflen = strlen(namebuf);
713 if (namebuflen > 0)
714 {
715 if (namebuf[namebuflen - 1] == '(' || namebuf[namebuflen - 1] == '>')
716 {
717 // Trim off trailing '(' and '>' characters for a bit more cleanup.
718 namebuflen--;
719 namebuf[namebuflen] = 0;
720 }
721 return Host::SetThreadName (pid, tid, namebuf);
722 }
723 return false;
724}
725
Greg Clayton2bddd342010-09-07 20:11:56 +0000726FileSpec
727Host::GetProgramFileSpec ()
728{
729 static FileSpec g_program_filespec;
730 if (!g_program_filespec)
731 {
732#if defined (__APPLE__)
733 char program_fullpath[PATH_MAX];
734 // If DST is NULL, then return the number of bytes needed.
735 uint32_t len = sizeof(program_fullpath);
736 int err = _NSGetExecutablePath (program_fullpath, &len);
737 if (err == 0)
Greg Claytonb3326392011-01-13 01:23:43 +0000738 g_program_filespec.SetFile (program_fullpath, false);
Greg Clayton2bddd342010-09-07 20:11:56 +0000739 else if (err == -1)
740 {
741 char *large_program_fullpath = (char *)::malloc (len + 1);
742
743 err = _NSGetExecutablePath (large_program_fullpath, &len);
744 if (err == 0)
Greg Claytonb3326392011-01-13 01:23:43 +0000745 g_program_filespec.SetFile (large_program_fullpath, false);
Greg Clayton2bddd342010-09-07 20:11:56 +0000746
747 ::free (large_program_fullpath);
748 }
749#elif defined (__linux__)
750 char exe_path[PATH_MAX];
Stephen Wilsone5b94a92011-01-12 04:21:21 +0000751 ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
752 if (len > 0) {
753 exe_path[len] = 0;
Greg Claytonb3326392011-01-13 01:23:43 +0000754 g_program_filespec.SetFile(exe_path, false);
Stephen Wilsone5b94a92011-01-12 04:21:21 +0000755 }
Sylvestre Ledru59405832013-07-01 08:21:36 +0000756#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
Greg Clayton2bddd342010-09-07 20:11:56 +0000757 int exe_path_mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid() };
758 size_t exe_path_size;
759 if (sysctl(exe_path_mib, 4, NULL, &exe_path_size, NULL, 0) == 0)
760 {
Greg Clayton87ff1ac2011-01-13 01:27:55 +0000761 char *exe_path = new char[exe_path_size];
762 if (sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0)
763 g_program_filespec.SetFile(exe_path, false);
764 delete[] exe_path;
Greg Clayton2bddd342010-09-07 20:11:56 +0000765 }
766#endif
767 }
768 return g_program_filespec;
769}
770
771FileSpec
772Host::GetModuleFileSpecForHostAddress (const void *host_addr)
773{
774 FileSpec module_filespec;
775 Dl_info info;
776 if (::dladdr (host_addr, &info))
777 {
778 if (info.dli_fname)
Greg Clayton274060b2010-10-20 20:54:39 +0000779 module_filespec.SetFile(info.dli_fname, true);
Greg Clayton2bddd342010-09-07 20:11:56 +0000780 }
781 return module_filespec;
782}
783
784#if !defined (__APPLE__) // see Host.mm
Greg Claytonc859e2d2012-02-13 23:10:39 +0000785
786bool
787Host::GetBundleDirectory (const FileSpec &file, FileSpec &bundle)
788{
789 bundle.Clear();
790 return false;
791}
792
Greg Clayton2bddd342010-09-07 20:11:56 +0000793bool
Greg Claytondd36def2010-10-17 22:03:32 +0000794Host::ResolveExecutableInBundle (FileSpec &file)
Greg Clayton2bddd342010-09-07 20:11:56 +0000795{
Greg Claytondd36def2010-10-17 22:03:32 +0000796 return false;
Greg Clayton2bddd342010-09-07 20:11:56 +0000797}
798#endif
799
Greg Clayton45319462011-02-08 00:35:34 +0000800// Opaque info that tracks a dynamic library that was loaded
801struct DynamicLibraryInfo
Greg Clayton4272cc72011-02-02 02:24:04 +0000802{
Greg Clayton45319462011-02-08 00:35:34 +0000803 DynamicLibraryInfo (const FileSpec &fs, int o, void *h) :
804 file_spec (fs),
805 open_options (o),
806 handle (h)
807 {
808 }
809
810 const FileSpec file_spec;
811 uint32_t open_options;
812 void * handle;
813};
814
815void *
816Host::DynamicLibraryOpen (const FileSpec &file_spec, uint32_t options, Error &error)
817{
Greg Clayton4272cc72011-02-02 02:24:04 +0000818 char path[PATH_MAX];
819 if (file_spec.GetPath(path, sizeof(path)))
820 {
Greg Clayton45319462011-02-08 00:35:34 +0000821 int mode = 0;
822
823 if (options & eDynamicLibraryOpenOptionLazy)
824 mode |= RTLD_LAZY;
Greg Claytonf9399452011-02-08 05:24:57 +0000825 else
826 mode |= RTLD_NOW;
827
Greg Clayton45319462011-02-08 00:35:34 +0000828
829 if (options & eDynamicLibraryOpenOptionLocal)
830 mode |= RTLD_LOCAL;
831 else
832 mode |= RTLD_GLOBAL;
833
834#ifdef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED
835 if (options & eDynamicLibraryOpenOptionLimitGetSymbol)
836 mode |= RTLD_FIRST;
Greg Clayton75852f52011-02-07 17:43:47 +0000837#endif
Greg Clayton45319462011-02-08 00:35:34 +0000838
839 void * opaque = ::dlopen (path, mode);
840
841 if (opaque)
Greg Clayton4272cc72011-02-02 02:24:04 +0000842 {
843 error.Clear();
Greg Clayton45319462011-02-08 00:35:34 +0000844 return new DynamicLibraryInfo (file_spec, options, opaque);
Greg Clayton4272cc72011-02-02 02:24:04 +0000845 }
846 else
847 {
848 error.SetErrorString(::dlerror());
849 }
850 }
851 else
852 {
853 error.SetErrorString("failed to extract path");
854 }
Greg Clayton45319462011-02-08 00:35:34 +0000855 return NULL;
Greg Clayton4272cc72011-02-02 02:24:04 +0000856}
857
858Error
Greg Clayton45319462011-02-08 00:35:34 +0000859Host::DynamicLibraryClose (void *opaque)
Greg Clayton4272cc72011-02-02 02:24:04 +0000860{
861 Error error;
Greg Clayton45319462011-02-08 00:35:34 +0000862 if (opaque == NULL)
Greg Clayton4272cc72011-02-02 02:24:04 +0000863 {
864 error.SetErrorString ("invalid dynamic library handle");
865 }
Greg Clayton45319462011-02-08 00:35:34 +0000866 else
Greg Clayton4272cc72011-02-02 02:24:04 +0000867 {
Greg Clayton45319462011-02-08 00:35:34 +0000868 DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque;
869 if (::dlclose (dylib_info->handle) != 0)
870 {
871 error.SetErrorString(::dlerror());
872 }
873
874 dylib_info->open_options = 0;
875 dylib_info->handle = 0;
876 delete dylib_info;
Greg Clayton4272cc72011-02-02 02:24:04 +0000877 }
878 return error;
879}
880
881void *
Greg Clayton45319462011-02-08 00:35:34 +0000882Host::DynamicLibraryGetSymbol (void *opaque, const char *symbol_name, Error &error)
Greg Clayton4272cc72011-02-02 02:24:04 +0000883{
Greg Clayton45319462011-02-08 00:35:34 +0000884 if (opaque == NULL)
Greg Clayton4272cc72011-02-02 02:24:04 +0000885 {
886 error.SetErrorString ("invalid dynamic library handle");
Greg Clayton4272cc72011-02-02 02:24:04 +0000887 }
Greg Clayton4272cc72011-02-02 02:24:04 +0000888 else
Greg Clayton45319462011-02-08 00:35:34 +0000889 {
890 DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque;
891
892 void *symbol_addr = ::dlsym (dylib_info->handle, symbol_name);
893 if (symbol_addr)
894 {
895#ifndef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED
896 // This host doesn't support limiting searches to this shared library
897 // so we need to verify that the match came from this shared library
898 // if it was requested in the Host::DynamicLibraryOpen() function.
Greg Claytonf9399452011-02-08 05:24:57 +0000899 if (dylib_info->open_options & eDynamicLibraryOpenOptionLimitGetSymbol)
Greg Clayton45319462011-02-08 00:35:34 +0000900 {
901 FileSpec match_dylib_spec (Host::GetModuleFileSpecForHostAddress (symbol_addr));
902 if (match_dylib_spec != dylib_info->file_spec)
903 {
904 char dylib_path[PATH_MAX];
905 if (dylib_info->file_spec.GetPath (dylib_path, sizeof(dylib_path)))
906 error.SetErrorStringWithFormat ("symbol not found in \"%s\"", dylib_path);
907 else
908 error.SetErrorString ("symbol not found");
909 return NULL;
910 }
911 }
912#endif
913 error.Clear();
914 return symbol_addr;
915 }
916 else
917 {
918 error.SetErrorString(::dlerror());
919 }
920 }
921 return NULL;
Greg Clayton4272cc72011-02-02 02:24:04 +0000922}
Greg Claytondd36def2010-10-17 22:03:32 +0000923
924bool
925Host::GetLLDBPath (PathType path_type, FileSpec &file_spec)
926{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000927 // To get paths related to LLDB we get the path to the executable that
Greg Claytondd36def2010-10-17 22:03:32 +0000928 // contains this function. On MacOSX this will be "LLDB.framework/.../LLDB",
929 // on linux this is assumed to be the "lldb" main executable. If LLDB on
Michael Sartain3cf443d2013-07-17 00:26:30 +0000930 // linux is actually in a shared library (liblldb.so) then this function will
Greg Claytondd36def2010-10-17 22:03:32 +0000931 // need to be modified to "do the right thing".
932
933 switch (path_type)
934 {
935 case ePathTypeLLDBShlibDir:
936 {
937 static ConstString g_lldb_so_dir;
938 if (!g_lldb_so_dir)
939 {
940 FileSpec lldb_file_spec (Host::GetModuleFileSpecForHostAddress ((void *)Host::GetLLDBPath));
941 g_lldb_so_dir = lldb_file_spec.GetDirectory();
942 }
943 file_spec.GetDirectory() = g_lldb_so_dir;
944 return file_spec.GetDirectory();
945 }
946 break;
947
948 case ePathTypeSupportExecutableDir:
949 {
950 static ConstString g_lldb_support_exe_dir;
951 if (!g_lldb_support_exe_dir)
952 {
953 FileSpec lldb_file_spec;
954 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
955 {
956 char raw_path[PATH_MAX];
957 char resolved_path[PATH_MAX];
958 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
959
960#if defined (__APPLE__)
961 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
962 if (framework_pos)
963 {
964 framework_pos += strlen("LLDB.framework");
Greg Claytondce502e2011-11-04 03:34:56 +0000965#if !defined (__arm__)
Greg Claytondd36def2010-10-17 22:03:32 +0000966 ::strncpy (framework_pos, "/Resources", PATH_MAX - (framework_pos - raw_path));
Greg Claytondce502e2011-11-04 03:34:56 +0000967#endif
Greg Claytondd36def2010-10-17 22:03:32 +0000968 }
969#endif
970 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
971 g_lldb_support_exe_dir.SetCString(resolved_path);
972 }
973 }
974 file_spec.GetDirectory() = g_lldb_support_exe_dir;
975 return file_spec.GetDirectory();
976 }
977 break;
978
979 case ePathTypeHeaderDir:
980 {
981 static ConstString g_lldb_headers_dir;
982 if (!g_lldb_headers_dir)
983 {
984#if defined (__APPLE__)
985 FileSpec lldb_file_spec;
986 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
987 {
988 char raw_path[PATH_MAX];
989 char resolved_path[PATH_MAX];
990 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
991
992 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
993 if (framework_pos)
994 {
995 framework_pos += strlen("LLDB.framework");
996 ::strncpy (framework_pos, "/Headers", PATH_MAX - (framework_pos - raw_path));
997 }
998 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
999 g_lldb_headers_dir.SetCString(resolved_path);
1000 }
1001#else
Greg Clayton4272cc72011-02-02 02:24:04 +00001002 // TODO: Anyone know how we can determine this for linux? Other systems??
Greg Claytondd36def2010-10-17 22:03:32 +00001003 g_lldb_headers_dir.SetCString ("/opt/local/include/lldb");
1004#endif
1005 }
1006 file_spec.GetDirectory() = g_lldb_headers_dir;
1007 return file_spec.GetDirectory();
1008 }
1009 break;
1010
Ed Mastea85d3642013-07-02 19:30:52 +00001011#ifndef LLDB_DISABLE_PYTHON
Greg Claytondd36def2010-10-17 22:03:32 +00001012 case ePathTypePythonDir:
1013 {
Greg Claytondd36def2010-10-17 22:03:32 +00001014 static ConstString g_lldb_python_dir;
1015 if (!g_lldb_python_dir)
1016 {
1017 FileSpec lldb_file_spec;
1018 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
1019 {
1020 char raw_path[PATH_MAX];
1021 char resolved_path[PATH_MAX];
1022 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
1023
1024#if defined (__APPLE__)
1025 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
1026 if (framework_pos)
1027 {
1028 framework_pos += strlen("LLDB.framework");
1029 ::strncpy (framework_pos, "/Resources/Python", PATH_MAX - (framework_pos - raw_path));
1030 }
Filipe Cabecinhas0b751162012-07-30 16:46:32 +00001031#else
Daniel Malea53430eb2013-01-04 23:35:13 +00001032 llvm::Twine python_version_dir;
1033 python_version_dir = "/python"
1034 + llvm::Twine(PY_MAJOR_VERSION)
1035 + "."
1036 + llvm::Twine(PY_MINOR_VERSION)
1037 + "/site-packages";
1038
Filipe Cabecinhascffbd092012-07-30 18:56:10 +00001039 // We may get our string truncated. Should we protect
1040 // this with an assert?
Daniel Malea53430eb2013-01-04 23:35:13 +00001041
1042 ::strncat(raw_path, python_version_dir.str().c_str(),
1043 sizeof(raw_path) - strlen(raw_path) - 1);
1044
Greg Claytondd36def2010-10-17 22:03:32 +00001045#endif
1046 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
1047 g_lldb_python_dir.SetCString(resolved_path);
1048 }
1049 }
1050 file_spec.GetDirectory() = g_lldb_python_dir;
1051 return file_spec.GetDirectory();
1052 }
1053 break;
Ed Mastea85d3642013-07-02 19:30:52 +00001054#endif
1055
Greg Clayton4272cc72011-02-02 02:24:04 +00001056 case ePathTypeLLDBSystemPlugins: // System plug-ins directory
1057 {
Michael Sartain3cf443d2013-07-17 00:26:30 +00001058#if defined (__APPLE__) || defined(__linux__)
Greg Clayton4272cc72011-02-02 02:24:04 +00001059 static ConstString g_lldb_system_plugin_dir;
Greg Clayton1cb64962011-03-24 04:28:38 +00001060 static bool g_lldb_system_plugin_dir_located = false;
1061 if (!g_lldb_system_plugin_dir_located)
Greg Clayton4272cc72011-02-02 02:24:04 +00001062 {
Greg Clayton1cb64962011-03-24 04:28:38 +00001063 g_lldb_system_plugin_dir_located = true;
Michael Sartain3cf443d2013-07-17 00:26:30 +00001064#if defined (__APPLE__)
Greg Clayton4272cc72011-02-02 02:24:04 +00001065 FileSpec lldb_file_spec;
1066 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
1067 {
1068 char raw_path[PATH_MAX];
1069 char resolved_path[PATH_MAX];
1070 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
1071
1072 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
1073 if (framework_pos)
1074 {
1075 framework_pos += strlen("LLDB.framework");
1076 ::strncpy (framework_pos, "/Resources/PlugIns", PATH_MAX - (framework_pos - raw_path));
Greg Clayton1cb64962011-03-24 04:28:38 +00001077 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
1078 g_lldb_system_plugin_dir.SetCString(resolved_path);
Greg Clayton4272cc72011-02-02 02:24:04 +00001079 }
Greg Clayton1cb64962011-03-24 04:28:38 +00001080 return false;
Greg Clayton4272cc72011-02-02 02:24:04 +00001081 }
Michael Sartain3cf443d2013-07-17 00:26:30 +00001082#elif defined (__linux__)
1083 FileSpec lldb_file_spec("/usr/lib/lldb", true);
1084 if (lldb_file_spec.Exists())
1085 {
1086 g_lldb_system_plugin_dir.SetCString(lldb_file_spec.GetPath().c_str());
1087 }
1088#endif // __APPLE__ || __linux__
Greg Clayton4272cc72011-02-02 02:24:04 +00001089 }
Greg Clayton1cb64962011-03-24 04:28:38 +00001090
1091 if (g_lldb_system_plugin_dir)
1092 {
1093 file_spec.GetDirectory() = g_lldb_system_plugin_dir;
1094 return true;
1095 }
Michael Sartain3cf443d2013-07-17 00:26:30 +00001096#else
1097 // TODO: where would system LLDB plug-ins be located on other systems?
Greg Clayton4272cc72011-02-02 02:24:04 +00001098 return false;
Michael Sartain3cf443d2013-07-17 00:26:30 +00001099#endif
Greg Clayton4272cc72011-02-02 02:24:04 +00001100 }
1101 break;
1102
1103 case ePathTypeLLDBUserPlugins: // User plug-ins directory
1104 {
1105#if defined (__APPLE__)
1106 static ConstString g_lldb_user_plugin_dir;
1107 if (!g_lldb_user_plugin_dir)
1108 {
1109 char user_plugin_path[PATH_MAX];
1110 if (FileSpec::Resolve ("~/Library/Application Support/LLDB/PlugIns",
1111 user_plugin_path,
1112 sizeof(user_plugin_path)))
1113 {
1114 g_lldb_user_plugin_dir.SetCString(user_plugin_path);
1115 }
1116 }
1117 file_spec.GetDirectory() = g_lldb_user_plugin_dir;
1118 return file_spec.GetDirectory();
Michael Sartain3cf443d2013-07-17 00:26:30 +00001119#elif defined (__linux__)
1120 static ConstString g_lldb_user_plugin_dir;
1121 if (!g_lldb_user_plugin_dir)
1122 {
1123 // XDG Base Directory Specification
1124 // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
1125 // If XDG_DATA_HOME exists, use that, otherwise use ~/.local/share/lldb.
1126 FileSpec lldb_file_spec;
1127 const char *xdg_data_home = getenv("XDG_DATA_HOME");
1128 if (xdg_data_home && xdg_data_home[0])
1129 {
1130 std::string user_plugin_dir (xdg_data_home);
1131 user_plugin_dir += "/lldb";
1132 lldb_file_spec.SetFile (user_plugin_dir.c_str(), true);
1133 }
1134 else
1135 {
1136 const char *home_dir = getenv("HOME");
1137 if (home_dir && home_dir[0])
1138 {
1139 std::string user_plugin_dir (home_dir);
1140 user_plugin_dir += "/.local/share/lldb";
1141 lldb_file_spec.SetFile (user_plugin_dir.c_str(), true);
1142 }
1143 }
1144
1145 if (lldb_file_spec.Exists())
1146 g_lldb_user_plugin_dir.SetCString(lldb_file_spec.GetPath().c_str());
1147 }
1148 file_spec.GetDirectory() = g_lldb_user_plugin_dir;
1149 return file_spec.GetDirectory();
Greg Clayton4272cc72011-02-02 02:24:04 +00001150#endif
Michael Sartain3cf443d2013-07-17 00:26:30 +00001151 // TODO: where would user LLDB plug-ins be located on other systems?
Greg Clayton4272cc72011-02-02 02:24:04 +00001152 return false;
1153 }
Greg Claytondd36def2010-10-17 22:03:32 +00001154 }
1155
1156 return false;
1157}
1158
Greg Clayton1cb64962011-03-24 04:28:38 +00001159
1160bool
1161Host::GetHostname (std::string &s)
1162{
1163 char hostname[PATH_MAX];
1164 hostname[sizeof(hostname) - 1] = '\0';
1165 if (::gethostname (hostname, sizeof(hostname) - 1) == 0)
1166 {
1167 struct hostent* h = ::gethostbyname (hostname);
1168 if (h)
1169 s.assign (h->h_name);
1170 else
1171 s.assign (hostname);
1172 return true;
1173 }
1174 return false;
1175}
1176
Greg Clayton32e0a752011-03-30 18:16:51 +00001177const char *
1178Host::GetUserName (uint32_t uid, std::string &user_name)
1179{
1180 struct passwd user_info;
1181 struct passwd *user_info_ptr = &user_info;
1182 char user_buffer[PATH_MAX];
1183 size_t user_buffer_size = sizeof(user_buffer);
1184 if (::getpwuid_r (uid,
1185 &user_info,
1186 user_buffer,
1187 user_buffer_size,
1188 &user_info_ptr) == 0)
1189 {
1190 if (user_info_ptr)
1191 {
1192 user_name.assign (user_info_ptr->pw_name);
1193 return user_name.c_str();
1194 }
1195 }
1196 user_name.clear();
1197 return NULL;
1198}
1199
1200const char *
1201Host::GetGroupName (uint32_t gid, std::string &group_name)
1202{
1203 char group_buffer[PATH_MAX];
1204 size_t group_buffer_size = sizeof(group_buffer);
1205 struct group group_info;
1206 struct group *group_info_ptr = &group_info;
1207 // Try the threadsafe version first
1208 if (::getgrgid_r (gid,
1209 &group_info,
1210 group_buffer,
1211 group_buffer_size,
1212 &group_info_ptr) == 0)
1213 {
1214 if (group_info_ptr)
1215 {
1216 group_name.assign (group_info_ptr->gr_name);
1217 return group_name.c_str();
1218 }
1219 }
1220 else
1221 {
1222 // The threadsafe version isn't currently working
1223 // for me on darwin, but the non-threadsafe version
1224 // is, so I am calling it below.
1225 group_info_ptr = ::getgrgid (gid);
1226 if (group_info_ptr)
1227 {
1228 group_name.assign (group_info_ptr->gr_name);
1229 return group_name.c_str();
1230 }
1231 }
1232 group_name.clear();
1233 return NULL;
1234}
1235
Sylvestre Ledru59405832013-07-01 08:21:36 +00001236#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) // see macosx/Host.mm
Greg Clayton1cb64962011-03-24 04:28:38 +00001237bool
1238Host::GetOSBuildString (std::string &s)
1239{
1240 s.clear();
1241 return false;
1242}
1243
1244bool
1245Host::GetOSKernelDescription (std::string &s)
1246{
1247 s.clear();
1248 return false;
1249}
Johnny Chen8f3d8382011-08-02 20:52:42 +00001250#endif
Greg Clayton1cb64962011-03-24 04:28:38 +00001251
Han Ming Ong84647042012-02-25 01:07:38 +00001252uint32_t
1253Host::GetUserID ()
1254{
1255 return getuid();
1256}
1257
1258uint32_t
1259Host::GetGroupID ()
1260{
1261 return getgid();
1262}
1263
1264uint32_t
1265Host::GetEffectiveUserID ()
1266{
1267 return geteuid();
1268}
1269
1270uint32_t
1271Host::GetEffectiveGroupID ()
1272{
1273 return getegid();
1274}
1275
Daniel Malea25d7eb02013-05-15 17:54:07 +00001276#if !defined (__APPLE__) && !defined(__linux__)
Greg Claytone996fd32011-03-08 22:40:15 +00001277uint32_t
Greg Clayton8b82f082011-04-12 05:54:46 +00001278Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos)
Greg Claytone996fd32011-03-08 22:40:15 +00001279{
1280 process_infos.Clear();
Greg Claytone996fd32011-03-08 22:40:15 +00001281 return process_infos.GetSize();
Greg Clayton2bddd342010-09-07 20:11:56 +00001282}
Daniel Malea25d7eb02013-05-15 17:54:07 +00001283#endif // #if !defined (__APPLE__) && !defined(__linux__)
Greg Clayton2bddd342010-09-07 20:11:56 +00001284
Sylvestre Ledru59405832013-07-01 08:21:36 +00001285#if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) && !defined(__linux__)
Greg Claytone996fd32011-03-08 22:40:15 +00001286bool
Greg Clayton8b82f082011-04-12 05:54:46 +00001287Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
Greg Clayton2bddd342010-09-07 20:11:56 +00001288{
Greg Claytone996fd32011-03-08 22:40:15 +00001289 process_info.Clear();
1290 return false;
Greg Clayton2bddd342010-09-07 20:11:56 +00001291}
Johnny Chen8f3d8382011-08-02 20:52:42 +00001292#endif
Greg Clayton2bddd342010-09-07 20:11:56 +00001293
Matt Kopec085d6ce2013-05-31 22:00:07 +00001294#if !defined(__linux__)
1295bool
1296Host::FindProcessThreads (const lldb::pid_t pid, TidMap &tids_to_attach)
1297{
1298 return false;
1299}
1300#endif
1301
Sean Callananc0a6e062011-10-27 21:22:25 +00001302lldb::TargetSP
1303Host::GetDummyTarget (lldb_private::Debugger &debugger)
1304{
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +00001305 static TargetSP g_dummy_target_sp;
Filipe Cabecinhasb0183452012-05-17 15:48:02 +00001306
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +00001307 // FIXME: Maybe the dummy target should be per-Debugger
1308 if (!g_dummy_target_sp || !g_dummy_target_sp->IsValid())
1309 {
1310 ArchSpec arch(Target::GetDefaultArchitecture());
1311 if (!arch.IsValid())
1312 arch = Host::GetArchitecture ();
1313 Error err = debugger.GetTargetList().CreateTarget(debugger,
Greg Claytona0ca6602012-10-18 16:33:33 +00001314 NULL,
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +00001315 arch.GetTriple().getTriple().c_str(),
1316 false,
1317 NULL,
1318 g_dummy_target_sp);
1319 }
Filipe Cabecinhasb0183452012-05-17 15:48:02 +00001320
Filipe Cabecinhas721ba3f2012-05-19 09:59:08 +00001321 return g_dummy_target_sp;
Sean Callananc0a6e062011-10-27 21:22:25 +00001322}
1323
Greg Claytond1cf11a2012-04-14 01:42:46 +00001324struct ShellInfo
1325{
1326 ShellInfo () :
1327 process_reaped (false),
1328 can_delete (false),
1329 pid (LLDB_INVALID_PROCESS_ID),
1330 signo(-1),
1331 status(-1)
1332 {
1333 }
1334
1335 lldb_private::Predicate<bool> process_reaped;
1336 lldb_private::Predicate<bool> can_delete;
1337 lldb::pid_t pid;
1338 int signo;
1339 int status;
1340};
1341
1342static bool
1343MonitorShellCommand (void *callback_baton,
1344 lldb::pid_t pid,
1345 bool exited, // True if the process did exit
1346 int signo, // Zero for no signal
1347 int status) // Exit value of process if signal is zero
1348{
1349 ShellInfo *shell_info = (ShellInfo *)callback_baton;
1350 shell_info->pid = pid;
1351 shell_info->signo = signo;
1352 shell_info->status = status;
1353 // Let the thread running Host::RunShellCommand() know that the process
1354 // exited and that ShellInfo has been filled in by broadcasting to it
1355 shell_info->process_reaped.SetValue(1, eBroadcastAlways);
1356 // Now wait for a handshake back from that thread running Host::RunShellCommand
1357 // so we know that we can delete shell_info_ptr
1358 shell_info->can_delete.WaitForValueEqualTo(true);
1359 // Sleep a bit to allow the shell_info->can_delete.SetValue() to complete...
1360 usleep(1000);
1361 // Now delete the shell info that was passed into this function
1362 delete shell_info;
1363 return true;
1364}
1365
1366Error
1367Host::RunShellCommand (const char *command,
1368 const char *working_dir,
1369 int *status_ptr,
1370 int *signo_ptr,
1371 std::string *command_output_ptr,
Greg Claytonc8f814d2012-09-27 03:13:55 +00001372 uint32_t timeout_sec,
1373 const char *shell)
Greg Claytond1cf11a2012-04-14 01:42:46 +00001374{
1375 Error error;
1376 ProcessLaunchInfo launch_info;
Greg Claytonc8f814d2012-09-27 03:13:55 +00001377 if (shell && shell[0])
1378 {
1379 // Run the command in a shell
1380 launch_info.SetShell(shell);
1381 launch_info.GetArguments().AppendArgument(command);
1382 const bool localhost = true;
1383 const bool will_debug = false;
1384 const bool first_arg_is_full_shell_command = true;
1385 launch_info.ConvertArgumentsForLaunchingInShell (error,
1386 localhost,
1387 will_debug,
1388 first_arg_is_full_shell_command);
1389 }
1390 else
1391 {
1392 // No shell, just run it
1393 Args args (command);
1394 const bool first_arg_is_executable = true;
Greg Clayton45392552012-10-17 22:57:12 +00001395 launch_info.SetArguments(args, first_arg_is_executable);
Greg Claytonc8f814d2012-09-27 03:13:55 +00001396 }
Greg Claytond1cf11a2012-04-14 01:42:46 +00001397
1398 if (working_dir)
1399 launch_info.SetWorkingDirectory(working_dir);
1400 char output_file_path_buffer[L_tmpnam];
1401 const char *output_file_path = NULL;
1402 if (command_output_ptr)
1403 {
1404 // Create a temporary file to get the stdout/stderr and redirect the
1405 // output of the command into this file. We will later read this file
1406 // if all goes well and fill the data into "command_output_ptr"
1407 output_file_path = ::tmpnam(output_file_path_buffer);
1408 launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
1409 launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_path, false, true);
Greg Claytonc8f814d2012-09-27 03:13:55 +00001410 launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO);
Greg Claytond1cf11a2012-04-14 01:42:46 +00001411 }
1412 else
1413 {
1414 launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false);
1415 launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true);
1416 launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true);
1417 }
1418
1419 // The process monitor callback will delete the 'shell_info_ptr' below...
Greg Clayton7b0992d2013-04-18 22:45:39 +00001420 std::unique_ptr<ShellInfo> shell_info_ap (new ShellInfo());
Greg Claytond1cf11a2012-04-14 01:42:46 +00001421
1422 const bool monitor_signals = false;
1423 launch_info.SetMonitorProcessCallback(MonitorShellCommand, shell_info_ap.get(), monitor_signals);
1424
1425 error = LaunchProcess (launch_info);
1426 const lldb::pid_t pid = launch_info.GetProcessID();
1427 if (pid != LLDB_INVALID_PROCESS_ID)
1428 {
1429 // The process successfully launched, so we can defer ownership of
1430 // "shell_info" to the MonitorShellCommand callback function that will
Greg Claytone01e07b2013-04-18 18:10:51 +00001431 // get called when the process dies. We release the unique pointer as it
Greg Claytond1cf11a2012-04-14 01:42:46 +00001432 // doesn't need to delete the ShellInfo anymore.
1433 ShellInfo *shell_info = shell_info_ap.release();
1434 TimeValue timeout_time(TimeValue::Now());
1435 timeout_time.OffsetWithSeconds(timeout_sec);
1436 bool timed_out = false;
1437 shell_info->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out);
1438 if (timed_out)
1439 {
1440 error.SetErrorString("timed out waiting for shell command to complete");
1441
1442 // Kill the process since it didn't complete withint the timeout specified
1443 ::kill (pid, SIGKILL);
1444 // Wait for the monitor callback to get the message
1445 timeout_time = TimeValue::Now();
1446 timeout_time.OffsetWithSeconds(1);
1447 timed_out = false;
1448 shell_info->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out);
1449 }
1450 else
1451 {
1452 if (status_ptr)
1453 *status_ptr = shell_info->status;
1454
1455 if (signo_ptr)
1456 *signo_ptr = shell_info->signo;
1457
1458 if (command_output_ptr)
1459 {
1460 command_output_ptr->clear();
1461 FileSpec file_spec(output_file_path, File::eOpenOptionRead);
1462 uint64_t file_size = file_spec.GetByteSize();
1463 if (file_size > 0)
1464 {
1465 if (file_size > command_output_ptr->max_size())
1466 {
1467 error.SetErrorStringWithFormat("shell command output is too large to fit into a std::string");
1468 }
1469 else
1470 {
1471 command_output_ptr->resize(file_size);
1472 file_spec.ReadFileContents(0, &((*command_output_ptr)[0]), command_output_ptr->size(), &error);
1473 }
1474 }
1475 }
1476 }
1477 shell_info->can_delete.SetValue(true, eBroadcastAlways);
1478 }
1479 else
1480 {
1481 error.SetErrorString("failed to get process ID");
1482 }
1483
1484 if (output_file_path)
1485 ::unlink (output_file_path);
1486 // Handshake with the monitor thread, or just let it know in advance that
1487 // it can delete "shell_info" in case we timed out and were not able to kill
1488 // the process...
1489 return error;
1490}
1491
1492
Greg Claytone3e3fee2013-02-17 20:46:30 +00001493uint32_t
1494Host::GetNumberCPUS ()
1495{
1496 static uint32_t g_num_cores = UINT32_MAX;
1497 if (g_num_cores == UINT32_MAX)
1498 {
Sylvestre Ledru59405832013-07-01 08:21:36 +00001499#if defined(__APPLE__) or defined (__linux__) or defined (__FreeBSD__) or defined (__FreeBSD_kernel__)
Greg Claytone3e3fee2013-02-17 20:46:30 +00001500
1501 g_num_cores = ::sysconf(_SC_NPROCESSORS_ONLN);
1502
1503#elif defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
1504
1505 // Header file for this might need to be included at the top of this file
1506 SYSTEM_INFO system_info;
1507 ::GetSystemInfo (&system_info);
1508 g_num_cores = system_info.dwNumberOfProcessors;
1509
1510#else
1511
1512 // Assume POSIX support if a host specific case has not been supplied above
1513 g_num_cores = 0;
1514 int num_cores = 0;
1515 size_t num_cores_len = sizeof(num_cores);
Sylvestre Ledru59405832013-07-01 08:21:36 +00001516#ifdef HW_AVAILCPU
Greg Claytone3e3fee2013-02-17 20:46:30 +00001517 int mib[] = { CTL_HW, HW_AVAILCPU };
Sylvestre Ledru59405832013-07-01 08:21:36 +00001518#else
1519 int mib[] = { CTL_HW, HW_NCPU };
1520#endif
Greg Claytone3e3fee2013-02-17 20:46:30 +00001521
1522 /* get the number of CPUs from the system */
1523 if (sysctl(mib, sizeof(mib)/sizeof(int), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0))
1524 {
1525 g_num_cores = num_cores;
1526 }
1527 else
1528 {
1529 mib[1] = HW_NCPU;
1530 num_cores_len = sizeof(num_cores);
1531 if (sysctl(mib, sizeof(mib)/sizeof(int), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0))
1532 {
1533 if (num_cores > 0)
1534 g_num_cores = num_cores;
1535 }
1536 }
1537#endif
1538 }
1539 return g_num_cores;
1540}
1541
1542
Greg Claytond1cf11a2012-04-14 01:42:46 +00001543
Johnny Chen8f3d8382011-08-02 20:52:42 +00001544#if !defined (__APPLE__)
Greg Clayton2bddd342010-09-07 20:11:56 +00001545bool
Greg Clayton3b147632010-12-18 01:54:34 +00001546Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no)
Greg Clayton2bddd342010-09-07 20:11:56 +00001547{
1548 return false;
1549}
Greg Claytondd36def2010-10-17 22:03:32 +00001550
Greg Clayton2d95dc9b2010-11-10 04:57:04 +00001551void
1552Host::SetCrashDescriptionWithFormat (const char *format, ...)
1553{
1554}
1555
1556void
1557Host::SetCrashDescription (const char *description)
1558{
1559}
Greg Claytondd36def2010-10-17 22:03:32 +00001560
1561lldb::pid_t
1562LaunchApplication (const FileSpec &app_file_spec)
1563{
1564 return LLDB_INVALID_PROCESS_ID;
1565}
1566
Greg Clayton2bddd342010-09-07 20:11:56 +00001567#endif