Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:49

0001 //===-- ProcessLaunchInfo.h -------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_HOST_PROCESSLAUNCHINFO_H
0010 #define LLDB_HOST_PROCESSLAUNCHINFO_H
0011 
0012 // C++ Headers
0013 #include <string>
0014 
0015 // LLDB Headers
0016 #include "lldb/Utility/Flags.h"
0017 
0018 #include "lldb/Host/FileAction.h"
0019 #include "lldb/Host/Host.h"
0020 #include "lldb/Host/PseudoTerminal.h"
0021 #include "lldb/Utility/FileSpec.h"
0022 #include "lldb/Utility/ProcessInfo.h"
0023 
0024 namespace lldb_private {
0025 
0026 // ProcessLaunchInfo
0027 //
0028 // Describes any information that is required to launch a process.
0029 
0030 class ProcessLaunchInfo : public ProcessInfo {
0031 public:
0032   ProcessLaunchInfo();
0033 
0034   ProcessLaunchInfo(const FileSpec &stdin_file_spec,
0035                     const FileSpec &stdout_file_spec,
0036                     const FileSpec &stderr_file_spec,
0037                     const FileSpec &working_dir, uint32_t launch_flags);
0038 
0039   void AppendFileAction(const FileAction &info) {
0040     m_file_actions.push_back(info);
0041   }
0042 
0043   bool AppendCloseFileAction(int fd);
0044 
0045   bool AppendDuplicateFileAction(int fd, int dup_fd);
0046 
0047   bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read,
0048                             bool write);
0049 
0050   bool AppendSuppressFileAction(int fd, bool read, bool write);
0051 
0052   // Redirect stdin/stdout/stderr to a pty, if no action for the respective file
0053   // descriptor is specified. (So if stdin and stdout already have file actions,
0054   // but stderr doesn't, then only stderr will be redirected to a pty.)
0055   llvm::Error SetUpPtyRedirection();
0056 
0057   size_t GetNumFileActions() const { return m_file_actions.size(); }
0058 
0059   const FileAction *GetFileActionAtIndex(size_t idx) const;
0060 
0061   const FileAction *GetFileActionForFD(int fd) const;
0062 
0063   Flags &GetFlags() { return m_flags; }
0064 
0065   const Flags &GetFlags() const { return m_flags; }
0066 
0067   const FileSpec &GetWorkingDirectory() const;
0068 
0069   void SetWorkingDirectory(const FileSpec &working_dir);
0070 
0071   llvm::StringRef GetProcessPluginName() const;
0072 
0073   void SetProcessPluginName(llvm::StringRef plugin);
0074 
0075   const FileSpec &GetShell() const;
0076 
0077   void SetShell(const FileSpec &shell);
0078 
0079   uint32_t GetResumeCount() const { return m_resume_count; }
0080 
0081   void SetResumeCount(uint32_t c) { m_resume_count = c; }
0082 
0083   bool GetLaunchInSeparateProcessGroup() const {
0084     return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
0085   }
0086 
0087   void SetLaunchInSeparateProcessGroup(bool separate);
0088 
0089   bool GetShellExpandArguments() const {
0090     return m_flags.Test(lldb::eLaunchFlagShellExpandArguments);
0091   }
0092 
0093   void SetShellExpandArguments(bool expand);
0094 
0095   void Clear();
0096 
0097   bool ConvertArgumentsForLaunchingInShell(Status &error, bool will_debug,
0098                                            bool first_arg_is_full_shell_command,
0099                                            uint32_t num_resumes);
0100 
0101   void SetMonitorProcessCallback(Host::MonitorChildProcessCallback callback) {
0102     m_monitor_callback = std::move(callback);
0103   }
0104 
0105   const Host::MonitorChildProcessCallback &GetMonitorProcessCallback() const {
0106     return m_monitor_callback;
0107   }
0108 
0109   /// A Monitor callback which does not take any action on process events. Use
0110   /// this if you don't need to take any particular action when the process
0111   /// terminates, but you still need to reap it.
0112   static void NoOpMonitorCallback(lldb::pid_t pid, int signal, int status);
0113 
0114   // If the LaunchInfo has a monitor callback, then arrange to monitor the
0115   // process. Return true if the LaunchInfo has taken care of monitoring the
0116   // process, and false if the caller might want to monitor the process
0117   // themselves.
0118 
0119   bool MonitorProcess() const;
0120 
0121   PseudoTerminal &GetPTY() { return *m_pty; }
0122 
0123   void SetLaunchEventData(const char *data) { m_event_data.assign(data); }
0124 
0125   const char *GetLaunchEventData() const { return m_event_data.c_str(); }
0126 
0127   void SetDetachOnError(bool enable);
0128 
0129   bool GetDetachOnError() const {
0130     return m_flags.Test(lldb::eLaunchFlagDetachOnError);
0131   }
0132 
0133 protected:
0134   FileSpec m_working_dir;
0135   std::string m_plugin_name;
0136   FileSpec m_shell;
0137   Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags
0138   std::vector<FileAction> m_file_actions; // File actions for any other files
0139   std::shared_ptr<PseudoTerminal> m_pty;
0140   uint32_t m_resume_count = 0; // How many times do we resume after launching
0141   Host::MonitorChildProcessCallback m_monitor_callback;
0142   std::string m_event_data; // A string passed to the plugin launch, having no
0143                             // meaning to the upper levels of lldb.
0144 };
0145 }
0146 
0147 #endif // LLDB_HOST_PROCESSLAUNCHINFO_H