Coverage Report

Created: 2023-09-12 09:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- ScriptedThreadPythonInterface.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 "ScriptedThreadPythonInterface.h"
21
#include <optional>
22
23
using namespace lldb;
24
using namespace lldb_private;
25
using namespace lldb_private::python;
26
using Locker = ScriptInterpreterPythonImpl::Locker;
27
28
ScriptedThreadPythonInterface::ScriptedThreadPythonInterface(
29
    ScriptInterpreterPythonImpl &interpreter)
30
14
    : ScriptedThreadInterface(), ScriptedPythonInterface(interpreter) {}
Unexecuted instantiation: lldb_private::ScriptedThreadPythonInterface::ScriptedThreadPythonInterface(lldb_private::ScriptInterpreterPythonImpl&)
lldb_private::ScriptedThreadPythonInterface::ScriptedThreadPythonInterface(lldb_private::ScriptInterpreterPythonImpl&)
Line
Count
Source
30
14
    : ScriptedThreadInterface(), ScriptedPythonInterface(interpreter) {}
31
32
StructuredData::GenericSP ScriptedThreadPythonInterface::CreatePluginObject(
33
    const llvm::StringRef class_name, ExecutionContext &exe_ctx,
34
14
    StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
35
14
  if (class_name.empty() && !script_obj)
36
0
    return {};
37
38
14
  StructuredDataImpl args_impl(args_sp);
39
14
  std::string error_string;
40
41
14
  Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
42
14
                 Locker::FreeLock);
43
44
14
  PythonObject ret_val;
45
46
14
  if (!script_obj) {
47
0
    lldb::ExecutionContextRefSP exe_ctx_ref_sp =
48
0
        std::make_shared<ExecutionContextRef>(exe_ctx);
49
0
    ret_val = SWIGBridge::LLDBSwigPythonCreateScriptedObject(
50
0
        class_name.str().c_str(), m_interpreter.GetDictionaryName(),
51
0
        exe_ctx_ref_sp, args_impl, error_string);
52
0
  } else
53
14
    ret_val = PythonObject(PyRefType::Borrowed,
54
14
                           static_cast<PyObject *>(script_obj->GetValue()));
55
56
14
  if (!ret_val)
57
0
    return {};
58
59
14
  m_object_instance_sp =
60
14
      StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
61
62
14
  return m_object_instance_sp;
63
14
}
64
65
14
lldb::tid_t ScriptedThreadPythonInterface::GetThreadID() {
66
14
  Status error;
67
14
  StructuredData::ObjectSP obj = Dispatch("get_thread_id", error);
68
69
14
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
70
0
    return LLDB_INVALID_THREAD_ID;
71
72
14
  return obj->GetUnsignedIntegerValue(LLDB_INVALID_THREAD_ID);
73
14
}
74
75
1
std::optional<std::string> ScriptedThreadPythonInterface::GetName() {
76
1
  Status error;
77
1
  StructuredData::ObjectSP obj = Dispatch("get_name", error);
78
79
1
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
80
0
    return {};
81
82
1
  return obj->GetStringValue().str();
83
1
}
84
85
0
lldb::StateType ScriptedThreadPythonInterface::GetState() {
86
0
  Status error;
87
0
  StructuredData::ObjectSP obj = Dispatch("get_state", error);
88
89
0
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
90
0
    return eStateInvalid;
91
92
0
  return static_cast<StateType>(obj->GetUnsignedIntegerValue(eStateInvalid));
93
0
}
94
95
0
std::optional<std::string> ScriptedThreadPythonInterface::GetQueue() {
96
0
  Status error;
97
0
  StructuredData::ObjectSP obj = Dispatch("get_queue", error);
98
99
0
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
100
0
    return {};
101
102
0
  return obj->GetStringValue().str();
103
0
}
104
105
3
StructuredData::DictionarySP ScriptedThreadPythonInterface::GetStopReason() {
106
3
  Status error;
107
3
  StructuredData::DictionarySP dict =
108
3
      Dispatch<StructuredData::DictionarySP>("get_stop_reason", error);
109
110
3
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
111
0
    return {};
112
113
3
  return dict;
114
3
}
115
116
2
StructuredData::ArraySP ScriptedThreadPythonInterface::GetStackFrames() {
117
2
  Status error;
118
2
  StructuredData::ArraySP arr =
119
2
      Dispatch<StructuredData::ArraySP>("get_stackframes", error);
120
121
2
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr, error))
122
0
    return {};
123
124
2
  return arr;
125
2
}
126
127
3
StructuredData::DictionarySP ScriptedThreadPythonInterface::GetRegisterInfo() {
128
3
  Status error;
129
3
  StructuredData::DictionarySP dict =
130
3
      Dispatch<StructuredData::DictionarySP>("get_register_info", error);
131
132
3
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
133
0
    return {};
134
135
3
  return dict;
136
3
}
137
138
15
std::optional<std::string> ScriptedThreadPythonInterface::GetRegisterContext() {
139
15
  Status error;
140
15
  StructuredData::ObjectSP obj = Dispatch("get_register_context", error);
141
142
15
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
143
11
    return {};
144
145
4
  return obj->GetAsString()->GetValue().str();
146
15
}
147
148
0
StructuredData::ArraySP ScriptedThreadPythonInterface::GetExtendedInfo() {
149
0
  Status error;
150
0
  StructuredData::ArraySP arr =
151
0
      Dispatch<StructuredData::ArraySP>("get_extended_info", error);
152
153
0
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr, error))
154
0
    return {};
155
156
0
  return arr;
157
0
}
158
159
#endif