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 /// Reset this FileAction to its default state.
33 void Clear();
34
35 /// Configure this action to close a file descriptor.
36 bool Close(int fd);
37
38 /// Configure this action to duplicate a file descriptor.
39 ///
40 /// \param[in] fd
41 /// The file descriptor to duplicate.
42 /// \param[in] dup_fd
43 /// The target file descriptor number.
44 bool Duplicate(int fd, int dup_fd);
45
46 /// Configure this action to open a file.
47 ///
48 /// \param[in] fd
49 /// The file descriptor to use for the opened file.
50 /// \param[in] file_spec
51 /// The file to open.
52 /// \param[in] read
53 /// Open for reading.
54 /// \param[in] write
55 /// Open for writing.
56 bool Open(int fd, const FileSpec &file_spec, bool read, bool write);
57
58 /// Get the file descriptor this action applies to.
59 int GetFD() const { return m_fd; }
60
61 /// Get the type of action.
62 Action GetAction() const { return m_action; }
63
64 /// Get the action-specific argument.
65 ///
66 /// For eFileActionOpen, returns the open flags (O_RDONLY, etc.).
67 /// For eFileActionDuplicate, returns the target fd to duplicate to.
68 int GetActionArgument() const { return m_arg; }
69
70 /// Get the file specification for open actions.
71 const FileSpec &GetFileSpec() const;
72
73 void Dump(Stream &stream) const;
74
75protected:
76 /// The action for this file.
78 /// The file descriptor this action applies to.
79 int m_fd = -1;
80 /// oflag for eFileActionOpen, dup_fd for eFileActionDuplicate.
81 int m_arg = -1;
82 /// File spec to use for opening after fork or posix_spawn.
84};
85
86} // namespace lldb_private
87
88#endif
Action GetAction() const
Get the type of action.
Definition FileAction.h:62
void Clear()
Reset this FileAction to its default state.
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:77
int m_fd
The file descriptor this action applies to.
Definition FileAction.h:79
int GetActionArgument() const
Get the action-specific argument.
Definition FileAction.h:68
int m_arg
oflag for eFileActionOpen, dup_fd for eFileActionDuplicate.
Definition FileAction.h:81
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:83
int GetFD() const
Get the file descriptor this action applies to.
Definition FileAction.h:59
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.