blob: f56c4b7dd748ba8739ea938dca9806d190d7aa5a [file] [log] [blame]
Greg Clayton8f3b21d2010-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
10#include "lldb/Host/Host.h"
11#include "lldb/Core/ArchSpec.h"
12#include "lldb/Core/ConstString.h"
13#include "lldb/Core/Error.h"
Greg Clayton8f3b21d2010-09-07 20:11:56 +000014#include "lldb/Core/Log.h"
15#include "lldb/Core/StreamString.h"
Greg Clayton14ef59f2011-02-08 00:35:34 +000016#include "lldb/Host/Config.h"
Greg Claytoncd548032011-02-01 01:31:41 +000017#include "lldb/Host/Endian.h"
Greg Claytone4b9c1f2011-03-08 22:40:15 +000018#include "lldb/Host/FileSpec.h"
Greg Clayton8f3b21d2010-09-07 20:11:56 +000019#include "lldb/Host/Mutex.h"
Greg Claytone4b9c1f2011-03-08 22:40:15 +000020#include "lldb/Target/Process.h"
Greg Clayton8f3b21d2010-09-07 20:11:56 +000021
Stephen Wilson7f513ba2011-02-24 19:15:09 +000022#include "llvm/Support/Host.h"
Greg Claytone4b9c1f2011-03-08 22:40:15 +000023#include "llvm/Support/MachO.h"
Stephen Wilson7f513ba2011-02-24 19:15:09 +000024
Greg Clayton8f3b21d2010-09-07 20:11:56 +000025#include <dlfcn.h>
26#include <errno.h>
Greg Clayton24bc5d92011-03-30 18:16:51 +000027#include <grp.h>
Stephen Wilsonec2d9782011-04-08 13:36:44 +000028#include <limits.h>
Greg Clayton58e26e02011-03-24 04:28:38 +000029#include <netdb.h>
Greg Clayton24bc5d92011-03-30 18:16:51 +000030#include <pwd.h>
31#include <sys/types.h>
32
Greg Clayton8f3b21d2010-09-07 20:11:56 +000033
34#if defined (__APPLE__)
Greg Clayton14ef59f2011-02-08 00:35:34 +000035
Greg Clayton49ce6822010-10-31 03:01:06 +000036#include <dispatch/dispatch.h>
Greg Clayton8f3b21d2010-09-07 20:11:56 +000037#include <libproc.h>
38#include <mach-o/dyld.h>
Greg Claytonb5f67fb2011-02-05 06:36:35 +000039#include <sys/sysctl.h>
Greg Clayton14ef59f2011-02-08 00:35:34 +000040
Greg Clayton24bc5d92011-03-30 18:16:51 +000041
Greg Clayton0f577c22011-02-07 17:43:47 +000042#elif defined (__linux__)
Greg Clayton14ef59f2011-02-08 00:35:34 +000043
Greg Clayton0f577c22011-02-07 17:43:47 +000044#include <sys/wait.h>
Greg Clayton14ef59f2011-02-08 00:35:34 +000045
Johnny Chen4b663292011-08-02 20:52:42 +000046#elif defined (__FreeBSD__)
47
48#include <sys/wait.h>
49#include <sys/sysctl.h>
50#include <pthread_np.h>
51
Greg Clayton8f3b21d2010-09-07 20:11:56 +000052#endif
53
54using namespace lldb;
55using namespace lldb_private;
56
57struct MonitorInfo
58{
59 lldb::pid_t pid; // The process ID to monitor
60 Host::MonitorChildProcessCallback callback; // The callback function to call when "pid" exits or signals
61 void *callback_baton; // The callback baton for the callback function
62 bool monitor_signals; // If true, call the callback when "pid" gets signaled.
63};
64
65static void *
66MonitorChildProcessThreadFunction (void *arg);
67
68lldb::thread_t
69Host::StartMonitoringChildProcess
70(
71 Host::MonitorChildProcessCallback callback,
72 void *callback_baton,
73 lldb::pid_t pid,
74 bool monitor_signals
75)
76{
77 lldb::thread_t thread = LLDB_INVALID_HOST_THREAD;
78 if (callback)
79 {
80 std::auto_ptr<MonitorInfo> info_ap(new MonitorInfo);
81
82 info_ap->pid = pid;
83 info_ap->callback = callback;
84 info_ap->callback_baton = callback_baton;
85 info_ap->monitor_signals = monitor_signals;
86
87 char thread_name[256];
88 ::snprintf (thread_name, sizeof(thread_name), "<lldb.host.wait4(pid=%i)>", pid);
89 thread = ThreadCreate (thread_name,
90 MonitorChildProcessThreadFunction,
91 info_ap.get(),
92 NULL);
93
Greg Clayton09c81ef2011-02-08 01:34:25 +000094 if (IS_VALID_LLDB_HOST_THREAD(thread))
Greg Clayton8f3b21d2010-09-07 20:11:56 +000095 info_ap.release();
96 }
97 return thread;
98}
99
100//------------------------------------------------------------------
101// Scoped class that will disable thread canceling when it is
102// constructed, and exception safely restore the previous value it
103// when it goes out of scope.
104//------------------------------------------------------------------
105class ScopedPThreadCancelDisabler
106{
107public:
108 ScopedPThreadCancelDisabler()
109 {
110 // Disable the ability for this thread to be cancelled
111 int err = ::pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &m_old_state);
112 if (err != 0)
113 m_old_state = -1;
114
115 }
116
117 ~ScopedPThreadCancelDisabler()
118 {
119 // Restore the ability for this thread to be cancelled to what it
120 // previously was.
121 if (m_old_state != -1)
122 ::pthread_setcancelstate (m_old_state, 0);
123 }
124private:
125 int m_old_state; // Save the old cancelability state.
126};
127
128static void *
129MonitorChildProcessThreadFunction (void *arg)
130{
Greg Claytone005f2c2010-11-06 01:53:30 +0000131 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000132 const char *function = __FUNCTION__;
133 if (log)
134 log->Printf ("%s (arg = %p) thread starting...", function, arg);
135
136 MonitorInfo *info = (MonitorInfo *)arg;
137
138 const Host::MonitorChildProcessCallback callback = info->callback;
139 void * const callback_baton = info->callback_baton;
140 const lldb::pid_t pid = info->pid;
141 const bool monitor_signals = info->monitor_signals;
142
143 delete info;
144
145 int status = -1;
146 const int options = 0;
147 struct rusage *rusage = NULL;
148 while (1)
149 {
Caroline Tice926060e2010-10-29 21:48:37 +0000150 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000151 if (log)
152 log->Printf("%s ::wait4 (pid = %i, &status, options = %i, rusage = %p)...", function, pid, options, rusage);
153
154 // Wait for all child processes
155 ::pthread_testcancel ();
156 const lldb::pid_t wait_pid = ::wait4 (pid, &status, options, rusage);
157 ::pthread_testcancel ();
158
159 if (wait_pid == -1)
160 {
161 if (errno == EINTR)
162 continue;
163 else
164 break;
165 }
166 else if (wait_pid == pid)
167 {
168 bool exited = false;
169 int signal = 0;
170 int exit_status = 0;
171 const char *status_cstr = NULL;
172 if (WIFSTOPPED(status))
173 {
174 signal = WSTOPSIG(status);
175 status_cstr = "STOPPED";
176 }
177 else if (WIFEXITED(status))
178 {
179 exit_status = WEXITSTATUS(status);
180 status_cstr = "EXITED";
181 exited = true;
182 }
183 else if (WIFSIGNALED(status))
184 {
185 signal = WTERMSIG(status);
186 status_cstr = "SIGNALED";
187 exited = true;
188 exit_status = -1;
189 }
190 else
191 {
Johnny Chen2bc9eb32011-07-19 19:48:13 +0000192 status_cstr = "(\?\?\?)";
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000193 }
194
195 // Scope for pthread_cancel_disabler
196 {
197 ScopedPThreadCancelDisabler pthread_cancel_disabler;
198
Caroline Tice926060e2010-10-29 21:48:37 +0000199 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000200 if (log)
201 log->Printf ("%s ::wait4 (pid = %i, &status, options = %i, rusage = %p) => pid = %i, status = 0x%8.8x (%s), signal = %i, exit_state = %i",
202 function,
203 wait_pid,
204 options,
205 rusage,
206 pid,
207 status,
208 status_cstr,
209 signal,
210 exit_status);
211
212 if (exited || (signal != 0 && monitor_signals))
213 {
214 bool callback_return = callback (callback_baton, pid, signal, exit_status);
215
216 // If our process exited, then this thread should exit
217 if (exited)
218 break;
219 // If the callback returns true, it means this process should
220 // exit
221 if (callback_return)
222 break;
223 }
224 }
225 }
226 }
227
Caroline Tice926060e2010-10-29 21:48:37 +0000228 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000229 if (log)
230 log->Printf ("%s (arg = %p) thread exiting...", __FUNCTION__, arg);
231
232 return NULL;
233}
234
235size_t
236Host::GetPageSize()
237{
238 return ::getpagesize();
239}
240
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000241const ArchSpec &
Greg Clayton395fc332011-02-15 21:59:32 +0000242Host::GetArchitecture (SystemDefaultArchitecture arch_kind)
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000243{
Greg Clayton395fc332011-02-15 21:59:32 +0000244 static bool g_supports_32 = false;
245 static bool g_supports_64 = false;
246 static ArchSpec g_host_arch_32;
247 static ArchSpec g_host_arch_64;
248
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000249#if defined (__APPLE__)
Greg Clayton395fc332011-02-15 21:59:32 +0000250
251 // Apple is different in that it can support both 32 and 64 bit executables
252 // in the same operating system running concurrently. Here we detect the
253 // correct host architectures for both 32 and 64 bit including if 64 bit
254 // executables are supported on the system.
255
256 if (g_supports_32 == false && g_supports_64 == false)
257 {
258 // All apple systems support 32 bit execution.
259 g_supports_32 = true;
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000260 uint32_t cputype, cpusubtype;
Greg Clayton395fc332011-02-15 21:59:32 +0000261 uint32_t is_64_bit_capable = false;
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000262 size_t len = sizeof(cputype);
Greg Clayton395fc332011-02-15 21:59:32 +0000263 ArchSpec host_arch;
264 // These will tell us about the kernel architecture, which even on a 64
265 // bit machine can be 32 bit...
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000266 if (::sysctlbyname("hw.cputype", &cputype, &len, NULL, 0) == 0)
267 {
Greg Clayton395fc332011-02-15 21:59:32 +0000268 len = sizeof (cpusubtype);
269 if (::sysctlbyname("hw.cpusubtype", &cpusubtype, &len, NULL, 0) != 0)
270 cpusubtype = CPU_TYPE_ANY;
271
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000272 len = sizeof (is_64_bit_capable);
273 if (::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0) == 0)
274 {
275 if (is_64_bit_capable)
Greg Clayton395fc332011-02-15 21:59:32 +0000276 g_supports_64 = true;
277 }
278
279 if (is_64_bit_capable)
280 {
Greg Clayton75c703d2011-02-16 04:46:07 +0000281#if defined (__i386__) || defined (__x86_64__)
282 if (cpusubtype == CPU_SUBTYPE_486)
283 cpusubtype = CPU_SUBTYPE_I386_ALL;
284#endif
Greg Clayton395fc332011-02-15 21:59:32 +0000285 if (cputype & CPU_ARCH_ABI64)
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000286 {
Greg Clayton395fc332011-02-15 21:59:32 +0000287 // We have a 64 bit kernel on a 64 bit system
Greg Claytonb3448432011-03-24 21:19:54 +0000288 g_host_arch_32.SetArchitecture (eArchTypeMachO, ~(CPU_ARCH_MASK) & cputype, cpusubtype);
289 g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton395fc332011-02-15 21:59:32 +0000290 }
291 else
292 {
293 // We have a 32 bit kernel on a 64 bit system
Greg Claytonb3448432011-03-24 21:19:54 +0000294 g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000295 cputype |= CPU_ARCH_ABI64;
Greg Claytonb3448432011-03-24 21:19:54 +0000296 g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000297 }
298 }
Greg Clayton395fc332011-02-15 21:59:32 +0000299 else
300 {
Greg Claytonb3448432011-03-24 21:19:54 +0000301 g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton395fc332011-02-15 21:59:32 +0000302 g_host_arch_64.Clear();
303 }
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000304 }
Greg Clayton395fc332011-02-15 21:59:32 +0000305 }
306
307#else // #if defined (__APPLE__)
Stephen Wilson7f513ba2011-02-24 19:15:09 +0000308
Greg Clayton395fc332011-02-15 21:59:32 +0000309 if (g_supports_32 == false && g_supports_64 == false)
310 {
Stephen Wilson7f513ba2011-02-24 19:15:09 +0000311 llvm::Triple triple(llvm::sys::getHostTriple());
Greg Clayton395fc332011-02-15 21:59:32 +0000312
Stephen Wilson7f513ba2011-02-24 19:15:09 +0000313 g_host_arch_32.Clear();
314 g_host_arch_64.Clear();
Greg Clayton395fc332011-02-15 21:59:32 +0000315
Stephen Wilson7f513ba2011-02-24 19:15:09 +0000316 switch (triple.getArch())
317 {
318 default:
319 g_host_arch_32.SetTriple(triple);
320 g_supports_32 = true;
321 break;
Greg Clayton395fc332011-02-15 21:59:32 +0000322
Stephen Wilson7f513ba2011-02-24 19:15:09 +0000323 case llvm::Triple::alpha:
324 case llvm::Triple::x86_64:
325 case llvm::Triple::sparcv9:
326 case llvm::Triple::ppc64:
327 case llvm::Triple::systemz:
328 case llvm::Triple::cellspu:
329 g_host_arch_64.SetTriple(triple);
330 g_supports_64 = true;
331 break;
332 }
Greg Clayton4fefe322011-02-17 02:05:38 +0000333
334 g_supports_32 = g_host_arch_32.IsValid();
335 g_supports_64 = g_host_arch_64.IsValid();
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000336 }
Greg Clayton395fc332011-02-15 21:59:32 +0000337
338#endif // #else for #if defined (__APPLE__)
339
340 if (arch_kind == eSystemDefaultArchitecture32)
341 return g_host_arch_32;
342 else if (arch_kind == eSystemDefaultArchitecture64)
343 return g_host_arch_64;
344
345 if (g_supports_64)
346 return g_host_arch_64;
347
348 return g_host_arch_32;
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000349}
350
351const ConstString &
352Host::GetVendorString()
353{
354 static ConstString g_vendor;
355 if (!g_vendor)
356 {
357#if defined (__APPLE__)
358 char ostype[64];
359 size_t len = sizeof(ostype);
360 if (::sysctlbyname("kern.ostype", &ostype, &len, NULL, 0) == 0)
361 g_vendor.SetCString (ostype);
362 else
363 g_vendor.SetCString("apple");
364#elif defined (__linux__)
365 g_vendor.SetCString("gnu");
Johnny Chen4b663292011-08-02 20:52:42 +0000366#elif defined (__FreeBSD__)
367 g_vendor.SetCString("freebsd");
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000368#endif
369 }
370 return g_vendor;
371}
372
373const ConstString &
374Host::GetOSString()
375{
376 static ConstString g_os_string;
377 if (!g_os_string)
378 {
379#if defined (__APPLE__)
380 g_os_string.SetCString("darwin");
381#elif defined (__linux__)
382 g_os_string.SetCString("linux");
Johnny Chen4b663292011-08-02 20:52:42 +0000383#elif defined (__FreeBSD__)
384 g_os_string.SetCString("freebsd");
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000385#endif
386 }
387 return g_os_string;
388}
389
390const ConstString &
391Host::GetTargetTriple()
392{
393 static ConstString g_host_triple;
394 if (!(g_host_triple))
395 {
396 StreamString triple;
397 triple.Printf("%s-%s-%s",
Greg Clayton940b1032011-02-23 00:35:02 +0000398 GetArchitecture().GetArchitectureName(),
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000399 GetVendorString().AsCString(),
400 GetOSString().AsCString());
401
402 std::transform (triple.GetString().begin(),
403 triple.GetString().end(),
404 triple.GetString().begin(),
405 ::tolower);
406
407 g_host_triple.SetCString(triple.GetString().c_str());
408 }
409 return g_host_triple;
410}
411
412lldb::pid_t
413Host::GetCurrentProcessID()
414{
415 return ::getpid();
416}
417
418lldb::tid_t
419Host::GetCurrentThreadID()
420{
421#if defined (__APPLE__)
422 return ::mach_thread_self();
Johnny Chen4b663292011-08-02 20:52:42 +0000423#elif defined(__FreeBSD__)
424 return lldb::tid_t(pthread_getthreadid_np());
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000425#else
426 return lldb::tid_t(pthread_self());
427#endif
428}
429
430const char *
431Host::GetSignalAsCString (int signo)
432{
433 switch (signo)
434 {
435 case SIGHUP: return "SIGHUP"; // 1 hangup
436 case SIGINT: return "SIGINT"; // 2 interrupt
437 case SIGQUIT: return "SIGQUIT"; // 3 quit
438 case SIGILL: return "SIGILL"; // 4 illegal instruction (not reset when caught)
439 case SIGTRAP: return "SIGTRAP"; // 5 trace trap (not reset when caught)
440 case SIGABRT: return "SIGABRT"; // 6 abort()
441#if defined(_POSIX_C_SOURCE)
442 case SIGPOLL: return "SIGPOLL"; // 7 pollable event ([XSR] generated, not supported)
443#else // !_POSIX_C_SOURCE
444 case SIGEMT: return "SIGEMT"; // 7 EMT instruction
445#endif // !_POSIX_C_SOURCE
446 case SIGFPE: return "SIGFPE"; // 8 floating point exception
447 case SIGKILL: return "SIGKILL"; // 9 kill (cannot be caught or ignored)
448 case SIGBUS: return "SIGBUS"; // 10 bus error
449 case SIGSEGV: return "SIGSEGV"; // 11 segmentation violation
450 case SIGSYS: return "SIGSYS"; // 12 bad argument to system call
451 case SIGPIPE: return "SIGPIPE"; // 13 write on a pipe with no one to read it
452 case SIGALRM: return "SIGALRM"; // 14 alarm clock
453 case SIGTERM: return "SIGTERM"; // 15 software termination signal from kill
454 case SIGURG: return "SIGURG"; // 16 urgent condition on IO channel
455 case SIGSTOP: return "SIGSTOP"; // 17 sendable stop signal not from tty
456 case SIGTSTP: return "SIGTSTP"; // 18 stop signal from tty
457 case SIGCONT: return "SIGCONT"; // 19 continue a stopped process
458 case SIGCHLD: return "SIGCHLD"; // 20 to parent on child stop or exit
459 case SIGTTIN: return "SIGTTIN"; // 21 to readers pgrp upon background tty read
460 case SIGTTOU: return "SIGTTOU"; // 22 like TTIN for output if (tp->t_local&LTOSTOP)
461#if !defined(_POSIX_C_SOURCE)
462 case SIGIO: return "SIGIO"; // 23 input/output possible signal
463#endif
464 case SIGXCPU: return "SIGXCPU"; // 24 exceeded CPU time limit
465 case SIGXFSZ: return "SIGXFSZ"; // 25 exceeded file size limit
466 case SIGVTALRM: return "SIGVTALRM"; // 26 virtual time alarm
467 case SIGPROF: return "SIGPROF"; // 27 profiling time alarm
468#if !defined(_POSIX_C_SOURCE)
469 case SIGWINCH: return "SIGWINCH"; // 28 window size changes
470 case SIGINFO: return "SIGINFO"; // 29 information request
471#endif
472 case SIGUSR1: return "SIGUSR1"; // 30 user defined signal 1
473 case SIGUSR2: return "SIGUSR2"; // 31 user defined signal 2
474 default:
475 break;
476 }
477 return NULL;
478}
479
480void
481Host::WillTerminate ()
482{
483}
484
Johnny Chen4b663292011-08-02 20:52:42 +0000485#if !defined (__APPLE__) && !defined (__FreeBSD__) // see macosx/Host.mm
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000486void
487Host::ThreadCreated (const char *thread_name)
488{
489}
Greg Claytonb749a262010-12-03 06:02:24 +0000490
Greg Claytonb749a262010-12-03 06:02:24 +0000491Host::Backtrace (Stream &strm, uint32_t max_frames)
492{
Greg Clayton52fd9842011-02-02 02:24:04 +0000493 // TODO: Is there a way to backtrace the current process on linux? Other systems?
Greg Claytonb749a262010-12-03 06:02:24 +0000494}
495
Greg Clayton638351a2010-12-04 00:10:17 +0000496size_t
497Host::GetEnvironment (StringList &env)
498{
Greg Clayton52fd9842011-02-02 02:24:04 +0000499 // TODO: Is there a way to the host environment for this process on linux? Other systems?
Greg Clayton638351a2010-12-04 00:10:17 +0000500 return 0;
501}
502
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000503#endif
504
505struct HostThreadCreateInfo
506{
507 std::string thread_name;
508 thread_func_t thread_fptr;
509 thread_arg_t thread_arg;
510
511 HostThreadCreateInfo (const char *name, thread_func_t fptr, thread_arg_t arg) :
512 thread_name (name ? name : ""),
513 thread_fptr (fptr),
514 thread_arg (arg)
515 {
516 }
517};
518
519static thread_result_t
520ThreadCreateTrampoline (thread_arg_t arg)
521{
522 HostThreadCreateInfo *info = (HostThreadCreateInfo *)arg;
523 Host::ThreadCreated (info->thread_name.c_str());
524 thread_func_t thread_fptr = info->thread_fptr;
525 thread_arg_t thread_arg = info->thread_arg;
526
Greg Claytone005f2c2010-11-06 01:53:30 +0000527 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000528 if (log)
529 log->Printf("thread created");
530
531 delete info;
532 return thread_fptr (thread_arg);
533}
534
535lldb::thread_t
536Host::ThreadCreate
537(
538 const char *thread_name,
539 thread_func_t thread_fptr,
540 thread_arg_t thread_arg,
541 Error *error
542)
543{
544 lldb::thread_t thread = LLDB_INVALID_HOST_THREAD;
545
546 // Host::ThreadCreateTrampoline will delete this pointer for us.
547 HostThreadCreateInfo *info_ptr = new HostThreadCreateInfo (thread_name, thread_fptr, thread_arg);
548
549 int err = ::pthread_create (&thread, NULL, ThreadCreateTrampoline, info_ptr);
550 if (err == 0)
551 {
552 if (error)
553 error->Clear();
554 return thread;
555 }
556
557 if (error)
558 error->SetError (err, eErrorTypePOSIX);
559
560 return LLDB_INVALID_HOST_THREAD;
561}
562
563bool
564Host::ThreadCancel (lldb::thread_t thread, Error *error)
565{
566 int err = ::pthread_cancel (thread);
567 if (error)
568 error->SetError(err, eErrorTypePOSIX);
569 return err == 0;
570}
571
572bool
573Host::ThreadDetach (lldb::thread_t thread, Error *error)
574{
575 int err = ::pthread_detach (thread);
576 if (error)
577 error->SetError(err, eErrorTypePOSIX);
578 return err == 0;
579}
580
581bool
582Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Error *error)
583{
584 int err = ::pthread_join (thread, thread_result_ptr);
585 if (error)
586 error->SetError(err, eErrorTypePOSIX);
587 return err == 0;
588}
589
590//------------------------------------------------------------------
591// Control access to a static file thread name map using a single
592// static function to avoid a static constructor.
593//------------------------------------------------------------------
594static const char *
595ThreadNameAccessor (bool get, lldb::pid_t pid, lldb::tid_t tid, const char *name)
596{
597 uint64_t pid_tid = ((uint64_t)pid << 32) | (uint64_t)tid;
598
599 static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
600 Mutex::Locker locker(&g_mutex);
601
602 typedef std::map<uint64_t, std::string> thread_name_map;
603 // rdar://problem/8153284
604 // Fixed a crasher where during shutdown, loggings attempted to access the
605 // thread name but the static map instance had already been destructed.
606 // Another approach is to introduce a static guard object which monitors its
607 // own destruction and raises a flag, but this incurs more overhead.
608 static thread_name_map *g_thread_names_ptr = new thread_name_map();
609 thread_name_map &g_thread_names = *g_thread_names_ptr;
610
611 if (get)
612 {
613 // See if the thread name exists in our thread name pool
614 thread_name_map::iterator pos = g_thread_names.find(pid_tid);
615 if (pos != g_thread_names.end())
616 return pos->second.c_str();
617 }
618 else
619 {
620 // Set the thread name
621 g_thread_names[pid_tid] = name;
622 }
623 return NULL;
624}
625
626const char *
627Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid)
628{
629 const char *name = ThreadNameAccessor (true, pid, tid, NULL);
630 if (name == NULL)
631 {
632#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
633 // We currently can only get the name of a thread in the current process.
634 if (pid == Host::GetCurrentProcessID())
635 {
636 char pthread_name[1024];
637 if (::pthread_getname_np (::pthread_from_mach_thread_np (tid), pthread_name, sizeof(pthread_name)) == 0)
638 {
639 if (pthread_name[0])
640 {
641 // Set the thread in our string pool
642 ThreadNameAccessor (false, pid, tid, pthread_name);
643 // Get our copy of the thread name string
644 name = ThreadNameAccessor (true, pid, tid, NULL);
645 }
646 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000647
648 if (name == NULL)
649 {
650 dispatch_queue_t current_queue = ::dispatch_get_current_queue ();
651 if (current_queue != NULL)
652 name = dispatch_queue_get_label (current_queue);
653 }
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000654 }
655#endif
656 }
657 return name;
658}
659
660void
661Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name)
662{
663 lldb::pid_t curr_pid = Host::GetCurrentProcessID();
664 lldb::tid_t curr_tid = Host::GetCurrentThreadID();
665 if (pid == LLDB_INVALID_PROCESS_ID)
666 pid = curr_pid;
667
668 if (tid == LLDB_INVALID_THREAD_ID)
669 tid = curr_tid;
670
671#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
672 // Set the pthread name if possible
673 if (pid == curr_pid && tid == curr_tid)
674 {
675 ::pthread_setname_np (name);
676 }
677#endif
678 ThreadNameAccessor (false, pid, tid, name);
679}
680
681FileSpec
682Host::GetProgramFileSpec ()
683{
684 static FileSpec g_program_filespec;
685 if (!g_program_filespec)
686 {
687#if defined (__APPLE__)
688 char program_fullpath[PATH_MAX];
689 // If DST is NULL, then return the number of bytes needed.
690 uint32_t len = sizeof(program_fullpath);
691 int err = _NSGetExecutablePath (program_fullpath, &len);
692 if (err == 0)
Greg Clayton20fbf8d2011-01-13 01:23:43 +0000693 g_program_filespec.SetFile (program_fullpath, false);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000694 else if (err == -1)
695 {
696 char *large_program_fullpath = (char *)::malloc (len + 1);
697
698 err = _NSGetExecutablePath (large_program_fullpath, &len);
699 if (err == 0)
Greg Clayton20fbf8d2011-01-13 01:23:43 +0000700 g_program_filespec.SetFile (large_program_fullpath, false);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000701
702 ::free (large_program_fullpath);
703 }
704#elif defined (__linux__)
705 char exe_path[PATH_MAX];
Stephen Wilsonf302a9e2011-01-12 04:21:21 +0000706 ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
707 if (len > 0) {
708 exe_path[len] = 0;
Greg Clayton20fbf8d2011-01-13 01:23:43 +0000709 g_program_filespec.SetFile(exe_path, false);
Stephen Wilsonf302a9e2011-01-12 04:21:21 +0000710 }
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000711#elif defined (__FreeBSD__)
712 int exe_path_mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid() };
713 size_t exe_path_size;
714 if (sysctl(exe_path_mib, 4, NULL, &exe_path_size, NULL, 0) == 0)
715 {
Greg Clayton366795e2011-01-13 01:27:55 +0000716 char *exe_path = new char[exe_path_size];
717 if (sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0)
718 g_program_filespec.SetFile(exe_path, false);
719 delete[] exe_path;
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000720 }
721#endif
722 }
723 return g_program_filespec;
724}
725
726FileSpec
727Host::GetModuleFileSpecForHostAddress (const void *host_addr)
728{
729 FileSpec module_filespec;
730 Dl_info info;
731 if (::dladdr (host_addr, &info))
732 {
733 if (info.dli_fname)
Greg Clayton537a7a82010-10-20 20:54:39 +0000734 module_filespec.SetFile(info.dli_fname, true);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000735 }
736 return module_filespec;
737}
738
739#if !defined (__APPLE__) // see Host.mm
740bool
Greg Clayton24b48ff2010-10-17 22:03:32 +0000741Host::ResolveExecutableInBundle (FileSpec &file)
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000742{
Greg Clayton24b48ff2010-10-17 22:03:32 +0000743 return false;
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000744}
745#endif
746
Greg Clayton14ef59f2011-02-08 00:35:34 +0000747// Opaque info that tracks a dynamic library that was loaded
748struct DynamicLibraryInfo
Greg Clayton52fd9842011-02-02 02:24:04 +0000749{
Greg Clayton14ef59f2011-02-08 00:35:34 +0000750 DynamicLibraryInfo (const FileSpec &fs, int o, void *h) :
751 file_spec (fs),
752 open_options (o),
753 handle (h)
754 {
755 }
756
757 const FileSpec file_spec;
758 uint32_t open_options;
759 void * handle;
760};
761
762void *
763Host::DynamicLibraryOpen (const FileSpec &file_spec, uint32_t options, Error &error)
764{
Greg Clayton52fd9842011-02-02 02:24:04 +0000765 char path[PATH_MAX];
766 if (file_spec.GetPath(path, sizeof(path)))
767 {
Greg Clayton14ef59f2011-02-08 00:35:34 +0000768 int mode = 0;
769
770 if (options & eDynamicLibraryOpenOptionLazy)
771 mode |= RTLD_LAZY;
Greg Claytonbf467b02011-02-08 05:24:57 +0000772 else
773 mode |= RTLD_NOW;
774
Greg Clayton14ef59f2011-02-08 00:35:34 +0000775
776 if (options & eDynamicLibraryOpenOptionLocal)
777 mode |= RTLD_LOCAL;
778 else
779 mode |= RTLD_GLOBAL;
780
781#ifdef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED
782 if (options & eDynamicLibraryOpenOptionLimitGetSymbol)
783 mode |= RTLD_FIRST;
Greg Clayton0f577c22011-02-07 17:43:47 +0000784#endif
Greg Clayton14ef59f2011-02-08 00:35:34 +0000785
786 void * opaque = ::dlopen (path, mode);
787
788 if (opaque)
Greg Clayton52fd9842011-02-02 02:24:04 +0000789 {
790 error.Clear();
Greg Clayton14ef59f2011-02-08 00:35:34 +0000791 return new DynamicLibraryInfo (file_spec, options, opaque);
Greg Clayton52fd9842011-02-02 02:24:04 +0000792 }
793 else
794 {
795 error.SetErrorString(::dlerror());
796 }
797 }
798 else
799 {
800 error.SetErrorString("failed to extract path");
801 }
Greg Clayton14ef59f2011-02-08 00:35:34 +0000802 return NULL;
Greg Clayton52fd9842011-02-02 02:24:04 +0000803}
804
805Error
Greg Clayton14ef59f2011-02-08 00:35:34 +0000806Host::DynamicLibraryClose (void *opaque)
Greg Clayton52fd9842011-02-02 02:24:04 +0000807{
808 Error error;
Greg Clayton14ef59f2011-02-08 00:35:34 +0000809 if (opaque == NULL)
Greg Clayton52fd9842011-02-02 02:24:04 +0000810 {
811 error.SetErrorString ("invalid dynamic library handle");
812 }
Greg Clayton14ef59f2011-02-08 00:35:34 +0000813 else
Greg Clayton52fd9842011-02-02 02:24:04 +0000814 {
Greg Clayton14ef59f2011-02-08 00:35:34 +0000815 DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque;
816 if (::dlclose (dylib_info->handle) != 0)
817 {
818 error.SetErrorString(::dlerror());
819 }
820
821 dylib_info->open_options = 0;
822 dylib_info->handle = 0;
823 delete dylib_info;
Greg Clayton52fd9842011-02-02 02:24:04 +0000824 }
825 return error;
826}
827
828void *
Greg Clayton14ef59f2011-02-08 00:35:34 +0000829Host::DynamicLibraryGetSymbol (void *opaque, const char *symbol_name, Error &error)
Greg Clayton52fd9842011-02-02 02:24:04 +0000830{
Greg Clayton14ef59f2011-02-08 00:35:34 +0000831 if (opaque == NULL)
Greg Clayton52fd9842011-02-02 02:24:04 +0000832 {
833 error.SetErrorString ("invalid dynamic library handle");
Greg Clayton52fd9842011-02-02 02:24:04 +0000834 }
Greg Clayton52fd9842011-02-02 02:24:04 +0000835 else
Greg Clayton14ef59f2011-02-08 00:35:34 +0000836 {
837 DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque;
838
839 void *symbol_addr = ::dlsym (dylib_info->handle, symbol_name);
840 if (symbol_addr)
841 {
842#ifndef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED
843 // This host doesn't support limiting searches to this shared library
844 // so we need to verify that the match came from this shared library
845 // if it was requested in the Host::DynamicLibraryOpen() function.
Greg Claytonbf467b02011-02-08 05:24:57 +0000846 if (dylib_info->open_options & eDynamicLibraryOpenOptionLimitGetSymbol)
Greg Clayton14ef59f2011-02-08 00:35:34 +0000847 {
848 FileSpec match_dylib_spec (Host::GetModuleFileSpecForHostAddress (symbol_addr));
849 if (match_dylib_spec != dylib_info->file_spec)
850 {
851 char dylib_path[PATH_MAX];
852 if (dylib_info->file_spec.GetPath (dylib_path, sizeof(dylib_path)))
853 error.SetErrorStringWithFormat ("symbol not found in \"%s\"", dylib_path);
854 else
855 error.SetErrorString ("symbol not found");
856 return NULL;
857 }
858 }
859#endif
860 error.Clear();
861 return symbol_addr;
862 }
863 else
864 {
865 error.SetErrorString(::dlerror());
866 }
867 }
868 return NULL;
Greg Clayton52fd9842011-02-02 02:24:04 +0000869}
Greg Clayton24b48ff2010-10-17 22:03:32 +0000870
871bool
872Host::GetLLDBPath (PathType path_type, FileSpec &file_spec)
873{
Greg Clayton5d187e52011-01-08 20:28:42 +0000874 // To get paths related to LLDB we get the path to the executable that
Greg Clayton24b48ff2010-10-17 22:03:32 +0000875 // contains this function. On MacOSX this will be "LLDB.framework/.../LLDB",
876 // on linux this is assumed to be the "lldb" main executable. If LLDB on
877 // linux is actually in a shared library (lldb.so??) then this function will
878 // need to be modified to "do the right thing".
879
880 switch (path_type)
881 {
882 case ePathTypeLLDBShlibDir:
883 {
884 static ConstString g_lldb_so_dir;
885 if (!g_lldb_so_dir)
886 {
887 FileSpec lldb_file_spec (Host::GetModuleFileSpecForHostAddress ((void *)Host::GetLLDBPath));
888 g_lldb_so_dir = lldb_file_spec.GetDirectory();
889 }
890 file_spec.GetDirectory() = g_lldb_so_dir;
891 return file_spec.GetDirectory();
892 }
893 break;
894
895 case ePathTypeSupportExecutableDir:
896 {
897 static ConstString g_lldb_support_exe_dir;
898 if (!g_lldb_support_exe_dir)
899 {
900 FileSpec lldb_file_spec;
901 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
902 {
903 char raw_path[PATH_MAX];
904 char resolved_path[PATH_MAX];
905 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
906
907#if defined (__APPLE__)
908 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
909 if (framework_pos)
910 {
911 framework_pos += strlen("LLDB.framework");
912 ::strncpy (framework_pos, "/Resources", PATH_MAX - (framework_pos - raw_path));
913 }
914#endif
915 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
916 g_lldb_support_exe_dir.SetCString(resolved_path);
917 }
918 }
919 file_spec.GetDirectory() = g_lldb_support_exe_dir;
920 return file_spec.GetDirectory();
921 }
922 break;
923
924 case ePathTypeHeaderDir:
925 {
926 static ConstString g_lldb_headers_dir;
927 if (!g_lldb_headers_dir)
928 {
929#if defined (__APPLE__)
930 FileSpec lldb_file_spec;
931 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
932 {
933 char raw_path[PATH_MAX];
934 char resolved_path[PATH_MAX];
935 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
936
937 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
938 if (framework_pos)
939 {
940 framework_pos += strlen("LLDB.framework");
941 ::strncpy (framework_pos, "/Headers", PATH_MAX - (framework_pos - raw_path));
942 }
943 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
944 g_lldb_headers_dir.SetCString(resolved_path);
945 }
946#else
Greg Clayton52fd9842011-02-02 02:24:04 +0000947 // TODO: Anyone know how we can determine this for linux? Other systems??
Greg Clayton24b48ff2010-10-17 22:03:32 +0000948 g_lldb_headers_dir.SetCString ("/opt/local/include/lldb");
949#endif
950 }
951 file_spec.GetDirectory() = g_lldb_headers_dir;
952 return file_spec.GetDirectory();
953 }
954 break;
955
956 case ePathTypePythonDir:
957 {
Greg Clayton52fd9842011-02-02 02:24:04 +0000958 // TODO: Anyone know how we can determine this for linux? Other systems?
Greg Clayton24b48ff2010-10-17 22:03:32 +0000959 // For linux we are currently assuming the location of the lldb
960 // binary that contains this function is the directory that will
961 // contain lldb.so, lldb.py and embedded_interpreter.py...
962
963 static ConstString g_lldb_python_dir;
964 if (!g_lldb_python_dir)
965 {
966 FileSpec lldb_file_spec;
967 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
968 {
969 char raw_path[PATH_MAX];
970 char resolved_path[PATH_MAX];
971 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
972
973#if defined (__APPLE__)
974 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
975 if (framework_pos)
976 {
977 framework_pos += strlen("LLDB.framework");
978 ::strncpy (framework_pos, "/Resources/Python", PATH_MAX - (framework_pos - raw_path));
979 }
980#endif
981 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
982 g_lldb_python_dir.SetCString(resolved_path);
983 }
984 }
985 file_spec.GetDirectory() = g_lldb_python_dir;
986 return file_spec.GetDirectory();
987 }
988 break;
989
Greg Clayton52fd9842011-02-02 02:24:04 +0000990 case ePathTypeLLDBSystemPlugins: // System plug-ins directory
991 {
992#if defined (__APPLE__)
993 static ConstString g_lldb_system_plugin_dir;
Greg Clayton58e26e02011-03-24 04:28:38 +0000994 static bool g_lldb_system_plugin_dir_located = false;
995 if (!g_lldb_system_plugin_dir_located)
Greg Clayton52fd9842011-02-02 02:24:04 +0000996 {
Greg Clayton58e26e02011-03-24 04:28:38 +0000997 g_lldb_system_plugin_dir_located = true;
Greg Clayton52fd9842011-02-02 02:24:04 +0000998 FileSpec lldb_file_spec;
999 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
1000 {
1001 char raw_path[PATH_MAX];
1002 char resolved_path[PATH_MAX];
1003 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
1004
1005 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
1006 if (framework_pos)
1007 {
1008 framework_pos += strlen("LLDB.framework");
1009 ::strncpy (framework_pos, "/Resources/PlugIns", PATH_MAX - (framework_pos - raw_path));
Greg Clayton58e26e02011-03-24 04:28:38 +00001010 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
1011 g_lldb_system_plugin_dir.SetCString(resolved_path);
Greg Clayton52fd9842011-02-02 02:24:04 +00001012 }
Greg Clayton58e26e02011-03-24 04:28:38 +00001013 return false;
Greg Clayton52fd9842011-02-02 02:24:04 +00001014 }
1015 }
Greg Clayton58e26e02011-03-24 04:28:38 +00001016
1017 if (g_lldb_system_plugin_dir)
1018 {
1019 file_spec.GetDirectory() = g_lldb_system_plugin_dir;
1020 return true;
1021 }
Greg Clayton52fd9842011-02-02 02:24:04 +00001022#endif
1023 // TODO: where would system LLDB plug-ins be located on linux? Other systems?
1024 return false;
1025 }
1026 break;
1027
1028 case ePathTypeLLDBUserPlugins: // User plug-ins directory
1029 {
1030#if defined (__APPLE__)
1031 static ConstString g_lldb_user_plugin_dir;
1032 if (!g_lldb_user_plugin_dir)
1033 {
1034 char user_plugin_path[PATH_MAX];
1035 if (FileSpec::Resolve ("~/Library/Application Support/LLDB/PlugIns",
1036 user_plugin_path,
1037 sizeof(user_plugin_path)))
1038 {
1039 g_lldb_user_plugin_dir.SetCString(user_plugin_path);
1040 }
1041 }
1042 file_spec.GetDirectory() = g_lldb_user_plugin_dir;
1043 return file_spec.GetDirectory();
1044#endif
1045 // TODO: where would user LLDB plug-ins be located on linux? Other systems?
1046 return false;
1047 }
Greg Clayton24b48ff2010-10-17 22:03:32 +00001048 default:
1049 assert (!"Unhandled PathType");
1050 break;
1051 }
1052
1053 return false;
1054}
1055
Greg Clayton58e26e02011-03-24 04:28:38 +00001056
1057bool
1058Host::GetHostname (std::string &s)
1059{
1060 char hostname[PATH_MAX];
1061 hostname[sizeof(hostname) - 1] = '\0';
1062 if (::gethostname (hostname, sizeof(hostname) - 1) == 0)
1063 {
1064 struct hostent* h = ::gethostbyname (hostname);
1065 if (h)
1066 s.assign (h->h_name);
1067 else
1068 s.assign (hostname);
1069 return true;
1070 }
1071 return false;
1072}
1073
Greg Clayton24bc5d92011-03-30 18:16:51 +00001074const char *
1075Host::GetUserName (uint32_t uid, std::string &user_name)
1076{
1077 struct passwd user_info;
1078 struct passwd *user_info_ptr = &user_info;
1079 char user_buffer[PATH_MAX];
1080 size_t user_buffer_size = sizeof(user_buffer);
1081 if (::getpwuid_r (uid,
1082 &user_info,
1083 user_buffer,
1084 user_buffer_size,
1085 &user_info_ptr) == 0)
1086 {
1087 if (user_info_ptr)
1088 {
1089 user_name.assign (user_info_ptr->pw_name);
1090 return user_name.c_str();
1091 }
1092 }
1093 user_name.clear();
1094 return NULL;
1095}
1096
1097const char *
1098Host::GetGroupName (uint32_t gid, std::string &group_name)
1099{
1100 char group_buffer[PATH_MAX];
1101 size_t group_buffer_size = sizeof(group_buffer);
1102 struct group group_info;
1103 struct group *group_info_ptr = &group_info;
1104 // Try the threadsafe version first
1105 if (::getgrgid_r (gid,
1106 &group_info,
1107 group_buffer,
1108 group_buffer_size,
1109 &group_info_ptr) == 0)
1110 {
1111 if (group_info_ptr)
1112 {
1113 group_name.assign (group_info_ptr->gr_name);
1114 return group_name.c_str();
1115 }
1116 }
1117 else
1118 {
1119 // The threadsafe version isn't currently working
1120 // for me on darwin, but the non-threadsafe version
1121 // is, so I am calling it below.
1122 group_info_ptr = ::getgrgid (gid);
1123 if (group_info_ptr)
1124 {
1125 group_name.assign (group_info_ptr->gr_name);
1126 return group_name.c_str();
1127 }
1128 }
1129 group_name.clear();
1130 return NULL;
1131}
1132
Johnny Chen4b663292011-08-02 20:52:42 +00001133#if !defined (__APPLE__) && !defined (__FreeBSD__) // see macosx/Host.mm
Greg Clayton58e26e02011-03-24 04:28:38 +00001134bool
1135Host::GetOSBuildString (std::string &s)
1136{
1137 s.clear();
1138 return false;
1139}
1140
1141bool
1142Host::GetOSKernelDescription (std::string &s)
1143{
1144 s.clear();
1145 return false;
1146}
Johnny Chen4b663292011-08-02 20:52:42 +00001147#endif
Greg Clayton58e26e02011-03-24 04:28:38 +00001148
Johnny Chen4b663292011-08-02 20:52:42 +00001149#if !defined(__APPLE__)
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001150uint32_t
Greg Claytonb72d0f02011-04-12 05:54:46 +00001151Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos)
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001152{
1153 process_infos.Clear();
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001154 return process_infos.GetSize();
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001155}
Johnny Chen4b663292011-08-02 20:52:42 +00001156#endif
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001157
Johnny Chen4b663292011-08-02 20:52:42 +00001158#if !defined (__APPLE__) && !defined (__FreeBSD__)
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001159bool
Greg Claytonb72d0f02011-04-12 05:54:46 +00001160Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001161{
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001162 process_info.Clear();
1163 return false;
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001164}
Johnny Chen4b663292011-08-02 20:52:42 +00001165#endif
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001166
Johnny Chen4b663292011-08-02 20:52:42 +00001167#if !defined (__APPLE__)
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001168bool
Greg Claytonb73620c2010-12-18 01:54:34 +00001169Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no)
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001170{
1171 return false;
1172}
Greg Clayton24b48ff2010-10-17 22:03:32 +00001173
Greg Claytone98ac252010-11-10 04:57:04 +00001174void
1175Host::SetCrashDescriptionWithFormat (const char *format, ...)
1176{
1177}
1178
1179void
1180Host::SetCrashDescription (const char *description)
1181{
1182}
Greg Clayton24b48ff2010-10-17 22:03:32 +00001183
1184lldb::pid_t
1185LaunchApplication (const FileSpec &app_file_spec)
1186{
1187 return LLDB_INVALID_PROCESS_ID;
1188}
1189
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001190#endif