blob: bf89021d3f9b20168acd3c65263f8c2a9dd7b366 [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
30/// the prmopt + command and command output. Can be NULL.
31///
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
51/// the prmopt + command and command output. Can be NULL.
52///
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
92} // namespace lldb_vscode
93
94#endif