[mlir][int-range] Limit xor int range inference to i1 (#116968)
[llvm-project.git] / lldb / tools / lldb-dap / RunInTerminal.h
blobb20f8beb6071dd922564e25d84c38480817894c2
1 //===-- RunInTerminal.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 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_TOOLS_LLDB_DAP_RUNINTERMINAL_H
10 #define LLDB_TOOLS_LLDB_DAP_RUNINTERMINAL_H
12 #include "FifoFiles.h"
13 #include "lldb/API/SBError.h"
15 #include <future>
16 #include <memory>
17 #include <string>
19 namespace lldb_dap {
21 enum RunInTerminalMessageKind {
22 eRunInTerminalMessageKindPID = 0,
23 eRunInTerminalMessageKindError,
24 eRunInTerminalMessageKindDidAttach,
27 struct RunInTerminalMessage;
28 struct RunInTerminalMessagePid;
29 struct RunInTerminalMessageError;
30 struct RunInTerminalMessageDidAttach;
32 struct RunInTerminalMessage {
33 RunInTerminalMessage(RunInTerminalMessageKind kind);
35 virtual ~RunInTerminalMessage() = default;
37 /// Serialize this object to JSON
38 virtual llvm::json::Value ToJSON() const = 0;
40 const RunInTerminalMessagePid *GetAsPidMessage() const;
42 const RunInTerminalMessageError *GetAsErrorMessage() const;
44 RunInTerminalMessageKind kind;
47 using RunInTerminalMessageUP = std::unique_ptr<RunInTerminalMessage>;
49 struct RunInTerminalMessagePid : RunInTerminalMessage {
50 RunInTerminalMessagePid(lldb::pid_t pid);
52 llvm::json::Value ToJSON() const override;
54 lldb::pid_t pid;
57 struct RunInTerminalMessageError : RunInTerminalMessage {
58 RunInTerminalMessageError(llvm::StringRef error);
60 llvm::json::Value ToJSON() const override;
62 std::string error;
65 struct RunInTerminalMessageDidAttach : RunInTerminalMessage {
66 RunInTerminalMessageDidAttach();
68 llvm::json::Value ToJSON() const override;
71 class RunInTerminalLauncherCommChannel {
72 public:
73 RunInTerminalLauncherCommChannel(llvm::StringRef comm_file);
75 /// Wait until the debug adaptor attaches.
76 ///
77 /// \param[in] timeout
78 /// How long to wait to be attached.
80 /// \return
81 /// An \a llvm::Error object in case of errors or if this operation times
82 /// out.
83 llvm::Error WaitUntilDebugAdaptorAttaches(std::chrono::milliseconds timeout);
85 /// Notify the debug adaptor this process' pid.
86 ///
87 /// \return
88 /// An \a llvm::Error object in case of errors or if this operation times
89 /// out.
90 llvm::Error NotifyPid();
92 /// Notify the debug adaptor that there's been an error.
93 void NotifyError(llvm::StringRef error);
95 private:
96 FifoFileIO m_io;
99 class RunInTerminalDebugAdapterCommChannel {
100 public:
101 RunInTerminalDebugAdapterCommChannel(llvm::StringRef comm_file);
103 /// Notify the runInTerminal launcher that it was attached.
105 /// \return
106 /// A future indicated whether the runInTerminal launcher received the
107 /// message correctly or not.
108 std::future<lldb::SBError> NotifyDidAttach();
110 /// Fetch the pid of the runInTerminal launcher.
112 /// \return
113 /// An \a llvm::Error object in case of errors or if this operation times
114 /// out.
115 llvm::Expected<lldb::pid_t> GetLauncherPid();
117 /// Fetch any errors emitted by the runInTerminal launcher or return a
118 /// default error message if a certain timeout if reached.
119 std::string GetLauncherError();
121 private:
122 FifoFileIO m_io;
125 /// Create a fifo file used to communicate the debug adaptor with
126 /// the runInTerminal launcher.
127 llvm::Expected<std::shared_ptr<FifoFile>> CreateRunInTerminalCommFile();
129 } // namespace lldb_dap
131 #endif // LLDB_TOOLS_LLDB_DAP_RUNINTERMINAL_H