Coverage Report

Created: 2022-01-18 06:27

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