LLDB mainline
common/Host.cpp
Go to the documentation of this file.
1//===-- Host.cpp ----------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// C includes
10#include <cctype>
11#include <cerrno>
12#include <climits>
13#include <cstdlib>
14#include <sys/types.h>
15
16#ifndef _WIN32
17#include <dlfcn.h>
18#include <grp.h>
19#include <netdb.h>
20#include <pwd.h>
21#include <spawn.h>
22#include <sys/stat.h>
23#include <sys/wait.h>
24#include <unistd.h>
25#endif
26
27#if defined(__APPLE__)
28#include <mach-o/dyld.h>
29#include <mach/mach_init.h>
30#include <mach/mach_port.h>
31#endif
32
33#if defined(__FreeBSD__)
34#include <pthread_np.h>
35#endif
36
37#if defined(__NetBSD__)
38#include <lwp.h>
39#endif
40
41#include <csignal>
42
45#include "lldb/Host/Host.h"
46#include "lldb/Host/HostInfo.h"
53#include "lldb/Utility/Args.h"
56#include "lldb/Utility/Log.h"
58#include "lldb/Utility/Status.h"
60#include "llvm/ADT/SmallString.h"
61#include "llvm/ADT/StringExtras.h"
62#include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
63#include "llvm/Support/Errno.h"
64#include "llvm/Support/FileSystem.h"
65#include "llvm/Support/Program.h"
66
67#if defined(_WIN32)
70#else
72#endif
73
74#if defined(__APPLE__)
75#ifndef _POSIX_SPAWN_DISABLE_ASLR
76#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
77#endif
78
79extern "C" {
80int __pthread_chdir(const char *path);
81int __pthread_fchdir(int fildes);
82}
83
84#endif
85
86using namespace lldb;
87using namespace lldb_private;
88
89#if !defined(__APPLE__) && !defined(_WIN32)
90// The system log is currently only meaningful on Darwin and Windows.
91// On Darwin, this means os_log. On Windows this means Events Viewer.
92// The meaning of a "system log" isn't as clear on other platforms, and
93// therefore we don't providate a default implementation. Vendors are free
94// to implement this function if they have a use for it.
95void Host::SystemLog(Severity severity, llvm::StringRef message) {}
96#endif
97
98static constexpr Log::Category g_categories[] = {
99 {{"system"}, {"system log"}, SystemLog::System}};
100
103
107
109 g_system_log.Enable(std::make_shared<SystemLogHandler>());
110}
111
113
114#if !defined(__APPLE__) && !defined(_WIN32)
115extern "C" char **environ;
116
118
119static thread_result_t
122
123llvm::Expected<HostThread> Host::StartMonitoringChildProcess(
124 const Host::MonitorChildProcessCallback &callback, lldb::pid_t pid) {
125 char thread_name[256];
126 ::snprintf(thread_name, sizeof(thread_name),
127 "<lldb.host.wait4(pid=%" PRIu64 ")>", pid);
128 assert(pid <= UINT32_MAX);
129 return ThreadLauncher::LaunchThread(thread_name, [pid, callback] {
130 return MonitorChildProcessThreadFunction(pid, callback);
131 });
132}
133
134#ifndef __linux__
135// Scoped class that will disable thread canceling when it is constructed, and
136// exception safely restore the previous value it when it goes out of scope.
138public:
140 // Disable the ability for this thread to be cancelled
141 int err = ::pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &m_old_state);
142 if (err != 0)
143 m_old_state = -1;
144 }
145
147 // Restore the ability for this thread to be cancelled to what it
148 // previously was.
149 if (m_old_state != -1)
150 ::pthread_setcancelstate(m_old_state, 0);
151 }
152
153private:
154 int m_old_state; // Save the old cancelability state.
155};
156#endif // __linux__
157
158#ifdef __linux__
159static thread_local volatile sig_atomic_t g_usr1_called;
160
161static void SigUsr1Handler(int) { g_usr1_called = 1; }
162#endif // __linux__
163
165#ifdef __linux__
166 if (g_usr1_called) {
167 g_usr1_called = 0;
168 return true;
169 }
170#else
171 ::pthread_testcancel();
172#endif
173 return false;
174}
175
176static thread_result_t
180 LLDB_LOG(log, "pid = {0}", pid);
181
182 int status = -1;
183
184#ifdef __linux__
185 // This signal is only used to interrupt the thread from waitpid
186 struct sigaction sigUsr1Action;
187 memset(&sigUsr1Action, 0, sizeof(sigUsr1Action));
188 sigUsr1Action.sa_handler = SigUsr1Handler;
189 ::sigaction(SIGUSR1, &sigUsr1Action, nullptr);
190#endif // __linux__
191
192 while (true) {
194 LLDB_LOG(log, "::waitpid({0}, &status, 0)...", pid);
195
197 return nullptr;
198
199 const ::pid_t wait_pid = ::waitpid(pid, &status, 0);
200
201 LLDB_LOG(log, "::waitpid({0}, &status, 0) => pid = {1}, status = {2:x}",
202 pid, wait_pid, status);
203
205 return nullptr;
206
207 if (wait_pid != -1)
208 break;
209 if (errno != EINTR) {
210 LLDB_LOG(log, "pid = {0}, thread exiting because waitpid failed ({1})...",
211 pid, llvm::sys::StrError());
212 return nullptr;
213 }
214 }
215
216 int signal = 0;
217 int exit_status = 0;
218 if (WIFEXITED(status)) {
219 exit_status = WEXITSTATUS(status);
220 } else if (WIFSIGNALED(status)) {
221 signal = WTERMSIG(status);
222 exit_status = -1;
223 } else {
224 llvm_unreachable("Unknown status");
225 }
226
227 // Scope for pthread_cancel_disabler
228 {
229#ifndef __linux__
230 ScopedPThreadCancelDisabler pthread_cancel_disabler;
231#endif
232
233 if (callback)
234 callback(pid, signal, exit_status);
235 }
236
237 LLDB_LOG(GetLog(LLDBLog::Process), "pid = {0} thread exiting...", pid);
238 return nullptr;
239}
240
241#endif // #if !defined (__APPLE__) && !defined (_WIN32)
242
244
245#ifndef _WIN32
246
248 return lldb::thread_t(pthread_self());
249}
250
251const char *Host::GetSignalAsCString(int signo) {
252 switch (signo) {
253 case SIGHUP:
254 return "SIGHUP"; // 1 hangup
255 case SIGINT:
256 return "SIGINT"; // 2 interrupt
257 case SIGQUIT:
258 return "SIGQUIT"; // 3 quit
259 case SIGILL:
260 return "SIGILL"; // 4 illegal instruction (not reset when caught)
261 case SIGTRAP:
262 return "SIGTRAP"; // 5 trace trap (not reset when caught)
263 case SIGABRT:
264 return "SIGABRT"; // 6 abort()
265#if defined(SIGPOLL)
266#if !defined(SIGIO) || (SIGPOLL != SIGIO)
267 // Under some GNU/Linux, SIGPOLL and SIGIO are the same. Causing the build to
268 // fail with 'multiple define cases with same value'
269 case SIGPOLL:
270 return "SIGPOLL"; // 7 pollable event ([XSR] generated, not supported)
271#endif
272#endif
273#if defined(SIGEMT)
274 case SIGEMT:
275 return "SIGEMT"; // 7 EMT instruction
276#endif
277 case SIGFPE:
278 return "SIGFPE"; // 8 floating point exception
279 case SIGKILL:
280 return "SIGKILL"; // 9 kill (cannot be caught or ignored)
281 case SIGBUS:
282 return "SIGBUS"; // 10 bus error
283 case SIGSEGV:
284 return "SIGSEGV"; // 11 segmentation violation
285 case SIGSYS:
286 return "SIGSYS"; // 12 bad argument to system call
287 case SIGPIPE:
288 return "SIGPIPE"; // 13 write on a pipe with no one to read it
289 case SIGALRM:
290 return "SIGALRM"; // 14 alarm clock
291 case SIGTERM:
292 return "SIGTERM"; // 15 software termination signal from kill
293 case SIGURG:
294 return "SIGURG"; // 16 urgent condition on IO channel
295 case SIGSTOP:
296 return "SIGSTOP"; // 17 sendable stop signal not from tty
297 case SIGTSTP:
298 return "SIGTSTP"; // 18 stop signal from tty
299 case SIGCONT:
300 return "SIGCONT"; // 19 continue a stopped process
301 case SIGCHLD:
302 return "SIGCHLD"; // 20 to parent on child stop or exit
303 case SIGTTIN:
304 return "SIGTTIN"; // 21 to readers pgrp upon background tty read
305 case SIGTTOU:
306 return "SIGTTOU"; // 22 like TTIN for output if (tp->t_local&LTOSTOP)
307#if defined(SIGIO)
308 case SIGIO:
309 return "SIGIO"; // 23 input/output possible signal
310#endif
311 case SIGXCPU:
312 return "SIGXCPU"; // 24 exceeded CPU time limit
313 case SIGXFSZ:
314 return "SIGXFSZ"; // 25 exceeded file size limit
315 case SIGVTALRM:
316 return "SIGVTALRM"; // 26 virtual time alarm
317 case SIGPROF:
318 return "SIGPROF"; // 27 profiling time alarm
319#if defined(SIGWINCH)
320 case SIGWINCH:
321 return "SIGWINCH"; // 28 window size changes
322#endif
323#if defined(SIGINFO)
324 case SIGINFO:
325 return "SIGINFO"; // 29 information request
326#endif
327 case SIGUSR1:
328 return "SIGUSR1"; // 30 user defined signal 1
329 case SIGUSR2:
330 return "SIGUSR2"; // 31 user defined signal 2
331 default:
332 break;
333 }
334 return nullptr;
335}
336
337#endif
338
339#if !defined(__APPLE__) // see Host.mm
340
341bool Host::GetBundleDirectory(const FileSpec &file, FileSpec &bundle) {
342 bundle.Clear();
343 return false;
344}
345
346bool Host::ResolveExecutableInBundle(FileSpec &file) { return false; }
347#endif
348
349#ifndef _WIN32
350
352 FileSpec module_filespec;
353 Dl_info info;
354 if (::dladdr(host_addr, &info)) {
355 if (info.dli_fname) {
356 module_filespec.SetFile(info.dli_fname, FileSpec::Style::native);
357 FileSystem::Instance().Resolve(module_filespec);
358 }
359 }
360 return module_filespec;
361}
362
363#endif
364
365#if !defined(__linux__)
366bool Host::FindProcessThreads(const lldb::pid_t pid, TidMap &tids_to_attach) {
367 return false;
368}
369#endif
370
379
380static void
381MonitorShellCommand(std::shared_ptr<ShellInfo> shell_info, lldb::pid_t pid,
382 int signo, // Zero for no signal
383 int status) // Exit value of process if signal is zero
384{
385 shell_info->pid = pid;
386 shell_info->signo = signo;
387 shell_info->status = status;
388 // Let the thread running Host::RunShellCommand() know that the process
389 // exited and that ShellInfo has been filled in by broadcasting to it
390 shell_info->process_reaped.SetValue(true, eBroadcastAlways);
391}
392
393Status Host::RunShellCommand(llvm::StringRef command,
394 const FileSpec &working_dir, int *status_ptr,
395 int *signo_ptr, std::string *command_output_ptr,
396 std::string *separated_error_output,
397 const Timeout<std::micro> &timeout,
398 bool run_in_shell) {
399 return RunShellCommand(llvm::StringRef(), Args(command), working_dir,
400 status_ptr, signo_ptr, command_output_ptr,
401 separated_error_output, timeout, run_in_shell);
402}
403
404Status Host::RunShellCommand(llvm::StringRef shell_path,
405 llvm::StringRef command,
406 const FileSpec &working_dir, int *status_ptr,
407 int *signo_ptr, std::string *command_output_ptr,
408 std::string *separated_error_output,
409 const Timeout<std::micro> &timeout,
410 bool run_in_shell) {
411 return RunShellCommand(shell_path, Args(command), working_dir, status_ptr,
412 signo_ptr, command_output_ptr, separated_error_output,
413 timeout, run_in_shell);
414}
415
416Status Host::RunShellCommand(const Args &args, const FileSpec &working_dir,
417 int *status_ptr, int *signo_ptr,
418 std::string *command_output_ptr,
419 std::string *separated_error_output,
420 const Timeout<std::micro> &timeout,
421 bool run_in_shell) {
422 return RunShellCommand(llvm::StringRef(), args, working_dir, status_ptr,
423 signo_ptr, command_output_ptr, separated_error_output,
424 timeout, run_in_shell);
425}
426
427Status Host::RunShellCommand(llvm::StringRef shell_path, const Args &args,
428 const FileSpec &working_dir, int *status_ptr,
429 int *signo_ptr, std::string *command_output_ptr,
430 std::string *separated_error_output,
431 const Timeout<std::micro> &timeout,
432 bool run_in_shell) {
434 ProcessLaunchInfo launch_info;
435 launch_info.SetArchitecture(HostInfo::GetArchitecture());
436 if (run_in_shell) {
437 // Run the command in a shell
438 FileSpec shell = HostInfo::GetDefaultShell();
439 if (!shell_path.empty())
440 shell.SetPath(shell_path);
441
442 launch_info.SetShell(shell);
443 launch_info.GetArguments().AppendArguments(args);
444 const bool will_debug = false;
445 const bool first_arg_is_full_shell_command = false;
447 error, will_debug, first_arg_is_full_shell_command, 0);
448 } else {
449 // No shell, just run it
450 const bool first_arg_is_executable = true;
451 launch_info.SetArguments(args, first_arg_is_executable);
452 }
453
454 launch_info.GetEnvironment() = Host::GetEnvironment();
455
456 if (working_dir)
457 launch_info.SetWorkingDirectory(working_dir);
458 llvm::SmallString<64> output_file_path;
459 llvm::SmallString<64> error_file_path;
460
461 if (command_output_ptr) {
462 // Create a temporary file to get the stdout and redirect the output
463 // of the command into this file. We will later read this file if all goes
464 // well and fill the data into "command_output_ptr"
465 if (FileSpec tmpdir_file_spec = HostInfo::GetProcessTempDir()) {
466 tmpdir_file_spec.AppendPathComponent("lldb-shell-output.%%%%%%");
467 llvm::sys::fs::createUniqueFile(tmpdir_file_spec.GetPath(),
468 output_file_path);
469 } else {
470 llvm::sys::fs::createTemporaryFile("lldb-shell-output.%%%%%%", "",
471 output_file_path);
472 }
473 }
474
475 if (separated_error_output) {
476 // Create a temporary file to get the stderr and redirect the output
477 // of the command into this file. We will later read this file if all goes
478 // well and fill the data into "separated_error_output".
479 if (FileSpec tmpdir_file_spec = HostInfo::GetProcessTempDir()) {
480 tmpdir_file_spec.AppendPathComponent("lldb-shell-error.%%%%%%");
481 llvm::sys::fs::createUniqueFile(tmpdir_file_spec.GetPath(),
482 error_file_path);
483 } else {
484 llvm::sys::fs::createTemporaryFile("lldb-shell-error.%%%%%%", "",
485 error_file_path);
486 }
487 }
488
489 FileSpec output_file_spec(output_file_path.str());
490 FileSpec error_file_spec(error_file_path.str());
491 // Set up file descriptors.
492 launch_info.AppendSuppressFileAction(STDIN_FILENO, true, false);
493 if (output_file_spec)
494 launch_info.AppendOpenFileAction(STDOUT_FILENO, output_file_spec, false,
495 true);
496 else
497 launch_info.AppendSuppressFileAction(STDOUT_FILENO, false, true);
498
499 if (error_file_spec)
500 launch_info.AppendOpenFileAction(STDERR_FILENO, error_file_spec, false,
501 true);
502 else
503 launch_info.AppendDuplicateFileAction(STDOUT_FILENO, STDERR_FILENO);
504
505 std::shared_ptr<ShellInfo> shell_info_sp(new ShellInfo());
506 launch_info.SetMonitorProcessCallback(
507 std::bind(MonitorShellCommand, shell_info_sp, std::placeholders::_1,
508 std::placeholders::_2, std::placeholders::_3));
509
510 error = LaunchProcess(launch_info);
511 const lldb::pid_t pid = launch_info.GetProcessID();
512
513 if (error.Success() && pid == LLDB_INVALID_PROCESS_ID)
514 error = Status::FromErrorString("failed to get process ID");
515
516 if (error.Success()) {
517 if (!shell_info_sp->process_reaped.WaitForValueEqualTo(true, timeout)) {
519 "timed out waiting for shell command to complete");
520
521 // Kill the process since it didn't complete within the timeout specified
522 Kill(pid, SIGKILL);
523 // Wait for the monitor callback to get the message
524 shell_info_sp->process_reaped.WaitForValueEqualTo(
525 true, std::chrono::seconds(1));
526 } else {
527 if (status_ptr)
528 *status_ptr = shell_info_sp->status;
529
530 if (signo_ptr)
531 *signo_ptr = shell_info_sp->signo;
532
533 if (command_output_ptr) {
534 command_output_ptr->clear();
535 uint64_t file_size =
536 FileSystem::Instance().GetByteSize(output_file_spec);
537 if (file_size > 0) {
538 if (file_size > command_output_ptr->max_size()) {
540 "shell command output is too large to fit into a std::string");
541 } else {
542 WritableDataBufferSP Buffer =
544 output_file_spec);
545 if (error.Success())
546 command_output_ptr->assign(
547 reinterpret_cast<char *>(Buffer->GetBytes()),
548 Buffer->GetByteSize());
549 }
550 }
551 }
552 if (separated_error_output) {
553 separated_error_output->clear();
554 uint64_t file_size =
555 FileSystem::Instance().GetByteSize(error_file_spec);
556 if (file_size > 0) {
557 if (file_size > separated_error_output->max_size()) {
559 "shell command error output is too large to fit into a "
560 "std::string");
561 } else {
562 WritableDataBufferSP Buffer =
564 error_file_spec);
565 if (error.Success())
566 separated_error_output->assign(
567 reinterpret_cast<char *>(Buffer->GetBytes()),
568 Buffer->GetByteSize());
569 }
570 }
571 }
572 }
573 }
574
575 if (output_file_spec)
576 llvm::sys::fs::remove(output_file_spec.GetPath());
577 if (error_file_spec)
578 llvm::sys::fs::remove(error_file_spec.GetPath());
579 return error;
580}
581
582// The functions below implement process launching for non-Apple-based
583// platforms
584#if !defined(__APPLE__)
586 std::unique_ptr<ProcessLauncher> delegate_launcher;
587#if defined(_WIN32)
588 delegate_launcher.reset(new ProcessLauncherWindows());
589#else
590 delegate_launcher.reset(new ProcessLauncherPosixFork());
591#endif
592 MonitoringProcessLauncher launcher(std::move(delegate_launcher));
593
595 HostProcess process = launcher.LaunchProcess(launch_info, error);
596
597 // TODO(zturner): It would be better if the entire HostProcess were returned
598 // instead of writing it into this structure.
599 launch_info.SetProcessID(process.GetProcessId());
600
601 return error;
602}
603#endif // !defined(__APPLE__)
604
605#ifndef _WIN32
606void Host::Kill(lldb::pid_t pid, int signo) { ::kill(pid, signo); }
607
608#endif
609
610#if !defined(__APPLE__)
611llvm::Error Host::OpenFileInExternalEditor(llvm::StringRef editor,
612 const FileSpec &file_spec,
613 uint32_t line_no) {
614 return llvm::errorCodeToError(
615 std::error_code(ENOTSUP, std::system_category()));
616}
617
618bool Host::IsInteractiveGraphicSession() { return false; }
619
620llvm::Error Host::OpenURL(llvm::StringRef url) {
621 if (url.empty())
622 return llvm::createStringError("cannot open empty URL");
623
624 LLDB_LOG(GetLog(LLDBLog::Host), "Opening URL: {0}", url);
625
626#if defined(_WIN32)
627 // TODO: open the URL with ShellExecuteW (needs a shell32 link dependency).
628 return llvm::errorCodeToError(
629 std::error_code(ENOTSUP, std::system_category()));
630#else
631 // Resolve xdg-open and run it directly (run_in_shell=false) so the URL is a
632 // literal argument the shell never parses; this keeps query-string
633 // metacharacters from being interpreted regardless of the user's shell.
634 llvm::ErrorOr<std::string> xdg_open =
635 llvm::sys::findProgramByName("xdg-open");
636 if (!xdg_open)
637 return llvm::createStringError("could not find xdg-open to open the URL");
638
639 Args args;
640 args.AppendArgument(*xdg_open);
641 args.AppendArgument(url);
642
643 int status = 0;
644 int signo = 0;
645 std::string output;
647 args, /*working_dir=*/FileSpec(), &status, &signo, &output,
648 /*separated_error_output=*/nullptr, std::chrono::seconds(10),
649 /*run_in_shell=*/false);
650 if (error.Fail())
651 return error.takeError();
652 if (status != 0)
653 return llvm::createStringError(
654 llvm::formatv("xdg-open exited with status {0}", status));
655 return llvm::Error::success();
656#endif
657}
658#endif
659
660std::string Host::URLEncode(llvm::StringRef str) {
661 std::string out;
662 llvm::raw_string_ostream os(out);
663 llvm::printPercentEncoded(str, os);
664 return out;
665}
666
667std::unique_ptr<Connection> Host::CreateDefaultConnection(llvm::StringRef url) {
668#if defined(_WIN32)
669 if (url.starts_with("file://"))
670 return std::unique_ptr<Connection>(new ConnectionGenericFile());
671#endif
672 return std::unique_ptr<Connection>(new ConnectionFileDescriptor());
673}
674
675#if defined(LLVM_ON_UNIX)
676WaitStatus WaitStatus::Decode(int wstatus) {
677 if (WIFEXITED(wstatus))
678 return {Exit, uint8_t(WEXITSTATUS(wstatus))};
679 else if (WIFSIGNALED(wstatus))
680 return {Signal, uint8_t(WTERMSIG(wstatus))};
681 else if (WIFSTOPPED(wstatus))
682 return {Stop, uint8_t(WSTOPSIG(wstatus))};
683 llvm_unreachable("Unknown wait status");
684}
685#endif
686
687void llvm::format_provider<WaitStatus>::format(const WaitStatus &WS,
688 raw_ostream &OS,
689 StringRef Options) {
690 if (Options == "g") {
691 char type;
692 switch (WS.type) {
693 case WaitStatus::Exit:
694 type = 'W';
695 break;
697 type = 'X';
698 break;
699 case WaitStatus::Stop:
700 type = 'S';
701 break;
702 }
703 OS << formatv("{0}{1:x-2}", type, WS.status);
704 return;
705 }
706
707 assert(Options.empty());
708 const char *desc;
709 switch (WS.type) {
710 case WaitStatus::Exit:
711 desc = "Exited with status";
712 break;
714 desc = "Killed by signal";
715 break;
716 case WaitStatus::Stop:
717 desc = "Stopped by signal";
718 break;
719 }
720 OS << desc << " " << int(WS.status);
721}
722
724 ProcessInstanceInfoList &process_infos) {
725 return FindProcessesImpl(match_info, process_infos);
726}
727
729
731
732void SystemLogHandler::Emit(llvm::StringRef message) {
734}
static llvm::raw_ostream & error(Stream &strm)
int __pthread_chdir(const char *path)
int __pthread_fchdir(int fildes)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:376
#define SIGILL
#define SIGFPE
#define SIGSEGV
#define SIGBUS
A command line argument class.
Definition Args.h:33
void AppendArguments(const Args &rhs)
Definition Args.cpp:307
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
Definition Args.cpp:332
A file utility class.
Definition FileSpec.h:57
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
void SetPath(llvm::StringRef p)
Temporary helper for FileSystem change.
Definition FileSpec.h:287
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:376
void Clear()
Clears the object state.
Definition FileSpec.cpp:261
uint64_t GetByteSize(const FileSpec &file_spec) const
Returns the on-disk size of the given file in bytes.
std::shared_ptr< WritableDataBuffer > CreateWritableDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
lldb::pid_t GetProcessId() const
static Status LaunchProcess(ProcessLaunchInfo &launch_info)
Launch the process specified in launch_info.
static bool FindProcessThreads(const lldb::pid_t pid, TidMap &tids_to_attach)
static bool ResolveExecutableInBundle(FileSpec &file)
When executable files may live within a directory, where the directory represents an executable bundl...
static void SystemLog(lldb::Severity severity, llvm::StringRef message)
Emit the given message to the operating system log.
std::map< lldb::pid_t, bool > TidMap
Definition Host.h:179
static llvm::Error OpenURL(llvm::StringRef url)
Open a URL with the host's default handler (Launch Services on macOS, xdg-open on other Unix).
static std::string URLEncode(llvm::StringRef str)
Percent-encode a string for use in a URL query component, per RFC 3986 (alphanumerics and "-_....
static lldb::thread_t GetCurrentThread()
Get the thread token (the one returned by ThreadCreate when the thread was created) for the calling t...
static Environment GetEnvironment()
static lldb::pid_t GetCurrentProcessID()
Get the process ID for the calling process.
static Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, std::string *error_output, const Timeout< std::micro > &timeout, bool run_in_shell=true)
Run a shell command.
static uint32_t FindProcessesImpl(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
Definition aix/Host.cpp:169
static FileSpec GetModuleFileSpecForHostAddress(const void *host_addr)
Given an address in the current process (the process that is running the LLDB code),...
std::function< void(lldb::pid_t pid, int signal, int status)> MonitorChildProcessCallback
Definition Host.h:88
static uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
static std::unique_ptr< Connection > CreateDefaultConnection(llvm::StringRef url)
static llvm::Expected< HostThread > StartMonitoringChildProcess(const MonitorChildProcessCallback &callback, lldb::pid_t pid)
Start monitoring a child process.
static void Kill(lldb::pid_t pid, int signo)
static const char * GetSignalAsCString(int signo)
static bool IsInteractiveGraphicSession()
Check if we're running in an interactive graphical session.
static bool GetBundleDirectory(const FileSpec &file, FileSpec &bundle_directory)
If you have an executable that is in a bundle and want to get back to the bundle directory from the p...
static llvm::Error OpenFileInExternalEditor(llvm::StringRef editor, const FileSpec &file_spec, uint32_t line_no)
HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info, Status &error) override
Launch the process specified in launch_info.
A command line option parsing protocol class.
Definition Options.h:58
A C++ wrapper class for providing threaded access to a value of type T.
Definition Predicate.h:42
void SetArchitecture(const ArchSpec &arch)
Definition ProcessInfo.h:64
lldb::pid_t GetProcessID() const
Definition ProcessInfo.h:66
void SetArguments(const Args &args, bool first_arg_is_executable)
void SetProcessID(lldb::pid_t pid)
Definition ProcessInfo.h:68
Environment & GetEnvironment()
Definition ProcessInfo.h:86
bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read, bool write)
bool AppendSuppressFileAction(int fd, bool read, bool write)
void SetShell(const FileSpec &shell)
void SetMonitorProcessCallback(Host::MonitorChildProcessCallback callback)
bool ConvertArgumentsForLaunchingInShell(Status &error, bool will_debug, bool first_arg_is_full_shell_command, uint32_t num_resumes)
bool AppendDuplicateFileAction(int fd, int dup_fd)
void SetWorkingDirectory(const FileSpec &working_dir)
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
void Emit(llvm::StringRef message) override
static llvm::Expected< HostThread > LaunchThread(llvm::StringRef name, std::function< lldb::thread_result_t()> thread_function, size_t min_stack_byte_size=0)
static constexpr Log::Category g_categories[]
static bool CheckForMonitorCancellation()
static void MonitorShellCommand(std::shared_ptr< ShellInfo > shell_info, lldb::pid_t pid, int signo, int status)
static Log g_system_log(g_system_channel)
static thread_result_t MonitorChildProcessThreadFunction(::pid_t pid, Host::MonitorChildProcessCallback callback)
char ** environ
static Log::Channel g_system_channel(g_categories, SystemLog::System)
#define UINT32_MAX
#define LLDB_INVALID_PROCESS_ID
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:339
Log::Channel & LogChannelFor< SystemLog >()
@ eBroadcastAlways
Always send a broadcast when the value is modified.
Definition Predicate.h:29
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
Definition Host.h:32
Severity
Used for expressing severity in logs and diagnostics.
void * thread_result_t
Definition lldb-types.h:62
pthread_t thread_t
Definition lldb-types.h:58
uint64_t pid_t
Definition lldb-types.h:83
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
lldb::pid_t pid
lldb_private::Predicate< bool > process_reaped
static WaitStatus Decode(int wstatus)
#define SIGSTOP
#define SIGTRAP
#define SIGKILL