Coverage Report

Created: 2022-07-16 07:03

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