blob: ebb15cc5ff10fd257e131f4442e890f53e617104 [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"
Sean Callananf35a96c2011-10-27 21:22:25 +000013#include "lldb/Core/Debugger.h"
Greg Clayton8f3b21d2010-09-07 20:11:56 +000014#include "lldb/Core/Error.h"
Greg Clayton8f3b21d2010-09-07 20:11:56 +000015#include "lldb/Core/Log.h"
16#include "lldb/Core/StreamString.h"
Greg Clayton14ef59f2011-02-08 00:35:34 +000017#include "lldb/Host/Config.h"
Greg Claytoncd548032011-02-01 01:31:41 +000018#include "lldb/Host/Endian.h"
Greg Claytone4b9c1f2011-03-08 22:40:15 +000019#include "lldb/Host/FileSpec.h"
Greg Clayton8f3b21d2010-09-07 20:11:56 +000020#include "lldb/Host/Mutex.h"
Greg Claytone4b9c1f2011-03-08 22:40:15 +000021#include "lldb/Target/Process.h"
Sean Callananf35a96c2011-10-27 21:22:25 +000022#include "lldb/Target/TargetList.h"
Greg Clayton8f3b21d2010-09-07 20:11:56 +000023
Stephen Wilson7f513ba2011-02-24 19:15:09 +000024#include "llvm/Support/Host.h"
Greg Claytone4b9c1f2011-03-08 22:40:15 +000025#include "llvm/Support/MachO.h"
Stephen Wilson7f513ba2011-02-24 19:15:09 +000026
Greg Clayton8f3b21d2010-09-07 20:11:56 +000027#include <dlfcn.h>
28#include <errno.h>
Greg Clayton24bc5d92011-03-30 18:16:51 +000029#include <grp.h>
Stephen Wilsonec2d9782011-04-08 13:36:44 +000030#include <limits.h>
Greg Clayton58e26e02011-03-24 04:28:38 +000031#include <netdb.h>
Greg Clayton24bc5d92011-03-30 18:16:51 +000032#include <pwd.h>
33#include <sys/types.h>
34
Greg Clayton8f3b21d2010-09-07 20:11:56 +000035
36#if defined (__APPLE__)
Greg Clayton14ef59f2011-02-08 00:35:34 +000037
Greg Clayton49ce6822010-10-31 03:01:06 +000038#include <dispatch/dispatch.h>
Greg Clayton8f3b21d2010-09-07 20:11:56 +000039#include <libproc.h>
40#include <mach-o/dyld.h>
Greg Claytonb5f67fb2011-02-05 06:36:35 +000041#include <sys/sysctl.h>
Greg Clayton14ef59f2011-02-08 00:35:34 +000042
Greg Clayton24bc5d92011-03-30 18:16:51 +000043
Greg Clayton0f577c22011-02-07 17:43:47 +000044#elif defined (__linux__)
Greg Clayton14ef59f2011-02-08 00:35:34 +000045
Greg Clayton0f577c22011-02-07 17:43:47 +000046#include <sys/wait.h>
Greg Clayton14ef59f2011-02-08 00:35:34 +000047
Johnny Chen4b663292011-08-02 20:52:42 +000048#elif defined (__FreeBSD__)
49
50#include <sys/wait.h>
51#include <sys/sysctl.h>
52#include <pthread_np.h>
53
Greg Clayton8f3b21d2010-09-07 20:11:56 +000054#endif
55
56using namespace lldb;
57using namespace lldb_private;
58
59struct MonitorInfo
60{
61 lldb::pid_t pid; // The process ID to monitor
62 Host::MonitorChildProcessCallback callback; // The callback function to call when "pid" exits or signals
63 void *callback_baton; // The callback baton for the callback function
64 bool monitor_signals; // If true, call the callback when "pid" gets signaled.
65};
66
67static void *
68MonitorChildProcessThreadFunction (void *arg);
69
70lldb::thread_t
71Host::StartMonitoringChildProcess
72(
73 Host::MonitorChildProcessCallback callback,
74 void *callback_baton,
75 lldb::pid_t pid,
76 bool monitor_signals
77)
78{
79 lldb::thread_t thread = LLDB_INVALID_HOST_THREAD;
80 if (callback)
81 {
82 std::auto_ptr<MonitorInfo> info_ap(new MonitorInfo);
83
84 info_ap->pid = pid;
85 info_ap->callback = callback;
86 info_ap->callback_baton = callback_baton;
87 info_ap->monitor_signals = monitor_signals;
88
89 char thread_name[256];
90 ::snprintf (thread_name, sizeof(thread_name), "<lldb.host.wait4(pid=%i)>", pid);
91 thread = ThreadCreate (thread_name,
92 MonitorChildProcessThreadFunction,
93 info_ap.get(),
94 NULL);
95
Greg Clayton09c81ef2011-02-08 01:34:25 +000096 if (IS_VALID_LLDB_HOST_THREAD(thread))
Greg Clayton8f3b21d2010-09-07 20:11:56 +000097 info_ap.release();
98 }
99 return thread;
100}
101
102//------------------------------------------------------------------
103// Scoped class that will disable thread canceling when it is
104// constructed, and exception safely restore the previous value it
105// when it goes out of scope.
106//------------------------------------------------------------------
107class ScopedPThreadCancelDisabler
108{
109public:
110 ScopedPThreadCancelDisabler()
111 {
112 // Disable the ability for this thread to be cancelled
113 int err = ::pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &m_old_state);
114 if (err != 0)
115 m_old_state = -1;
116
117 }
118
119 ~ScopedPThreadCancelDisabler()
120 {
121 // Restore the ability for this thread to be cancelled to what it
122 // previously was.
123 if (m_old_state != -1)
124 ::pthread_setcancelstate (m_old_state, 0);
125 }
126private:
127 int m_old_state; // Save the old cancelability state.
128};
129
130static void *
131MonitorChildProcessThreadFunction (void *arg)
132{
Greg Claytone005f2c2010-11-06 01:53:30 +0000133 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000134 const char *function = __FUNCTION__;
135 if (log)
136 log->Printf ("%s (arg = %p) thread starting...", function, arg);
137
138 MonitorInfo *info = (MonitorInfo *)arg;
139
140 const Host::MonitorChildProcessCallback callback = info->callback;
141 void * const callback_baton = info->callback_baton;
142 const lldb::pid_t pid = info->pid;
143 const bool monitor_signals = info->monitor_signals;
144
145 delete info;
146
147 int status = -1;
148 const int options = 0;
149 struct rusage *rusage = NULL;
150 while (1)
151 {
Caroline Tice926060e2010-10-29 21:48:37 +0000152 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000153 if (log)
154 log->Printf("%s ::wait4 (pid = %i, &status, options = %i, rusage = %p)...", function, pid, options, rusage);
155
156 // Wait for all child processes
157 ::pthread_testcancel ();
158 const lldb::pid_t wait_pid = ::wait4 (pid, &status, options, rusage);
159 ::pthread_testcancel ();
160
161 if (wait_pid == -1)
162 {
163 if (errno == EINTR)
164 continue;
165 else
166 break;
167 }
168 else if (wait_pid == pid)
169 {
170 bool exited = false;
171 int signal = 0;
172 int exit_status = 0;
173 const char *status_cstr = NULL;
174 if (WIFSTOPPED(status))
175 {
176 signal = WSTOPSIG(status);
177 status_cstr = "STOPPED";
178 }
179 else if (WIFEXITED(status))
180 {
181 exit_status = WEXITSTATUS(status);
182 status_cstr = "EXITED";
183 exited = true;
184 }
185 else if (WIFSIGNALED(status))
186 {
187 signal = WTERMSIG(status);
188 status_cstr = "SIGNALED";
189 exited = true;
190 exit_status = -1;
191 }
192 else
193 {
Johnny Chen2bc9eb32011-07-19 19:48:13 +0000194 status_cstr = "(\?\?\?)";
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000195 }
196
197 // Scope for pthread_cancel_disabler
198 {
199 ScopedPThreadCancelDisabler pthread_cancel_disabler;
200
Caroline Tice926060e2010-10-29 21:48:37 +0000201 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000202 if (log)
203 log->Printf ("%s ::wait4 (pid = %i, &status, options = %i, rusage = %p) => pid = %i, status = 0x%8.8x (%s), signal = %i, exit_state = %i",
204 function,
205 wait_pid,
206 options,
207 rusage,
208 pid,
209 status,
210 status_cstr,
211 signal,
212 exit_status);
213
214 if (exited || (signal != 0 && monitor_signals))
215 {
216 bool callback_return = callback (callback_baton, pid, signal, exit_status);
217
218 // If our process exited, then this thread should exit
219 if (exited)
220 break;
221 // If the callback returns true, it means this process should
222 // exit
223 if (callback_return)
224 break;
225 }
226 }
227 }
228 }
229
Caroline Tice926060e2010-10-29 21:48:37 +0000230 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000231 if (log)
232 log->Printf ("%s (arg = %p) thread exiting...", __FUNCTION__, arg);
233
234 return NULL;
235}
236
237size_t
238Host::GetPageSize()
239{
240 return ::getpagesize();
241}
242
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000243const ArchSpec &
Greg Clayton395fc332011-02-15 21:59:32 +0000244Host::GetArchitecture (SystemDefaultArchitecture arch_kind)
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000245{
Greg Clayton395fc332011-02-15 21:59:32 +0000246 static bool g_supports_32 = false;
247 static bool g_supports_64 = false;
248 static ArchSpec g_host_arch_32;
249 static ArchSpec g_host_arch_64;
250
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000251#if defined (__APPLE__)
Greg Clayton395fc332011-02-15 21:59:32 +0000252
253 // Apple is different in that it can support both 32 and 64 bit executables
254 // in the same operating system running concurrently. Here we detect the
255 // correct host architectures for both 32 and 64 bit including if 64 bit
256 // executables are supported on the system.
257
258 if (g_supports_32 == false && g_supports_64 == false)
259 {
260 // All apple systems support 32 bit execution.
261 g_supports_32 = true;
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000262 uint32_t cputype, cpusubtype;
Greg Clayton395fc332011-02-15 21:59:32 +0000263 uint32_t is_64_bit_capable = false;
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000264 size_t len = sizeof(cputype);
Greg Clayton395fc332011-02-15 21:59:32 +0000265 ArchSpec host_arch;
266 // These will tell us about the kernel architecture, which even on a 64
267 // bit machine can be 32 bit...
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000268 if (::sysctlbyname("hw.cputype", &cputype, &len, NULL, 0) == 0)
269 {
Greg Clayton395fc332011-02-15 21:59:32 +0000270 len = sizeof (cpusubtype);
271 if (::sysctlbyname("hw.cpusubtype", &cpusubtype, &len, NULL, 0) != 0)
272 cpusubtype = CPU_TYPE_ANY;
273
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000274 len = sizeof (is_64_bit_capable);
275 if (::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0) == 0)
276 {
277 if (is_64_bit_capable)
Greg Clayton395fc332011-02-15 21:59:32 +0000278 g_supports_64 = true;
279 }
280
281 if (is_64_bit_capable)
282 {
Greg Clayton75c703d2011-02-16 04:46:07 +0000283#if defined (__i386__) || defined (__x86_64__)
284 if (cpusubtype == CPU_SUBTYPE_486)
285 cpusubtype = CPU_SUBTYPE_I386_ALL;
286#endif
Greg Clayton395fc332011-02-15 21:59:32 +0000287 if (cputype & CPU_ARCH_ABI64)
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000288 {
Greg Clayton395fc332011-02-15 21:59:32 +0000289 // We have a 64 bit kernel on a 64 bit system
Greg Claytonb3448432011-03-24 21:19:54 +0000290 g_host_arch_32.SetArchitecture (eArchTypeMachO, ~(CPU_ARCH_MASK) & cputype, cpusubtype);
291 g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton395fc332011-02-15 21:59:32 +0000292 }
293 else
294 {
295 // We have a 32 bit kernel on a 64 bit system
Greg Claytonb3448432011-03-24 21:19:54 +0000296 g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000297 cputype |= CPU_ARCH_ABI64;
Greg Claytonb3448432011-03-24 21:19:54 +0000298 g_host_arch_64.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000299 }
300 }
Greg Clayton395fc332011-02-15 21:59:32 +0000301 else
302 {
Greg Claytonb3448432011-03-24 21:19:54 +0000303 g_host_arch_32.SetArchitecture (eArchTypeMachO, cputype, cpusubtype);
Greg Clayton395fc332011-02-15 21:59:32 +0000304 g_host_arch_64.Clear();
305 }
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000306 }
Greg Clayton395fc332011-02-15 21:59:32 +0000307 }
308
309#else // #if defined (__APPLE__)
Stephen Wilson7f513ba2011-02-24 19:15:09 +0000310
Greg Clayton395fc332011-02-15 21:59:32 +0000311 if (g_supports_32 == false && g_supports_64 == false)
312 {
Stephen Wilson7f513ba2011-02-24 19:15:09 +0000313 llvm::Triple triple(llvm::sys::getHostTriple());
Greg Clayton395fc332011-02-15 21:59:32 +0000314
Stephen Wilson7f513ba2011-02-24 19:15:09 +0000315 g_host_arch_32.Clear();
316 g_host_arch_64.Clear();
Greg Clayton395fc332011-02-15 21:59:32 +0000317
Stephen Wilson7f513ba2011-02-24 19:15:09 +0000318 switch (triple.getArch())
319 {
320 default:
321 g_host_arch_32.SetTriple(triple);
322 g_supports_32 = true;
323 break;
Greg Clayton395fc332011-02-15 21:59:32 +0000324
Stephen Wilson7f513ba2011-02-24 19:15:09 +0000325 case llvm::Triple::alpha:
326 case llvm::Triple::x86_64:
327 case llvm::Triple::sparcv9:
328 case llvm::Triple::ppc64:
329 case llvm::Triple::systemz:
330 case llvm::Triple::cellspu:
331 g_host_arch_64.SetTriple(triple);
332 g_supports_64 = true;
333 break;
334 }
Greg Clayton4fefe322011-02-17 02:05:38 +0000335
336 g_supports_32 = g_host_arch_32.IsValid();
337 g_supports_64 = g_host_arch_64.IsValid();
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000338 }
Greg Clayton395fc332011-02-15 21:59:32 +0000339
340#endif // #else for #if defined (__APPLE__)
341
342 if (arch_kind == eSystemDefaultArchitecture32)
343 return g_host_arch_32;
344 else if (arch_kind == eSystemDefaultArchitecture64)
345 return g_host_arch_64;
346
347 if (g_supports_64)
348 return g_host_arch_64;
349
350 return g_host_arch_32;
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000351}
352
353const ConstString &
354Host::GetVendorString()
355{
356 static ConstString g_vendor;
357 if (!g_vendor)
358 {
359#if defined (__APPLE__)
360 char ostype[64];
361 size_t len = sizeof(ostype);
362 if (::sysctlbyname("kern.ostype", &ostype, &len, NULL, 0) == 0)
363 g_vendor.SetCString (ostype);
364 else
365 g_vendor.SetCString("apple");
366#elif defined (__linux__)
367 g_vendor.SetCString("gnu");
Johnny Chen4b663292011-08-02 20:52:42 +0000368#elif defined (__FreeBSD__)
369 g_vendor.SetCString("freebsd");
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000370#endif
371 }
372 return g_vendor;
373}
374
375const ConstString &
376Host::GetOSString()
377{
378 static ConstString g_os_string;
379 if (!g_os_string)
380 {
381#if defined (__APPLE__)
382 g_os_string.SetCString("darwin");
383#elif defined (__linux__)
384 g_os_string.SetCString("linux");
Johnny Chen4b663292011-08-02 20:52:42 +0000385#elif defined (__FreeBSD__)
386 g_os_string.SetCString("freebsd");
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000387#endif
388 }
389 return g_os_string;
390}
391
392const ConstString &
393Host::GetTargetTriple()
394{
395 static ConstString g_host_triple;
396 if (!(g_host_triple))
397 {
398 StreamString triple;
399 triple.Printf("%s-%s-%s",
Greg Clayton940b1032011-02-23 00:35:02 +0000400 GetArchitecture().GetArchitectureName(),
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000401 GetVendorString().AsCString(),
402 GetOSString().AsCString());
403
404 std::transform (triple.GetString().begin(),
405 triple.GetString().end(),
406 triple.GetString().begin(),
407 ::tolower);
408
409 g_host_triple.SetCString(triple.GetString().c_str());
410 }
411 return g_host_triple;
412}
413
414lldb::pid_t
415Host::GetCurrentProcessID()
416{
417 return ::getpid();
418}
419
420lldb::tid_t
421Host::GetCurrentThreadID()
422{
423#if defined (__APPLE__)
424 return ::mach_thread_self();
Johnny Chen4b663292011-08-02 20:52:42 +0000425#elif defined(__FreeBSD__)
426 return lldb::tid_t(pthread_getthreadid_np());
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000427#else
428 return lldb::tid_t(pthread_self());
429#endif
430}
431
432const char *
433Host::GetSignalAsCString (int signo)
434{
435 switch (signo)
436 {
437 case SIGHUP: return "SIGHUP"; // 1 hangup
438 case SIGINT: return "SIGINT"; // 2 interrupt
439 case SIGQUIT: return "SIGQUIT"; // 3 quit
440 case SIGILL: return "SIGILL"; // 4 illegal instruction (not reset when caught)
441 case SIGTRAP: return "SIGTRAP"; // 5 trace trap (not reset when caught)
442 case SIGABRT: return "SIGABRT"; // 6 abort()
443#if defined(_POSIX_C_SOURCE)
444 case SIGPOLL: return "SIGPOLL"; // 7 pollable event ([XSR] generated, not supported)
445#else // !_POSIX_C_SOURCE
446 case SIGEMT: return "SIGEMT"; // 7 EMT instruction
447#endif // !_POSIX_C_SOURCE
448 case SIGFPE: return "SIGFPE"; // 8 floating point exception
449 case SIGKILL: return "SIGKILL"; // 9 kill (cannot be caught or ignored)
450 case SIGBUS: return "SIGBUS"; // 10 bus error
451 case SIGSEGV: return "SIGSEGV"; // 11 segmentation violation
452 case SIGSYS: return "SIGSYS"; // 12 bad argument to system call
453 case SIGPIPE: return "SIGPIPE"; // 13 write on a pipe with no one to read it
454 case SIGALRM: return "SIGALRM"; // 14 alarm clock
455 case SIGTERM: return "SIGTERM"; // 15 software termination signal from kill
456 case SIGURG: return "SIGURG"; // 16 urgent condition on IO channel
457 case SIGSTOP: return "SIGSTOP"; // 17 sendable stop signal not from tty
458 case SIGTSTP: return "SIGTSTP"; // 18 stop signal from tty
459 case SIGCONT: return "SIGCONT"; // 19 continue a stopped process
460 case SIGCHLD: return "SIGCHLD"; // 20 to parent on child stop or exit
461 case SIGTTIN: return "SIGTTIN"; // 21 to readers pgrp upon background tty read
462 case SIGTTOU: return "SIGTTOU"; // 22 like TTIN for output if (tp->t_local&LTOSTOP)
463#if !defined(_POSIX_C_SOURCE)
464 case SIGIO: return "SIGIO"; // 23 input/output possible signal
465#endif
466 case SIGXCPU: return "SIGXCPU"; // 24 exceeded CPU time limit
467 case SIGXFSZ: return "SIGXFSZ"; // 25 exceeded file size limit
468 case SIGVTALRM: return "SIGVTALRM"; // 26 virtual time alarm
469 case SIGPROF: return "SIGPROF"; // 27 profiling time alarm
470#if !defined(_POSIX_C_SOURCE)
471 case SIGWINCH: return "SIGWINCH"; // 28 window size changes
472 case SIGINFO: return "SIGINFO"; // 29 information request
473#endif
474 case SIGUSR1: return "SIGUSR1"; // 30 user defined signal 1
475 case SIGUSR2: return "SIGUSR2"; // 31 user defined signal 2
476 default:
477 break;
478 }
479 return NULL;
480}
481
482void
483Host::WillTerminate ()
484{
485}
486
Johnny Chen4b663292011-08-02 20:52:42 +0000487#if !defined (__APPLE__) && !defined (__FreeBSD__) // see macosx/Host.mm
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000488void
489Host::ThreadCreated (const char *thread_name)
490{
491}
Greg Claytonb749a262010-12-03 06:02:24 +0000492
Peter Collingbourne5f0559d2011-08-05 00:35:43 +0000493void
Greg Claytonb749a262010-12-03 06:02:24 +0000494Host::Backtrace (Stream &strm, uint32_t max_frames)
495{
Greg Clayton52fd9842011-02-02 02:24:04 +0000496 // TODO: Is there a way to backtrace the current process on linux? Other systems?
Greg Claytonb749a262010-12-03 06:02:24 +0000497}
498
Greg Clayton638351a2010-12-04 00:10:17 +0000499size_t
500Host::GetEnvironment (StringList &env)
501{
Greg Clayton52fd9842011-02-02 02:24:04 +0000502 // TODO: Is there a way to the host environment for this process on linux? Other systems?
Greg Clayton638351a2010-12-04 00:10:17 +0000503 return 0;
504}
505
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000506#endif
507
508struct HostThreadCreateInfo
509{
510 std::string thread_name;
511 thread_func_t thread_fptr;
512 thread_arg_t thread_arg;
513
514 HostThreadCreateInfo (const char *name, thread_func_t fptr, thread_arg_t arg) :
515 thread_name (name ? name : ""),
516 thread_fptr (fptr),
517 thread_arg (arg)
518 {
519 }
520};
521
522static thread_result_t
523ThreadCreateTrampoline (thread_arg_t arg)
524{
525 HostThreadCreateInfo *info = (HostThreadCreateInfo *)arg;
526 Host::ThreadCreated (info->thread_name.c_str());
527 thread_func_t thread_fptr = info->thread_fptr;
528 thread_arg_t thread_arg = info->thread_arg;
529
Greg Claytone005f2c2010-11-06 01:53:30 +0000530 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000531 if (log)
532 log->Printf("thread created");
533
534 delete info;
535 return thread_fptr (thread_arg);
536}
537
538lldb::thread_t
539Host::ThreadCreate
540(
541 const char *thread_name,
542 thread_func_t thread_fptr,
543 thread_arg_t thread_arg,
544 Error *error
545)
546{
547 lldb::thread_t thread = LLDB_INVALID_HOST_THREAD;
548
549 // Host::ThreadCreateTrampoline will delete this pointer for us.
550 HostThreadCreateInfo *info_ptr = new HostThreadCreateInfo (thread_name, thread_fptr, thread_arg);
551
552 int err = ::pthread_create (&thread, NULL, ThreadCreateTrampoline, info_ptr);
553 if (err == 0)
554 {
555 if (error)
556 error->Clear();
557 return thread;
558 }
559
560 if (error)
561 error->SetError (err, eErrorTypePOSIX);
562
563 return LLDB_INVALID_HOST_THREAD;
564}
565
566bool
567Host::ThreadCancel (lldb::thread_t thread, Error *error)
568{
569 int err = ::pthread_cancel (thread);
570 if (error)
571 error->SetError(err, eErrorTypePOSIX);
572 return err == 0;
573}
574
575bool
576Host::ThreadDetach (lldb::thread_t thread, Error *error)
577{
578 int err = ::pthread_detach (thread);
579 if (error)
580 error->SetError(err, eErrorTypePOSIX);
581 return err == 0;
582}
583
584bool
585Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Error *error)
586{
587 int err = ::pthread_join (thread, thread_result_ptr);
588 if (error)
589 error->SetError(err, eErrorTypePOSIX);
590 return err == 0;
591}
592
593//------------------------------------------------------------------
594// Control access to a static file thread name map using a single
595// static function to avoid a static constructor.
596//------------------------------------------------------------------
597static const char *
598ThreadNameAccessor (bool get, lldb::pid_t pid, lldb::tid_t tid, const char *name)
599{
600 uint64_t pid_tid = ((uint64_t)pid << 32) | (uint64_t)tid;
601
602 static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
603 Mutex::Locker locker(&g_mutex);
604
605 typedef std::map<uint64_t, std::string> thread_name_map;
606 // rdar://problem/8153284
607 // Fixed a crasher where during shutdown, loggings attempted to access the
608 // thread name but the static map instance had already been destructed.
609 // Another approach is to introduce a static guard object which monitors its
610 // own destruction and raises a flag, but this incurs more overhead.
611 static thread_name_map *g_thread_names_ptr = new thread_name_map();
612 thread_name_map &g_thread_names = *g_thread_names_ptr;
613
614 if (get)
615 {
616 // See if the thread name exists in our thread name pool
617 thread_name_map::iterator pos = g_thread_names.find(pid_tid);
618 if (pos != g_thread_names.end())
619 return pos->second.c_str();
620 }
621 else
622 {
623 // Set the thread name
624 g_thread_names[pid_tid] = name;
625 }
626 return NULL;
627}
628
629const char *
630Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid)
631{
632 const char *name = ThreadNameAccessor (true, pid, tid, NULL);
633 if (name == NULL)
634 {
635#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
636 // We currently can only get the name of a thread in the current process.
637 if (pid == Host::GetCurrentProcessID())
638 {
639 char pthread_name[1024];
640 if (::pthread_getname_np (::pthread_from_mach_thread_np (tid), pthread_name, sizeof(pthread_name)) == 0)
641 {
642 if (pthread_name[0])
643 {
644 // Set the thread in our string pool
645 ThreadNameAccessor (false, pid, tid, pthread_name);
646 // Get our copy of the thread name string
647 name = ThreadNameAccessor (true, pid, tid, NULL);
648 }
649 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000650
651 if (name == NULL)
652 {
653 dispatch_queue_t current_queue = ::dispatch_get_current_queue ();
654 if (current_queue != NULL)
655 name = dispatch_queue_get_label (current_queue);
656 }
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000657 }
658#endif
659 }
660 return name;
661}
662
663void
664Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name)
665{
666 lldb::pid_t curr_pid = Host::GetCurrentProcessID();
667 lldb::tid_t curr_tid = Host::GetCurrentThreadID();
668 if (pid == LLDB_INVALID_PROCESS_ID)
669 pid = curr_pid;
670
671 if (tid == LLDB_INVALID_THREAD_ID)
672 tid = curr_tid;
673
674#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
675 // Set the pthread name if possible
676 if (pid == curr_pid && tid == curr_tid)
677 {
678 ::pthread_setname_np (name);
679 }
680#endif
681 ThreadNameAccessor (false, pid, tid, name);
682}
683
684FileSpec
685Host::GetProgramFileSpec ()
686{
687 static FileSpec g_program_filespec;
688 if (!g_program_filespec)
689 {
690#if defined (__APPLE__)
691 char program_fullpath[PATH_MAX];
692 // If DST is NULL, then return the number of bytes needed.
693 uint32_t len = sizeof(program_fullpath);
694 int err = _NSGetExecutablePath (program_fullpath, &len);
695 if (err == 0)
Greg Clayton20fbf8d2011-01-13 01:23:43 +0000696 g_program_filespec.SetFile (program_fullpath, false);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000697 else if (err == -1)
698 {
699 char *large_program_fullpath = (char *)::malloc (len + 1);
700
701 err = _NSGetExecutablePath (large_program_fullpath, &len);
702 if (err == 0)
Greg Clayton20fbf8d2011-01-13 01:23:43 +0000703 g_program_filespec.SetFile (large_program_fullpath, false);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000704
705 ::free (large_program_fullpath);
706 }
707#elif defined (__linux__)
708 char exe_path[PATH_MAX];
Stephen Wilsonf302a9e2011-01-12 04:21:21 +0000709 ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
710 if (len > 0) {
711 exe_path[len] = 0;
Greg Clayton20fbf8d2011-01-13 01:23:43 +0000712 g_program_filespec.SetFile(exe_path, false);
Stephen Wilsonf302a9e2011-01-12 04:21:21 +0000713 }
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000714#elif defined (__FreeBSD__)
715 int exe_path_mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid() };
716 size_t exe_path_size;
717 if (sysctl(exe_path_mib, 4, NULL, &exe_path_size, NULL, 0) == 0)
718 {
Greg Clayton366795e2011-01-13 01:27:55 +0000719 char *exe_path = new char[exe_path_size];
720 if (sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0)
721 g_program_filespec.SetFile(exe_path, false);
722 delete[] exe_path;
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000723 }
724#endif
725 }
726 return g_program_filespec;
727}
728
729FileSpec
730Host::GetModuleFileSpecForHostAddress (const void *host_addr)
731{
732 FileSpec module_filespec;
733 Dl_info info;
734 if (::dladdr (host_addr, &info))
735 {
736 if (info.dli_fname)
Greg Clayton537a7a82010-10-20 20:54:39 +0000737 module_filespec.SetFile(info.dli_fname, true);
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000738 }
739 return module_filespec;
740}
741
742#if !defined (__APPLE__) // see Host.mm
743bool
Greg Clayton24b48ff2010-10-17 22:03:32 +0000744Host::ResolveExecutableInBundle (FileSpec &file)
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000745{
Greg Clayton24b48ff2010-10-17 22:03:32 +0000746 return false;
Greg Clayton8f3b21d2010-09-07 20:11:56 +0000747}
748#endif
749
Greg Clayton14ef59f2011-02-08 00:35:34 +0000750// Opaque info that tracks a dynamic library that was loaded
751struct DynamicLibraryInfo
Greg Clayton52fd9842011-02-02 02:24:04 +0000752{
Greg Clayton14ef59f2011-02-08 00:35:34 +0000753 DynamicLibraryInfo (const FileSpec &fs, int o, void *h) :
754 file_spec (fs),
755 open_options (o),
756 handle (h)
757 {
758 }
759
760 const FileSpec file_spec;
761 uint32_t open_options;
762 void * handle;
763};
764
765void *
766Host::DynamicLibraryOpen (const FileSpec &file_spec, uint32_t options, Error &error)
767{
Greg Clayton52fd9842011-02-02 02:24:04 +0000768 char path[PATH_MAX];
769 if (file_spec.GetPath(path, sizeof(path)))
770 {
Greg Clayton14ef59f2011-02-08 00:35:34 +0000771 int mode = 0;
772
773 if (options & eDynamicLibraryOpenOptionLazy)
774 mode |= RTLD_LAZY;
Greg Claytonbf467b02011-02-08 05:24:57 +0000775 else
776 mode |= RTLD_NOW;
777
Greg Clayton14ef59f2011-02-08 00:35:34 +0000778
779 if (options & eDynamicLibraryOpenOptionLocal)
780 mode |= RTLD_LOCAL;
781 else
782 mode |= RTLD_GLOBAL;
783
784#ifdef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED
785 if (options & eDynamicLibraryOpenOptionLimitGetSymbol)
786 mode |= RTLD_FIRST;
Greg Clayton0f577c22011-02-07 17:43:47 +0000787#endif
Greg Clayton14ef59f2011-02-08 00:35:34 +0000788
789 void * opaque = ::dlopen (path, mode);
790
791 if (opaque)
Greg Clayton52fd9842011-02-02 02:24:04 +0000792 {
793 error.Clear();
Greg Clayton14ef59f2011-02-08 00:35:34 +0000794 return new DynamicLibraryInfo (file_spec, options, opaque);
Greg Clayton52fd9842011-02-02 02:24:04 +0000795 }
796 else
797 {
798 error.SetErrorString(::dlerror());
799 }
800 }
801 else
802 {
803 error.SetErrorString("failed to extract path");
804 }
Greg Clayton14ef59f2011-02-08 00:35:34 +0000805 return NULL;
Greg Clayton52fd9842011-02-02 02:24:04 +0000806}
807
808Error
Greg Clayton14ef59f2011-02-08 00:35:34 +0000809Host::DynamicLibraryClose (void *opaque)
Greg Clayton52fd9842011-02-02 02:24:04 +0000810{
811 Error error;
Greg Clayton14ef59f2011-02-08 00:35:34 +0000812 if (opaque == NULL)
Greg Clayton52fd9842011-02-02 02:24:04 +0000813 {
814 error.SetErrorString ("invalid dynamic library handle");
815 }
Greg Clayton14ef59f2011-02-08 00:35:34 +0000816 else
Greg Clayton52fd9842011-02-02 02:24:04 +0000817 {
Greg Clayton14ef59f2011-02-08 00:35:34 +0000818 DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque;
819 if (::dlclose (dylib_info->handle) != 0)
820 {
821 error.SetErrorString(::dlerror());
822 }
823
824 dylib_info->open_options = 0;
825 dylib_info->handle = 0;
826 delete dylib_info;
Greg Clayton52fd9842011-02-02 02:24:04 +0000827 }
828 return error;
829}
830
831void *
Greg Clayton14ef59f2011-02-08 00:35:34 +0000832Host::DynamicLibraryGetSymbol (void *opaque, const char *symbol_name, Error &error)
Greg Clayton52fd9842011-02-02 02:24:04 +0000833{
Greg Clayton14ef59f2011-02-08 00:35:34 +0000834 if (opaque == NULL)
Greg Clayton52fd9842011-02-02 02:24:04 +0000835 {
836 error.SetErrorString ("invalid dynamic library handle");
Greg Clayton52fd9842011-02-02 02:24:04 +0000837 }
Greg Clayton52fd9842011-02-02 02:24:04 +0000838 else
Greg Clayton14ef59f2011-02-08 00:35:34 +0000839 {
840 DynamicLibraryInfo *dylib_info = (DynamicLibraryInfo *) opaque;
841
842 void *symbol_addr = ::dlsym (dylib_info->handle, symbol_name);
843 if (symbol_addr)
844 {
845#ifndef LLDB_CONFIG_DLOPEN_RTLD_FIRST_SUPPORTED
846 // This host doesn't support limiting searches to this shared library
847 // so we need to verify that the match came from this shared library
848 // if it was requested in the Host::DynamicLibraryOpen() function.
Greg Claytonbf467b02011-02-08 05:24:57 +0000849 if (dylib_info->open_options & eDynamicLibraryOpenOptionLimitGetSymbol)
Greg Clayton14ef59f2011-02-08 00:35:34 +0000850 {
851 FileSpec match_dylib_spec (Host::GetModuleFileSpecForHostAddress (symbol_addr));
852 if (match_dylib_spec != dylib_info->file_spec)
853 {
854 char dylib_path[PATH_MAX];
855 if (dylib_info->file_spec.GetPath (dylib_path, sizeof(dylib_path)))
856 error.SetErrorStringWithFormat ("symbol not found in \"%s\"", dylib_path);
857 else
858 error.SetErrorString ("symbol not found");
859 return NULL;
860 }
861 }
862#endif
863 error.Clear();
864 return symbol_addr;
865 }
866 else
867 {
868 error.SetErrorString(::dlerror());
869 }
870 }
871 return NULL;
Greg Clayton52fd9842011-02-02 02:24:04 +0000872}
Greg Clayton24b48ff2010-10-17 22:03:32 +0000873
874bool
875Host::GetLLDBPath (PathType path_type, FileSpec &file_spec)
876{
Greg Clayton5d187e52011-01-08 20:28:42 +0000877 // To get paths related to LLDB we get the path to the executable that
Greg Clayton24b48ff2010-10-17 22:03:32 +0000878 // contains this function. On MacOSX this will be "LLDB.framework/.../LLDB",
879 // on linux this is assumed to be the "lldb" main executable. If LLDB on
880 // linux is actually in a shared library (lldb.so??) then this function will
881 // need to be modified to "do the right thing".
882
883 switch (path_type)
884 {
885 case ePathTypeLLDBShlibDir:
886 {
887 static ConstString g_lldb_so_dir;
888 if (!g_lldb_so_dir)
889 {
890 FileSpec lldb_file_spec (Host::GetModuleFileSpecForHostAddress ((void *)Host::GetLLDBPath));
891 g_lldb_so_dir = lldb_file_spec.GetDirectory();
892 }
893 file_spec.GetDirectory() = g_lldb_so_dir;
894 return file_spec.GetDirectory();
895 }
896 break;
897
898 case ePathTypeSupportExecutableDir:
899 {
900 static ConstString g_lldb_support_exe_dir;
901 if (!g_lldb_support_exe_dir)
902 {
903 FileSpec lldb_file_spec;
904 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
905 {
906 char raw_path[PATH_MAX];
907 char resolved_path[PATH_MAX];
908 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
909
910#if defined (__APPLE__)
911 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
912 if (framework_pos)
913 {
914 framework_pos += strlen("LLDB.framework");
915 ::strncpy (framework_pos, "/Resources", PATH_MAX - (framework_pos - raw_path));
916 }
917#endif
918 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
919 g_lldb_support_exe_dir.SetCString(resolved_path);
920 }
921 }
922 file_spec.GetDirectory() = g_lldb_support_exe_dir;
923 return file_spec.GetDirectory();
924 }
925 break;
926
927 case ePathTypeHeaderDir:
928 {
929 static ConstString g_lldb_headers_dir;
930 if (!g_lldb_headers_dir)
931 {
932#if defined (__APPLE__)
933 FileSpec lldb_file_spec;
934 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
935 {
936 char raw_path[PATH_MAX];
937 char resolved_path[PATH_MAX];
938 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
939
940 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
941 if (framework_pos)
942 {
943 framework_pos += strlen("LLDB.framework");
944 ::strncpy (framework_pos, "/Headers", PATH_MAX - (framework_pos - raw_path));
945 }
946 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
947 g_lldb_headers_dir.SetCString(resolved_path);
948 }
949#else
Greg Clayton52fd9842011-02-02 02:24:04 +0000950 // TODO: Anyone know how we can determine this for linux? Other systems??
Greg Clayton24b48ff2010-10-17 22:03:32 +0000951 g_lldb_headers_dir.SetCString ("/opt/local/include/lldb");
952#endif
953 }
954 file_spec.GetDirectory() = g_lldb_headers_dir;
955 return file_spec.GetDirectory();
956 }
957 break;
958
959 case ePathTypePythonDir:
960 {
Greg Clayton52fd9842011-02-02 02:24:04 +0000961 // TODO: Anyone know how we can determine this for linux? Other systems?
Greg Clayton24b48ff2010-10-17 22:03:32 +0000962 // For linux we are currently assuming the location of the lldb
963 // binary that contains this function is the directory that will
964 // contain lldb.so, lldb.py and embedded_interpreter.py...
965
966 static ConstString g_lldb_python_dir;
967 if (!g_lldb_python_dir)
968 {
969 FileSpec lldb_file_spec;
970 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
971 {
972 char raw_path[PATH_MAX];
973 char resolved_path[PATH_MAX];
974 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
975
976#if defined (__APPLE__)
977 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
978 if (framework_pos)
979 {
980 framework_pos += strlen("LLDB.framework");
981 ::strncpy (framework_pos, "/Resources/Python", PATH_MAX - (framework_pos - raw_path));
982 }
983#endif
984 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
985 g_lldb_python_dir.SetCString(resolved_path);
986 }
987 }
988 file_spec.GetDirectory() = g_lldb_python_dir;
989 return file_spec.GetDirectory();
990 }
991 break;
992
Greg Clayton52fd9842011-02-02 02:24:04 +0000993 case ePathTypeLLDBSystemPlugins: // System plug-ins directory
994 {
995#if defined (__APPLE__)
996 static ConstString g_lldb_system_plugin_dir;
Greg Clayton58e26e02011-03-24 04:28:38 +0000997 static bool g_lldb_system_plugin_dir_located = false;
998 if (!g_lldb_system_plugin_dir_located)
Greg Clayton52fd9842011-02-02 02:24:04 +0000999 {
Greg Clayton58e26e02011-03-24 04:28:38 +00001000 g_lldb_system_plugin_dir_located = true;
Greg Clayton52fd9842011-02-02 02:24:04 +00001001 FileSpec lldb_file_spec;
1002 if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec))
1003 {
1004 char raw_path[PATH_MAX];
1005 char resolved_path[PATH_MAX];
1006 lldb_file_spec.GetPath(raw_path, sizeof(raw_path));
1007
1008 char *framework_pos = ::strstr (raw_path, "LLDB.framework");
1009 if (framework_pos)
1010 {
1011 framework_pos += strlen("LLDB.framework");
1012 ::strncpy (framework_pos, "/Resources/PlugIns", PATH_MAX - (framework_pos - raw_path));
Greg Clayton58e26e02011-03-24 04:28:38 +00001013 FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path));
1014 g_lldb_system_plugin_dir.SetCString(resolved_path);
Greg Clayton52fd9842011-02-02 02:24:04 +00001015 }
Greg Clayton58e26e02011-03-24 04:28:38 +00001016 return false;
Greg Clayton52fd9842011-02-02 02:24:04 +00001017 }
1018 }
Greg Clayton58e26e02011-03-24 04:28:38 +00001019
1020 if (g_lldb_system_plugin_dir)
1021 {
1022 file_spec.GetDirectory() = g_lldb_system_plugin_dir;
1023 return true;
1024 }
Greg Clayton52fd9842011-02-02 02:24:04 +00001025#endif
1026 // TODO: where would system LLDB plug-ins be located on linux? Other systems?
1027 return false;
1028 }
1029 break;
1030
1031 case ePathTypeLLDBUserPlugins: // User plug-ins directory
1032 {
1033#if defined (__APPLE__)
1034 static ConstString g_lldb_user_plugin_dir;
1035 if (!g_lldb_user_plugin_dir)
1036 {
1037 char user_plugin_path[PATH_MAX];
1038 if (FileSpec::Resolve ("~/Library/Application Support/LLDB/PlugIns",
1039 user_plugin_path,
1040 sizeof(user_plugin_path)))
1041 {
1042 g_lldb_user_plugin_dir.SetCString(user_plugin_path);
1043 }
1044 }
1045 file_spec.GetDirectory() = g_lldb_user_plugin_dir;
1046 return file_spec.GetDirectory();
1047#endif
1048 // TODO: where would user LLDB plug-ins be located on linux? Other systems?
1049 return false;
1050 }
Greg Clayton24b48ff2010-10-17 22:03:32 +00001051 default:
1052 assert (!"Unhandled PathType");
1053 break;
1054 }
1055
1056 return false;
1057}
1058
Greg Clayton58e26e02011-03-24 04:28:38 +00001059
1060bool
1061Host::GetHostname (std::string &s)
1062{
1063 char hostname[PATH_MAX];
1064 hostname[sizeof(hostname) - 1] = '\0';
1065 if (::gethostname (hostname, sizeof(hostname) - 1) == 0)
1066 {
1067 struct hostent* h = ::gethostbyname (hostname);
1068 if (h)
1069 s.assign (h->h_name);
1070 else
1071 s.assign (hostname);
1072 return true;
1073 }
1074 return false;
1075}
1076
Greg Clayton24bc5d92011-03-30 18:16:51 +00001077const char *
1078Host::GetUserName (uint32_t uid, std::string &user_name)
1079{
1080 struct passwd user_info;
1081 struct passwd *user_info_ptr = &user_info;
1082 char user_buffer[PATH_MAX];
1083 size_t user_buffer_size = sizeof(user_buffer);
1084 if (::getpwuid_r (uid,
1085 &user_info,
1086 user_buffer,
1087 user_buffer_size,
1088 &user_info_ptr) == 0)
1089 {
1090 if (user_info_ptr)
1091 {
1092 user_name.assign (user_info_ptr->pw_name);
1093 return user_name.c_str();
1094 }
1095 }
1096 user_name.clear();
1097 return NULL;
1098}
1099
1100const char *
1101Host::GetGroupName (uint32_t gid, std::string &group_name)
1102{
1103 char group_buffer[PATH_MAX];
1104 size_t group_buffer_size = sizeof(group_buffer);
1105 struct group group_info;
1106 struct group *group_info_ptr = &group_info;
1107 // Try the threadsafe version first
1108 if (::getgrgid_r (gid,
1109 &group_info,
1110 group_buffer,
1111 group_buffer_size,
1112 &group_info_ptr) == 0)
1113 {
1114 if (group_info_ptr)
1115 {
1116 group_name.assign (group_info_ptr->gr_name);
1117 return group_name.c_str();
1118 }
1119 }
1120 else
1121 {
1122 // The threadsafe version isn't currently working
1123 // for me on darwin, but the non-threadsafe version
1124 // is, so I am calling it below.
1125 group_info_ptr = ::getgrgid (gid);
1126 if (group_info_ptr)
1127 {
1128 group_name.assign (group_info_ptr->gr_name);
1129 return group_name.c_str();
1130 }
1131 }
1132 group_name.clear();
1133 return NULL;
1134}
1135
Johnny Chen4b663292011-08-02 20:52:42 +00001136#if !defined (__APPLE__) && !defined (__FreeBSD__) // see macosx/Host.mm
Greg Clayton58e26e02011-03-24 04:28:38 +00001137bool
1138Host::GetOSBuildString (std::string &s)
1139{
1140 s.clear();
1141 return false;
1142}
1143
1144bool
1145Host::GetOSKernelDescription (std::string &s)
1146{
1147 s.clear();
1148 return false;
1149}
Johnny Chen4b663292011-08-02 20:52:42 +00001150#endif
Greg Clayton58e26e02011-03-24 04:28:38 +00001151
Johnny Chen4b663292011-08-02 20:52:42 +00001152#if !defined(__APPLE__)
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001153uint32_t
Greg Claytonb72d0f02011-04-12 05:54:46 +00001154Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos)
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001155{
1156 process_infos.Clear();
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001157 return process_infos.GetSize();
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001158}
Johnny Chen4b663292011-08-02 20:52:42 +00001159#endif
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001160
Johnny Chen4b663292011-08-02 20:52:42 +00001161#if !defined (__APPLE__) && !defined (__FreeBSD__)
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001162bool
Greg Claytonb72d0f02011-04-12 05:54:46 +00001163Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info)
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001164{
Greg Claytone4b9c1f2011-03-08 22:40:15 +00001165 process_info.Clear();
1166 return false;
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001167}
Johnny Chen4b663292011-08-02 20:52:42 +00001168#endif
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001169
Sean Callananf35a96c2011-10-27 21:22:25 +00001170lldb::TargetSP
1171Host::GetDummyTarget (lldb_private::Debugger &debugger)
1172{
1173 static TargetSP dummy_target;
1174
1175 if (!dummy_target)
1176 {
1177 Error err = debugger.GetTargetList().CreateTarget(debugger,
1178 FileSpec(),
1179 Host::GetTargetTriple().AsCString(),
1180 false,
1181 NULL,
1182 dummy_target);
1183 }
1184
1185 return dummy_target;
1186}
1187
Johnny Chen4b663292011-08-02 20:52:42 +00001188#if !defined (__APPLE__)
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001189bool
Greg Claytonb73620c2010-12-18 01:54:34 +00001190Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no)
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001191{
1192 return false;
1193}
Greg Clayton24b48ff2010-10-17 22:03:32 +00001194
Greg Claytone98ac252010-11-10 04:57:04 +00001195void
1196Host::SetCrashDescriptionWithFormat (const char *format, ...)
1197{
1198}
1199
1200void
1201Host::SetCrashDescription (const char *description)
1202{
1203}
Greg Clayton24b48ff2010-10-17 22:03:32 +00001204
1205lldb::pid_t
1206LaunchApplication (const FileSpec &app_file_spec)
1207{
1208 return LLDB_INVALID_PROCESS_ID;
1209}
1210
Greg Clayton8f3b21d2010-09-07 20:11:56 +00001211#endif