Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/tools/lldb-vscode/LLDBUtils.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- LLDBUtils.cpp -------------------------------------------*- C++ -*-===//
2
//
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
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "LLDBUtils.h"
10
#include "VSCode.h"
11
12
namespace lldb_vscode {
13
14
void RunLLDBCommands(llvm::StringRef prefix,
15
                     const llvm::ArrayRef<std::string> &commands,
16
16
                     llvm::raw_ostream &strm) {
17
16
  if (commands.empty())
18
12
    return;
19
4
  lldb::SBCommandInterpreter interp = g_vsc.debugger.GetCommandInterpreter();
20
4
  if (!prefix.empty())
21
4
    strm << prefix << "\n";
22
25
  for (const auto &command : commands) {
23
25
    lldb::SBCommandReturnObject result;
24
25
    strm << "(lldb) " << command << "\n";
25
25
    interp.HandleCommand(command.c_str(), result);
26
25
    auto output_len = result.GetOutputSize();
27
25
    if (output_len) {
28
0
      const char *output = result.GetOutput();
29
0
      strm << output;
30
0
    }
31
25
    auto error_len = result.GetErrorSize();
32
25
    if (error_len) {
33
1
      const char *error = result.GetError();
34
1
      strm << error;
35
1
    }
36
25
  }
37
4
}
38
39
std::string RunLLDBCommands(llvm::StringRef prefix,
40
16
                            const llvm::ArrayRef<std::string> &commands) {
41
16
  std::string s;
42
16
  llvm::raw_string_ostream strm(s);
43
16
  RunLLDBCommands(prefix, commands, strm);
44
16
  strm.flush();
45
16
  return s;
46
16
}
47
48
2
bool ThreadHasStopReason(lldb::SBThread &thread) {
49
2
  switch (thread.GetStopReason()) {
50
0
  case lldb::eStopReasonTrace:
51
0
  case lldb::eStopReasonPlanComplete:
52
2
  case lldb::eStopReasonBreakpoint:
53
2
  case lldb::eStopReasonWatchpoint:
54
2
  case lldb::eStopReasonInstrumentation:
55
2
  case lldb::eStopReasonSignal:
56
2
  case lldb::eStopReasonException:
57
2
  case lldb::eStopReasonExec:
58
2
  case lldb::eStopReasonProcessorTrace:
59
2
  case lldb::eStopReasonFork:
60
2
  case lldb::eStopReasonVFork:
61
2
  case lldb::eStopReasonVForkDone:
62
2
    return true;
63
0
  case lldb::eStopReasonThreadExiting:
64
0
  case lldb::eStopReasonInvalid:
65
0
  case lldb::eStopReasonNone:
66
0
    break;
67
2
  }
68
0
  return false;
69
2
}
70
71
static uint32_t constexpr THREAD_INDEX_SHIFT = 19;
72
73
1
uint32_t GetLLDBThreadIndexID(uint64_t dap_frame_id) {
74
1
  return dap_frame_id >> THREAD_INDEX_SHIFT;
75
1
}
76
77
1
uint32_t GetLLDBFrameID(uint64_t dap_frame_id) {
78
1
  return dap_frame_id & ((1u << THREAD_INDEX_SHIFT) - 1);
79
1
}
80
81
1
int64_t MakeVSCodeFrameID(lldb::SBFrame &frame) {
82
1
  return ((int64_t)frame.GetThread().GetIndexID() << THREAD_INDEX_SHIFT) |
83
1
         frame.GetFrameID();
84
1
}
85
86
} // namespace lldb_vscode