aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp162
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h15
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp25
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp44
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp19
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h2
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp9
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h7
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp10
9 files changed, 53 insertions, 240 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index 68f4e90d70f6..ae61736fbbb3 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -16,6 +16,7 @@
#include "lldb/Host/File.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Stream.h"
@@ -70,9 +71,7 @@ Expected<std::string> python::As<std::string>(Expected<PythonObject> &&obj) {
}
static bool python_is_finalizing() {
-#if PY_MAJOR_VERSION == 2
- return false;
-#elif PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
+#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
return _Py_Finalizing != nullptr;
#else
return _Py_IsFinalizing();
@@ -96,12 +95,6 @@ void PythonObject::Reset() {
Expected<long long> PythonObject::AsLongLong() const {
if (!m_py_obj)
return nullDeref();
-#if PY_MAJOR_VERSION < 3
- if (!PyLong_Check(m_py_obj)) {
- PythonInteger i(PyRefType::Borrowed, m_py_obj);
- return i.AsLongLong();
- }
-#endif
assert(!PyErr_Occurred());
long long r = PyLong_AsLongLong(m_py_obj);
if (PyErr_Occurred())
@@ -112,12 +105,6 @@ Expected<long long> PythonObject::AsLongLong() const {
Expected<long long> PythonObject::AsUnsignedLongLong() const {
if (!m_py_obj)
return nullDeref();
-#if PY_MAJOR_VERSION < 3
- if (!PyLong_Check(m_py_obj)) {
- PythonInteger i(PyRefType::Borrowed, m_py_obj);
- return i.AsUnsignedLongLong();
- }
-#endif
assert(!PyErr_Occurred());
long long r = PyLong_AsUnsignedLongLong(m_py_obj);
if (PyErr_Occurred())
@@ -129,12 +116,6 @@ Expected<long long> PythonObject::AsUnsignedLongLong() const {
Expected<unsigned long long> PythonObject::AsModuloUnsignedLongLong() const {
if (!m_py_obj)
return nullDeref();
-#if PY_MAJOR_VERSION < 3
- if (!PyLong_Check(m_py_obj)) {
- PythonInteger i(PyRefType::Borrowed, m_py_obj);
- return i.AsModuloUnsignedLongLong();
- }
-#endif
assert(!PyErr_Occurred());
unsigned long long r = PyLong_AsUnsignedLongLongMask(m_py_obj);
if (PyErr_Occurred())
@@ -182,10 +163,8 @@ PyObjectType PythonObject::GetObjectType() const {
return PyObjectType::Dictionary;
if (PythonString::Check(m_py_obj))
return PyObjectType::String;
-#if PY_MAJOR_VERSION >= 3
if (PythonBytes::Check(m_py_obj))
return PyObjectType::Bytes;
-#endif
if (PythonByteArray::Check(m_py_obj))
return PyObjectType::ByteArray;
if (PythonBoolean::Check(m_py_obj))
@@ -281,9 +260,7 @@ PythonObject PythonObject::GetAttributeValue(llvm::StringRef attr) const {
}
StructuredData::ObjectSP PythonObject::CreateStructuredObject() const {
-#if PY_MAJOR_VERSION >= 3
assert(PyGILState_Check());
-#endif
switch (GetObjectType()) {
case PyObjectType::Dictionary:
return PythonDictionary(PyRefType::Borrowed, m_py_obj)
@@ -397,11 +374,7 @@ StructuredData::StringSP PythonByteArray::CreateStructuredString() const {
// PythonString
Expected<PythonString> PythonString::FromUTF8(llvm::StringRef string) {
-#if PY_MAJOR_VERSION >= 3
PyObject *str = PyUnicode_FromStringAndSize(string.data(), string.size());
-#else
- PyObject *str = PyString_FromStringAndSize(string.data(), string.size());
-#endif
if (!str)
return llvm::make_error<PythonException>();
return Take<PythonString>(str);
@@ -415,35 +388,9 @@ bool PythonString::Check(PyObject *py_obj) {
if (PyUnicode_Check(py_obj))
return true;
-#if PY_MAJOR_VERSION < 3
- if (PyString_Check(py_obj))
- return true;
-#endif
return false;
}
-void PythonString::Convert(PyRefType &type, PyObject *&py_obj) {
-#if PY_MAJOR_VERSION < 3
- // In Python 2, Don't store PyUnicode objects directly, because we need
- // access to their underlying character buffers which Python 2 doesn't
- // provide.
- if (PyUnicode_Check(py_obj)) {
- PyObject *s = PyUnicode_AsUTF8String(py_obj);
- if (s == nullptr) {
- PyErr_Clear();
- if (type == PyRefType::Owned)
- Py_DECREF(py_obj);
- return;
- }
- if (type == PyRefType::Owned)
- Py_DECREF(py_obj);
- else
- type = PyRefType::Owned;
- py_obj = s;
- }
-#endif
-}
-
llvm::StringRef PythonString::GetString() const {
auto s = AsUTF8();
if (!s) {
@@ -460,15 +407,7 @@ Expected<llvm::StringRef> PythonString::AsUTF8() const {
Py_ssize_t size;
const char *data;
-#if PY_MAJOR_VERSION >= 3
data = PyUnicode_AsUTF8AndSize(m_py_obj, &size);
-#else
- char *c = NULL;
- int r = PyString_AsStringAndSize(m_py_obj, &c, &size);
- if (r < 0)
- c = NULL;
- data = c;
-#endif
if (!data)
return exception();
@@ -478,15 +417,11 @@ Expected<llvm::StringRef> PythonString::AsUTF8() const {
size_t PythonString::GetSize() const {
if (IsValid()) {
-#if PY_MAJOR_VERSION >= 3
#if PY_MINOR_VERSION >= 3
return PyUnicode_GetLength(m_py_obj);
#else
return PyUnicode_GetSize(m_py_obj);
#endif
-#else
- return PyString_Size(m_py_obj);
-#endif
}
return 0;
}
@@ -515,41 +450,9 @@ bool PythonInteger::Check(PyObject *py_obj) {
if (!py_obj)
return false;
-#if PY_MAJOR_VERSION >= 3
// Python 3 does not have PyInt_Check. There is only one type of integral
// value, long.
return PyLong_Check(py_obj);
-#else
- return PyLong_Check(py_obj) || PyInt_Check(py_obj);
-#endif
-}
-
-void PythonInteger::Convert(PyRefType &type, PyObject *&py_obj) {
-#if PY_MAJOR_VERSION < 3
- // Always store this as a PyLong, which makes interoperability between Python
- // 2.x and Python 3.x easier. This is only necessary in 2.x, since 3.x
- // doesn't even have a PyInt.
- if (PyInt_Check(py_obj)) {
- // Since we converted the original object to a different type, the new
- // object is an owned object regardless of the ownership semantics
- // requested by the user.
- long long value = PyInt_AsLong(py_obj);
- PyObject *l = nullptr;
- if (!PyErr_Occurred())
- l = PyLong_FromLongLong(value);
- if (l == nullptr) {
- PyErr_Clear();
- if (type == PyRefType::Owned)
- Py_DECREF(py_obj);
- return;
- }
- if (type == PyRefType::Owned)
- Py_DECREF(py_obj);
- else
- type = PyRefType::Owned;
- py_obj = l;
- }
-#endif
}
void PythonInteger::SetInteger(int64_t value) {
@@ -761,13 +664,9 @@ Expected<PythonObject>
PythonDictionary::GetItem(const PythonObject &key) const {
if (!IsValid())
return nullDeref();
-#if PY_MAJOR_VERSION >= 3
PyObject *o = PyDict_GetItemWithError(m_py_obj, key.get());
if (PyErr_Occurred())
return exception();
-#else
- PyObject *o = PyDict_GetItem(m_py_obj, key.get());
-#endif
if (!o)
return keyError();
return Retain<PythonObject>(o);
@@ -825,13 +724,7 @@ PythonDictionary::CreateStructuredDictionary() const {
return result;
}
-PythonModule PythonModule::BuiltinsModule() {
-#if PY_MAJOR_VERSION >= 3
- return AddModule("builtins");
-#else
- return AddModule("__builtin__");
-#endif
-}
+PythonModule PythonModule::BuiltinsModule() { return AddModule("builtins"); }
PythonModule PythonModule::MainModule() { return AddModule("__main__"); }
@@ -999,9 +892,6 @@ operator()(std::initializer_list<PythonObject> args) {
bool PythonFile::Check(PyObject *py_obj) {
if (!py_obj)
return false;
-#if PY_MAJOR_VERSION < 3
- return PyFile_Check(py_obj);
-#else
// In Python 3, there is no `PyFile_Check`, and in fact PyFile is not even a
// first-class object type anymore. `PyFile_FromFd` is just a thin wrapper
// over `io.open()`, which returns some object derived from `io.IOBase`. As a
@@ -1023,7 +913,6 @@ bool PythonFile::Check(PyObject *py_obj) {
return false;
}
return !!r;
-#endif
}
const char *PythonException::toCString() const {
@@ -1050,7 +939,7 @@ PythonException::PythonException(const char *caller) {
PyErr_Clear();
}
}
- Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT);
+ Log *log = GetLog(LLDBLog::Script);
if (caller)
LLDB_LOGF(log, "%s failed with exception: %s", caller, toCString());
else
@@ -1120,7 +1009,6 @@ char PythonException::ID = 0;
llvm::Expected<File::OpenOptions>
GetOptionsForPyObject(const PythonObject &obj) {
-#if PY_MAJOR_VERSION >= 3
auto options = File::OpenOptions(0);
auto readable = As<bool>(obj.CallMethod("readable"));
if (!readable)
@@ -1135,10 +1023,6 @@ GetOptionsForPyObject(const PythonObject &obj) {
else if (readable.get())
options |= File::eOpenOptionReadOnly;
return options;
-#else
- PythonString py_mode = obj.GetAttributeValue("mode").AsType<PythonString>();
- return File::GetOptionsFromMode(py_mode.GetString());
-#endif
}
// Base class template for python files. All it knows how to do
@@ -1222,8 +1106,6 @@ public:
char SimplePythonFile::ID = 0;
} // namespace
-#if PY_MAJOR_VERSION >= 3
-
namespace {
class PythonBuffer {
public:
@@ -1413,8 +1295,6 @@ public:
};
} // namespace
-#endif
-
llvm::Expected<FileSP> PythonFile::ConvertToFile(bool borrowed) {
if (!IsValid())
return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -1465,13 +1345,6 @@ PythonFile::ConvertToFileForcingUseOfScriptingIOMethods(bool borrowed) {
return llvm::createStringError(llvm::inconvertibleErrorCode(),
"invalid PythonFile");
-#if PY_MAJOR_VERSION < 3
-
- return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "not supported on python 2");
-
-#else
-
int fd = PyObject_AsFileDescriptor(m_py_obj);
if (fd < 0) {
PyErr_Clear();
@@ -1521,8 +1394,6 @@ PythonFile::ConvertToFileForcingUseOfScriptingIOMethods(bool borrowed) {
"invalid File");
return file_sp;
-
-#endif
}
Expected<PythonFile> PythonFile::FromFile(File &file, const char *mode) {
@@ -1532,10 +1403,8 @@ Expected<PythonFile> PythonFile::FromFile(File &file, const char *mode) {
if (auto *simple = llvm::dyn_cast<SimplePythonFile>(&file))
return Retain<PythonFile>(simple->GetPythonObject());
-#if PY_MAJOR_VERSION >= 3
if (auto *pythonio = llvm::dyn_cast<PythonIOFile>(&file))
return Retain<PythonFile>(pythonio->GetPythonObject());
-#endif
if (!mode) {
auto m = file.GetOpenMode();
@@ -1545,26 +1414,8 @@ Expected<PythonFile> PythonFile::FromFile(File &file, const char *mode) {
}
PyObject *file_obj;
-#if PY_MAJOR_VERSION >= 3
file_obj = PyFile_FromFd(file.GetDescriptor(), nullptr, mode, -1, nullptr,
"ignore", nullptr, /*closefd=*/0);
-#else
- // I'd like to pass ::fflush here if the file is writable, so that
- // when the python side destructs the file object it will be flushed.
- // However, this would be dangerous. It can cause fflush to be called
- // after fclose if the python program keeps a reference to the file after
- // the original lldb_private::File has been destructed.
- //
- // It's all well and good to ask a python program not to use a closed file
- // but asking a python program to make sure objects get released in a
- // particular order is not safe.
- //
- // The tradeoff here is that if a python 2 program wants to make sure this
- // file gets flushed, they'll have to do it explicitly or wait untill the
- // original lldb File itself gets flushed.
- file_obj = PyFile_FromFile(file.GetStream(), py2_const_cast(""),
- py2_const_cast(mode), [](FILE *) { return 0; });
-#endif
if (!file_obj)
return exception();
@@ -1611,12 +1462,7 @@ python::runStringOneLine(const llvm::Twine &string,
return exception();
auto code_ref = Take<PythonObject>(code);
-#if PY_MAJOR_VERSION < 3
- PyObject *result =
- PyEval_EvalCode((PyCodeObject *)code, globals.get(), locals.get());
-#else
PyObject *result = PyEval_EvalCode(code, globals.get(), locals.get());
-#endif
if (!result)
return exception();
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 2094f0b3afd2..76ad47f2907e 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -181,13 +181,7 @@ inline llvm::Error keyError() {
"key not in dict");
}
-#if PY_MAJOR_VERSION < 3
-// The python 2 API declares some arguments as char* that should
-// be const char *, but it doesn't actually modify them.
-inline char *py2_const_cast(const char *s) { return const_cast<char *>(s); }
-#else
inline const char *py2_const_cast(const char *s) { return s; }
-#endif
enum class PyInitialValue { Invalid, Empty };
@@ -391,14 +385,9 @@ llvm::Expected<std::string> As<std::string>(llvm::Expected<PythonObject> &&obj);
template <class T> class TypedPythonObject : public PythonObject {
public:
- // override to perform implicit type conversions on Reset
- // This can be eliminated once we drop python 2 support.
- static void Convert(PyRefType &type, PyObject *&py_obj) {}
-
TypedPythonObject(PyRefType type, PyObject *py_obj) {
if (!py_obj)
return;
- T::Convert(type, py_obj);
if (T::Check(py_obj))
PythonObject::operator=(PythonObject(type, py_obj));
else if (type == PyRefType::Owned)
@@ -453,7 +442,6 @@ public:
explicit PythonString(llvm::StringRef string); // safe, null on error
static bool Check(PyObject *py_obj);
- static void Convert(PyRefType &type, PyObject *&py_obj);
llvm::StringRef GetString() const; // safe, empty string on error
@@ -475,7 +463,6 @@ public:
explicit PythonInteger(int64_t value);
static bool Check(PyObject *py_obj);
- static void Convert(PyRefType &type, PyObject *&py_obj);
void SetInteger(int64_t value);
@@ -649,7 +636,7 @@ public:
const char *toCString() const;
PythonException(const char *caller = nullptr);
void Restore();
- ~PythonException();
+ ~PythonException() override;
void log(llvm::raw_ostream &OS) const override;
std::error_code convertToErrorCode() const override;
bool Matches(PyObject *exc) const;
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp
index 95a3365ed983..2753847f39f8 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonReadline.cpp
@@ -22,7 +22,6 @@
PyDoc_STRVAR(moduleDocumentation,
"Simple readline module implementation based on libedit.");
-#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef readline_module = {
PyModuleDef_HEAD_INIT, // m_base
"lldb_editline", // m_name
@@ -34,26 +33,13 @@ static struct PyModuleDef readline_module = {
nullptr, // m_clear
nullptr, // m_free
};
-#else
-static struct PyMethodDef moduleMethods[] = {{nullptr, nullptr, 0, nullptr}};
-#endif
-static char *
-#if PY_MAJOR_VERSION >= 3
-simple_readline(FILE *stdin, FILE *stdout, const char *prompt)
-#else
-simple_readline(FILE *stdin, FILE *stdout, char *prompt)
-#endif
-{
+static char *simple_readline(FILE *stdin, FILE *stdout, const char *prompt) {
rl_instream = stdin;
rl_outstream = stdout;
char *line = readline(prompt);
if (!line) {
-#if PY_MAJOR_VERSION >= 3
char *ret = (char *)PyMem_RawMalloc(1);
-#else
- char *ret = (char *)PyMem_Malloc(1);
-#endif
if (ret != NULL)
*ret = '\0';
return ret;
@@ -61,11 +47,7 @@ simple_readline(FILE *stdin, FILE *stdout, char *prompt)
if (*line)
add_history(line);
int n = strlen(line);
-#if PY_MAJOR_VERSION >= 3
char *ret = (char *)PyMem_RawMalloc(n + 2);
-#else
- char *ret = (char *)PyMem_Malloc(n + 2);
-#endif
if (ret) {
memcpy(ret, line, n);
free(line);
@@ -78,11 +60,6 @@ simple_readline(FILE *stdin, FILE *stdout, char *prompt)
PyMODINIT_FUNC initlldb_readline(void) {
PyOS_ReadlineFunctionPointer = simple_readline;
-#if PY_MAJOR_VERSION >= 3
return PyModule_Create(&readline_module);
-#else
- Py_InitModule4("readline", moduleMethods, moduleDocumentation,
- static_cast<PyObject *>(NULL), PYTHON_API_VERSION);
-#endif
}
#endif
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 1bf647e4acfc..53e2bcaccafb 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -38,6 +38,7 @@
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadPlan.h"
#include "lldb/Utility/Instrumentation.h"
+#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Timer.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
@@ -59,17 +60,10 @@ using llvm::Expected;
LLDB_PLUGIN_DEFINE(ScriptInterpreterPython)
// Defined in the SWIG source file
-#if PY_MAJOR_VERSION >= 3
extern "C" PyObject *PyInit__lldb(void);
#define LLDBSwigPyInit PyInit__lldb
-#else
-extern "C" void init_lldb(void);
-
-#define LLDBSwigPyInit init_lldb
-#endif
-
#if defined(_WIN32)
// Don't mess with the signal handlers on Windows.
#define LLDB_USE_PYTHON_SET_INTERRUPT 0
@@ -131,7 +125,7 @@ public:
~InitializePythonRAII() {
if (m_was_already_initialized) {
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT));
+ Log *log = GetLog(LLDBLog::Script);
LLDB_LOGV(log, "Releasing PyGILState. Returning to state = {0}locked",
m_gil_state == PyGILState_UNLOCKED ? "un" : "");
PyGILState_Release(m_gil_state);
@@ -144,11 +138,7 @@ public:
private:
void InitializePythonHome() {
#if LLDB_EMBED_PYTHON_HOME
-#if PY_MAJOR_VERSION >= 3
- typedef wchar_t* str_type;
-#else
- typedef char* str_type;
-#endif
+ typedef wchar_t *str_type;
static str_type g_python_home = []() -> str_type {
const char *lldb_python_home = LLDB_PYTHON_HOME;
const char *absolute_python_home = nullptr;
@@ -163,27 +153,12 @@ private:
llvm::sys::path::append(path, lldb_python_home);
absolute_python_home = path.c_str();
}
-#if PY_MAJOR_VERSION >= 3
size_t size = 0;
return Py_DecodeLocale(absolute_python_home, &size);
-#else
- return strdup(absolute_python_home);
-#endif
}();
if (g_python_home != nullptr) {
Py_SetPythonHome(g_python_home);
}
-#else
-#if defined(__APPLE__) && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7
- // For Darwin, the only Python version supported is the one shipped in the
- // OS OS and linked with lldb. Other installation of Python may have higher
- // priorities in the path, overriding PYTHONHOME and causing
- // problems/incompatibilities. In order to avoid confusion, always hardcode
- // the PythonHome to be right, as it's not going to change.
- static char path[] =
- "/System/Library/Frameworks/Python.framework/Versions/2.7";
- Py_SetPythonHome(path);
-#endif
#endif
}
@@ -201,7 +176,7 @@ private:
#endif
if (PyEval_ThreadsInitialized()) {
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT));
+ Log *log = GetLog(LLDBLog::Script);
m_was_already_initialized = true;
m_gil_state = PyGILState_Ensure();
@@ -380,7 +355,7 @@ ScriptInterpreterPythonImpl::Locker::Locker(
}
bool ScriptInterpreterPythonImpl::Locker::DoAcquireLock() {
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT));
+ Log *log = GetLog(LLDBLog::Script);
m_GILState = PyGILState_Ensure();
LLDB_LOGV(log, "Ensured PyGILState. Previous state = {0}locked",
m_GILState == PyGILState_UNLOCKED ? "un" : "");
@@ -404,7 +379,7 @@ bool ScriptInterpreterPythonImpl::Locker::DoInitSession(uint16_t on_entry_flags,
}
bool ScriptInterpreterPythonImpl::Locker::DoFreeLock() {
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT));
+ Log *log = GetLog(LLDBLog::Script);
LLDB_LOGV(log, "Releasing PyGILState. Returning to state = {0}locked",
m_GILState == PyGILState_UNLOCKED ? "un" : "");
PyGILState_Release(m_GILState);
@@ -590,7 +565,7 @@ ScriptInterpreterPythonImpl::CreateInstance(Debugger &debugger) {
}
void ScriptInterpreterPythonImpl::LeaveSession() {
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT));
+ Log *log = GetLog(LLDBLog::Script);
if (log)
log->PutCString("ScriptInterpreterPythonImpl::LeaveSession()");
@@ -660,7 +635,7 @@ bool ScriptInterpreterPythonImpl::EnterSession(uint16_t on_entry_flags,
FileSP err_sp) {
// If we have already entered the session, without having officially 'left'
// it, then there is no need to 'enter' it again.
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT));
+ Log *log = GetLog(LLDBLog::Script);
if (m_session_is_active) {
LLDB_LOGF(
log,
@@ -962,7 +937,7 @@ bool ScriptInterpreterPythonImpl::Interrupt() {
// just our (hardcoded) input signal code SIGINT, so that's not useful at all.
return true;
#else
- Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT));
+ Log *log = GetLog(LLDBLog::Script);
if (IsExecutingPython()) {
PyThreadState *state = PyThreadState_GET();
@@ -2722,7 +2697,6 @@ bool ScriptInterpreterPythonImpl::LoadScriptingModule(
} else {
FileSpec module_file(pathname);
FileSystem::Instance().Resolve(module_file);
- FileSystem::Instance().Collect(module_file);
fs::file_status st;
std::error_code ec = status(module_file.GetPath(), st);
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
index e39f8be73e49..576bf69c9258 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
@@ -8,7 +8,6 @@
#include "lldb/Host/Config.h"
#include "lldb/Utility/Log.h"
-#include "lldb/Utility/Logging.h"
#include "lldb/lldb-enumerations.h"
#if LLDB_ENABLE_PYTHON
@@ -125,9 +124,21 @@ lldb::DataExtractorSP ScriptedProcessPythonInterface::ReadMemoryAtAddress(
address, size);
}
-StructuredData::DictionarySP ScriptedProcessPythonInterface::GetLoadedImages() {
- // TODO: Implement
- return {};
+StructuredData::ArraySP ScriptedProcessPythonInterface::GetLoadedImages() {
+ Status error;
+ StructuredData::ArraySP array =
+ Dispatch<StructuredData::ArraySP>("get_loaded_images", error);
+
+ if (!array || !array->IsValid() || error.Fail()) {
+ return ScriptedInterface::ErrorWithMessage<StructuredData::ArraySP>(
+ LLVM_PRETTY_FUNCTION,
+ llvm::Twine("Null or invalid object (" +
+ llvm::Twine(error.AsCString()) + llvm::Twine(")."))
+ .str(),
+ error);
+ }
+
+ return array;
}
lldb::pid_t ScriptedProcessPythonInterface::GetProcessID() {
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
index e34a181849eb..7f458b1dd9bd 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h
@@ -49,7 +49,7 @@ public:
lldb::DataExtractorSP ReadMemoryAtAddress(lldb::addr_t address, size_t size,
Status &error) override;
- StructuredData::DictionarySP GetLoadedImages() override;
+ StructuredData::ArraySP GetLoadedImages() override;
lldb::pid_t GetProcessID() override;
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
index 07bf952bf840..d5c527c61a5c 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
@@ -8,7 +8,6 @@
#include "lldb/Host/Config.h"
#include "lldb/Utility/Log.h"
-#include "lldb/Utility/Logging.h"
#include "lldb/lldb-enumerations.h"
#if LLDB_ENABLE_PYTHON
@@ -36,6 +35,14 @@ ScriptedPythonInterface::GetStatusFromMethod(llvm::StringRef method_name) {
}
template <>
+StructuredData::ArraySP
+ScriptedPythonInterface::ExtractValueFromPythonObject<StructuredData::ArraySP>(
+ python::PythonObject &p, Status &error) {
+ python::PythonList result_list(python::PyRefType::Borrowed, p.get());
+ return result_list.CreateStructuredArray();
+}
+
+template <>
StructuredData::DictionarySP
ScriptedPythonInterface::ExtractValueFromPythonObject<
StructuredData::DictionarySP>(python::PythonObject &p, Status &error) {
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
index da112eb72022..7c2fadc21d42 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
@@ -25,7 +25,7 @@ class ScriptInterpreterPythonImpl;
class ScriptedPythonInterface : virtual public ScriptedInterface {
public:
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter);
- virtual ~ScriptedPythonInterface() = default;
+ ~ScriptedPythonInterface() override = default;
protected:
template <typename T = StructuredData::ObjectSP>
@@ -127,6 +127,11 @@ protected:
};
template <>
+StructuredData::ArraySP
+ScriptedPythonInterface::ExtractValueFromPythonObject<StructuredData::ArraySP>(
+ python::PythonObject &p, Status &error);
+
+template <>
StructuredData::DictionarySP
ScriptedPythonInterface::ExtractValueFromPythonObject<
StructuredData::DictionarySP>(python::PythonObject &p, Status &error);
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
index d471b2c5f7e3..3ff592fb83cd 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
@@ -8,7 +8,6 @@
#include "lldb/Host/Config.h"
#include "lldb/Utility/Log.h"
-#include "lldb/Utility/Logging.h"
#include "lldb/lldb-enumerations.h"
#if LLDB_ENABLE_PYTHON
@@ -113,7 +112,14 @@ StructuredData::DictionarySP ScriptedThreadPythonInterface::GetStopReason() {
}
StructuredData::ArraySP ScriptedThreadPythonInterface::GetStackFrames() {
- return nullptr;
+ Status error;
+ StructuredData::ArraySP arr =
+ Dispatch<StructuredData::ArraySP>("get_stackframes", error);
+
+ if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr, error))
+ return {};
+
+ return arr;
}
StructuredData::DictionarySP ScriptedThreadPythonInterface::GetRegisterInfo() {