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_DAP_LLDBUTILS_H
10 #define LLDB_TOOLS_LLDB_DAP_LLDBUTILS_H
12 #include "DAPForward.h"
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/raw_ostream.h"
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.
26 /// Each individual command can be prefixed with \b ! and/or \b ? in no
27 /// particular order. If \b ? is provided, then the output of that command is
28 /// only emitted if it fails, and if \b ! is provided, then the output is
29 /// emitted regardless, and \b false is returned without executing the
30 /// remaining commands.
33 /// A string that will be printed into \a strm prior to emitting
34 /// the prompt + command and command output. Can be NULL.
36 /// \param[in] commands
37 /// An array of LLDB commands to execute.
40 /// The stream that will receive the prefix, prompt + command and
41 /// all command output.
43 /// \param[in] parse_command_directives
44 /// If \b false, then command prefixes like \b ! or \b ? are not parsed and
45 /// each command is executed verbatim.
48 /// \b true, unless a command prefixed with \b ! fails and parsing of
49 /// command directives is enabled.
50 bool RunLLDBCommands(llvm::StringRef prefix
,
51 const llvm::ArrayRef
<std::string
> &commands
,
52 llvm::raw_ostream
&strm
, bool parse_command_directives
);
54 /// Run a list of LLDB commands in the LLDB command interpreter.
56 /// All output from every command, including the prompt + the command
57 /// is returned in the std::string return value.
60 /// A string that will be printed into \a strm prior to emitting
61 /// the prompt + command and command output. Can be NULL.
63 /// \param[in] commands
64 /// An array of LLDB commands to execute.
66 /// \param[out] required_command_failed
67 /// If parsing of command directives is enabled, this variable is set to
68 /// \b true if one of the commands prefixed with \b ! fails.
70 /// \param[in] parse_command_directives
71 /// If \b false, then command prefixes like \b ! or \b ? are not parsed and
72 /// each command is executed verbatim.
75 /// A std::string that contains the prefix and all commands and
77 std::string
RunLLDBCommands(llvm::StringRef prefix
,
78 const llvm::ArrayRef
<std::string
> &commands
,
79 bool &required_command_failed
,
80 bool parse_command_directives
= true);
82 /// Similar to the method above, but without parsing command directives.
84 RunLLDBCommandsVerbatim(llvm::StringRef prefix
,
85 const llvm::ArrayRef
<std::string
> &commands
);
87 /// Check if a thread has a stop reason.
90 /// The LLDB thread object to check
93 /// \b True if the thread has a valid stop reason, \b false
95 bool ThreadHasStopReason(lldb::SBThread
&thread
);
97 /// Given a LLDB frame, make a frame ID that is unique to a specific
100 /// DAP requires a Stackframe "id" to be unique, so we use the frame
101 /// index in the lower 32 bits and the thread index ID in the upper 32
105 /// The LLDB stack frame object generate the ID for
108 /// A unique integer that allows us to easily find the right
109 /// stack frame within a thread on subsequent VS code requests.
110 int64_t MakeDAPFrameID(lldb::SBFrame
&frame
);
112 /// Given a DAP frame ID, convert to a LLDB thread index id.
114 /// DAP requires a Stackframe "id" to be unique, so we use the frame
115 /// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in
116 /// the upper 32 - THREAD_INDEX_SHIFT bits.
118 /// \param[in] dap_frame_id
119 /// The DAP frame ID to convert to a thread index ID.
122 /// The LLDB thread index ID.
123 uint32_t GetLLDBThreadIndexID(uint64_t dap_frame_id
);
125 /// Given a DAP frame ID, convert to a LLDB frame ID.
127 /// DAP requires a Stackframe "id" to be unique, so we use the frame
128 /// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in
129 /// the upper 32 - THREAD_INDEX_SHIFT bits.
131 /// \param[in] dap_frame_id
132 /// The DAP frame ID to convert to a frame ID.
135 /// The LLDB frame index ID.
136 uint32_t GetLLDBFrameID(uint64_t dap_frame_id
);
138 } // namespace lldb_dap