1061da546Spatrick //===-- LLDBUtils.h ---------------------------------------------*- C++ -*-===// 2061da546Spatrick // 3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6061da546Spatrick // 7061da546Spatrick //===----------------------------------------------------------------------===// 8061da546Spatrick 9*dda28197Spatrick #ifndef LLDB_TOOLS_LLDB_VSCODE_LLDBUTILS_H 10*dda28197Spatrick #define LLDB_TOOLS_LLDB_VSCODE_LLDBUTILS_H 11061da546Spatrick 12061da546Spatrick #include "VSCodeForward.h" 13061da546Spatrick #include "llvm/ADT/ArrayRef.h" 14061da546Spatrick #include "llvm/ADT/StringRef.h" 15061da546Spatrick #include "llvm/Support/raw_ostream.h" 16061da546Spatrick #include <string> 17061da546Spatrick #include <vector> 18061da546Spatrick 19061da546Spatrick namespace lldb_vscode { 20061da546Spatrick 21061da546Spatrick /// Run a list of LLDB commands in the LLDB command interpreter. 22061da546Spatrick /// 23061da546Spatrick /// All output from every command, including the prompt + the command 24061da546Spatrick /// is placed into the "strm" argument. 25061da546Spatrick /// 26061da546Spatrick /// \param[in] prefix 27061da546Spatrick /// A string that will be printed into \a strm prior to emitting 28061da546Spatrick /// the prompt + command and command output. Can be NULL. 29061da546Spatrick /// 30061da546Spatrick /// \param[in] commands 31061da546Spatrick /// An array of LLDB commands to execute. 32061da546Spatrick /// 33061da546Spatrick /// \param[in] strm 34061da546Spatrick /// The stream that will receive the prefix, prompt + command and 35061da546Spatrick /// all command output. 36061da546Spatrick void RunLLDBCommands(llvm::StringRef prefix, 37061da546Spatrick const llvm::ArrayRef<std::string> &commands, 38061da546Spatrick llvm::raw_ostream &strm); 39061da546Spatrick 40061da546Spatrick /// Run a list of LLDB commands in the LLDB command interpreter. 41061da546Spatrick /// 42061da546Spatrick /// All output from every command, including the prompt + the command 43061da546Spatrick /// is returned in the std::string return value. 44061da546Spatrick /// 45061da546Spatrick /// \param[in] prefix 46061da546Spatrick /// A string that will be printed into \a strm prior to emitting 47061da546Spatrick /// the prompt + command and command output. Can be NULL. 48061da546Spatrick /// 49061da546Spatrick /// \param[in] commands 50061da546Spatrick /// An array of LLDB commands to execute. 51061da546Spatrick /// 52061da546Spatrick /// \return 53061da546Spatrick /// A std::string that contains the prefix and all commands and 54061da546Spatrick /// command output 55061da546Spatrick std::string RunLLDBCommands(llvm::StringRef prefix, 56061da546Spatrick const llvm::ArrayRef<std::string> &commands); 57061da546Spatrick 58061da546Spatrick /// Check if a thread has a stop reason. 59061da546Spatrick /// 60061da546Spatrick /// \param[in] thread 61061da546Spatrick /// The LLDB thread object to check 62061da546Spatrick /// 63061da546Spatrick /// \return 64061da546Spatrick /// \b True if the thread has a valid stop reason, \b false 65061da546Spatrick /// otherwise. 66061da546Spatrick bool ThreadHasStopReason(lldb::SBThread &thread); 67061da546Spatrick 68061da546Spatrick /// Given a LLDB frame, make a frame ID that is unique to a specific 69061da546Spatrick /// thread and frame. 70061da546Spatrick /// 71061da546Spatrick /// VSCode requires a Stackframe "id" to be unique, so we use the frame 72061da546Spatrick /// index in the lower 32 bits and the thread index ID in the upper 32 73061da546Spatrick /// bits. 74061da546Spatrick /// 75061da546Spatrick /// \param[in] frame 76061da546Spatrick /// The LLDB stack frame object generate the ID for 77061da546Spatrick /// 78061da546Spatrick /// \return 79061da546Spatrick /// A unique integer that allows us to easily find the right 80061da546Spatrick /// stack frame within a thread on subsequent VS code requests. 81061da546Spatrick int64_t MakeVSCodeFrameID(lldb::SBFrame &frame); 82061da546Spatrick 83061da546Spatrick /// Given a VSCode frame ID, convert to a LLDB thread index id. 84061da546Spatrick /// 85061da546Spatrick /// VSCode requires a Stackframe "id" to be unique, so we use the frame 86061da546Spatrick /// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in 87061da546Spatrick /// the upper 32 - THREAD_INDEX_SHIFT bits. 88061da546Spatrick /// 89061da546Spatrick /// \param[in] dap_frame_id 90061da546Spatrick /// The VSCode frame ID to convert to a thread index ID. 91061da546Spatrick /// 92061da546Spatrick /// \return 93061da546Spatrick /// The LLDB thread index ID. 94061da546Spatrick uint32_t GetLLDBThreadIndexID(uint64_t dap_frame_id); 95061da546Spatrick 96061da546Spatrick /// Given a VSCode frame ID, convert to a LLDB frame ID. 97061da546Spatrick /// 98061da546Spatrick /// VSCode requires a Stackframe "id" to be unique, so we use the frame 99061da546Spatrick /// index in the lower THREAD_INDEX_SHIFT bits and the thread index ID in 100061da546Spatrick /// the upper 32 - THREAD_INDEX_SHIFT bits. 101061da546Spatrick /// 102061da546Spatrick /// \param[in] dap_frame_id 103061da546Spatrick /// The VSCode frame ID to convert to a frame ID. 104061da546Spatrick /// 105061da546Spatrick /// \return 106061da546Spatrick /// The LLDB frame index ID. 107061da546Spatrick uint32_t GetLLDBFrameID(uint64_t dap_frame_id); 108061da546Spatrick 109061da546Spatrick } // namespace lldb_vscode 110061da546Spatrick 111061da546Spatrick #endif 112