1 //===-- RunInTerminal.h ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_TOOLS_LLDB_DAP_RUNINTERMINAL_H
10 #define LLDB_TOOLS_LLDB_DAP_RUNINTERMINAL_H
12 #include "FifoFiles.h"
19 enum RunInTerminalMessageKind
{
20 eRunInTerminalMessageKindPID
= 0,
21 eRunInTerminalMessageKindError
,
22 eRunInTerminalMessageKindDidAttach
,
25 struct RunInTerminalMessage
;
26 struct RunInTerminalMessagePid
;
27 struct RunInTerminalMessageError
;
28 struct RunInTerminalMessageDidAttach
;
30 struct RunInTerminalMessage
{
31 RunInTerminalMessage(RunInTerminalMessageKind kind
);
33 virtual ~RunInTerminalMessage() = default;
35 /// Serialize this object to JSON
36 virtual llvm::json::Value
ToJSON() const = 0;
38 const RunInTerminalMessagePid
*GetAsPidMessage() const;
40 const RunInTerminalMessageError
*GetAsErrorMessage() const;
42 RunInTerminalMessageKind kind
;
45 using RunInTerminalMessageUP
= std::unique_ptr
<RunInTerminalMessage
>;
47 struct RunInTerminalMessagePid
: RunInTerminalMessage
{
48 RunInTerminalMessagePid(lldb::pid_t pid
);
50 llvm::json::Value
ToJSON() const override
;
55 struct RunInTerminalMessageError
: RunInTerminalMessage
{
56 RunInTerminalMessageError(llvm::StringRef error
);
58 llvm::json::Value
ToJSON() const override
;
63 struct RunInTerminalMessageDidAttach
: RunInTerminalMessage
{
64 RunInTerminalMessageDidAttach();
66 llvm::json::Value
ToJSON() const override
;
69 class RunInTerminalLauncherCommChannel
{
71 RunInTerminalLauncherCommChannel(llvm::StringRef comm_file
);
73 /// Wait until the debug adaptor attaches.
75 /// \param[in] timeout
76 /// How long to wait to be attached.
79 /// An \a llvm::Error object in case of errors or if this operation times
81 llvm::Error
WaitUntilDebugAdaptorAttaches(std::chrono::milliseconds timeout
);
83 /// Notify the debug adaptor this process' pid.
86 /// An \a llvm::Error object in case of errors or if this operation times
88 llvm::Error
NotifyPid();
90 /// Notify the debug adaptor that there's been an error.
91 void NotifyError(llvm::StringRef error
);
97 class RunInTerminalDebugAdapterCommChannel
{
99 RunInTerminalDebugAdapterCommChannel(llvm::StringRef comm_file
);
101 /// Notify the runInTerminal launcher that it was attached.
104 /// A future indicated whether the runInTerminal launcher received the
105 /// message correctly or not.
106 std::future
<lldb::SBError
> NotifyDidAttach();
108 /// Fetch the pid of the runInTerminal launcher.
111 /// An \a llvm::Error object in case of errors or if this operation times
113 llvm::Expected
<lldb::pid_t
> GetLauncherPid();
115 /// Fetch any errors emitted by the runInTerminal launcher or return a
116 /// default error message if a certain timeout if reached.
117 std::string
GetLauncherError();
123 /// Create a fifo file used to communicate the debug adaptor with
124 /// the runInTerminal launcher.
125 llvm::Expected
<std::shared_ptr
<FifoFile
>> CreateRunInTerminalCommFile();
127 } // namespace lldb_dap
129 #endif // LLDB_TOOLS_LLDB_DAP_RUNINTERMINAL_H