LLDB mainline
FileAction.h
Go to the documentation of this file.
1//===-- FileAction.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_FILEACTION_H
10#define LLDB_HOST_FILEACTION_H
11
13#include <string>
14
15namespace lldb_private {
16
17/// Represents a file descriptor action to be performed during process launch.
18///
19/// FileAction encapsulates operations like opening, closing, or duplicating
20/// file descriptors that should be applied when spawning a new process.
22public:
29
30 FileAction();
31
32 /// Configure this action to close a file descriptor.
33 bool Close(int fd);
34
35 /// Configure this action to duplicate a file descriptor.
36 ///
37 /// \param[in] fd
38 /// The file descriptor to duplicate.
39 /// \param[in] dup_fd
40 /// The target file descriptor number.
41 bool Duplicate(int fd, int dup_fd);
42
43 /// Configure this action to open a file.
44 ///
45 /// \param[in] fd
46 /// The file descriptor to use for the opened file.
47 /// \param[in] file_spec
48 /// The file to open.
49 /// \param[in] read
50 /// Open for reading.
51 /// \param[in] write
52 /// Open for writing.
53 bool Open(int fd, const FileSpec &file_spec, bool read, bool write);
54
55 /// Get the file descriptor this action applies to.
56 int GetFD() const { return m_fd; }
57
58 /// Get the type of action.
59 Action GetAction() const { return m_action; }
60
61 /// Get the action-specific argument.
62 ///
63 /// For eFileActionOpen, returns the open flags (O_RDONLY, etc.).
64 /// For eFileActionDuplicate, returns the target fd to duplicate to.
65 int GetActionArgument() const { return m_arg; }
66
67 /// Get the file specification for open actions.
68 const FileSpec &GetFileSpec() const;
69
70 void Dump(Stream &stream) const;
71
72protected:
73 /// The action for this file.
75 /// The file descriptor this action applies to.
76 int m_fd = -1;
77 /// oflag for eFileActionOpen, dup_fd for eFileActionDuplicate.
78 int m_arg = -1;
79 /// File spec to use for opening after fork or posix_spawn.
81};
82
83} // namespace lldb_private
84
85#endif
Action GetAction() const
Get the type of action.
Definition FileAction.h:59
bool Duplicate(int fd, int dup_fd)
Configure this action to duplicate a file descriptor.
void Dump(Stream &stream) const
Action m_action
The action for this file.
Definition FileAction.h:74
int m_fd
The file descriptor this action applies to.
Definition FileAction.h:76
int GetActionArgument() const
Get the action-specific argument.
Definition FileAction.h:65
int m_arg
oflag for eFileActionOpen, dup_fd for eFileActionDuplicate.
Definition FileAction.h:78
const FileSpec & GetFileSpec() const
Get the file specification for open actions.
bool Open(int fd, const FileSpec &file_spec, bool read, bool write)
Configure this action to open a file.
bool Close(int fd)
Configure this action to close a file descriptor.
FileSpec m_file_spec
File spec to use for opening after fork or posix_spawn.
Definition FileAction.h:80
int GetFD() const
Get the file descriptor this action applies to.
Definition FileAction.h:56
A file utility class.
Definition FileSpec.h:57
A stream class that can stream formatted output to a file.
Definition Stream.h:28
A class that represents a running process on the host machine.