Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 1 | //===-- 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 Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 12 | // C includes |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 13 | #include <errno.h> |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 14 | #include <limits.h> |
Greg Clayton | 23f8c95 | 2014-03-24 23:10:19 +0000 | [diff] [blame] | 15 | #include <stdlib.h> |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 16 | #include <sys/types.h> |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 17 | #ifdef _WIN32 |
| 18 | #include "lldb/Host/windows/windows.h" |
| 19 | #include <winsock2.h> |
Hafiz Abid Qadeer | a667875 | 2014-03-10 22:31:39 +0000 | [diff] [blame] | 20 | #include <ws2tcpip.h> |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 21 | #else |
Deepak Panickal | b36da43 | 2014-01-13 14:55:15 +0000 | [diff] [blame] | 22 | #include <unistd.h> |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 23 | #include <dlfcn.h> |
| 24 | #include <grp.h> |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 25 | #include <netdb.h> |
| 26 | #include <pwd.h> |
Jason Molenda | 4a4b5dc | 2013-11-21 02:45:55 +0000 | [diff] [blame] | 27 | #include <sys/stat.h> |
Sylvestre Ledru | 785ee47 | 2013-09-05 15:39:09 +0000 | [diff] [blame] | 28 | #endif |
| 29 | |
| 30 | #if !defined (__GNU__) && !defined (_WIN32) |
| 31 | // Does not exist under GNU/HURD or Windows |
Ed Maste | f2b0162 | 2013-06-28 12:35:08 +0000 | [diff] [blame] | 32 | #include <sys/sysctl.h> |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 33 | #endif |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 34 | |
| 35 | #if defined (__APPLE__) |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 36 | #include <mach/mach_port.h> |
Charles Davis | 510938e | 2013-08-27 05:04:57 +0000 | [diff] [blame] | 37 | #include <mach/mach_init.h> |
| 38 | #include <mach-o/dyld.h> |
Ed Maste | 8b006c6 | 2013-06-25 18:58:11 +0000 | [diff] [blame] | 39 | #endif |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 40 | |
Joerg Sonnenberger | a53b359 | 2014-05-02 19:09:40 +0000 | [diff] [blame] | 41 | #if defined (__linux__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) || defined(__NetBSD__) |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 42 | #include <spawn.h> |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 43 | #include <sys/wait.h> |
Michael Sartain | c205243 | 2013-08-01 18:51:08 +0000 | [diff] [blame] | 44 | #include <sys/syscall.h> |
Ed Maste | 8b006c6 | 2013-06-25 18:58:11 +0000 | [diff] [blame] | 45 | #endif |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 46 | |
Ed Maste | 8b006c6 | 2013-06-25 18:58:11 +0000 | [diff] [blame] | 47 | #if defined (__FreeBSD__) |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 48 | #include <pthread_np.h> |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 49 | #endif |
| 50 | |
Todd Fiala | 17096d7 | 2014-07-16 19:03:16 +0000 | [diff] [blame] | 51 | // C++ includes |
| 52 | #include <limits> |
| 53 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 54 | #include "lldb/Host/Host.h" |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 55 | #include "lldb/Host/HostInfo.h" |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 56 | #include "lldb/Core/ArchSpec.h" |
| 57 | #include "lldb/Core/ConstString.h" |
Sean Callanan | c0a6e06 | 2011-10-27 21:22:25 +0000 | [diff] [blame] | 58 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 59 | #include "lldb/Core/Error.h" |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 60 | #include "lldb/Core/Log.h" |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 61 | #include "lldb/Core/Module.h" |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 62 | #include "lldb/Core/StreamString.h" |
Jim Ingham | c075ecd | 2012-05-04 19:24:49 +0000 | [diff] [blame] | 63 | #include "lldb/Core/ThreadSafeSTLMap.h" |
Greg Clayton | 4531946 | 2011-02-08 00:35:34 +0000 | [diff] [blame] | 64 | #include "lldb/Host/Config.h" |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 65 | #include "lldb/Host/Endian.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 66 | #include "lldb/Host/FileSpec.h" |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 67 | #include "lldb/Host/FileSystem.h" |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 68 | #include "lldb/Host/Mutex.h" |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 69 | #include "lldb/Target/FileAction.h" |
Greg Clayton | e996fd3 | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 70 | #include "lldb/Target/Process.h" |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 71 | #include "lldb/Target/ProcessLaunchInfo.h" |
Sean Callanan | c0a6e06 | 2011-10-27 21:22:25 +0000 | [diff] [blame] | 72 | #include "lldb/Target/TargetList.h" |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 73 | #include "lldb/Utility/CleanUp.h" |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 74 | |
Saleem Abdulrasool | 2860695 | 2014-06-27 05:17:41 +0000 | [diff] [blame] | 75 | #include "llvm/ADT/STLExtras.h" |
Daniel Malea | fa7425d | 2013-08-06 21:40:08 +0000 | [diff] [blame] | 76 | #include "llvm/ADT/SmallString.h" |
Stephen Wilson | bd58871 | 2011-02-24 19:15:09 +0000 | [diff] [blame] | 77 | #include "llvm/Support/Host.h" |
Zachary Turner | 9e757b7 | 2014-07-28 16:45:05 +0000 | [diff] [blame] | 78 | #include "llvm/Support/Path.h" |
Daniel Malea | fa7425d | 2013-08-06 21:40:08 +0000 | [diff] [blame] | 79 | #include "llvm/Support/raw_ostream.h" |
Stephen Wilson | bd58871 | 2011-02-24 19:15:09 +0000 | [diff] [blame] | 80 | |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 81 | #if defined (__APPLE__) |
| 82 | #ifndef _POSIX_SPAWN_DISABLE_ASLR |
| 83 | #define _POSIX_SPAWN_DISABLE_ASLR 0x0100 |
| 84 | #endif |
| 85 | |
| 86 | extern "C" |
| 87 | { |
| 88 | int __pthread_chdir(const char *path); |
| 89 | int __pthread_fchdir (int fildes); |
| 90 | } |
| 91 | |
| 92 | #endif |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 93 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 94 | using namespace lldb; |
| 95 | using namespace lldb_private; |
| 96 | |
Todd Fiala | 17096d7 | 2014-07-16 19:03:16 +0000 | [diff] [blame] | 97 | // Define maximum thread name length |
| 98 | #if defined (__linux__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__NetBSD__) |
| 99 | uint32_t const Host::MAX_THREAD_NAME_LENGTH = 16; |
| 100 | #else |
| 101 | uint32_t const Host::MAX_THREAD_NAME_LENGTH = std::numeric_limits<uint32_t>::max (); |
| 102 | #endif |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 103 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 104 | #if !defined (__APPLE__) && !defined (_WIN32) |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 105 | struct MonitorInfo |
| 106 | { |
| 107 | lldb::pid_t pid; // The process ID to monitor |
| 108 | Host::MonitorChildProcessCallback callback; // The callback function to call when "pid" exits or signals |
| 109 | void *callback_baton; // The callback baton for the callback function |
| 110 | bool monitor_signals; // If true, call the callback when "pid" gets signaled. |
| 111 | }; |
| 112 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 113 | static thread_result_t |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 114 | MonitorChildProcessThreadFunction (void *arg); |
| 115 | |
| 116 | lldb::thread_t |
| 117 | Host::StartMonitoringChildProcess |
| 118 | ( |
| 119 | Host::MonitorChildProcessCallback callback, |
| 120 | void *callback_baton, |
| 121 | lldb::pid_t pid, |
| 122 | bool monitor_signals |
| 123 | ) |
| 124 | { |
| 125 | lldb::thread_t thread = LLDB_INVALID_HOST_THREAD; |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 126 | MonitorInfo * info_ptr = new MonitorInfo(); |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 127 | |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 128 | info_ptr->pid = pid; |
| 129 | info_ptr->callback = callback; |
| 130 | info_ptr->callback_baton = callback_baton; |
| 131 | info_ptr->monitor_signals = monitor_signals; |
| 132 | |
| 133 | char thread_name[256]; |
Todd Fiala | 0b903a0 | 2014-08-28 21:21:39 +0000 | [diff] [blame] | 134 | |
| 135 | if (Host::MAX_THREAD_NAME_LENGTH <= 16) |
| 136 | { |
| 137 | // On some platforms, the thread name is limited to 16 characters. We need to |
| 138 | // abbreviate there or the pid info would get truncated. |
| 139 | ::snprintf (thread_name, sizeof(thread_name), "wait4(%" PRIu64 ")", pid); |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | ::snprintf (thread_name, sizeof(thread_name), "<lldb.host.wait4(pid=%" PRIu64 ")>", pid); |
| 144 | } |
| 145 | |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 146 | thread = ThreadCreate (thread_name, |
| 147 | MonitorChildProcessThreadFunction, |
| 148 | info_ptr, |
| 149 | NULL); |
| 150 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 151 | return thread; |
| 152 | } |
| 153 | |
| 154 | //------------------------------------------------------------------ |
| 155 | // Scoped class that will disable thread canceling when it is |
| 156 | // constructed, and exception safely restore the previous value it |
| 157 | // when it goes out of scope. |
| 158 | //------------------------------------------------------------------ |
| 159 | class ScopedPThreadCancelDisabler |
| 160 | { |
| 161 | public: |
| 162 | ScopedPThreadCancelDisabler() |
| 163 | { |
| 164 | // Disable the ability for this thread to be cancelled |
| 165 | int err = ::pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &m_old_state); |
| 166 | if (err != 0) |
| 167 | m_old_state = -1; |
| 168 | |
| 169 | } |
| 170 | |
| 171 | ~ScopedPThreadCancelDisabler() |
| 172 | { |
| 173 | // Restore the ability for this thread to be cancelled to what it |
| 174 | // previously was. |
| 175 | if (m_old_state != -1) |
| 176 | ::pthread_setcancelstate (m_old_state, 0); |
| 177 | } |
| 178 | private: |
| 179 | int m_old_state; // Save the old cancelability state. |
| 180 | }; |
| 181 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 182 | static thread_result_t |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 183 | MonitorChildProcessThreadFunction (void *arg) |
| 184 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 185 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 186 | const char *function = __FUNCTION__; |
| 187 | if (log) |
| 188 | log->Printf ("%s (arg = %p) thread starting...", function, arg); |
| 189 | |
| 190 | MonitorInfo *info = (MonitorInfo *)arg; |
| 191 | |
| 192 | const Host::MonitorChildProcessCallback callback = info->callback; |
| 193 | void * const callback_baton = info->callback_baton; |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 194 | const bool monitor_signals = info->monitor_signals; |
| 195 | |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 196 | assert (info->pid <= UINT32_MAX); |
Andrew MacPherson | 82aae0d | 2014-04-02 06:57:45 +0000 | [diff] [blame] | 197 | const ::pid_t pid = monitor_signals ? -1 * getpgid(info->pid) : info->pid; |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 198 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 199 | delete info; |
| 200 | |
| 201 | int status = -1; |
Sylvestre Ledru | 5940583 | 2013-07-01 08:21:36 +0000 | [diff] [blame] | 202 | #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) |
Ashok Thirumurthi | 0f3b9b8 | 2013-05-01 20:38:19 +0000 | [diff] [blame] | 203 | #define __WALL 0 |
| 204 | #endif |
Matt Kopec | 650648f | 2013-01-08 16:30:18 +0000 | [diff] [blame] | 205 | const int options = __WALL; |
| 206 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 207 | while (1) |
| 208 | { |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 209 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 210 | if (log) |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 211 | log->Printf("%s ::wait_pid (pid = %" PRIi32 ", &status, options = %i)...", function, pid, options); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 212 | |
| 213 | // Wait for all child processes |
| 214 | ::pthread_testcancel (); |
Matt Kopec | 650648f | 2013-01-08 16:30:18 +0000 | [diff] [blame] | 215 | // Get signals from all children with same process group of pid |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 216 | const ::pid_t wait_pid = ::waitpid (pid, &status, options); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 217 | ::pthread_testcancel (); |
| 218 | |
| 219 | if (wait_pid == -1) |
| 220 | { |
| 221 | if (errno == EINTR) |
| 222 | continue; |
| 223 | else |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 224 | { |
| 225 | if (log) |
| 226 | log->Printf ("%s (arg = %p) thread exiting because waitpid failed (%s)...", __FUNCTION__, arg, strerror(errno)); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 227 | break; |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 228 | } |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 229 | } |
Matt Kopec | 650648f | 2013-01-08 16:30:18 +0000 | [diff] [blame] | 230 | else if (wait_pid > 0) |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 231 | { |
| 232 | bool exited = false; |
| 233 | int signal = 0; |
| 234 | int exit_status = 0; |
| 235 | const char *status_cstr = NULL; |
| 236 | if (WIFSTOPPED(status)) |
| 237 | { |
| 238 | signal = WSTOPSIG(status); |
| 239 | status_cstr = "STOPPED"; |
| 240 | } |
| 241 | else if (WIFEXITED(status)) |
| 242 | { |
| 243 | exit_status = WEXITSTATUS(status); |
| 244 | status_cstr = "EXITED"; |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 245 | exited = true; |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 246 | } |
| 247 | else if (WIFSIGNALED(status)) |
| 248 | { |
| 249 | signal = WTERMSIG(status); |
| 250 | status_cstr = "SIGNALED"; |
Andrew Kaylor | 7d2abdf | 2013-09-04 16:06:04 +0000 | [diff] [blame] | 251 | if (wait_pid == abs(pid)) { |
Matt Kopec | 650648f | 2013-01-08 16:30:18 +0000 | [diff] [blame] | 252 | exited = true; |
| 253 | exit_status = -1; |
| 254 | } |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 255 | } |
| 256 | else |
| 257 | { |
Johnny Chen | 4480530 | 2011-07-19 19:48:13 +0000 | [diff] [blame] | 258 | status_cstr = "(\?\?\?)"; |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | // Scope for pthread_cancel_disabler |
| 262 | { |
| 263 | ScopedPThreadCancelDisabler pthread_cancel_disabler; |
| 264 | |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 265 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 266 | if (log) |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 267 | log->Printf ("%s ::waitpid (pid = %" PRIi32 ", &status, options = %i) => pid = %" PRIi32 ", status = 0x%8.8x (%s), signal = %i, exit_state = %i", |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 268 | function, |
| 269 | wait_pid, |
| 270 | options, |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 271 | pid, |
| 272 | status, |
| 273 | status_cstr, |
| 274 | signal, |
| 275 | exit_status); |
| 276 | |
| 277 | if (exited || (signal != 0 && monitor_signals)) |
| 278 | { |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 279 | bool callback_return = false; |
| 280 | if (callback) |
Matt Kopec | 650648f | 2013-01-08 16:30:18 +0000 | [diff] [blame] | 281 | callback_return = callback (callback_baton, wait_pid, exited, signal, exit_status); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 282 | |
| 283 | // If our process exited, then this thread should exit |
Andrew Kaylor | 7d2abdf | 2013-09-04 16:06:04 +0000 | [diff] [blame] | 284 | if (exited && wait_pid == abs(pid)) |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 285 | { |
| 286 | if (log) |
| 287 | log->Printf ("%s (arg = %p) thread exiting because pid received exit signal...", __FUNCTION__, arg); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 288 | break; |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 289 | } |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 290 | // If the callback returns true, it means this process should |
| 291 | // exit |
| 292 | if (callback_return) |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 293 | { |
| 294 | if (log) |
| 295 | log->Printf ("%s (arg = %p) thread exiting because callback returned true...", __FUNCTION__, arg); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 296 | break; |
Andrew Kaylor | 93132f5 | 2013-05-28 23:04:25 +0000 | [diff] [blame] | 297 | } |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
Caroline Tice | 20ad3c4 | 2010-10-29 21:48:37 +0000 | [diff] [blame] | 303 | log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 304 | if (log) |
| 305 | log->Printf ("%s (arg = %p) thread exiting...", __FUNCTION__, arg); |
| 306 | |
| 307 | return NULL; |
| 308 | } |
| 309 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 310 | #endif // #if !defined (__APPLE__) && !defined (_WIN32) |
| 311 | |
| 312 | #if !defined (__APPLE__) |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 313 | |
| 314 | void |
| 315 | Host::SystemLog (SystemLogType type, const char *format, va_list args) |
| 316 | { |
| 317 | vfprintf (stderr, format, args); |
| 318 | } |
| 319 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 320 | #endif |
Greg Clayton | e4e4592 | 2011-11-16 05:37:56 +0000 | [diff] [blame] | 321 | |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 322 | void |
| 323 | Host::SystemLog (SystemLogType type, const char *format, ...) |
| 324 | { |
| 325 | va_list args; |
| 326 | va_start (args, format); |
| 327 | SystemLog (type, format, args); |
| 328 | va_end (args); |
| 329 | } |
| 330 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 331 | lldb::pid_t |
| 332 | Host::GetCurrentProcessID() |
| 333 | { |
| 334 | return ::getpid(); |
| 335 | } |
| 336 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 337 | #ifndef _WIN32 |
| 338 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 339 | lldb::tid_t |
| 340 | Host::GetCurrentThreadID() |
| 341 | { |
| 342 | #if defined (__APPLE__) |
Jean-Daniel Dupas | 3cfa8e2 | 2013-12-06 09:35:53 +0000 | [diff] [blame] | 343 | // Calling "mach_thread_self()" bumps the reference count on the thread |
Greg Clayton | 813ddfc | 2012-09-18 18:19:49 +0000 | [diff] [blame] | 344 | // port, so we need to deallocate it. mach_task_self() doesn't bump the ref |
| 345 | // count. |
| 346 | thread_port_t thread_self = mach_thread_self(); |
| 347 | mach_port_deallocate(mach_task_self(), thread_self); |
| 348 | return thread_self; |
Johnny Chen | 8f3d838 | 2011-08-02 20:52:42 +0000 | [diff] [blame] | 349 | #elif defined(__FreeBSD__) |
| 350 | return lldb::tid_t(pthread_getthreadid_np()); |
Michael Sartain | c205243 | 2013-08-01 18:51:08 +0000 | [diff] [blame] | 351 | #elif defined(__linux__) |
| 352 | return lldb::tid_t(syscall(SYS_gettid)); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 353 | #else |
| 354 | return lldb::tid_t(pthread_self()); |
| 355 | #endif |
| 356 | } |
| 357 | |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 358 | lldb::thread_t |
| 359 | Host::GetCurrentThread () |
| 360 | { |
| 361 | return lldb::thread_t(pthread_self()); |
| 362 | } |
| 363 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 364 | const char * |
| 365 | Host::GetSignalAsCString (int signo) |
| 366 | { |
| 367 | switch (signo) |
| 368 | { |
| 369 | case SIGHUP: return "SIGHUP"; // 1 hangup |
| 370 | case SIGINT: return "SIGINT"; // 2 interrupt |
| 371 | case SIGQUIT: return "SIGQUIT"; // 3 quit |
| 372 | case SIGILL: return "SIGILL"; // 4 illegal instruction (not reset when caught) |
| 373 | case SIGTRAP: return "SIGTRAP"; // 5 trace trap (not reset when caught) |
| 374 | case SIGABRT: return "SIGABRT"; // 6 abort() |
Jean-Daniel Dupas | 13698b2 | 2013-12-12 18:12:16 +0000 | [diff] [blame] | 375 | #if defined(SIGPOLL) |
Sylvestre Ledru | a4cc7de | 2013-12-13 09:51:39 +0000 | [diff] [blame] | 376 | #if !defined(SIGIO) || (SIGPOLL != SIGIO) |
| 377 | // Under some GNU/Linux, SIGPOLL and SIGIO are the same. Causing the build to |
| 378 | // fail with 'multiple define cases with same value' |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 379 | case SIGPOLL: return "SIGPOLL"; // 7 pollable event ([XSR] generated, not supported) |
Benjamin Kramer | 44030f1 | 2011-11-04 16:06:40 +0000 | [diff] [blame] | 380 | #endif |
Sylvestre Ledru | a4cc7de | 2013-12-13 09:51:39 +0000 | [diff] [blame] | 381 | #endif |
Jean-Daniel Dupas | 13698b2 | 2013-12-12 18:12:16 +0000 | [diff] [blame] | 382 | #if defined(SIGEMT) |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 383 | case SIGEMT: return "SIGEMT"; // 7 EMT instruction |
Benjamin Kramer | 44030f1 | 2011-11-04 16:06:40 +0000 | [diff] [blame] | 384 | #endif |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 385 | case SIGFPE: return "SIGFPE"; // 8 floating point exception |
| 386 | case SIGKILL: return "SIGKILL"; // 9 kill (cannot be caught or ignored) |
| 387 | case SIGBUS: return "SIGBUS"; // 10 bus error |
| 388 | case SIGSEGV: return "SIGSEGV"; // 11 segmentation violation |
| 389 | case SIGSYS: return "SIGSYS"; // 12 bad argument to system call |
| 390 | case SIGPIPE: return "SIGPIPE"; // 13 write on a pipe with no one to read it |
| 391 | case SIGALRM: return "SIGALRM"; // 14 alarm clock |
| 392 | case SIGTERM: return "SIGTERM"; // 15 software termination signal from kill |
| 393 | case SIGURG: return "SIGURG"; // 16 urgent condition on IO channel |
| 394 | case SIGSTOP: return "SIGSTOP"; // 17 sendable stop signal not from tty |
| 395 | case SIGTSTP: return "SIGTSTP"; // 18 stop signal from tty |
| 396 | case SIGCONT: return "SIGCONT"; // 19 continue a stopped process |
| 397 | case SIGCHLD: return "SIGCHLD"; // 20 to parent on child stop or exit |
| 398 | case SIGTTIN: return "SIGTTIN"; // 21 to readers pgrp upon background tty read |
| 399 | case SIGTTOU: return "SIGTTOU"; // 22 like TTIN for output if (tp->t_local<OSTOP) |
Jean-Daniel Dupas | 13698b2 | 2013-12-12 18:12:16 +0000 | [diff] [blame] | 400 | #if defined(SIGIO) |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 401 | case SIGIO: return "SIGIO"; // 23 input/output possible signal |
| 402 | #endif |
| 403 | case SIGXCPU: return "SIGXCPU"; // 24 exceeded CPU time limit |
| 404 | case SIGXFSZ: return "SIGXFSZ"; // 25 exceeded file size limit |
| 405 | case SIGVTALRM: return "SIGVTALRM"; // 26 virtual time alarm |
| 406 | case SIGPROF: return "SIGPROF"; // 27 profiling time alarm |
Jean-Daniel Dupas | 13698b2 | 2013-12-12 18:12:16 +0000 | [diff] [blame] | 407 | #if defined(SIGWINCH) |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 408 | case SIGWINCH: return "SIGWINCH"; // 28 window size changes |
Jean-Daniel Dupas | 13698b2 | 2013-12-12 18:12:16 +0000 | [diff] [blame] | 409 | #endif |
| 410 | #if defined(SIGINFO) |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 411 | case SIGINFO: return "SIGINFO"; // 29 information request |
| 412 | #endif |
| 413 | case SIGUSR1: return "SIGUSR1"; // 30 user defined signal 1 |
| 414 | case SIGUSR2: return "SIGUSR2"; // 31 user defined signal 2 |
| 415 | default: |
| 416 | break; |
| 417 | } |
| 418 | return NULL; |
| 419 | } |
| 420 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 421 | #endif |
| 422 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 423 | void |
| 424 | Host::WillTerminate () |
| 425 | { |
| 426 | } |
| 427 | |
Sylvestre Ledru | 5940583 | 2013-07-01 08:21:36 +0000 | [diff] [blame] | 428 | #if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) && !defined (__linux__) // see macosx/Host.mm |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 429 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 430 | void |
| 431 | Host::ThreadCreated (const char *thread_name) |
| 432 | { |
| 433 | } |
Greg Clayton | e521966 | 2010-12-03 06:02:24 +0000 | [diff] [blame] | 434 | |
Peter Collingbourne | 2ced913 | 2011-08-05 00:35:43 +0000 | [diff] [blame] | 435 | void |
Greg Clayton | e521966 | 2010-12-03 06:02:24 +0000 | [diff] [blame] | 436 | Host::Backtrace (Stream &strm, uint32_t max_frames) |
| 437 | { |
Michael Sartain | 3cf443d | 2013-07-17 00:26:30 +0000 | [diff] [blame] | 438 | // TODO: Is there a way to backtrace the current process on other systems? |
Greg Clayton | e521966 | 2010-12-03 06:02:24 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 +0000 | [diff] [blame] | 441 | size_t |
| 442 | Host::GetEnvironment (StringList &env) |
| 443 | { |
Michael Sartain | 3cf443d | 2013-07-17 00:26:30 +0000 | [diff] [blame] | 444 | // TODO: Is there a way to the host environment for this process on other systems? |
Greg Clayton | 85851dd | 2010-12-04 00:10:17 +0000 | [diff] [blame] | 445 | return 0; |
| 446 | } |
| 447 | |
Sylvestre Ledru | 5940583 | 2013-07-01 08:21:36 +0000 | [diff] [blame] | 448 | #endif // #if !defined (__APPLE__) && !defined (__FreeBSD__) && !defined (__FreeBSD_kernel__) && !defined (__linux__) |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 449 | |
| 450 | struct HostThreadCreateInfo |
| 451 | { |
| 452 | std::string thread_name; |
| 453 | thread_func_t thread_fptr; |
| 454 | thread_arg_t thread_arg; |
| 455 | |
| 456 | HostThreadCreateInfo (const char *name, thread_func_t fptr, thread_arg_t arg) : |
| 457 | thread_name (name ? name : ""), |
| 458 | thread_fptr (fptr), |
| 459 | thread_arg (arg) |
| 460 | { |
| 461 | } |
| 462 | }; |
| 463 | |
| 464 | static thread_result_t |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 465 | #ifdef _WIN32 |
| 466 | __stdcall |
| 467 | #endif |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 468 | ThreadCreateTrampoline (thread_arg_t arg) |
| 469 | { |
| 470 | HostThreadCreateInfo *info = (HostThreadCreateInfo *)arg; |
| 471 | Host::ThreadCreated (info->thread_name.c_str()); |
| 472 | thread_func_t thread_fptr = info->thread_fptr; |
| 473 | thread_arg_t thread_arg = info->thread_arg; |
| 474 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 475 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD)); |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 476 | if (log) |
| 477 | log->Printf("thread created"); |
| 478 | |
| 479 | delete info; |
| 480 | return thread_fptr (thread_arg); |
| 481 | } |
| 482 | |
| 483 | lldb::thread_t |
| 484 | Host::ThreadCreate |
| 485 | ( |
| 486 | const char *thread_name, |
| 487 | thread_func_t thread_fptr, |
| 488 | thread_arg_t thread_arg, |
| 489 | Error *error |
| 490 | ) |
| 491 | { |
| 492 | lldb::thread_t thread = LLDB_INVALID_HOST_THREAD; |
| 493 | |
| 494 | // Host::ThreadCreateTrampoline will delete this pointer for us. |
| 495 | HostThreadCreateInfo *info_ptr = new HostThreadCreateInfo (thread_name, thread_fptr, thread_arg); |
| 496 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 497 | #ifdef _WIN32 |
| 498 | thread = ::_beginthreadex(0, 0, ThreadCreateTrampoline, info_ptr, 0, NULL); |
| 499 | int err = thread <= 0 ? GetLastError() : 0; |
| 500 | #else |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 501 | int err = ::pthread_create (&thread, NULL, ThreadCreateTrampoline, info_ptr); |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 502 | #endif |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 503 | if (err == 0) |
| 504 | { |
| 505 | if (error) |
| 506 | error->Clear(); |
| 507 | return thread; |
| 508 | } |
| 509 | |
| 510 | if (error) |
| 511 | error->SetError (err, eErrorTypePOSIX); |
| 512 | |
| 513 | return LLDB_INVALID_HOST_THREAD; |
| 514 | } |
| 515 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 516 | #ifndef _WIN32 |
| 517 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 518 | bool |
| 519 | Host::ThreadCancel (lldb::thread_t thread, Error *error) |
| 520 | { |
| 521 | int err = ::pthread_cancel (thread); |
| 522 | if (error) |
| 523 | error->SetError(err, eErrorTypePOSIX); |
| 524 | return err == 0; |
| 525 | } |
| 526 | |
| 527 | bool |
| 528 | Host::ThreadDetach (lldb::thread_t thread, Error *error) |
| 529 | { |
| 530 | int err = ::pthread_detach (thread); |
| 531 | if (error) |
| 532 | error->SetError(err, eErrorTypePOSIX); |
| 533 | return err == 0; |
| 534 | } |
| 535 | |
| 536 | bool |
| 537 | Host::ThreadJoin (lldb::thread_t thread, thread_result_t *thread_result_ptr, Error *error) |
| 538 | { |
| 539 | int err = ::pthread_join (thread, thread_result_ptr); |
| 540 | if (error) |
| 541 | error->SetError(err, eErrorTypePOSIX); |
| 542 | return err == 0; |
| 543 | } |
| 544 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 545 | lldb::thread_key_t |
| 546 | Host::ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback) |
| 547 | { |
| 548 | pthread_key_t key; |
| 549 | ::pthread_key_create (&key, callback); |
| 550 | return key; |
| 551 | } |
| 552 | |
| 553 | void* |
| 554 | Host::ThreadLocalStorageGet(lldb::thread_key_t key) |
| 555 | { |
| 556 | return ::pthread_getspecific (key); |
| 557 | } |
| 558 | |
| 559 | void |
| 560 | Host::ThreadLocalStorageSet(lldb::thread_key_t key, void *value) |
| 561 | { |
| 562 | ::pthread_setspecific (key, value); |
| 563 | } |
| 564 | |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 565 | bool |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 566 | Host::SetThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name) |
| 567 | { |
Greg Clayton | 8571963 | 2013-02-27 22:51:58 +0000 | [diff] [blame] | 568 | #if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 569 | lldb::pid_t curr_pid = Host::GetCurrentProcessID(); |
| 570 | lldb::tid_t curr_tid = Host::GetCurrentThreadID(); |
| 571 | if (pid == LLDB_INVALID_PROCESS_ID) |
| 572 | pid = curr_pid; |
| 573 | |
| 574 | if (tid == LLDB_INVALID_THREAD_ID) |
| 575 | tid = curr_tid; |
| 576 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 577 | // Set the pthread name if possible |
| 578 | if (pid == curr_pid && tid == curr_tid) |
| 579 | { |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 580 | if (::pthread_setname_np (name) == 0) |
| 581 | return true; |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 582 | } |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 583 | return false; |
Ed Maste | 02983be | 2013-07-25 19:10:32 +0000 | [diff] [blame] | 584 | #elif defined (__FreeBSD__) |
| 585 | lldb::pid_t curr_pid = Host::GetCurrentProcessID(); |
| 586 | lldb::tid_t curr_tid = Host::GetCurrentThreadID(); |
| 587 | if (pid == LLDB_INVALID_PROCESS_ID) |
| 588 | pid = curr_pid; |
| 589 | |
| 590 | if (tid == LLDB_INVALID_THREAD_ID) |
| 591 | tid = curr_tid; |
| 592 | |
| 593 | // Set the pthread name if possible |
| 594 | if (pid == curr_pid && tid == curr_tid) |
| 595 | { |
Michael Sartain | c205243 | 2013-08-01 18:51:08 +0000 | [diff] [blame] | 596 | ::pthread_set_name_np (::pthread_self(), name); |
Ed Maste | 02983be | 2013-07-25 19:10:32 +0000 | [diff] [blame] | 597 | return true; |
| 598 | } |
| 599 | return false; |
Sylvestre Ledru | 5940583 | 2013-07-01 08:21:36 +0000 | [diff] [blame] | 600 | #elif defined (__linux__) || defined (__GLIBC__) |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 601 | void *fn = dlsym (RTLD_DEFAULT, "pthread_setname_np"); |
| 602 | if (fn) |
| 603 | { |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 604 | lldb::pid_t curr_pid = Host::GetCurrentProcessID(); |
| 605 | lldb::tid_t curr_tid = Host::GetCurrentThreadID(); |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 606 | if (pid == LLDB_INVALID_PROCESS_ID) |
| 607 | pid = curr_pid; |
| 608 | |
| 609 | if (tid == LLDB_INVALID_THREAD_ID) |
| 610 | tid = curr_tid; |
| 611 | |
Michael Sartain | c205243 | 2013-08-01 18:51:08 +0000 | [diff] [blame] | 612 | if (pid == curr_pid && tid == curr_tid) |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 613 | { |
Michael Sartain | c205243 | 2013-08-01 18:51:08 +0000 | [diff] [blame] | 614 | int (*pthread_setname_np_func)(pthread_t thread, const char *name); |
| 615 | *reinterpret_cast<void **> (&pthread_setname_np_func) = fn; |
| 616 | |
| 617 | if (pthread_setname_np_func (::pthread_self(), name) == 0) |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 618 | return true; |
| 619 | } |
| 620 | } |
| 621 | return false; |
Jim Ingham | 5c42d8a | 2013-05-15 18:27:08 +0000 | [diff] [blame] | 622 | #else |
| 623 | return false; |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 624 | #endif |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 625 | } |
| 626 | |
Ed Maste | 02983be | 2013-07-25 19:10:32 +0000 | [diff] [blame] | 627 | bool |
| 628 | Host::SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid, |
| 629 | const char *thread_name, size_t len) |
| 630 | { |
Enrico Granata | 67530b6 | 2014-02-12 03:37:33 +0000 | [diff] [blame] | 631 | std::unique_ptr<char[]> namebuf(new char[len+1]); |
| 632 | |
Ed Maste | 02983be | 2013-07-25 19:10:32 +0000 | [diff] [blame] | 633 | // Thread names are coming in like '<lldb.comm.debugger.edit>' and |
| 634 | // '<lldb.comm.debugger.editline>'. So just chopping the end of the string |
| 635 | // off leads to a lot of similar named threads. Go through the thread name |
| 636 | // and search for the last dot and use that. |
| 637 | const char *lastdot = ::strrchr (thread_name, '.'); |
| 638 | |
| 639 | if (lastdot && lastdot != thread_name) |
| 640 | thread_name = lastdot + 1; |
Enrico Granata | 67530b6 | 2014-02-12 03:37:33 +0000 | [diff] [blame] | 641 | ::strncpy (namebuf.get(), thread_name, len); |
Ed Maste | 02983be | 2013-07-25 19:10:32 +0000 | [diff] [blame] | 642 | namebuf[len] = 0; |
| 643 | |
Enrico Granata | 67530b6 | 2014-02-12 03:37:33 +0000 | [diff] [blame] | 644 | int namebuflen = strlen(namebuf.get()); |
Ed Maste | 02983be | 2013-07-25 19:10:32 +0000 | [diff] [blame] | 645 | if (namebuflen > 0) |
| 646 | { |
| 647 | if (namebuf[namebuflen - 1] == '(' || namebuf[namebuflen - 1] == '>') |
| 648 | { |
| 649 | // Trim off trailing '(' and '>' characters for a bit more cleanup. |
| 650 | namebuflen--; |
| 651 | namebuf[namebuflen] = 0; |
| 652 | } |
Enrico Granata | 67530b6 | 2014-02-12 03:37:33 +0000 | [diff] [blame] | 653 | return Host::SetThreadName (pid, tid, namebuf.get()); |
Ed Maste | 02983be | 2013-07-25 19:10:32 +0000 | [diff] [blame] | 654 | } |
| 655 | return false; |
| 656 | } |
| 657 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 658 | #endif |
| 659 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 660 | #if !defined (__APPLE__) // see Host.mm |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 661 | |
| 662 | bool |
| 663 | Host::GetBundleDirectory (const FileSpec &file, FileSpec &bundle) |
| 664 | { |
| 665 | bundle.Clear(); |
| 666 | return false; |
| 667 | } |
| 668 | |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 669 | bool |
Greg Clayton | dd36def | 2010-10-17 22:03:32 +0000 | [diff] [blame] | 670 | Host::ResolveExecutableInBundle (FileSpec &file) |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 671 | { |
Greg Clayton | dd36def | 2010-10-17 22:03:32 +0000 | [diff] [blame] | 672 | return false; |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 673 | } |
| 674 | #endif |
| 675 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 676 | #ifndef _WIN32 |
| 677 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 678 | FileSpec |
| 679 | Host::GetModuleFileSpecForHostAddress (const void *host_addr) |
| 680 | { |
| 681 | FileSpec module_filespec; |
| 682 | Dl_info info; |
| 683 | if (::dladdr (host_addr, &info)) |
| 684 | { |
| 685 | if (info.dli_fname) |
| 686 | module_filespec.SetFile(info.dli_fname, true); |
| 687 | } |
| 688 | return module_filespec; |
| 689 | } |
| 690 | |
| 691 | #endif |
| 692 | |
Matt Kopec | 085d6ce | 2013-05-31 22:00:07 +0000 | [diff] [blame] | 693 | #if !defined(__linux__) |
| 694 | bool |
| 695 | Host::FindProcessThreads (const lldb::pid_t pid, TidMap &tids_to_attach) |
| 696 | { |
| 697 | return false; |
| 698 | } |
| 699 | #endif |
| 700 | |
Sean Callanan | c0a6e06 | 2011-10-27 21:22:25 +0000 | [diff] [blame] | 701 | lldb::TargetSP |
| 702 | Host::GetDummyTarget (lldb_private::Debugger &debugger) |
| 703 | { |
Filipe Cabecinhas | 721ba3f | 2012-05-19 09:59:08 +0000 | [diff] [blame] | 704 | static TargetSP g_dummy_target_sp; |
Filipe Cabecinhas | b018345 | 2012-05-17 15:48:02 +0000 | [diff] [blame] | 705 | |
Filipe Cabecinhas | 721ba3f | 2012-05-19 09:59:08 +0000 | [diff] [blame] | 706 | // FIXME: Maybe the dummy target should be per-Debugger |
| 707 | if (!g_dummy_target_sp || !g_dummy_target_sp->IsValid()) |
| 708 | { |
| 709 | ArchSpec arch(Target::GetDefaultArchitecture()); |
| 710 | if (!arch.IsValid()) |
Zachary Turner | 13b1826 | 2014-08-20 16:42:51 +0000 | [diff] [blame] | 711 | arch = HostInfo::GetArchitecture(); |
Filipe Cabecinhas | 721ba3f | 2012-05-19 09:59:08 +0000 | [diff] [blame] | 712 | Error err = debugger.GetTargetList().CreateTarget(debugger, |
Greg Clayton | a0ca660 | 2012-10-18 16:33:33 +0000 | [diff] [blame] | 713 | NULL, |
Filipe Cabecinhas | 721ba3f | 2012-05-19 09:59:08 +0000 | [diff] [blame] | 714 | arch.GetTriple().getTriple().c_str(), |
| 715 | false, |
| 716 | NULL, |
| 717 | g_dummy_target_sp); |
| 718 | } |
Filipe Cabecinhas | b018345 | 2012-05-17 15:48:02 +0000 | [diff] [blame] | 719 | |
Filipe Cabecinhas | 721ba3f | 2012-05-19 09:59:08 +0000 | [diff] [blame] | 720 | return g_dummy_target_sp; |
Sean Callanan | c0a6e06 | 2011-10-27 21:22:25 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 723 | struct ShellInfo |
| 724 | { |
| 725 | ShellInfo () : |
| 726 | process_reaped (false), |
| 727 | can_delete (false), |
| 728 | pid (LLDB_INVALID_PROCESS_ID), |
| 729 | signo(-1), |
| 730 | status(-1) |
| 731 | { |
| 732 | } |
| 733 | |
| 734 | lldb_private::Predicate<bool> process_reaped; |
| 735 | lldb_private::Predicate<bool> can_delete; |
| 736 | lldb::pid_t pid; |
| 737 | int signo; |
| 738 | int status; |
| 739 | }; |
| 740 | |
| 741 | static bool |
| 742 | MonitorShellCommand (void *callback_baton, |
| 743 | lldb::pid_t pid, |
| 744 | bool exited, // True if the process did exit |
| 745 | int signo, // Zero for no signal |
| 746 | int status) // Exit value of process if signal is zero |
| 747 | { |
| 748 | ShellInfo *shell_info = (ShellInfo *)callback_baton; |
| 749 | shell_info->pid = pid; |
| 750 | shell_info->signo = signo; |
| 751 | shell_info->status = status; |
| 752 | // Let the thread running Host::RunShellCommand() know that the process |
| 753 | // exited and that ShellInfo has been filled in by broadcasting to it |
| 754 | shell_info->process_reaped.SetValue(1, eBroadcastAlways); |
| 755 | // Now wait for a handshake back from that thread running Host::RunShellCommand |
| 756 | // so we know that we can delete shell_info_ptr |
| 757 | shell_info->can_delete.WaitForValueEqualTo(true); |
| 758 | // Sleep a bit to allow the shell_info->can_delete.SetValue() to complete... |
| 759 | usleep(1000); |
| 760 | // Now delete the shell info that was passed into this function |
| 761 | delete shell_info; |
| 762 | return true; |
| 763 | } |
| 764 | |
| 765 | Error |
| 766 | Host::RunShellCommand (const char *command, |
| 767 | const char *working_dir, |
| 768 | int *status_ptr, |
| 769 | int *signo_ptr, |
| 770 | std::string *command_output_ptr, |
Greg Clayton | c8f814d | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 771 | uint32_t timeout_sec, |
| 772 | const char *shell) |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 773 | { |
| 774 | Error error; |
| 775 | ProcessLaunchInfo launch_info; |
Greg Clayton | c8f814d | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 776 | if (shell && shell[0]) |
| 777 | { |
| 778 | // Run the command in a shell |
| 779 | launch_info.SetShell(shell); |
| 780 | launch_info.GetArguments().AppendArgument(command); |
| 781 | const bool localhost = true; |
| 782 | const bool will_debug = false; |
| 783 | const bool first_arg_is_full_shell_command = true; |
| 784 | launch_info.ConvertArgumentsForLaunchingInShell (error, |
| 785 | localhost, |
| 786 | will_debug, |
Jim Ingham | df0ae22 | 2013-09-10 02:09:47 +0000 | [diff] [blame] | 787 | first_arg_is_full_shell_command, |
| 788 | 0); |
Greg Clayton | c8f814d | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 789 | } |
| 790 | else |
| 791 | { |
| 792 | // No shell, just run it |
| 793 | Args args (command); |
| 794 | const bool first_arg_is_executable = true; |
Greg Clayton | 4539255 | 2012-10-17 22:57:12 +0000 | [diff] [blame] | 795 | launch_info.SetArguments(args, first_arg_is_executable); |
Greg Clayton | c8f814d | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 796 | } |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 797 | |
| 798 | if (working_dir) |
| 799 | launch_info.SetWorkingDirectory(working_dir); |
Greg Clayton | c6931fc | 2013-12-04 18:53:50 +0000 | [diff] [blame] | 800 | char output_file_path_buffer[PATH_MAX]; |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 801 | const char *output_file_path = NULL; |
Greg Clayton | c6931fc | 2013-12-04 18:53:50 +0000 | [diff] [blame] | 802 | |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 803 | if (command_output_ptr) |
| 804 | { |
| 805 | // Create a temporary file to get the stdout/stderr and redirect the |
| 806 | // output of the command into this file. We will later read this file |
| 807 | // if all goes well and fill the data into "command_output_ptr" |
Greg Clayton | c6931fc | 2013-12-04 18:53:50 +0000 | [diff] [blame] | 808 | FileSpec tmpdir_file_spec; |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 809 | if (HostInfo::GetLLDBPath(ePathTypeLLDBTempSystemDir, tmpdir_file_spec)) |
Greg Clayton | c6931fc | 2013-12-04 18:53:50 +0000 | [diff] [blame] | 810 | { |
Zachary Turner | c25146b | 2014-08-21 23:56:55 +0000 | [diff] [blame] | 811 | tmpdir_file_spec.AppendPathComponent("lldb-shell-output.XXXXXX"); |
Greg Clayton | c6931fc | 2013-12-04 18:53:50 +0000 | [diff] [blame] | 812 | strncpy(output_file_path_buffer, tmpdir_file_spec.GetPath().c_str(), sizeof(output_file_path_buffer)); |
| 813 | } |
| 814 | else |
| 815 | { |
| 816 | strncpy(output_file_path_buffer, "/tmp/lldb-shell-output.XXXXXX", sizeof(output_file_path_buffer)); |
| 817 | } |
| 818 | |
| 819 | output_file_path = ::mktemp(output_file_path_buffer); |
| 820 | } |
| 821 | |
| 822 | launch_info.AppendSuppressFileAction (STDIN_FILENO, true, false); |
| 823 | if (output_file_path) |
| 824 | { |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 825 | launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_path, false, true); |
Greg Clayton | c8f814d | 2012-09-27 03:13:55 +0000 | [diff] [blame] | 826 | launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO); |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 827 | } |
| 828 | else |
| 829 | { |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 830 | launch_info.AppendSuppressFileAction (STDOUT_FILENO, false, true); |
| 831 | launch_info.AppendSuppressFileAction (STDERR_FILENO, false, true); |
| 832 | } |
| 833 | |
| 834 | // The process monitor callback will delete the 'shell_info_ptr' below... |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 835 | std::unique_ptr<ShellInfo> shell_info_ap (new ShellInfo()); |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 836 | |
| 837 | const bool monitor_signals = false; |
| 838 | launch_info.SetMonitorProcessCallback(MonitorShellCommand, shell_info_ap.get(), monitor_signals); |
| 839 | |
| 840 | error = LaunchProcess (launch_info); |
| 841 | const lldb::pid_t pid = launch_info.GetProcessID(); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 842 | |
| 843 | if (error.Success() && pid == LLDB_INVALID_PROCESS_ID) |
| 844 | error.SetErrorString("failed to get process ID"); |
| 845 | |
| 846 | if (error.Success()) |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 847 | { |
| 848 | // The process successfully launched, so we can defer ownership of |
| 849 | // "shell_info" to the MonitorShellCommand callback function that will |
Greg Clayton | e01e07b | 2013-04-18 18:10:51 +0000 | [diff] [blame] | 850 | // get called when the process dies. We release the unique pointer as it |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 851 | // doesn't need to delete the ShellInfo anymore. |
| 852 | ShellInfo *shell_info = shell_info_ap.release(); |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 853 | TimeValue *timeout_ptr = nullptr; |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 854 | TimeValue timeout_time(TimeValue::Now()); |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 855 | if (timeout_sec > 0) { |
| 856 | timeout_time.OffsetWithSeconds(timeout_sec); |
| 857 | timeout_ptr = &timeout_time; |
| 858 | } |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 859 | bool timed_out = false; |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 860 | shell_info->process_reaped.WaitForValueEqualTo(true, timeout_ptr, &timed_out); |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 861 | if (timed_out) |
| 862 | { |
| 863 | error.SetErrorString("timed out waiting for shell command to complete"); |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 864 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 865 | // Kill the process since it didn't complete within the timeout specified |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 866 | Kill (pid, SIGKILL); |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 867 | // Wait for the monitor callback to get the message |
| 868 | timeout_time = TimeValue::Now(); |
| 869 | timeout_time.OffsetWithSeconds(1); |
| 870 | timed_out = false; |
| 871 | shell_info->process_reaped.WaitForValueEqualTo(true, &timeout_time, &timed_out); |
| 872 | } |
| 873 | else |
| 874 | { |
| 875 | if (status_ptr) |
| 876 | *status_ptr = shell_info->status; |
| 877 | |
| 878 | if (signo_ptr) |
| 879 | *signo_ptr = shell_info->signo; |
| 880 | |
| 881 | if (command_output_ptr) |
| 882 | { |
| 883 | command_output_ptr->clear(); |
| 884 | FileSpec file_spec(output_file_path, File::eOpenOptionRead); |
| 885 | uint64_t file_size = file_spec.GetByteSize(); |
| 886 | if (file_size > 0) |
| 887 | { |
| 888 | if (file_size > command_output_ptr->max_size()) |
| 889 | { |
| 890 | error.SetErrorStringWithFormat("shell command output is too large to fit into a std::string"); |
| 891 | } |
| 892 | else |
| 893 | { |
| 894 | command_output_ptr->resize(file_size); |
| 895 | file_spec.ReadFileContents(0, &((*command_output_ptr)[0]), command_output_ptr->size(), &error); |
| 896 | } |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | shell_info->can_delete.SetValue(true, eBroadcastAlways); |
| 901 | } |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 902 | |
| 903 | if (output_file_path) |
| 904 | ::unlink (output_file_path); |
| 905 | // Handshake with the monitor thread, or just let it know in advance that |
| 906 | // it can delete "shell_info" in case we timed out and were not able to kill |
| 907 | // the process... |
| 908 | return error; |
| 909 | } |
| 910 | |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 911 | |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 912 | // LaunchProcessPosixSpawn for Apple, Linux, FreeBSD and other GLIBC |
| 913 | // systems |
| 914 | |
Joerg Sonnenberger | a53b359 | 2014-05-02 19:09:40 +0000 | [diff] [blame] | 915 | #if defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__) || defined(__NetBSD__) |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 916 | |
| 917 | // this method needs to be visible to macosx/Host.cpp and |
| 918 | // common/Host.cpp. |
| 919 | |
| 920 | short |
| 921 | Host::GetPosixspawnFlags (ProcessLaunchInfo &launch_info) |
| 922 | { |
| 923 | short flags = POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK; |
| 924 | |
| 925 | #if defined (__APPLE__) |
| 926 | if (launch_info.GetFlags().Test (eLaunchFlagExec)) |
| 927 | flags |= POSIX_SPAWN_SETEXEC; // Darwin specific posix_spawn flag |
| 928 | |
| 929 | if (launch_info.GetFlags().Test (eLaunchFlagDebug)) |
| 930 | flags |= POSIX_SPAWN_START_SUSPENDED; // Darwin specific posix_spawn flag |
| 931 | |
| 932 | if (launch_info.GetFlags().Test (eLaunchFlagDisableASLR)) |
| 933 | flags |= _POSIX_SPAWN_DISABLE_ASLR; // Darwin specific posix_spawn flag |
| 934 | |
| 935 | if (launch_info.GetLaunchInSeparateProcessGroup()) |
| 936 | flags |= POSIX_SPAWN_SETPGROUP; |
| 937 | |
| 938 | #ifdef POSIX_SPAWN_CLOEXEC_DEFAULT |
| 939 | #if defined (__APPLE__) && (defined (__x86_64__) || defined (__i386__)) |
| 940 | static LazyBool g_use_close_on_exec_flag = eLazyBoolCalculate; |
| 941 | if (g_use_close_on_exec_flag == eLazyBoolCalculate) |
| 942 | { |
| 943 | g_use_close_on_exec_flag = eLazyBoolNo; |
| 944 | |
| 945 | uint32_t major, minor, update; |
Zachary Turner | 97a14e6 | 2014-08-19 17:18:29 +0000 | [diff] [blame] | 946 | if (HostInfo::GetOSVersion(major, minor, update)) |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 947 | { |
| 948 | // Kernel panic if we use the POSIX_SPAWN_CLOEXEC_DEFAULT on 10.7 or earlier |
| 949 | if (major > 10 || (major == 10 && minor > 7)) |
| 950 | { |
| 951 | // Only enable for 10.8 and later OS versions |
| 952 | g_use_close_on_exec_flag = eLazyBoolYes; |
| 953 | } |
| 954 | } |
| 955 | } |
| 956 | #else |
| 957 | static LazyBool g_use_close_on_exec_flag = eLazyBoolYes; |
| 958 | #endif |
| 959 | // Close all files exception those with file actions if this is supported. |
| 960 | if (g_use_close_on_exec_flag == eLazyBoolYes) |
| 961 | flags |= POSIX_SPAWN_CLOEXEC_DEFAULT; |
| 962 | #endif |
| 963 | #endif // #if defined (__APPLE__) |
| 964 | return flags; |
| 965 | } |
| 966 | |
| 967 | Error |
| 968 | Host::LaunchProcessPosixSpawn (const char *exe_path, ProcessLaunchInfo &launch_info, ::pid_t &pid) |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 969 | { |
| 970 | Error error; |
| 971 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_HOST | LIBLLDB_LOG_PROCESS)); |
| 972 | |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 973 | posix_spawnattr_t attr; |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 974 | error.SetError( ::posix_spawnattr_init (&attr), eErrorTypePOSIX); |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 975 | |
| 976 | if (error.Fail() || log) |
| 977 | error.PutToLog(log, "::posix_spawnattr_init ( &attr )"); |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 978 | if (error.Fail()) |
| 979 | return error; |
| 980 | |
| 981 | // Make a quick class that will cleanup the posix spawn attributes in case |
| 982 | // we return in the middle of this function. |
| 983 | lldb_utility::CleanUp <posix_spawnattr_t *, int> posix_spawnattr_cleanup(&attr, posix_spawnattr_destroy); |
| 984 | |
| 985 | sigset_t no_signals; |
| 986 | sigset_t all_signals; |
| 987 | sigemptyset (&no_signals); |
| 988 | sigfillset (&all_signals); |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 989 | ::posix_spawnattr_setsigmask(&attr, &no_signals); |
Todd Fiala | 571768c | 2014-01-23 17:07:54 +0000 | [diff] [blame] | 990 | #if defined (__linux__) || defined (__FreeBSD__) |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 991 | ::posix_spawnattr_setsigdefault(&attr, &no_signals); |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 992 | #else |
| 993 | ::posix_spawnattr_setsigdefault(&attr, &all_signals); |
| 994 | #endif |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 995 | |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 996 | short flags = GetPosixspawnFlags(launch_info); |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 997 | |
| 998 | error.SetError( ::posix_spawnattr_setflags (&attr, flags), eErrorTypePOSIX); |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 999 | if (error.Fail() || log) |
| 1000 | error.PutToLog(log, "::posix_spawnattr_setflags ( &attr, flags=0x%8.8x )", flags); |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1001 | if (error.Fail()) |
| 1002 | return error; |
| 1003 | |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1004 | // posix_spawnattr_setbinpref_np appears to be an Apple extension per: |
| 1005 | // http://www.unix.com/man-page/OSX/3/posix_spawnattr_setbinpref_np/ |
| 1006 | #if defined (__APPLE__) && !defined (__arm__) |
Jim Ingham | 90331d5 | 2014-02-21 01:25:21 +0000 | [diff] [blame] | 1007 | |
| 1008 | // Don't set the binpref if a shell was provided. After all, that's only going to affect what version of the shell |
| 1009 | // is launched, not what fork of the binary is launched. We insert "arch --arch <ARCH> as part of the shell invocation |
| 1010 | // to do that job on OSX. |
| 1011 | |
| 1012 | if (launch_info.GetShell() == nullptr) |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1013 | { |
Jim Ingham | 90331d5 | 2014-02-21 01:25:21 +0000 | [diff] [blame] | 1014 | // We don't need to do this for ARM, and we really shouldn't now that we |
| 1015 | // have multiple CPU subtypes and no posix_spawnattr call that allows us |
| 1016 | // to set which CPU subtype to launch... |
| 1017 | const ArchSpec &arch_spec = launch_info.GetArchitecture(); |
| 1018 | cpu_type_t cpu = arch_spec.GetMachOCPUType(); |
| 1019 | cpu_type_t sub = arch_spec.GetMachOCPUSubType(); |
| 1020 | if (cpu != 0 && |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 1021 | cpu != static_cast<cpu_type_t>(UINT32_MAX) && |
| 1022 | cpu != static_cast<cpu_type_t>(LLDB_INVALID_CPUTYPE) && |
Jim Ingham | 90331d5 | 2014-02-21 01:25:21 +0000 | [diff] [blame] | 1023 | !(cpu == 0x01000007 && sub == 8)) // If haswell is specified, don't try to set the CPU type or we will fail |
| 1024 | { |
| 1025 | size_t ocount = 0; |
| 1026 | error.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX); |
| 1027 | if (error.Fail() || log) |
| 1028 | error.PutToLog(log, "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %llu )", cpu, (uint64_t)ocount); |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1029 | |
Jim Ingham | 90331d5 | 2014-02-21 01:25:21 +0000 | [diff] [blame] | 1030 | if (error.Fail() || ocount != 1) |
| 1031 | return error; |
| 1032 | } |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1035 | #endif |
| 1036 | |
| 1037 | const char *tmp_argv[2]; |
| 1038 | char * const *argv = (char * const*)launch_info.GetArguments().GetConstArgumentVector(); |
| 1039 | char * const *envp = (char * const*)launch_info.GetEnvironmentEntries().GetConstArgumentVector(); |
| 1040 | if (argv == NULL) |
| 1041 | { |
| 1042 | // posix_spawn gets very unhappy if it doesn't have at least the program |
| 1043 | // name in argv[0]. One of the side affects I have noticed is the environment |
| 1044 | // variables don't make it into the child process if "argv == NULL"!!! |
| 1045 | tmp_argv[0] = exe_path; |
| 1046 | tmp_argv[1] = NULL; |
| 1047 | argv = (char * const*)tmp_argv; |
| 1048 | } |
| 1049 | |
| 1050 | #if !defined (__APPLE__) |
| 1051 | // manage the working directory |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1052 | char current_dir[PATH_MAX]; |
| 1053 | current_dir[0] = '\0'; |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1054 | #endif |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1055 | |
| 1056 | const char *working_dir = launch_info.GetWorkingDirectory(); |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1057 | if (working_dir) |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1058 | { |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1059 | #if defined (__APPLE__) |
| 1060 | // Set the working directory on this thread only |
| 1061 | if (__pthread_chdir (working_dir) < 0) { |
| 1062 | if (errno == ENOENT) { |
| 1063 | error.SetErrorStringWithFormat("No such file or directory: %s", working_dir); |
| 1064 | } else if (errno == ENOTDIR) { |
| 1065 | error.SetErrorStringWithFormat("Path doesn't name a directory: %s", working_dir); |
| 1066 | } else { |
| 1067 | error.SetErrorStringWithFormat("An unknown error occurred when changing directory for process execution."); |
| 1068 | } |
| 1069 | return error; |
| 1070 | } |
| 1071 | #else |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1072 | if (::getcwd(current_dir, sizeof(current_dir)) == NULL) |
| 1073 | { |
| 1074 | error.SetError(errno, eErrorTypePOSIX); |
| 1075 | error.LogIfError(log, "unable to save the current directory"); |
| 1076 | return error; |
| 1077 | } |
| 1078 | |
| 1079 | if (::chdir(working_dir) == -1) |
| 1080 | { |
| 1081 | error.SetError(errno, eErrorTypePOSIX); |
| 1082 | error.LogIfError(log, "unable to change working directory to %s", working_dir); |
| 1083 | return error; |
| 1084 | } |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1085 | #endif |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1088 | const size_t num_file_actions = launch_info.GetNumFileActions (); |
| 1089 | if (num_file_actions > 0) |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1090 | { |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1091 | posix_spawn_file_actions_t file_actions; |
| 1092 | error.SetError( ::posix_spawn_file_actions_init (&file_actions), eErrorTypePOSIX); |
| 1093 | if (error.Fail() || log) |
| 1094 | error.PutToLog(log, "::posix_spawn_file_actions_init ( &file_actions )"); |
| 1095 | if (error.Fail()) |
| 1096 | return error; |
| 1097 | |
| 1098 | // Make a quick class that will cleanup the posix spawn attributes in case |
| 1099 | // we return in the middle of this function. |
| 1100 | lldb_utility::CleanUp <posix_spawn_file_actions_t *, int> posix_spawn_file_actions_cleanup (&file_actions, posix_spawn_file_actions_destroy); |
| 1101 | |
| 1102 | for (size_t i=0; i<num_file_actions; ++i) |
| 1103 | { |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 1104 | const FileAction *launch_file_action = launch_info.GetFileActionAtIndex(i); |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1105 | if (launch_file_action) |
| 1106 | { |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 1107 | if (!AddPosixSpawnFileAction(&file_actions, launch_file_action, log, error)) |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1108 | return error; |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | error.SetError (::posix_spawnp (&pid, |
| 1113 | exe_path, |
| 1114 | &file_actions, |
| 1115 | &attr, |
| 1116 | argv, |
| 1117 | envp), |
| 1118 | eErrorTypePOSIX); |
| 1119 | |
| 1120 | if (error.Fail() || log) |
| 1121 | { |
| 1122 | error.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1123 | pid, exe_path, static_cast<void*>(&file_actions), |
| 1124 | static_cast<void*>(&attr), |
| 1125 | reinterpret_cast<const void*>(argv), |
| 1126 | reinterpret_cast<const void*>(envp)); |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1127 | if (log) |
| 1128 | { |
| 1129 | for (int ii=0; argv[ii]; ++ii) |
| 1130 | log->Printf("argv[%i] = '%s'", ii, argv[ii]); |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | } |
| 1135 | else |
| 1136 | { |
| 1137 | error.SetError (::posix_spawnp (&pid, |
| 1138 | exe_path, |
| 1139 | NULL, |
| 1140 | &attr, |
| 1141 | argv, |
| 1142 | envp), |
| 1143 | eErrorTypePOSIX); |
| 1144 | |
| 1145 | if (error.Fail() || log) |
| 1146 | { |
| 1147 | error.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = NULL, attr = %p, argv = %p, envp = %p )", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1148 | pid, exe_path, static_cast<void*>(&attr), |
| 1149 | reinterpret_cast<const void*>(argv), |
| 1150 | reinterpret_cast<const void*>(envp)); |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1151 | if (log) |
| 1152 | { |
| 1153 | for (int ii=0; argv[ii]; ++ii) |
| 1154 | log->Printf("argv[%i] = '%s'", ii, argv[ii]); |
| 1155 | } |
| 1156 | } |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1159 | if (working_dir) |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1160 | { |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1161 | #if defined (__APPLE__) |
| 1162 | // No more thread specific current working directory |
| 1163 | __pthread_fchdir (-1); |
| 1164 | #else |
| 1165 | if (::chdir(current_dir) == -1 && error.Success()) |
| 1166 | { |
| 1167 | error.SetError(errno, eErrorTypePOSIX); |
| 1168 | error.LogIfError(log, "unable to change current directory back to %s", |
| 1169 | current_dir); |
| 1170 | } |
| 1171 | #endif |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | return error; |
| 1175 | } |
| 1176 | |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 1177 | bool |
| 1178 | Host::AddPosixSpawnFileAction(void *_file_actions, const FileAction *info, Log *log, Error &error) |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 1179 | { |
| 1180 | if (info == NULL) |
| 1181 | return false; |
| 1182 | |
| 1183 | posix_spawn_file_actions_t *file_actions = reinterpret_cast<posix_spawn_file_actions_t *>(_file_actions); |
| 1184 | |
| 1185 | switch (info->GetAction()) |
| 1186 | { |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 1187 | case FileAction::eFileActionNone: |
| 1188 | error.Clear(); |
| 1189 | break; |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 1190 | |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 1191 | case FileAction::eFileActionClose: |
| 1192 | if (info->GetFD() == -1) |
| 1193 | error.SetErrorString("invalid fd for posix_spawn_file_actions_addclose(...)"); |
| 1194 | else |
| 1195 | { |
| 1196 | error.SetError(::posix_spawn_file_actions_addclose(file_actions, info->GetFD()), eErrorTypePOSIX); |
| 1197 | if (log && (error.Fail() || log)) |
| 1198 | error.PutToLog(log, "posix_spawn_file_actions_addclose (action=%p, fd=%i)", |
| 1199 | static_cast<void *>(file_actions), info->GetFD()); |
| 1200 | } |
| 1201 | break; |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 1202 | |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 1203 | case FileAction::eFileActionDuplicate: |
| 1204 | if (info->GetFD() == -1) |
| 1205 | error.SetErrorString("invalid fd for posix_spawn_file_actions_adddup2(...)"); |
| 1206 | else if (info->GetActionArgument() == -1) |
| 1207 | error.SetErrorString("invalid duplicate fd for posix_spawn_file_actions_adddup2(...)"); |
| 1208 | else |
| 1209 | { |
| 1210 | error.SetError( |
| 1211 | ::posix_spawn_file_actions_adddup2(file_actions, info->GetFD(), info->GetActionArgument()), |
| 1212 | eErrorTypePOSIX); |
| 1213 | if (log && (error.Fail() || log)) |
| 1214 | error.PutToLog(log, "posix_spawn_file_actions_adddup2 (action=%p, fd=%i, dup_fd=%i)", |
| 1215 | static_cast<void *>(file_actions), info->GetFD(), info->GetActionArgument()); |
| 1216 | } |
| 1217 | break; |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 1218 | |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 1219 | case FileAction::eFileActionOpen: |
| 1220 | if (info->GetFD() == -1) |
| 1221 | error.SetErrorString("invalid fd in posix_spawn_file_actions_addopen(...)"); |
| 1222 | else |
| 1223 | { |
| 1224 | int oflag = info->GetActionArgument(); |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 1225 | |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 1226 | mode_t mode = 0; |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 1227 | |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 1228 | if (oflag & O_CREAT) |
| 1229 | mode = 0640; |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 1230 | |
Zachary Turner | c00cf4a | 2014-08-15 22:04:21 +0000 | [diff] [blame] | 1231 | error.SetError( |
| 1232 | ::posix_spawn_file_actions_addopen(file_actions, info->GetFD(), info->GetPath(), oflag, mode), |
| 1233 | eErrorTypePOSIX); |
| 1234 | if (error.Fail() || log) |
| 1235 | error.PutToLog(log, |
| 1236 | "posix_spawn_file_actions_addopen (action=%p, fd=%i, path='%s', oflag=%i, mode=%i)", |
| 1237 | static_cast<void *>(file_actions), info->GetFD(), info->GetPath(), oflag, mode); |
| 1238 | } |
| 1239 | break; |
Zachary Turner | 696b528 | 2014-08-14 16:01:25 +0000 | [diff] [blame] | 1240 | } |
| 1241 | return error.Success(); |
| 1242 | } |
| 1243 | |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1244 | #endif // LaunchProcedssPosixSpawn: Apple, Linux, FreeBSD and other GLIBC systems |
| 1245 | |
| 1246 | |
Joerg Sonnenberger | a53b359 | 2014-05-02 19:09:40 +0000 | [diff] [blame] | 1247 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__GLIBC__) || defined(__NetBSD__) |
| 1248 | // The functions below implement process launching via posix_spawn() for Linux, |
| 1249 | // FreeBSD and NetBSD. |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1250 | |
| 1251 | Error |
| 1252 | Host::LaunchProcess (ProcessLaunchInfo &launch_info) |
| 1253 | { |
| 1254 | Error error; |
| 1255 | char exe_path[PATH_MAX]; |
| 1256 | |
| 1257 | PlatformSP host_platform_sp (Platform::GetDefaultPlatform ()); |
| 1258 | |
| 1259 | const ArchSpec &arch_spec = launch_info.GetArchitecture(); |
| 1260 | |
| 1261 | FileSpec exe_spec(launch_info.GetExecutableFile()); |
| 1262 | |
| 1263 | FileSpec::FileType file_type = exe_spec.GetFileType(); |
| 1264 | if (file_type != FileSpec::eFileTypeRegular) |
| 1265 | { |
| 1266 | lldb::ModuleSP exe_module_sp; |
| 1267 | error = host_platform_sp->ResolveExecutable (exe_spec, |
| 1268 | arch_spec, |
| 1269 | exe_module_sp, |
| 1270 | NULL); |
| 1271 | |
| 1272 | if (error.Fail()) |
| 1273 | return error; |
| 1274 | |
| 1275 | if (exe_module_sp) |
| 1276 | exe_spec = exe_module_sp->GetFileSpec(); |
| 1277 | } |
| 1278 | |
| 1279 | if (exe_spec.Exists()) |
| 1280 | { |
| 1281 | exe_spec.GetPath (exe_path, sizeof(exe_path)); |
| 1282 | } |
| 1283 | else |
| 1284 | { |
| 1285 | launch_info.GetExecutableFile().GetPath (exe_path, sizeof(exe_path)); |
| 1286 | error.SetErrorStringWithFormat ("executable doesn't exist: '%s'", exe_path); |
| 1287 | return error; |
| 1288 | } |
| 1289 | |
| 1290 | assert(!launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY)); |
| 1291 | |
| 1292 | ::pid_t pid = LLDB_INVALID_PROCESS_ID; |
| 1293 | |
| 1294 | error = LaunchProcessPosixSpawn(exe_path, launch_info, pid); |
| 1295 | |
| 1296 | if (pid != LLDB_INVALID_PROCESS_ID) |
| 1297 | { |
| 1298 | // If all went well, then set the process ID into the launch info |
| 1299 | launch_info.SetProcessID(pid); |
| 1300 | |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1301 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); |
| 1302 | |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1303 | // Make sure we reap any processes we spawn or we will have zombies. |
| 1304 | if (!launch_info.MonitorProcess()) |
| 1305 | { |
| 1306 | const bool monitor_signals = false; |
| 1307 | StartMonitoringChildProcess (Process::SetProcessExitStatus, |
| 1308 | NULL, |
| 1309 | pid, |
| 1310 | monitor_signals); |
Todd Fiala | 7674712 | 2014-01-23 00:52:28 +0000 | [diff] [blame] | 1311 | if (log) |
| 1312 | log->PutCString ("monitored child process with default Process::SetProcessExitStatus."); |
| 1313 | } |
| 1314 | else |
| 1315 | { |
| 1316 | if (log) |
| 1317 | log->PutCString ("monitored child process with user-specified process monitor."); |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | else |
| 1321 | { |
| 1322 | // Invalid process ID, something didn't go well |
| 1323 | if (error.Success()) |
| 1324 | error.SetErrorString ("process launch failed for unknown reasons"); |
| 1325 | } |
| 1326 | return error; |
| 1327 | } |
| 1328 | |
Joerg Sonnenberger | a53b359 | 2014-05-02 19:09:40 +0000 | [diff] [blame] | 1329 | #endif // defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) |
Daniel Malea | 4244cbd | 2013-08-27 20:58:59 +0000 | [diff] [blame] | 1330 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 1331 | #ifndef _WIN32 |
| 1332 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 1333 | void |
| 1334 | Host::Kill(lldb::pid_t pid, int signo) |
| 1335 | { |
| 1336 | ::kill(pid, signo); |
| 1337 | } |
Greg Clayton | e3e3fee | 2013-02-17 20:46:30 +0000 | [diff] [blame] | 1338 | |
Virgile Bello | b2f1fb2 | 2013-08-23 12:44:05 +0000 | [diff] [blame] | 1339 | #endif |
Greg Clayton | d1cf11a | 2012-04-14 01:42:46 +0000 | [diff] [blame] | 1340 | |
Johnny Chen | 8f3d838 | 2011-08-02 20:52:42 +0000 | [diff] [blame] | 1341 | #if !defined (__APPLE__) |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 1342 | bool |
Greg Clayton | 3b14763 | 2010-12-18 01:54:34 +0000 | [diff] [blame] | 1343 | Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no) |
Greg Clayton | 2bddd34 | 2010-09-07 20:11:56 +0000 | [diff] [blame] | 1344 | { |
| 1345 | return false; |
| 1346 | } |
Greg Clayton | dd36def | 2010-10-17 22:03:32 +0000 | [diff] [blame] | 1347 | |
Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 1348 | void |
| 1349 | Host::SetCrashDescriptionWithFormat (const char *format, ...) |
| 1350 | { |
| 1351 | } |
| 1352 | |
| 1353 | void |
| 1354 | Host::SetCrashDescription (const char *description) |
| 1355 | { |
| 1356 | } |
Greg Clayton | dd36def | 2010-10-17 22:03:32 +0000 | [diff] [blame] | 1357 | |
| 1358 | lldb::pid_t |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 1359 | Host::LaunchApplication (const FileSpec &app_file_spec) |
Greg Clayton | dd36def | 2010-10-17 22:03:32 +0000 | [diff] [blame] | 1360 | { |
| 1361 | return LLDB_INVALID_PROCESS_ID; |
| 1362 | } |
| 1363 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 1364 | #endif |