Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Host/ProcessLaunchInfo.h
Line
Count
Source (jump to first uncovered line)
1
//===-- ProcessLaunchInfo.h -------------------------------------*- C++ -*-===//
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
#ifndef LLDB_HOST_PROCESSLAUNCHINFO_H
10
#define LLDB_HOST_PROCESSLAUNCHINFO_H
11
12
// C++ Headers
13
#include <string>
14
15
// LLDB Headers
16
#include "lldb/Utility/Flags.h"
17
18
#include "lldb/Host/FileAction.h"
19
#include "lldb/Host/Host.h"
20
#include "lldb/Host/PseudoTerminal.h"
21
#include "lldb/Utility/FileSpec.h"
22
#include "lldb/Utility/ProcessInfo.h"
23
#include "lldb/Utility/StructuredData.h"
24
25
namespace lldb_private {
26
27
// ProcessLaunchInfo
28
//
29
// Describes any information that is required to launch a process.
30
31
class ProcessLaunchInfo : public ProcessInfo {
32
public:
33
  ProcessLaunchInfo();
34
35
  ProcessLaunchInfo(const FileSpec &stdin_file_spec,
36
                    const FileSpec &stdout_file_spec,
37
                    const FileSpec &stderr_file_spec,
38
                    const FileSpec &working_dir, uint32_t launch_flags);
39
40
30.0k
  void AppendFileAction(const FileAction &info) {
41
30.0k
    m_file_actions.push_back(info);
42
30.0k
  }
43
44
  bool AppendCloseFileAction(int fd);
45
46
  bool AppendDuplicateFileAction(int fd, int dup_fd);
47
48
  bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read,
49
                            bool write);
50
51
  bool AppendSuppressFileAction(int fd, bool read, bool write);
52
53
  // Redirect stdin/stdout/stderr to a pty, if no action for the respective file
54
  // descriptor is specified. (So if stdin and stdout already have file actions,
55
  // but stderr doesn't, then only stderr will be redirected to a pty.)
56
  llvm::Error SetUpPtyRedirection();
57
58
6.56k
  size_t GetNumFileActions() const { return m_file_actions.size(); }
59
60
  const FileAction *GetFileActionAtIndex(size_t idx) const;
61
62
  const FileAction *GetFileActionForFD(int fd) const;
63
64
69.4k
  Flags &GetFlags() { return m_flags; }
65
66
19.7k
  const Flags &GetFlags() const { return m_flags; }
67
68
  const FileSpec &GetWorkingDirectory() const;
69
70
  void SetWorkingDirectory(const FileSpec &working_dir);
71
72
  const char *GetProcessPluginName() const;
73
74
  void SetProcessPluginName(llvm::StringRef plugin);
75
76
  const FileSpec &GetShell() const;
77
78
  void SetShell(const FileSpec &shell);
79
80
2.56k
  uint32_t GetResumeCount() const { return m_resume_count; }
81
82
0
  void SetResumeCount(uint32_t c) { m_resume_count = c; }
83
84
9.15k
  bool GetLaunchInSeparateProcessGroup() const {
85
9.15k
    return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
86
9.15k
  }
87
88
  void SetLaunchInSeparateProcessGroup(bool separate);
89
90
0
  bool GetShellExpandArguments() const {
91
0
    return m_flags.Test(lldb::eLaunchFlagShellExpandArguments);
92
0
  }
93
94
  void SetShellExpandArguments(bool expand);
95
96
  void Clear();
97
98
  bool ConvertArgumentsForLaunchingInShell(Status &error, bool will_debug,
99
                                           bool first_arg_is_full_shell_command,
100
                                           uint32_t num_resumes);
101
102
  void
103
  SetMonitorProcessCallback(const Host::MonitorChildProcessCallback &callback,
104
                            bool monitor_signals);
105
106
0
  Host::MonitorChildProcessCallback GetMonitorProcessCallback() const {
107
0
    return m_monitor_callback;
108
0
  }
109
110
  /// A Monitor callback which does not take any action on process events. Use
111
  /// this if you don't need to take any particular action when the process
112
  /// terminates, but you still need to reap it.
113
  static bool NoOpMonitorCallback(lldb::pid_t pid, bool exited, int signal,
114
                                  int status);
115
116
0
  bool GetMonitorSignals() const { return m_monitor_signals; }
117
118
  // If the LaunchInfo has a monitor callback, then arrange to monitor the
119
  // process. Return true if the LaunchInfo has taken care of monitoring the
120
  // process, and false if the caller might want to monitor the process
121
  // themselves.
122
123
  bool MonitorProcess() const;
124
125
2.57k
  PseudoTerminal &GetPTY() { return *m_pty; }
126
127
  // Get and set the actual listener that will be used for the process events
128
2.58k
  lldb::ListenerSP GetListener() const { return m_listener_sp; }
129
130
14
  void SetListener(const lldb::ListenerSP &listener_sp) {
131
14
    m_listener_sp = listener_sp;
132
14
  }
133
134
5.13k
  lldb::ListenerSP GetHijackListener() const { return m_hijack_listener_sp; }
135
136
2.57k
  void SetHijackListener(const lldb::ListenerSP &listener_sp) {
137
2.57k
    m_hijack_listener_sp = listener_sp;
138
2.57k
  }
139
140
0
  void SetLaunchEventData(const char *data) { m_event_data.assign(data); }
141
142
7
  const char *GetLaunchEventData() const { return m_event_data.c_str(); }
143
144
  void SetDetachOnError(bool enable);
145
146
2.56k
  bool GetDetachOnError() const {
147
2.56k
    return m_flags.Test(lldb::eLaunchFlagDetachOnError);
148
2.56k
  }
149
150
5.16k
  bool IsScriptedProcess() const {
151
5.16k
    return !m_scripted_process_class_name.empty();
152
5.16k
  }
153
154
186
  std::string GetScriptedProcessClassName() const {
155
186
    return m_scripted_process_class_name;
156
186
  }
157
158
12
  void SetScriptedProcessClassName(std::string name) {
159
12
    m_scripted_process_class_name = name;
160
12
  }
161
162
  lldb_private::StructuredData::DictionarySP
163
186
  GetScriptedProcessDictionarySP() const {
164
186
    return m_scripted_process_dictionary_sp;
165
186
  }
166
167
  void SetScriptedProcessDictionarySP(
168
6
      lldb_private::StructuredData::DictionarySP dictionary_sp) {
169
6
    m_scripted_process_dictionary_sp = dictionary_sp;
170
6
  }
171
172
protected:
173
  FileSpec m_working_dir;
174
  std::string m_plugin_name;
175
  FileSpec m_shell;
176
  Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags
177
  std::vector<FileAction> m_file_actions; // File actions for any other files
178
  std::shared_ptr<PseudoTerminal> m_pty;
179
  uint32_t m_resume_count = 0; // How many times do we resume after launching
180
  Host::MonitorChildProcessCallback m_monitor_callback;
181
  void *m_monitor_callback_baton = nullptr;
182
  bool m_monitor_signals = false;
183
  std::string m_event_data; // A string passed to the plugin launch, having no
184
                            // meaning to the upper levels of lldb.
185
  lldb::ListenerSP m_listener_sp;
186
  lldb::ListenerSP m_hijack_listener_sp;
187
  std::string m_scripted_process_class_name; // The name of the class that will
188
                                             // manage a scripted process.
189
  StructuredData::DictionarySP
190
      m_scripted_process_dictionary_sp; // A dictionary that holds key/value
191
                                        // pairs passed to the scripted process.
192
};
193
}
194
195
#endif // LLDB_HOST_PROCESSLAUNCHINFO_H