Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPlatformPythonInterface.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- ScriptedPlatformPythonInterface.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/Status.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 "ScriptedPlatformPythonInterface.h"
22
23
using namespace lldb;
24
using namespace lldb_private;
25
using namespace lldb_private::python;
26
using Locker = ScriptInterpreterPythonImpl::Locker;
27
28
ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
29
    ScriptInterpreterPythonImpl &interpreter)
30
1.80k
    : ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
Unexecuted instantiation: lldb_private::ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(lldb_private::ScriptInterpreterPythonImpl&)
lldb_private::ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(lldb_private::ScriptInterpreterPythonImpl&)
Line
Count
Source
30
1.80k
    : ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
31
32
StructuredData::GenericSP ScriptedPlatformPythonInterface::CreatePluginObject(
33
    llvm::StringRef class_name, ExecutionContext &exe_ctx,
34
0
    StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
35
0
  if (class_name.empty())
36
0
    return {};
37
38
0
  StructuredDataImpl args_impl(args_sp);
39
0
  std::string error_string;
40
41
0
  Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
42
0
                 Locker::FreeLock);
43
44
0
  lldb::ExecutionContextRefSP exe_ctx_ref_sp =
45
0
      std::make_shared<ExecutionContextRef>(exe_ctx);
46
47
0
  PythonObject ret_val = SWIGBridge::LLDBSwigPythonCreateScriptedObject(
48
0
      class_name.str().c_str(), m_interpreter.GetDictionaryName(),
49
0
      exe_ctx_ref_sp, args_impl, error_string);
50
51
0
  m_object_instance_sp =
52
0
      StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
53
54
0
  return m_object_instance_sp;
55
0
}
56
57
0
StructuredData::DictionarySP ScriptedPlatformPythonInterface::ListProcesses() {
58
0
  Status error;
59
0
  StructuredData::DictionarySP dict_sp =
60
0
      Dispatch<StructuredData::DictionarySP>("list_processes", error);
61
62
0
  if (!dict_sp || !dict_sp->IsValid() || error.Fail()) {
63
0
    return ScriptedInterface::ErrorWithMessage<StructuredData::DictionarySP>(
64
0
        LLVM_PRETTY_FUNCTION,
65
0
        llvm::Twine("Null or invalid object (" +
66
0
                    llvm::Twine(error.AsCString()) + llvm::Twine(")."))
67
0
            .str(),
68
0
        error);
69
0
  }
70
71
0
  return dict_sp;
72
0
}
73
74
StructuredData::DictionarySP
75
0
ScriptedPlatformPythonInterface::GetProcessInfo(lldb::pid_t pid) {
76
0
  Status error;
77
0
  StructuredData::DictionarySP dict_sp =
78
0
      Dispatch<StructuredData::DictionarySP>("get_process_info", error, pid);
79
80
0
  if (!dict_sp || !dict_sp->IsValid() || error.Fail()) {
81
0
    return ScriptedInterface::ErrorWithMessage<StructuredData::DictionarySP>(
82
0
        LLVM_PRETTY_FUNCTION,
83
0
        llvm::Twine("Null or invalid object (" +
84
0
                    llvm::Twine(error.AsCString()) + llvm::Twine(")."))
85
0
            .str(),
86
0
        error);
87
0
  }
88
89
0
  return dict_sp;
90
0
}
91
92
Status ScriptedPlatformPythonInterface::AttachToProcess(
93
0
    ProcessAttachInfoSP attach_info) {
94
  // FIXME: Pass `attach_info` to method call
95
0
  return GetStatusFromMethod("attach_to_process");
96
0
}
97
98
Status ScriptedPlatformPythonInterface::LaunchProcess(
99
0
    ProcessLaunchInfoSP launch_info) {
100
  // FIXME: Pass `launch_info` to method call
101
0
  return GetStatusFromMethod("launch_process");
102
0
}
103
104
0
Status ScriptedPlatformPythonInterface::KillProcess(lldb::pid_t pid) {
105
0
  return GetStatusFromMethod("kill_process", pid);
106
0
}
107
108
#endif // LLDB_ENABLE_PYTHON