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"
13 #include "lldb/API/SBError.h"
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
;
57 struct RunInTerminalMessageError
: RunInTerminalMessage
{
58 RunInTerminalMessageError(llvm::StringRef error
);
60 llvm::json::Value
ToJSON() const override
;
65 struct RunInTerminalMessageDidAttach
: RunInTerminalMessage
{
66 RunInTerminalMessageDidAttach();
68 llvm::json::Value
ToJSON() const override
;
71 class RunInTerminalLauncherCommChannel
{
73 RunInTerminalLauncherCommChannel(llvm::StringRef comm_file
);
75 /// Wait until the debug adaptor attaches.
77 /// \param[in] timeout
78 /// How long to wait to be attached.
81 /// An \a llvm::Error object in case of errors or if this operation times
83 llvm::Error
WaitUntilDebugAdaptorAttaches(std::chrono::milliseconds timeout
);
85 /// Notify the debug adaptor this process' pid.
88 /// An \a llvm::Error object in case of errors or if this operation times
90 llvm::Error
NotifyPid();
92 /// Notify the debug adaptor that there's been an error.
93 void NotifyError(llvm::StringRef error
);
99 class RunInTerminalDebugAdapterCommChannel
{
101 RunInTerminalDebugAdapterCommChannel(llvm::StringRef comm_file
);
103 /// Notify the runInTerminal launcher that it was attached.
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.
113 /// An \a llvm::Error object in case of errors or if this operation times
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();
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