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