1 //===-- LLDBUtils.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_VSCODE_LLDBUTILS_H
10 #define LLDB_TOOLS_LLDB_VSCODE_LLDBUTILS_H
12 #include "VSCodeForward.h"
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/raw_ostream.h"
19 namespace lldb_vscode
{
21 /// Run a list of LLDB commands in the LLDB command interpreter.
23 /// All output from every command, including the prompt + the command
24 /// is placed into the "strm" argument.
27 /// A string that will be printed into \a strm prior to emitting
28 /// the prompt + command and command output. Can be NULL.
30 /// \param[in] commands
31 /// An array of LLDB commands to execute.
34 /// The stream that will receive the prefix, prompt + command and
35 /// all command output.
36 void RunLLDBCommands(llvm::StringRef prefix
,
37 const llvm::ArrayRef
<std::string
> &commands
,
38 llvm::raw_ostream
&strm
);
40 /// Run a list of LLDB commands in the LLDB command interpreter.
42 /// All output from every command, including the prompt + the command
43 /// is returned in the std::string return value.
46 /// A string that will be printed into \a strm prior to emitting
47 /// the prompt + command and command output. Can be NULL.
49 /// \param[in] commands
50 /// An array of LLDB commands to execute.
53 /// A std::string that contains the prefix and all commands and
55 std::string
RunLLDBCommands(llvm::StringRef prefix
,
56 const llvm::ArrayRef
<std::string
> &commands
);
58 /// Check if a thread has a stop reason.
61 /// The LLDB thread object to check
64 /// \b True if the thread has a valid stop reason, \b false
66 bool ThreadHasStopReason(lldb::SBThread
&thread
);
68 /// Given a LLDB frame, make a frame ID that is unique to a specific
71 /// VSCode requires a Stackframe "id" to be unique, so we use the frame
72 /// index in the lower 32 bits and the thread index ID in the upper 32
76 /// The LLDB stack frame object generate the ID for
79 /// A unique integer that allows us to easily find the right
80 /// stack frame within a thread on subsequent VS code requests.
81 int64_t MakeVSCodeFrameID(lldb::SBFrame
&frame
);
83 /// Given a VSCode frame ID, convert to a LLDB thread index id.
85 /// VSCode requires a Stackframe "id" to be unique, so we use the frame
86 /// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in
87 /// the upper 32 - THREAD_INDEX_SHIFT bits.
89 /// \param[in] dap_frame_id
90 /// The VSCode frame ID to convert to a thread index ID.
93 /// The LLDB thread index ID.
94 uint32_t GetLLDBThreadIndexID(uint64_t dap_frame_id
);
96 /// Given a VSCode frame ID, convert to a LLDB frame ID.
98 /// VSCode requires a Stackframe "id" to be unique, so we use the frame
99 /// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in
100 /// the upper 32 - THREAD_INDEX_SHIFT bits.
102 /// \param[in] dap_frame_id
103 /// The VSCode frame ID to convert to a frame ID.
106 /// The LLDB frame index ID.
107 uint32_t GetLLDBFrameID(uint64_t dap_frame_id
);
109 } // namespace lldb_vscode