1 //===-- LLDBUtils.cpp -------------------------------------------*- 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 //===----------------------------------------------------------------------===//
12 namespace lldb_vscode
{
14 void RunLLDBCommands(llvm::StringRef prefix
,
15 const llvm::ArrayRef
<std::string
> &commands
,
16 llvm::raw_ostream
&strm
) {
19 lldb::SBCommandInterpreter interp
= g_vsc
.debugger
.GetCommandInterpreter();
21 strm
<< prefix
<< "\n";
22 for (const auto &command
: commands
) {
23 lldb::SBCommandReturnObject result
;
24 strm
<< "(lldb) " << command
<< "\n";
25 interp
.HandleCommand(command
.c_str(), result
);
26 auto output_len
= result
.GetOutputSize();
28 const char *output
= result
.GetOutput();
31 auto error_len
= result
.GetErrorSize();
33 const char *error
= result
.GetError();
39 std::string
RunLLDBCommands(llvm::StringRef prefix
,
40 const llvm::ArrayRef
<std::string
> &commands
) {
42 llvm::raw_string_ostream
strm(s
);
43 RunLLDBCommands(prefix
, commands
, strm
);
48 bool ThreadHasStopReason(lldb::SBThread
&thread
) {
49 switch (thread
.GetStopReason()) {
50 case lldb::eStopReasonTrace
:
51 case lldb::eStopReasonPlanComplete
:
52 case lldb::eStopReasonBreakpoint
:
53 case lldb::eStopReasonWatchpoint
:
54 case lldb::eStopReasonInstrumentation
:
55 case lldb::eStopReasonSignal
:
56 case lldb::eStopReasonException
:
57 case lldb::eStopReasonExec
:
58 case lldb::eStopReasonProcessorTrace
:
59 case lldb::eStopReasonFork
:
60 case lldb::eStopReasonVFork
:
61 case lldb::eStopReasonVForkDone
:
63 case lldb::eStopReasonThreadExiting
:
64 case lldb::eStopReasonInvalid
:
65 case lldb::eStopReasonNone
:
71 static uint32_t constexpr THREAD_INDEX_SHIFT
= 19;
73 uint32_t GetLLDBThreadIndexID(uint64_t dap_frame_id
) {
74 return dap_frame_id
>> THREAD_INDEX_SHIFT
;
77 uint32_t GetLLDBFrameID(uint64_t dap_frame_id
) {
78 return dap_frame_id
& ((1u << THREAD_INDEX_SHIFT
) - 1);
81 int64_t MakeVSCodeFrameID(lldb::SBFrame
&frame
) {
82 return (int64_t)(frame
.GetThread().GetIndexID() << THREAD_INDEX_SHIFT
|
86 } // namespace lldb_vscode