/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/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 "ScriptInterpreterPythonImpl.h" |
19 | | #include "ScriptedPythonInterface.h" |
20 | | #include <optional> |
21 | | |
22 | | using namespace lldb; |
23 | | using namespace lldb_private; |
24 | | |
25 | | ScriptedPythonInterface::ScriptedPythonInterface( |
26 | | ScriptInterpreterPythonImpl &interpreter) |
27 | 2.01k | : ScriptedInterface(), m_interpreter(interpreter) {} |
28 | | |
29 | | template <> |
30 | | StructuredData::ArraySP |
31 | | ScriptedPythonInterface::ExtractValueFromPythonObject<StructuredData::ArraySP>( |
32 | 4 | python::PythonObject &p, Status &error) { |
33 | 4 | python::PythonList result_list(python::PyRefType::Borrowed, p.get()); |
34 | 4 | return result_list.CreateStructuredArray(); |
35 | 4 | } |
36 | | |
37 | | template <> |
38 | | StructuredData::DictionarySP |
39 | | ScriptedPythonInterface::ExtractValueFromPythonObject< |
40 | 21 | StructuredData::DictionarySP>(python::PythonObject &p, Status &error) { |
41 | 21 | python::PythonDictionary result_dict(python::PyRefType::Borrowed, p.get()); |
42 | 21 | return result_dict.CreateStructuredDictionary(); |
43 | 21 | } |
44 | | |
45 | | template <> |
46 | | Status ScriptedPythonInterface::ExtractValueFromPythonObject<Status>( |
47 | 10 | python::PythonObject &p, Status &error) { |
48 | 10 | if (lldb::SBError *sb_error = reinterpret_cast<lldb::SBError *>( |
49 | 10 | python::LLDBSWIGPython_CastPyObjectToSBError(p.get()))) |
50 | 10 | return m_interpreter.GetStatusFromSBError(*sb_error); |
51 | 0 | else |
52 | 0 | error.SetErrorString("Couldn't cast lldb::SBError to lldb::Status."); |
53 | | |
54 | 0 | return {}; |
55 | 10 | } |
56 | | |
57 | | template <> |
58 | | lldb::DataExtractorSP |
59 | | ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::DataExtractorSP>( |
60 | 5 | python::PythonObject &p, Status &error) { |
61 | 5 | lldb::SBData *sb_data = reinterpret_cast<lldb::SBData *>( |
62 | 5 | python::LLDBSWIGPython_CastPyObjectToSBData(p.get())); |
63 | | |
64 | 5 | if (!sb_data) { |
65 | 0 | error.SetErrorString( |
66 | 0 | "Couldn't cast lldb::SBData to lldb::DataExtractorSP."); |
67 | 0 | return nullptr; |
68 | 0 | } |
69 | | |
70 | 5 | return m_interpreter.GetDataExtractorFromSBData(*sb_data); |
71 | 5 | } |
72 | | |
73 | | template <> |
74 | | lldb::BreakpointSP |
75 | | ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::BreakpointSP>( |
76 | 0 | python::PythonObject &p, Status &error) { |
77 | 0 | lldb::SBBreakpoint *sb_breakpoint = reinterpret_cast<lldb::SBBreakpoint *>( |
78 | 0 | python::LLDBSWIGPython_CastPyObjectToSBBreakpoint(p.get())); |
79 | |
|
80 | 0 | if (!sb_breakpoint) { |
81 | 0 | error.SetErrorString( |
82 | 0 | "Couldn't cast lldb::SBBreakpoint to lldb::BreakpointSP."); |
83 | 0 | return nullptr; |
84 | 0 | } |
85 | | |
86 | 0 | return m_interpreter.GetOpaqueTypeFromSBBreakpoint(*sb_breakpoint); |
87 | 0 | } |
88 | | |
89 | | template <> |
90 | | lldb::ProcessAttachInfoSP ScriptedPythonInterface::ExtractValueFromPythonObject< |
91 | 1 | lldb::ProcessAttachInfoSP>(python::PythonObject &p, Status &error) { |
92 | 1 | lldb::SBAttachInfo *sb_attach_info = reinterpret_cast<lldb::SBAttachInfo *>( |
93 | 1 | python::LLDBSWIGPython_CastPyObjectToSBAttachInfo(p.get())); |
94 | | |
95 | 1 | if (!sb_attach_info) { |
96 | 0 | error.SetErrorString( |
97 | 0 | "Couldn't cast lldb::SBAttachInfo to lldb::ProcessAttachInfoSP."); |
98 | 0 | return nullptr; |
99 | 0 | } |
100 | | |
101 | 1 | return m_interpreter.GetOpaqueTypeFromSBAttachInfo(*sb_attach_info); |
102 | 1 | } |
103 | | |
104 | | template <> |
105 | | lldb::ProcessLaunchInfoSP ScriptedPythonInterface::ExtractValueFromPythonObject< |
106 | 0 | lldb::ProcessLaunchInfoSP>(python::PythonObject &p, Status &error) { |
107 | 0 | lldb::SBLaunchInfo *sb_launch_info = reinterpret_cast<lldb::SBLaunchInfo *>( |
108 | 0 | python::LLDBSWIGPython_CastPyObjectToSBLaunchInfo(p.get())); |
109 | |
|
110 | 0 | if (!sb_launch_info) { |
111 | 0 | error.SetErrorString( |
112 | 0 | "Couldn't cast lldb::SBLaunchInfo to lldb::ProcessLaunchInfoSP."); |
113 | 0 | return nullptr; |
114 | 0 | } |
115 | | |
116 | 0 | return m_interpreter.GetOpaqueTypeFromSBLaunchInfo(*sb_launch_info); |
117 | 0 | } |
118 | | |
119 | | template <> |
120 | | std::optional<MemoryRegionInfo> |
121 | | ScriptedPythonInterface::ExtractValueFromPythonObject< |
122 | 0 | std::optional<MemoryRegionInfo>>(python::PythonObject &p, Status &error) { |
123 | |
|
124 | 0 | lldb::SBMemoryRegionInfo *sb_mem_reg_info = |
125 | 0 | reinterpret_cast<lldb::SBMemoryRegionInfo *>( |
126 | 0 | python::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(p.get())); |
127 | |
|
128 | 0 | if (!sb_mem_reg_info) { |
129 | 0 | error.SetErrorString( |
130 | 0 | "Couldn't cast lldb::SBMemoryRegionInfo to lldb::MemoryRegionInfoSP."); |
131 | 0 | return {}; |
132 | 0 | } |
133 | | |
134 | 0 | return m_interpreter.GetOpaqueTypeFromSBMemoryRegionInfo(*sb_mem_reg_info); |
135 | 0 | } |
136 | | |
137 | | #endif |