Coverage Report

Created: 2022-01-22 13:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- ScriptedProcessPythonInterface.cpp --------------------------------===//
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 "lldb/Host/Config.h"
10
#include "lldb/Utility/Log.h"
11
#include "lldb/Utility/Logging.h"
12
#include "lldb/lldb-enumerations.h"
13
14
#if LLDB_ENABLE_PYTHON
15
16
// LLDB Python header must be included first
17
#include "lldb-python.h"
18
19
#include "SWIGPythonBridge.h"
20
#include "ScriptInterpreterPythonImpl.h"
21
#include "ScriptedProcessPythonInterface.h"
22
#include "ScriptedThreadPythonInterface.h"
23
24
using namespace lldb;
25
using namespace lldb_private;
26
using namespace lldb_private::python;
27
using Locker = ScriptInterpreterPythonImpl::Locker;
28
29
ScriptedProcessPythonInterface::ScriptedProcessPythonInterface(
30
    ScriptInterpreterPythonImpl &interpreter)
31
1.43k
    : ScriptedProcessInterface(), ScriptedPythonInterface(interpreter) {}
Unexecuted instantiation: lldb_private::ScriptedProcessPythonInterface::ScriptedProcessPythonInterface(lldb_private::ScriptInterpreterPythonImpl&)
lldb_private::ScriptedProcessPythonInterface::ScriptedProcessPythonInterface(lldb_private::ScriptInterpreterPythonImpl&)
Line
Count
Source
31
1.43k
    : ScriptedProcessInterface(), ScriptedPythonInterface(interpreter) {}
32
33
StructuredData::GenericSP ScriptedProcessPythonInterface::CreatePluginObject(
34
    llvm::StringRef class_name, ExecutionContext &exe_ctx,
35
180
    StructuredData::DictionarySP args_sp) {
36
180
  if (class_name.empty())
37
174
    return {};
38
39
6
  TargetSP target_sp = exe_ctx.GetTargetSP();
40
6
  StructuredDataImpl args_impl(args_sp);
41
6
  std::string error_string;
42
43
6
  Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
44
6
                 Locker::FreeLock);
45
46
6
  PythonObject ret_val = LLDBSwigPythonCreateScriptedProcess(
47
6
      class_name.str().c_str(), m_interpreter.GetDictionaryName(), target_sp,
48
6
      args_impl, error_string);
49
50
6
  if (!ret_val)
51
0
    return {};
52
53
6
  m_object_instance_sp =
54
6
      StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
55
56
6
  return m_object_instance_sp;
57
6
}
58
59
6
Status ScriptedProcessPythonInterface::Launch() {
60
6
  return GetStatusFromMethod("launch");
61
6
}
62
63
6
Status ScriptedProcessPythonInterface::Resume() {
64
6
  return GetStatusFromMethod("resume");
65
6
}
66
67
0
bool ScriptedProcessPythonInterface::ShouldStop() {
68
0
  Status error;
69
0
  StructuredData::ObjectSP obj = Dispatch("is_alive", error);
70
71
0
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
72
0
    return {};
73
74
0
  return obj->GetBooleanValue();
75
0
}
76
77
0
Status ScriptedProcessPythonInterface::Stop() {
78
0
  return GetStatusFromMethod("stop");
79
0
}
80
81
llvm::Optional<MemoryRegionInfo>
82
ScriptedProcessPythonInterface::GetMemoryRegionContainingAddress(
83
3
    lldb::addr_t address, Status &error) {
84
3
  auto mem_region = Dispatch<llvm::Optional<MemoryRegionInfo>>(
85
3
      "get_memory_region_containing_address", error, address);
86
87
3
  if (error.Fail()) {
88
3
    return ErrorWithMessage<MemoryRegionInfo>(LLVM_PRETTY_FUNCTION,
89
3
                                              error.AsCString(), error);
90
3
  }
91
92
0
  return mem_region;
93
3
}
94
95
StructuredData::DictionarySP
96
0
ScriptedProcessPythonInterface::GetThreadWithID(lldb::tid_t tid) {
97
0
  Status error;
98
0
  StructuredData::ObjectSP obj = Dispatch("get_thread_with_id", error, tid);
99
100
0
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
101
0
    return {};
102
103
0
  StructuredData::DictionarySP dict{obj->GetAsDictionary()};
104
105
0
  return dict;
106
0
}
107
108
StructuredData::DictionarySP
109
0
ScriptedProcessPythonInterface::GetRegistersForThread(lldb::tid_t tid) {
110
  // TODO: Implement
111
0
  return {};
112
0
}
113
114
lldb::DataExtractorSP ScriptedProcessPythonInterface::ReadMemoryAtAddress(
115
3
    lldb::addr_t address, size_t size, Status &error) {
116
3
  return Dispatch<lldb::DataExtractorSP>("read_memory_at_address", error,
117
3
                                         address, size);
118
3
}
119
120
0
StructuredData::DictionarySP ScriptedProcessPythonInterface::GetLoadedImages() {
121
  // TODO: Implement
122
0
  return {};
123
0
}
124
125
6
lldb::pid_t ScriptedProcessPythonInterface::GetProcessID() {
126
6
  Status error;
127
6
  StructuredData::ObjectSP obj = Dispatch("get_process_id", error);
128
129
6
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
130
0
    return LLDB_INVALID_PROCESS_ID;
131
132
6
  return obj->GetIntegerValue(LLDB_INVALID_PROCESS_ID);
133
6
}
134
135
12
bool ScriptedProcessPythonInterface::IsAlive() {
136
12
  Status error;
137
12
  StructuredData::ObjectSP obj = Dispatch("is_alive", error);
138
139
12
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
140
0
    return {};
141
142
12
  return obj->GetBooleanValue();
143
12
}
144
145
llvm::Optional<std::string>
146
42
ScriptedProcessPythonInterface::GetScriptedThreadPluginName() {
147
42
  Status error;
148
42
  StructuredData::ObjectSP obj = Dispatch("get_scripted_thread_plugin", error);
149
150
42
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
151
0
    return {};
152
153
42
  return obj->GetStringValue().str();
154
42
}
155
156
lldb::ScriptedThreadInterfaceSP
157
144
ScriptedProcessPythonInterface::GetScriptedThreadInterface() {
158
144
  if (!m_scripted_thread_interface_sp)
159
6
    m_scripted_thread_interface_sp =
160
6
        std::make_shared<ScriptedThreadPythonInterface>(m_interpreter);
161
162
144
  return m_scripted_thread_interface_sp;
163
144
}
164
165
#endif