Coverage Report

Created: 2022-01-18 06:27

/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/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 "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
ScriptedThreadPythonInterface::ScriptedThreadPythonInterface(
29
    ScriptInterpreterPythonImpl &interpreter)
30
6
    : ScriptedThreadInterface(), ScriptedPythonInterface(interpreter) {}
Unexecuted instantiation: lldb_private::ScriptedThreadPythonInterface::ScriptedThreadPythonInterface(lldb_private::ScriptInterpreterPythonImpl&)
lldb_private::ScriptedThreadPythonInterface::ScriptedThreadPythonInterface(lldb_private::ScriptInterpreterPythonImpl&)
Line
Count
Source
30
6
    : ScriptedThreadInterface(), ScriptedPythonInterface(interpreter) {}
31
32
StructuredData::GenericSP ScriptedThreadPythonInterface::CreatePluginObject(
33
    const llvm::StringRef class_name, ExecutionContext &exe_ctx,
34
42
    StructuredData::DictionarySP args_sp) {
35
36
42
  if (class_name.empty())
37
0
    return {};
38
39
42
  ProcessSP process_sp = exe_ctx.GetProcessSP();
40
42
  StructuredDataImpl args_impl(args_sp);
41
42
  std::string error_string;
42
43
42
  Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
44
42
                 Locker::FreeLock);
45
46
42
  PythonObject ret_val = LLDBSwigPythonCreateScriptedThread(
47
42
      class_name.str().c_str(), m_interpreter.GetDictionaryName(), process_sp,
48
42
      args_impl, error_string);
49
50
42
  if (!ret_val)
51
0
    return {};
52
53
42
  m_object_instance_sp =
54
42
      StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
55
56
42
  return m_object_instance_sp;
57
42
}
58
59
42
lldb::tid_t ScriptedThreadPythonInterface::GetThreadID() {
60
42
  Status error;
61
42
  StructuredData::ObjectSP obj = Dispatch("get_thread_id", error);
62
63
42
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
64
0
    return LLDB_INVALID_THREAD_ID;
65
66
42
  return obj->GetIntegerValue(LLDB_INVALID_THREAD_ID);
67
42
}
68
69
3
llvm::Optional<std::string> ScriptedThreadPythonInterface::GetName() {
70
3
  Status error;
71
3
  StructuredData::ObjectSP obj = Dispatch("get_name", error);
72
73
3
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
74
0
    return {};
75
76
3
  return obj->GetStringValue().str();
77
3
}
78
79
0
lldb::StateType ScriptedThreadPythonInterface::GetState() {
80
0
  Status error;
81
0
  StructuredData::ObjectSP obj = Dispatch("get_state", error);
82
83
0
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
84
0
    return eStateInvalid;
85
86
0
  return static_cast<StateType>(obj->GetIntegerValue(eStateInvalid));
87
0
}
88
89
0
llvm::Optional<std::string> ScriptedThreadPythonInterface::GetQueue() {
90
0
  Status error;
91
0
  StructuredData::ObjectSP obj = Dispatch("get_queue", error);
92
93
0
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
94
0
    return {};
95
96
0
  return obj->GetStringValue().str();
97
0
}
98
99
6
StructuredData::DictionarySP ScriptedThreadPythonInterface::GetStopReason() {
100
6
  Status error;
101
6
  StructuredData::DictionarySP dict =
102
6
      Dispatch<StructuredData::DictionarySP>("get_stop_reason", error);
103
104
6
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
105
0
    return {};
106
107
6
  return dict;
108
6
}
109
110
0
StructuredData::ArraySP ScriptedThreadPythonInterface::GetStackFrames() {
111
0
  return nullptr;
112
0
}
113
114
6
StructuredData::DictionarySP ScriptedThreadPythonInterface::GetRegisterInfo() {
115
6
  Status error;
116
6
  StructuredData::DictionarySP dict =
117
6
      Dispatch<StructuredData::DictionarySP>("get_register_info", error);
118
119
6
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict, error))
120
0
    return {};
121
122
6
  return dict;
123
6
}
124
125
llvm::Optional<std::string>
126
42
ScriptedThreadPythonInterface::GetRegisterContext() {
127
42
  Status error;
128
42
  StructuredData::ObjectSP obj = Dispatch("get_register_context", error);
129
130
42
  if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error))
131
36
    return {};
132
133
6
  return obj->GetAsString()->GetValue().str();
134
42
}
135
136
#endif