Greg Clayton | 2f5cf85 | 2018-08-16 17:59:38 +0000 | [diff] [blame] | 1 | //===-- LLDBUtils.h ---------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Greg Clayton | 2f5cf85 | 2018-08-16 17:59:38 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLDBVSCODE_LLDBUTILS_H_ |
| 10 | #define LLDBVSCODE_LLDBUTILS_H_ |
| 11 | |
| 12 | #include "VSCodeForward.h" |
| 13 | #include "llvm/ADT/ArrayRef.h" |
| 14 | #include "llvm/ADT/StringRef.h" |
| 15 | #include "llvm/Support/raw_ostream.h" |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
| 19 | namespace lldb_vscode { |
| 20 | |
| 21 | ///---------------------------------------------------------------------- |
| 22 | /// Run a list of LLDB commands in the LLDB command interpreter. |
| 23 | /// |
| 24 | /// All output from every command, including the prompt + the command |
| 25 | /// is placed into the "strm" argument. |
| 26 | /// |
| 27 | /// @param[in] prefix |
| 28 | /// A string that will be printed into \a strm prior to emitting |
Bruce Mitchener | 173946d | 2018-10-04 22:33:39 +0000 | [diff] [blame] | 29 | /// the prompt + command and command output. Can be NULL. |
Greg Clayton | 2f5cf85 | 2018-08-16 17:59:38 +0000 | [diff] [blame] | 30 | /// |
| 31 | /// @param[in] commands |
| 32 | /// An array of LLDB commands to execute. |
| 33 | /// |
| 34 | /// @param[in] strm |
| 35 | /// The stream that will receive the prefix, prompt + command and |
| 36 | /// all command output. |
| 37 | //---------------------------------------------------------------------- |
| 38 | void RunLLDBCommands(llvm::StringRef prefix, |
| 39 | const llvm::ArrayRef<std::string> &commands, |
| 40 | llvm::raw_ostream &strm); |
| 41 | |
| 42 | ///---------------------------------------------------------------------- |
| 43 | /// Run a list of LLDB commands in the LLDB command interpreter. |
| 44 | /// |
| 45 | /// All output from every command, including the prompt + the command |
| 46 | /// is returned in the std::string return value. |
| 47 | /// |
| 48 | /// @param[in] prefix |
| 49 | /// A string that will be printed into \a strm prior to emitting |
Bruce Mitchener | 173946d | 2018-10-04 22:33:39 +0000 | [diff] [blame] | 50 | /// the prompt + command and command output. Can be NULL. |
Greg Clayton | 2f5cf85 | 2018-08-16 17:59:38 +0000 | [diff] [blame] | 51 | /// |
| 52 | /// @param[in] commands |
| 53 | /// An array of LLDB commands to execute. |
| 54 | /// |
| 55 | /// @return |
| 56 | /// A std::string that contains the prefix and all commands and |
| 57 | /// command output |
| 58 | //---------------------------------------------------------------------- |
| 59 | std::string RunLLDBCommands(llvm::StringRef prefix, |
| 60 | const llvm::ArrayRef<std::string> &commands); |
| 61 | |
| 62 | ///---------------------------------------------------------------------- |
| 63 | /// Check if a thread has a stop reason. |
| 64 | /// |
| 65 | /// @param[in] thread |
| 66 | /// The LLDB thread object to check |
| 67 | /// |
| 68 | /// @return |
| 69 | /// \b True if the thread has a valid stop reason, \b false |
| 70 | /// otherwise. |
| 71 | //---------------------------------------------------------------------- |
| 72 | bool ThreadHasStopReason(lldb::SBThread &thread); |
| 73 | |
| 74 | ///---------------------------------------------------------------------- |
| 75 | /// Given a LLDB frame, make a frame ID that is unique to a specific |
| 76 | /// thread and frame. |
| 77 | /// |
| 78 | /// VSCode requires a Stackframe "id" to be unique, so we use the frame |
| 79 | /// index in the lower 32 bits and the thread index ID in the upper 32 |
| 80 | /// bits. |
| 81 | /// |
| 82 | /// @param[in] frame |
| 83 | /// The LLDB stack frame object generate the ID for |
| 84 | /// |
| 85 | /// @return |
| 86 | /// A unique integer that allows us to easily find the right |
| 87 | /// stack frame within a thread on subsequent VS code requests. |
| 88 | //---------------------------------------------------------------------- |
| 89 | int64_t MakeVSCodeFrameID(lldb::SBFrame &frame); |
| 90 | |
Nathan Lanza | 067cc50 | 2018-11-07 19:27:36 +0000 | [diff] [blame] | 91 | ///---------------------------------------------------------------------- |
| 92 | /// Given a VSCode frame ID, convert to a LLDB thread index id. |
| 93 | /// |
| 94 | /// VSCode requires a Stackframe "id" to be unique, so we use the frame |
| 95 | /// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in |
| 96 | /// the upper 32 - THREAD_INDEX_SHIFT bits. |
| 97 | /// |
| 98 | /// @param[in] dap_frame_id |
| 99 | /// The VSCode frame ID to convert to a thread index ID. |
| 100 | /// |
| 101 | /// @return |
| 102 | /// The LLDB thread index ID. |
| 103 | //---------------------------------------------------------------------- |
| 104 | uint32_t GetLLDBThreadIndexID(uint64_t dap_frame_id); |
| 105 | |
| 106 | ///---------------------------------------------------------------------- |
| 107 | /// Given a VSCode frame ID, convert to a LLDB frame ID. |
| 108 | /// |
| 109 | /// VSCode requires a Stackframe "id" to be unique, so we use the frame |
| 110 | /// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in |
| 111 | /// the upper 32 - THREAD_INDEX_SHIFT bits. |
| 112 | /// |
| 113 | /// @param[in] dap_frame_id |
| 114 | /// The VSCode frame ID to convert to a frame ID. |
| 115 | /// |
| 116 | /// @return |
| 117 | /// The LLDB frame index ID. |
| 118 | //---------------------------------------------------------------------- |
| 119 | uint32_t GetLLDBFrameID(uint64_t dap_frame_id); |
| 120 | |
| 121 | ///---------------------------------------------------------------------- |
| 122 | /// Given a LLDB breakpoint, make a breakpoint ID that is unique to a |
| 123 | /// specific breakpoint and breakpoint location. |
| 124 | /// |
| 125 | /// VSCode requires a Breakpoint "id" to be unique, so we use the |
| 126 | /// breakpoint ID in the lower BREAKPOINT_ID_SHIFT bits and the |
| 127 | /// breakpoint location ID in the upper BREAKPOINT_ID_SHIFT bits. |
| 128 | /// |
| 129 | /// @param[in] frame |
| 130 | /// The LLDB stack frame object generate the ID for |
| 131 | /// |
| 132 | /// @return |
| 133 | /// A unique integer that allows us to easily find the right |
| 134 | /// stack frame within a thread on subsequent VS code requests. |
| 135 | //---------------------------------------------------------------------- |
| 136 | int64_t MakeVSCodeBreakpointID(lldb::SBBreakpointLocation &bp_loc); |
| 137 | |
| 138 | ///---------------------------------------------------------------------- |
| 139 | /// Given a VSCode breakpoint ID, convert to a LLDB breakpoint ID. |
| 140 | /// |
| 141 | /// VSCode requires a Breakpoint "id" to be unique, so we use the |
| 142 | /// breakpoint ID in the lower BREAKPOINT_ID_SHIFT bits and the |
| 143 | /// breakpoint location ID in the upper BREAKPOINT_ID_SHIFT bits. |
| 144 | /// |
| 145 | /// @param[in] dap_breakpoint_id |
| 146 | /// The VSCode breakpoint ID to convert to an LLDB breakpoint ID. |
| 147 | /// |
| 148 | /// @return |
| 149 | /// The LLDB breakpoint ID. |
| 150 | //---------------------------------------------------------------------- |
| 151 | uint32_t GetLLDBBreakpointID(uint64_t dap_breakpoint_id); |
| 152 | |
| 153 | ///---------------------------------------------------------------------- |
| 154 | /// Given a VSCode breakpoint ID, convert to a LLDB breakpoint location ID. |
| 155 | /// |
| 156 | /// VSCode requires a Breakpoint "id" to be unique, so we use the |
| 157 | /// breakpoint ID in the lower BREAKPOINT_ID_SHIFT bits and the |
| 158 | /// breakpoint location ID in the upper BREAKPOINT_ID_SHIFT bits. |
| 159 | /// |
| 160 | /// @param[in] dap_breakpoint_id |
| 161 | /// The VSCode frame ID to convert to a breakpoint location ID. |
| 162 | /// |
| 163 | /// @return |
| 164 | /// The LLDB breakpoint location ID. |
| 165 | //---------------------------------------------------------------------- |
| 166 | uint32_t GetLLDBBreakpointLocationID(uint64_t dap_breakpoint_id); |
Greg Clayton | 2f5cf85 | 2018-08-16 17:59:38 +0000 | [diff] [blame] | 167 | } // namespace lldb_vscode |
| 168 | |
| 169 | #endif |