Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- ScriptedPythonInterface.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 "ScriptedPythonInterface.h"
22
23
using namespace lldb;
24
using namespace lldb_private;
25
26
ScriptedPythonInterface::ScriptedPythonInterface(
27
    ScriptInterpreterPythonImpl &interpreter)
28
1.43k
    : ScriptedInterface(), m_interpreter(interpreter) {}
29
30
Status
31
12
ScriptedPythonInterface::GetStatusFromMethod(llvm::StringRef method_name) {
32
12
  Status error;
33
12
  Dispatch<Status>(method_name, error);
34
35
12
  return error;
36
12
}
37
38
template <>
39
StructuredData::DictionarySP
40
ScriptedPythonInterface::ExtractValueFromPythonObject<
41
12
    StructuredData::DictionarySP>(python::PythonObject &p, Status &error) {
42
12
  python::PythonDictionary result_dict(python::PyRefType::Borrowed, p.get());
43
12
  return result_dict.CreateStructuredDictionary();
44
12
}
45
46
template <>
47
Status ScriptedPythonInterface::ExtractValueFromPythonObject<Status>(
48
12
    python::PythonObject &p, Status &error) {
49
12
  if (lldb::SBError *sb_error = reinterpret_cast<lldb::SBError *>(
50
12
          LLDBSWIGPython_CastPyObjectToSBError(p.get())))
51
12
    error = m_interpreter.GetStatusFromSBError(*sb_error);
52
0
  else
53
0
    error.SetErrorString("Couldn't cast lldb::SBError to lldb::Status.");
54
55
12
  return error;
56
12
}
57
58
template <>
59
lldb::DataExtractorSP
60
ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::DataExtractorSP>(
61
3
    python::PythonObject &p, Status &error) {
62
3
  lldb::SBData *sb_data = reinterpret_cast<lldb::SBData *>(
63
3
      LLDBSWIGPython_CastPyObjectToSBData(p.get()));
64
65
3
  if (!sb_data) {
66
0
    error.SetErrorString(
67
0
        "Couldn't cast lldb::SBData to lldb::DataExtractorSP.");
68
0
    return nullptr;
69
0
  }
70
71
3
  return m_interpreter.GetDataExtractorFromSBData(*sb_data);
72
3
}
73
74
template <>
75
llvm::Optional<MemoryRegionInfo>
76
ScriptedPythonInterface::ExtractValueFromPythonObject<
77
0
    llvm::Optional<MemoryRegionInfo>>(python::PythonObject &p, Status &error) {
78
79
0
  lldb::SBMemoryRegionInfo *sb_mem_reg_info =
80
0
      reinterpret_cast<lldb::SBMemoryRegionInfo *>(
81
0
          LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(p.get()));
82
83
0
  if (!sb_mem_reg_info) {
84
0
    error.SetErrorString(
85
0
        "Couldn't cast lldb::SBMemoryRegionInfo to lldb::MemoryRegionInfoSP.");
86
0
    return {};
87
0
  }
88
89
0
  return m_interpreter.GetOpaqueTypeFromSBMemoryRegionInfo(*sb_mem_reg_info);
90
0
}
91
92
#endif