Stephen Wilson | 3e2a18f | 2011-03-23 01:58:26 +0000 | [diff] [blame] | 1 | //===-- source/Host/linux/Host.cpp ------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // C Includes |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 11 | #include <dirent.h> |
Oleksiy Vyalov | 9d90186 | 2016-07-12 18:14:27 +0000 | [diff] [blame] | 12 | #include <errno.h> |
Johnny Chen | 30213ff | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 13 | #include <fcntl.h> |
Oleksiy Vyalov | 9d90186 | 2016-07-12 18:14:27 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <string.h> |
| 16 | #include <sys/stat.h> |
| 17 | #include <sys/types.h> |
| 18 | #include <sys/utsname.h> |
Johnny Chen | 30213ff | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 19 | |
Stephen Wilson | 3e2a18f | 2011-03-23 01:58:26 +0000 | [diff] [blame] | 20 | // C++ Includes |
| 21 | // Other libraries and framework includes |
Pavel Labath | 1eb0d42 | 2016-08-08 12:54:36 +0000 | [diff] [blame^] | 22 | #include "llvm/Support/ScopedPrinter.h" |
Stephen Wilson | 3e2a18f | 2011-03-23 01:58:26 +0000 | [diff] [blame] | 23 | // Project includes |
Johnny Chen | c18a538 | 2011-05-19 23:07:19 +0000 | [diff] [blame] | 24 | #include "lldb/Core/Error.h" |
Todd Fiala | f3d61de | 2014-01-17 20:18:59 +0000 | [diff] [blame] | 25 | #include "lldb/Core/Log.h" |
Johnny Chen | 30213ff | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Process.h" |
| 27 | |
Stephen Wilson | 3e2a18f | 2011-03-23 01:58:26 +0000 | [diff] [blame] | 28 | #include "lldb/Host/Host.h" |
Tamas Berghammer | a109421 | 2015-03-13 11:16:12 +0000 | [diff] [blame] | 29 | #include "lldb/Host/HostInfo.h" |
Johnny Chen | 30213ff | 2012-01-05 19:17:38 +0000 | [diff] [blame] | 30 | #include "lldb/Core/DataBufferHeap.h" |
| 31 | #include "lldb/Core/DataExtractor.h" |
Stephen Wilson | 3e2a18f | 2011-03-23 01:58:26 +0000 | [diff] [blame] | 32 | |
Michael Sartain | c836ae7 | 2013-05-23 20:57:03 +0000 | [diff] [blame] | 33 | #include "lldb/Core/ModuleSpec.h" |
| 34 | #include "lldb/Symbol/ObjectFile.h" |
Todd Fiala | 3dc2fb2 | 2014-06-30 04:14:13 +0000 | [diff] [blame] | 35 | #include "Plugins/Process/Linux/ProcFileReader.h" |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 36 | |
Stephen Wilson | 3e2a18f | 2011-03-23 01:58:26 +0000 | [diff] [blame] | 37 | using namespace lldb; |
| 38 | using namespace lldb_private; |
| 39 | |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 40 | typedef enum ProcessStateFlags |
| 41 | { |
| 42 | eProcessStateRunning = (1u << 0), // Running |
| 43 | eProcessStateSleeping = (1u << 1), // Sleeping in an interruptible wait |
| 44 | eProcessStateWaiting = (1u << 2), // Waiting in an uninterruptible disk sleep |
| 45 | eProcessStateZombie = (1u << 3), // Zombie |
| 46 | eProcessStateTracedOrStopped = (1u << 4), // Traced or stopped (on a signal) |
| 47 | eProcessStatePaging = (1u << 5) // Paging |
| 48 | } ProcessStateFlags; |
| 49 | |
| 50 | typedef struct ProcessStatInfo |
| 51 | { |
| 52 | lldb::pid_t ppid; // Parent Process ID |
| 53 | uint32_t fProcessState; // ProcessStateFlags |
| 54 | } ProcessStatInfo; |
| 55 | |
| 56 | // Get the process info with additional information from /proc/$PID/stat (like process state, and tracer pid). |
| 57 | static bool GetProcessAndStatInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info, ProcessStatInfo &stat_info, lldb::pid_t &tracerpid); |
| 58 | |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 59 | static bool |
| 60 | ReadProcPseudoFileStat (lldb::pid_t pid, ProcessStatInfo& stat_info) |
| 61 | { |
| 62 | // Read the /proc/$PID/stat file. |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 63 | lldb::DataBufferSP buf_sp = process_linux::ProcFileReader::ReadIntoDataBuffer (pid, "stat"); |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 64 | |
| 65 | // The filename of the executable is stored in parenthesis right after the pid. We look for the closing |
| 66 | // parenthesis for the filename and work from there in case the name has something funky like ')' in it. |
| 67 | const char *filename_end = strrchr ((const char *)buf_sp->GetBytes(), ')'); |
| 68 | if (filename_end) |
| 69 | { |
| 70 | char state = '\0'; |
| 71 | int ppid = LLDB_INVALID_PROCESS_ID; |
| 72 | |
| 73 | // Read state and ppid. |
| 74 | sscanf (filename_end + 1, " %c %d", &state, &ppid); |
| 75 | |
| 76 | stat_info.ppid = ppid; |
| 77 | |
| 78 | switch (state) |
| 79 | { |
| 80 | case 'R': |
| 81 | stat_info.fProcessState |= eProcessStateRunning; |
| 82 | break; |
| 83 | case 'S': |
| 84 | stat_info.fProcessState |= eProcessStateSleeping; |
| 85 | break; |
| 86 | case 'D': |
| 87 | stat_info.fProcessState |= eProcessStateWaiting; |
| 88 | break; |
| 89 | case 'Z': |
| 90 | stat_info.fProcessState |= eProcessStateZombie; |
| 91 | break; |
| 92 | case 'T': |
| 93 | stat_info.fProcessState |= eProcessStateTracedOrStopped; |
| 94 | break; |
| 95 | case 'W': |
| 96 | stat_info.fProcessState |= eProcessStatePaging; |
| 97 | break; |
| 98 | } |
| 99 | |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | static void |
| 107 | GetLinuxProcessUserAndGroup (lldb::pid_t pid, ProcessInstanceInfo &process_info, lldb::pid_t &tracerpid) |
| 108 | { |
| 109 | tracerpid = 0; |
| 110 | uint32_t rUid = UINT32_MAX; // Real User ID |
| 111 | uint32_t eUid = UINT32_MAX; // Effective User ID |
| 112 | uint32_t rGid = UINT32_MAX; // Real Group ID |
| 113 | uint32_t eGid = UINT32_MAX; // Effective Group ID |
| 114 | |
| 115 | // Read the /proc/$PID/status file and parse the Uid:, Gid:, and TracerPid: fields. |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 116 | lldb::DataBufferSP buf_sp = process_linux::ProcFileReader::ReadIntoDataBuffer (pid, "status"); |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 117 | |
| 118 | static const char uid_token[] = "Uid:"; |
| 119 | char *buf_uid = strstr ((char *)buf_sp->GetBytes(), uid_token); |
| 120 | if (buf_uid) |
| 121 | { |
| 122 | // Real, effective, saved set, and file system UIDs. Read the first two. |
| 123 | buf_uid += sizeof(uid_token); |
| 124 | rUid = strtol (buf_uid, &buf_uid, 10); |
| 125 | eUid = strtol (buf_uid, &buf_uid, 10); |
| 126 | } |
| 127 | |
| 128 | static const char gid_token[] = "Gid:"; |
| 129 | char *buf_gid = strstr ((char *)buf_sp->GetBytes(), gid_token); |
| 130 | if (buf_gid) |
| 131 | { |
| 132 | // Real, effective, saved set, and file system GIDs. Read the first two. |
| 133 | buf_gid += sizeof(gid_token); |
| 134 | rGid = strtol (buf_gid, &buf_gid, 10); |
| 135 | eGid = strtol (buf_gid, &buf_gid, 10); |
| 136 | } |
| 137 | |
| 138 | static const char tracerpid_token[] = "TracerPid:"; |
| 139 | char *buf_tracerpid = strstr((char *)buf_sp->GetBytes(), tracerpid_token); |
| 140 | if (buf_tracerpid) |
| 141 | { |
| 142 | // Tracer PID. 0 if we're not being debugged. |
| 143 | buf_tracerpid += sizeof(tracerpid_token); |
| 144 | tracerpid = strtol (buf_tracerpid, &buf_tracerpid, 10); |
| 145 | } |
| 146 | |
| 147 | process_info.SetUserID (rUid); |
| 148 | process_info.SetEffectiveUserID (eUid); |
| 149 | process_info.SetGroupID (rGid); |
| 150 | process_info.SetEffectiveGroupID (eGid); |
| 151 | } |
| 152 | |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 153 | lldb::DataBufferSP |
| 154 | Host::GetAuxvData(lldb_private::Process *process) |
| 155 | { |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 156 | return process_linux::ProcFileReader::ReadIntoDataBuffer (process->GetID(), "auxv"); |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 159 | lldb::DataBufferSP |
| 160 | Host::GetAuxvData (lldb::pid_t pid) |
| 161 | { |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 162 | return process_linux::ProcFileReader::ReadIntoDataBuffer (pid, "auxv"); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 165 | static bool |
| 166 | IsDirNumeric(const char *dname) |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 167 | { |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 168 | for (; *dname; dname++) |
| 169 | { |
| 170 | if (!isdigit (*dname)) |
| 171 | return false; |
| 172 | } |
| 173 | return true; |
| 174 | } |
| 175 | |
| 176 | uint32_t |
| 177 | Host::FindProcesses (const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos) |
| 178 | { |
| 179 | static const char procdir[] = "/proc/"; |
| 180 | |
| 181 | DIR *dirproc = opendir (procdir); |
| 182 | if (dirproc) |
| 183 | { |
| 184 | struct dirent *direntry = NULL; |
| 185 | const uid_t our_uid = getuid(); |
| 186 | const lldb::pid_t our_pid = getpid(); |
| 187 | bool all_users = match_info.GetMatchAllUsers(); |
| 188 | |
| 189 | while ((direntry = readdir (dirproc)) != NULL) |
| 190 | { |
| 191 | if (direntry->d_type != DT_DIR || !IsDirNumeric (direntry->d_name)) |
| 192 | continue; |
| 193 | |
| 194 | lldb::pid_t pid = atoi (direntry->d_name); |
| 195 | |
| 196 | // Skip this process. |
| 197 | if (pid == our_pid) |
| 198 | continue; |
| 199 | |
| 200 | lldb::pid_t tracerpid; |
| 201 | ProcessStatInfo stat_info; |
| 202 | ProcessInstanceInfo process_info; |
| 203 | |
| 204 | if (!GetProcessAndStatInfo (pid, process_info, stat_info, tracerpid)) |
| 205 | continue; |
| 206 | |
| 207 | // Skip if process is being debugged. |
| 208 | if (tracerpid != 0) |
| 209 | continue; |
| 210 | |
| 211 | // Skip zombies. |
| 212 | if (stat_info.fProcessState & eProcessStateZombie) |
| 213 | continue; |
| 214 | |
| 215 | // Check for user match if we're not matching all users and not running as root. |
| 216 | if (!all_users && (our_uid != 0) && (process_info.GetUserID() != our_uid)) |
| 217 | continue; |
| 218 | |
| 219 | if (match_info.Matches (process_info)) |
| 220 | { |
| 221 | process_infos.Append (process_info); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | closedir (dirproc); |
| 226 | } |
| 227 | |
| 228 | return process_infos.GetSize(); |
| 229 | } |
| 230 | |
Matt Kopec | 085d6ce | 2013-05-31 22:00:07 +0000 | [diff] [blame] | 231 | bool |
| 232 | Host::FindProcessThreads (const lldb::pid_t pid, TidMap &tids_to_attach) |
| 233 | { |
| 234 | bool tids_changed = false; |
| 235 | static const char procdir[] = "/proc/"; |
| 236 | static const char taskdir[] = "/task/"; |
Pavel Labath | 1eb0d42 | 2016-08-08 12:54:36 +0000 | [diff] [blame^] | 237 | std::string process_task_dir = procdir + llvm::to_string(pid) + taskdir; |
Matt Kopec | 085d6ce | 2013-05-31 22:00:07 +0000 | [diff] [blame] | 238 | DIR *dirproc = opendir (process_task_dir.c_str()); |
| 239 | |
| 240 | if (dirproc) |
| 241 | { |
| 242 | struct dirent *direntry = NULL; |
| 243 | while ((direntry = readdir (dirproc)) != NULL) |
| 244 | { |
| 245 | if (direntry->d_type != DT_DIR || !IsDirNumeric (direntry->d_name)) |
| 246 | continue; |
| 247 | |
| 248 | lldb::tid_t tid = atoi(direntry->d_name); |
| 249 | TidMap::iterator it = tids_to_attach.find(tid); |
| 250 | if (it == tids_to_attach.end()) |
| 251 | { |
| 252 | tids_to_attach.insert(TidPair(tid, false)); |
| 253 | tids_changed = true; |
| 254 | } |
| 255 | } |
| 256 | closedir (dirproc); |
| 257 | } |
| 258 | |
| 259 | return tids_changed; |
| 260 | } |
| 261 | |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 262 | static bool |
Michael Sartain | c836ae7 | 2013-05-23 20:57:03 +0000 | [diff] [blame] | 263 | GetELFProcessCPUType (const char *exe_path, ProcessInstanceInfo &process_info) |
| 264 | { |
| 265 | // Clear the architecture. |
| 266 | process_info.GetArchitecture().Clear(); |
| 267 | |
| 268 | ModuleSpecList specs; |
| 269 | FileSpec filespec (exe_path, false); |
Jason Molenda | d6cfc16 | 2013-07-15 03:25:21 +0000 | [diff] [blame] | 270 | const size_t num_specs = ObjectFile::GetModuleSpecifications (filespec, 0, 0, specs); |
Michael Sartain | c836ae7 | 2013-05-23 20:57:03 +0000 | [diff] [blame] | 271 | // GetModuleSpecifications() could fail if the executable has been deleted or is locked. |
| 272 | // But it shouldn't return more than 1 architecture. |
| 273 | assert(num_specs <= 1 && "Linux plugin supports only a single architecture"); |
| 274 | if (num_specs == 1) |
| 275 | { |
| 276 | ModuleSpec module_spec; |
| 277 | if (specs.GetModuleSpecAtIndex (0, module_spec) && module_spec.GetArchitecture().IsValid()) |
| 278 | { |
| 279 | process_info.GetArchitecture () = module_spec.GetArchitecture(); |
| 280 | return true; |
| 281 | } |
| 282 | } |
| 283 | return false; |
| 284 | } |
| 285 | |
| 286 | static bool |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 287 | GetProcessAndStatInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info, ProcessStatInfo &stat_info, lldb::pid_t &tracerpid) |
| 288 | { |
| 289 | tracerpid = 0; |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 290 | process_info.Clear(); |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 291 | ::memset (&stat_info, 0, sizeof(stat_info)); |
| 292 | stat_info.ppid = LLDB_INVALID_PROCESS_ID; |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 293 | |
Oleksiy Vyalov | 9d90186 | 2016-07-12 18:14:27 +0000 | [diff] [blame] | 294 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
| 295 | |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 296 | // Use special code here because proc/[pid]/exe is a symbolic link. |
| 297 | char link_path[PATH_MAX]; |
| 298 | char exe_path[PATH_MAX] = ""; |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 299 | if (snprintf (link_path, PATH_MAX, "/proc/%" PRIu64 "/exe", pid) <= 0) |
Oleksiy Vyalov | 9d90186 | 2016-07-12 18:14:27 +0000 | [diff] [blame] | 300 | { |
| 301 | if (log) |
| 302 | log->Printf("%s: failed to sprintf pid %" PRIu64, __FUNCTION__, pid); |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 303 | return false; |
Oleksiy Vyalov | 9d90186 | 2016-07-12 18:14:27 +0000 | [diff] [blame] | 304 | } |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 305 | |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 306 | ssize_t len = readlink (link_path, exe_path, sizeof(exe_path) - 1); |
| 307 | if (len <= 0) |
Oleksiy Vyalov | 9d90186 | 2016-07-12 18:14:27 +0000 | [diff] [blame] | 308 | { |
| 309 | if (log) |
| 310 | log->Printf("%s: failed to read link %s: %s", __FUNCTION__, link_path, strerror(errno)); |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 311 | return false; |
Oleksiy Vyalov | 9d90186 | 2016-07-12 18:14:27 +0000 | [diff] [blame] | 312 | } |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 313 | |
| 314 | // readlink does not append a null byte. |
| 315 | exe_path[len] = 0; |
| 316 | |
| 317 | // If the binary has been deleted, the link name has " (deleted)" appended. |
| 318 | // Remove if there. |
| 319 | static const ssize_t deleted_len = strlen(" (deleted)"); |
| 320 | if (len > deleted_len && |
| 321 | !strcmp(exe_path + len - deleted_len, " (deleted)")) |
| 322 | { |
| 323 | exe_path[len - deleted_len] = 0; |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 324 | } |
Michael Sartain | c836ae7 | 2013-05-23 20:57:03 +0000 | [diff] [blame] | 325 | else |
| 326 | { |
| 327 | GetELFProcessCPUType (exe_path, process_info); |
| 328 | } |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 329 | |
| 330 | process_info.SetProcessID(pid); |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 331 | process_info.GetExecutableFile().SetFile(exe_path, false); |
Tamas Berghammer | a109421 | 2015-03-13 11:16:12 +0000 | [diff] [blame] | 332 | process_info.GetArchitecture().MergeFrom(HostInfo::GetArchitecture()); |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 333 | |
| 334 | lldb::DataBufferSP buf_sp; |
| 335 | |
| 336 | // Get the process environment. |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 337 | buf_sp = process_linux::ProcFileReader::ReadIntoDataBuffer(pid, "environ"); |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 338 | Args &info_env = process_info.GetEnvironmentEntries(); |
| 339 | char *next_var = (char *)buf_sp->GetBytes(); |
| 340 | char *end_buf = next_var + buf_sp->GetByteSize(); |
| 341 | while (next_var < end_buf && 0 != *next_var) |
| 342 | { |
| 343 | info_env.AppendArgument(next_var); |
| 344 | next_var += strlen(next_var) + 1; |
| 345 | } |
| 346 | |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 347 | // Get the command line used to start the process. |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 348 | buf_sp = process_linux::ProcFileReader::ReadIntoDataBuffer(pid, "cmdline"); |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 349 | |
Matt Kopec | dc7c73c | 2013-10-09 19:23:34 +0000 | [diff] [blame] | 350 | // Grab Arg0 first, if there is one. |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 351 | char *cmd = (char *)buf_sp->GetBytes(); |
Matt Kopec | dc7c73c | 2013-10-09 19:23:34 +0000 | [diff] [blame] | 352 | if (cmd) |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 353 | { |
Matt Kopec | dc7c73c | 2013-10-09 19:23:34 +0000 | [diff] [blame] | 354 | process_info.SetArg0(cmd); |
| 355 | |
| 356 | // Now process any remaining arguments. |
| 357 | Args &info_args = process_info.GetArguments(); |
| 358 | char *next_arg = cmd + strlen(cmd) + 1; |
| 359 | end_buf = cmd + buf_sp->GetByteSize(); |
| 360 | while (next_arg < end_buf && 0 != *next_arg) |
| 361 | { |
| 362 | info_args.AppendArgument(next_arg); |
| 363 | next_arg += strlen(next_arg) + 1; |
| 364 | } |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 367 | // Read /proc/$PID/stat to get our parent pid. |
| 368 | if (ReadProcPseudoFileStat (pid, stat_info)) |
| 369 | { |
| 370 | process_info.SetParentProcessID (stat_info.ppid); |
| 371 | } |
| 372 | |
| 373 | // Get User and Group IDs and get tracer pid. |
| 374 | GetLinuxProcessUserAndGroup (pid, process_info, tracerpid); |
Andrew Kaylor | bf9b4c1 | 2013-05-07 22:46:38 +0000 | [diff] [blame] | 375 | |
| 376 | return true; |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Daniel Malea | 25d7eb0 | 2013-05-15 17:54:07 +0000 | [diff] [blame] | 379 | bool |
| 380 | Host::GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &process_info) |
| 381 | { |
| 382 | lldb::pid_t tracerpid; |
| 383 | ProcessStatInfo stat_info; |
| 384 | |
| 385 | return GetProcessAndStatInfo (pid, process_info, stat_info, tracerpid); |
| 386 | } |
| 387 | |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 388 | size_t |
| 389 | Host::GetEnvironment (StringList &env) |
| 390 | { |
Michael Sartain | 3cf443d | 2013-07-17 00:26:30 +0000 | [diff] [blame] | 391 | char **host_env = environ; |
| 392 | char *env_entry; |
| 393 | size_t i; |
| 394 | for (i=0; (env_entry = host_env[i]) != NULL; ++i) |
| 395 | env.AppendString(env_entry); |
| 396 | return i; |
Matt Kopec | 62502c6 | 2013-05-13 19:33:58 +0000 | [diff] [blame] | 397 | } |
Todd Fiala | 4ceced3 | 2014-08-29 17:35:57 +0000 | [diff] [blame] | 398 | |
Enrico Granata | 83a1437 | 2015-02-20 21:48:38 +0000 | [diff] [blame] | 399 | Error |
Enrico Granata | b38ef8c | 2015-02-20 22:20:30 +0000 | [diff] [blame] | 400 | Host::ShellExpandArguments (ProcessLaunchInfo &launch_info) |
Enrico Granata | 83a1437 | 2015-02-20 21:48:38 +0000 | [diff] [blame] | 401 | { |
| 402 | return Error("unimplemented"); |
| 403 | } |