[Lldb-commits] [lldb] [lldb] Use PyBytes and PyByteArray in Python Data Objects unittest (PR #82098)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes Use a Python Bytes and ByteArray object instead of Integers for TestOwnedReferences and TestBorrowedReferences. These two tests were failing when building against Python 3.12 because these Integer objects had a refcount of 4294967296 (-1). I didn't dig into it, but I suspect the Python runtime has adopted an optimization to decrease refcounting traffic for these simple objects. --- Full diff: https://github.com/llvm/llvm-project/pull/82098.diff 1 Files Affected: - (modified) lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp (+18-12) ``diff diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp index efb8f725f6739a..a4db4627f935b4 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp @@ -51,21 +51,24 @@ class PythonDataObjectsTest : public PythonTestSuite { TEST_F(PythonDataObjectsTest, TestOwnedReferences) { // After creating a new object, the refcount should be >= 1 - PyObject *obj = PyLong_FromLong(3); - Py_ssize_t original_refcnt = obj->ob_refcnt; + PyObject *obj = PyBytes_FromString("foo"); + Py_ssize_t original_refcnt = Py_REFCNT(obj); EXPECT_LE(1, original_refcnt); // If we take an owned reference, the refcount should be the same - PythonObject owned_long(PyRefType::Owned, obj); - EXPECT_EQ(original_refcnt, owned_long.get()->ob_refcnt); + PythonObject owned(PyRefType::Owned, obj); + Py_ssize_t owned_refcnt = Py_REFCNT(owned.get()); + EXPECT_EQ(original_refcnt, owned_refcnt); // Take another reference and verify that the refcount increases by 1 - PythonObject strong_ref(owned_long); - EXPECT_EQ(original_refcnt + 1, strong_ref.get()->ob_refcnt); + PythonObject strong_ref(owned); + Py_ssize_t strong_refcnt = Py_REFCNT(strong_ref.get()); + EXPECT_EQ(original_refcnt + 1, strong_refcnt); // If we reset the first one, the refcount should be the original value. - owned_long.Reset(); - EXPECT_EQ(original_refcnt, strong_ref.get()->ob_refcnt); + owned.Reset(); + strong_refcnt = Py_REFCNT(strong_ref.get()); + EXPECT_EQ(original_refcnt, strong_refcnt); } TEST_F(PythonDataObjectsTest, TestResetting) { @@ -82,12 +85,15 @@ TEST_F(PythonDataObjectsTest, TestResetting) { } TEST_F(PythonDataObjectsTest, TestBorrowedReferences) { - PythonInteger long_value(PyRefType::Owned, PyLong_FromLong(3)); - Py_ssize_t original_refcnt = long_value.get()->ob_refcnt; + PythonByteArray byte_value(PyRefType::Owned, + PyByteArray_FromStringAndSize("foo", 3)); + Py_ssize_t original_refcnt = Py_REFCNT(byte_value.get()); EXPECT_LE(1, original_refcnt); - PythonInteger borrowed_long(PyRefType::Borrowed, long_value.get()); - EXPECT_EQ(original_refcnt + 1, borrowed_long.get()->ob_refcnt); + PythonByteArray borrowed_byte(PyRefType::Borrowed, byte_value.get()); + Py_ssize_t borrowed_refcnt = Py_REFCNT(borrowed_byte.get()); + + EXPECT_EQ(original_refcnt + 1, borrowed_refcnt); } TEST_F(PythonDataObjectsTest, TestGlobalNameResolutionNoDot) { `` https://github.com/llvm/llvm-project/pull/82098 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use PyBytes and PyByteArray in Python Data Objects unittest (PR #82098)
https://github.com/JDevlieghere ready_for_review https://github.com/llvm/llvm-project/pull/82098 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Use PyBytes and PyByteArray in Python Data Objects unittest (PR #82098)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/82098 Use a Python Bytes and ByteArray object instead of Integers for TestOwnedReferences and TestBorrowedReferences. These two tests were failing when building against Python 3.12 because these Integer objects had a refcount of 4294967296 (-1). I didn't dig into it, but I suspect the Python runtime has adopted an optimization to decrease refcounting traffic for these simple objects. >From e0abbba764acd5e7685780e79628219728052005 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 16 Feb 2024 23:20:40 -0800 Subject: [PATCH 1/2] [lldb] Use Py_REFCNT instead of accessing ob_refcnt directly --- .../Python/PythonDataObjectsTests.cpp | 17 +++-- 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp index efb8f725f6739a..d9e39ac9fcd9a1 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp @@ -52,20 +52,23 @@ class PythonDataObjectsTest : public PythonTestSuite { TEST_F(PythonDataObjectsTest, TestOwnedReferences) { // After creating a new object, the refcount should be >= 1 PyObject *obj = PyLong_FromLong(3); - Py_ssize_t original_refcnt = obj->ob_refcnt; + Py_ssize_t original_refcnt = Py_REFCNT(obj); EXPECT_LE(1, original_refcnt); // If we take an owned reference, the refcount should be the same PythonObject owned_long(PyRefType::Owned, obj); - EXPECT_EQ(original_refcnt, owned_long.get()->ob_refcnt); + Py_ssize_t owned_refcnt = Py_REFCNT(owned_long.get()); + EXPECT_EQ(original_refcnt, owned_refcnt); // Take another reference and verify that the refcount increases by 1 PythonObject strong_ref(owned_long); - EXPECT_EQ(original_refcnt + 1, strong_ref.get()->ob_refcnt); + Py_ssize_t strong_refcnt = Py_REFCNT(strong_ref.get()); + EXPECT_EQ(original_refcnt + 1, strong_refcnt); // If we reset the first one, the refcount should be the original value. owned_long.Reset(); - EXPECT_EQ(original_refcnt, strong_ref.get()->ob_refcnt); + strong_refcnt = Py_REFCNT(strong_ref.get()); + EXPECT_EQ(original_refcnt, strong_refcnt); } TEST_F(PythonDataObjectsTest, TestResetting) { @@ -83,11 +86,13 @@ TEST_F(PythonDataObjectsTest, TestResetting) { TEST_F(PythonDataObjectsTest, TestBorrowedReferences) { PythonInteger long_value(PyRefType::Owned, PyLong_FromLong(3)); - Py_ssize_t original_refcnt = long_value.get()->ob_refcnt; + Py_ssize_t original_refcnt = Py_REFCNT(long_value.get()); EXPECT_LE(1, original_refcnt); PythonInteger borrowed_long(PyRefType::Borrowed, long_value.get()); - EXPECT_EQ(original_refcnt + 1, borrowed_long.get()->ob_refcnt); + Py_ssize_t borrowed_refcnt = Py_REFCNT(borrowed_long.get()); + + EXPECT_EQ(original_refcnt + 1, borrowed_refcnt); } TEST_F(PythonDataObjectsTest, TestGlobalNameResolutionNoDot) { >From bf1e1d469b20614ca7ec4819b5f77e23cfbb7441 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 16 Feb 2024 23:35:01 -0800 Subject: [PATCH 2/2] [lldb] Use PyBytes and PyByteArray in Python Data Objects unittest Use a Python Bytes and ByteArray object instead of Integers for TestOwnedReferences and TestBorrowedReferences. These two tests were failing when building against Python 3.12 because these Integer objects had a refcount of 4294967296 (-1). I didn't dig into it, but I suspect the Python runtime has adopted an optimization to decrease refcounting traffic for these simple objects. --- .../Python/PythonDataObjectsTests.cpp | 19 ++- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp index d9e39ac9fcd9a1..a4db4627f935b4 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp @@ -51,22 +51,22 @@ class PythonDataObjectsTest : public PythonTestSuite { TEST_F(PythonDataObjectsTest, TestOwnedReferences) { // After creating a new object, the refcount should be >= 1 - PyObject *obj = PyLong_FromLong(3); + PyObject *obj = PyBytes_FromString("foo"); Py_ssize_t original_refcnt = Py_REFCNT(obj); EXPECT_LE(1, original_refcnt); // If we take an owned reference, the refcount should be the same - PythonObject owned_long(PyRefType::Owned, obj); - Py_ssize_t owned_refcnt = Py_REFCNT(owned_long.get()); + PythonObject owned(PyRefType::Owned, obj); + Py_ssize_t owned_refcnt = Py_REFCNT(owned.get()); EXPECT_EQ(original_refcnt, owned_refcnt); // Take another reference and verify that the refcount increases by 1 - PythonObject strong_ref(owned_long); + PythonObject strong_ref(owned);
[Lldb-commits] [lldb] [lldb] Don't rely on ScriptInterpreterPythonImpl::Initialize in the unit tests (PR #82096)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes The unit tests only test the Python objects and don't actually use anything from the LLDB module. That means that all the additional complexity in ScriptInterpreterPythonImpl::Initialize is overkill. By doing the initialization by hand, we avoid the annoying ModuleNotFoundError. Traceback (most recent call last): File "string", line 1, in module ModuleNotFoundError: No module named 'lldb' The error is the result of us stubbing out the SWIG (specifically `PyInit__lldb`) because we cannot link against libLLDB from the unit tests. The downside of doing the initialization manually is that we do lose a bit of test coverage. For example, issue #70453 also manifested itself in the unit tests. --- Full diff: https://github.com/llvm/llvm-project/pull/82096.diff 1 Files Affected: - (modified) lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp (+5-21) ``diff diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp index 5f0cc4c23db7b2..23162436d42c94 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp @@ -9,43 +9,27 @@ #include "gtest/gtest.h" #include "Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h" -#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" -#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h" #include "Plugins/ScriptInterpreter/Python/lldb-python.h" -#include "lldb/Host/FileSystem.h" -#include "lldb/Host/HostInfo.h" - #include "PythonTestSuite.h" #include -using namespace lldb_private; -class TestScriptInterpreterPython : public ScriptInterpreterPythonImpl { -public: - using ScriptInterpreterPythonImpl::Initialize; -}; - void PythonTestSuite::SetUp() { - FileSystem::Initialize(); - HostInfoBase::Initialize(); - // ScriptInterpreterPython::Initialize() depends on HostInfo being - // initializedso it can compute the python directory etc. - TestScriptInterpreterPython::Initialize(); - // Although we don't care about concurrency for the purposes of running // this test suite, Python requires the GIL to be locked even for // deallocating memory, which can happen when you call Py_DECREF or // Py_INCREF. So acquire the GIL for the entire duration of this // test suite. + Py_InitializeEx(0); m_gil_state = PyGILState_Ensure(); + PyRun_SimpleString("import sys"); } void PythonTestSuite::TearDown() { PyGILState_Release(m_gil_state); - TestScriptInterpreterPython::Terminate(); - HostInfoBase::Terminate(); - FileSystem::Terminate(); + // We could call Py_FinalizeEx here, but initializing and finalizing Python is + // pretty slow, so just keep Python initialized across tests. } // The following functions are the Pythonic implementations of the required @@ -219,7 +203,7 @@ bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject( } bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject( -PyObject *implementor, lldb::DebuggerSP debugger, +PyObject *implementor, lldb::DebuggerSP debugger, StructuredDataImpl _impl, lldb_private::CommandReturnObject _retobj, lldb::ExecutionContextRefSP exe_ctx_ref_sp) { `` https://github.com/llvm/llvm-project/pull/82096 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Don't rely on ScriptInterpreterPythonImpl::Initialize in the unit tests (PR #82096)
https://github.com/JDevlieghere ready_for_review https://github.com/llvm/llvm-project/pull/82096 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Don't rely on ScriptInterpreterPythonImpl::Initialize in the unit tests (PR #82096)
https://github.com/JDevlieghere edited https://github.com/llvm/llvm-project/pull/82096 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Don't rely on ScriptInterpreterPythonImpl::Initialize in the u… (PR #82096)
https://github.com/JDevlieghere edited https://github.com/llvm/llvm-project/pull/82096 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Don't rely on ScriptInterpreterPythonImpl::Initialize in the u… (PR #82096)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/82096 >From 7a05913528f2d747f4c5b7c0385a38a3c4e27d83 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 16 Feb 2024 22:51:08 -0800 Subject: [PATCH] [lldb] Don't rely on ScriptInterpreterPythonImpl::Initialize in the unittests The unit tests only test the Python objects and don't actually use anything from the LLDB module. That means that all the additional complexity in ScriptInterpreterPythonImpl::Initialize is overkill. By doing the initialization by hand, we avoid the annoying ModuleNotFoundError. Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'lldb' The error is the result of us stubbing out the SWIG (specifically `PyInit__lldb`) because we cannot link against libLLDB from the unit tests. The downside of doing the initialization manually is that we do lose a bit of test coverage. For example, issue #70453 also manifested itself in the unit tests. --- .../Python/PythonTestSuite.cpp| 26 --- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp index 5f0cc4c23db7b2..23162436d42c94 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp @@ -9,43 +9,27 @@ #include "gtest/gtest.h" #include "Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h" -#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" -#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h" #include "Plugins/ScriptInterpreter/Python/lldb-python.h" -#include "lldb/Host/FileSystem.h" -#include "lldb/Host/HostInfo.h" - #include "PythonTestSuite.h" #include -using namespace lldb_private; -class TestScriptInterpreterPython : public ScriptInterpreterPythonImpl { -public: - using ScriptInterpreterPythonImpl::Initialize; -}; - void PythonTestSuite::SetUp() { - FileSystem::Initialize(); - HostInfoBase::Initialize(); - // ScriptInterpreterPython::Initialize() depends on HostInfo being - // initializedso it can compute the python directory etc. - TestScriptInterpreterPython::Initialize(); - // Although we don't care about concurrency for the purposes of running // this test suite, Python requires the GIL to be locked even for // deallocating memory, which can happen when you call Py_DECREF or // Py_INCREF. So acquire the GIL for the entire duration of this // test suite. + Py_InitializeEx(0); m_gil_state = PyGILState_Ensure(); + PyRun_SimpleString("import sys"); } void PythonTestSuite::TearDown() { PyGILState_Release(m_gil_state); - TestScriptInterpreterPython::Terminate(); - HostInfoBase::Terminate(); - FileSystem::Terminate(); + // We could call Py_FinalizeEx here, but initializing and finalizing Python is + // pretty slow, so just keep Python initialized across tests. } // The following functions are the Pythonic implementations of the required @@ -219,7 +203,7 @@ bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject( } bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject( -PyObject *implementor, lldb::DebuggerSP debugger, +PyObject *implementor, lldb::DebuggerSP debugger, StructuredDataImpl _impl, lldb_private::CommandReturnObject _retobj, lldb::ExecutionContextRefSP exe_ctx_ref_sp) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Call Import_AppendInittab exactly once before Py_Initialize (PR #82095)
https://github.com/bulbazord approved this pull request. Makes sense to me. https://github.com/llvm/llvm-project/pull/82095 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Call Import_AppendInittab exactly once before Py_Initialize (PR #82095)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/82095 >From b937713b2733f2da9de4919b3da881ca0ea0aa04 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 16 Feb 2024 22:56:28 -0800 Subject: [PATCH] [lldb] Call Import_AppendInittab exactly once before Py_Initialize The Python documentation [1] says that `PyImport_AppendInittab` should be called before `Py_Initialize()`. Starting with Python 3.12, this is enforced with a fatal error: Fatal Python error: PyImport_AppendInittab: PyImport_AppendInittab() may not be called after Py_Initialize() This commit ensures we only modify the table of built-in modules if Python hasn't been initialized. For Python embedded in LLDB, that means this happen exactly once, before the first call to `Py_Initialize`, which becomes a NO-OP after. However, when lldb is imported in an existing Python interpreter, Python will have already been initialized, but by definition, the lldb module will already have been loaded, so it's safe to skip adding it (again). This fixes #70453. [1] https://docs.python.org/3.12/c-api/import.html#c.PyImport_AppendInittab --- .../Python/ScriptInterpreterPython.cpp| 32 +++ 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index dadcde612614ba..a1ad3f569ec71a 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -97,24 +97,28 @@ struct InitializePythonRAII { InitializePythonRAII() { InitializePythonHome(); +// The table of built-in modules can only be extended before Python is +// initialized. +if (!Py_IsInitialized()) { #ifdef LLDB_USE_LIBEDIT_READLINE_COMPAT_MODULE -// Python's readline is incompatible with libedit being linked into lldb. -// Provide a patched version local to the embedded interpreter. -bool ReadlinePatched = false; -for (auto *p = PyImport_Inittab; p->name != nullptr; p++) { - if (strcmp(p->name, "readline") == 0) { -p->initfunc = initlldb_readline; -break; + // Python's readline is incompatible with libedit being linked into lldb. + // Provide a patched version local to the embedded interpreter. + bool ReadlinePatched = false; + for (auto *p = PyImport_Inittab; p->name != nullptr; p++) { +if (strcmp(p->name, "readline") == 0) { + p->initfunc = initlldb_readline; + break; +} + } + if (!ReadlinePatched) { +PyImport_AppendInittab("readline", initlldb_readline); +ReadlinePatched = true; } -} -if (!ReadlinePatched) { - PyImport_AppendInittab("readline", initlldb_readline); - ReadlinePatched = true; -} #endif -// Register _lldb as a built-in module. -PyImport_AppendInittab("_lldb", LLDBSwigPyInit); + // Register _lldb as a built-in module. + PyImport_AppendInittab("_lldb", LLDBSwigPyInit); +} // Python < 3.2 and Python >= 3.2 reversed the ordering requirements for // calling `Py_Initialize` and `PyEval_InitThreads`. < 3.2 requires that you ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Don't rely on ScriptInterpreterPythonImpl::Initialize in the u… (PR #82096)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/82096 …nittests The unit tests only test the Python objects and don't actually use anything from the LLDB module. On the one hand that means that everything we do in ScriptInterpreterPythonImpl::Initialize is overkill, but on the other hand it means that we get test coverage for the initialization. In other words I'm not sure if I think this is the right direction. While looking at #70453 I wanted to prove that the two test failures were unrelated to the call to PyImport_AppendInittab by doing the initialization manually. >From 5e3abb8d28def3c8a4d1d2fac1ef74a6969fe7b7 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 16 Feb 2024 22:51:08 -0800 Subject: [PATCH] [lldb] Don't rely on ScriptInterpreterPythonImpl::Initialize in the unittests The unit tests only test the Python objects and don't actually use anything from the LLDB module. On the one hand that means that everything we do in ScriptInterpreterPythonImpl::Initialize is overkill, but on the other hand it means that we get test coverage for the initialization. In other words I'm not sure if I think this is the right direction. While looking at #70453 I wanted to prove that the two test failures were unrelated to the call to PyImport_AppendInittab by doing the initialization manually. --- .../Python/PythonTestSuite.cpp| 26 --- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp index 5f0cc4c23db7b2..23162436d42c94 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp @@ -9,43 +9,27 @@ #include "gtest/gtest.h" #include "Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h" -#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" -#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h" #include "Plugins/ScriptInterpreter/Python/lldb-python.h" -#include "lldb/Host/FileSystem.h" -#include "lldb/Host/HostInfo.h" - #include "PythonTestSuite.h" #include -using namespace lldb_private; -class TestScriptInterpreterPython : public ScriptInterpreterPythonImpl { -public: - using ScriptInterpreterPythonImpl::Initialize; -}; - void PythonTestSuite::SetUp() { - FileSystem::Initialize(); - HostInfoBase::Initialize(); - // ScriptInterpreterPython::Initialize() depends on HostInfo being - // initializedso it can compute the python directory etc. - TestScriptInterpreterPython::Initialize(); - // Although we don't care about concurrency for the purposes of running // this test suite, Python requires the GIL to be locked even for // deallocating memory, which can happen when you call Py_DECREF or // Py_INCREF. So acquire the GIL for the entire duration of this // test suite. + Py_InitializeEx(0); m_gil_state = PyGILState_Ensure(); + PyRun_SimpleString("import sys"); } void PythonTestSuite::TearDown() { PyGILState_Release(m_gil_state); - TestScriptInterpreterPython::Terminate(); - HostInfoBase::Terminate(); - FileSystem::Terminate(); + // We could call Py_FinalizeEx here, but initializing and finalizing Python is + // pretty slow, so just keep Python initialized across tests. } // The following functions are the Pythonic implementations of the required @@ -219,7 +203,7 @@ bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject( } bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject( -PyObject *implementor, lldb::DebuggerSP debugger, +PyObject *implementor, lldb::DebuggerSP debugger, StructuredDataImpl _impl, lldb_private::CommandReturnObject _retobj, lldb::ExecutionContextRefSP exe_ctx_ref_sp) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Call Import_AppendInittab exactly once before Py_Initialize (PR #82095)
https://github.com/medismailben approved this pull request. LGTM! https://github.com/llvm/llvm-project/pull/82095 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Call Import_AppendInittab exactly once before Py_Initialize (PR #82095)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes The Python documentation [1] says that `PyImport_AppendInittab` should be called before `Py_Initialize()`. Starting with Python 3.12, this is enforced with a fatal error: Fatal Python error: PyImport_AppendInittab: PyImport_AppendInittab() may not be called after Py_Initialize() This commit ensures we only modify the table of built-in modules if Python hasn't been initialized. For Python embedded in LLDB, that means this happen exactly once, before the first call to `Py_Initialize`, which becomes a NO-OP after. However, when lldb is imported in an existing Python interpreter, Python will have already been initialized, but by definition, the lldb module will already have been loaded, so it's safe to skip adding it (again). This fixes #70453. [1] https://docs.python.org/3.12/c-api/import.html#c.PyImport_AppendInittab --- Full diff: https://github.com/llvm/llvm-project/pull/82095.diff 1 Files Affected: - (modified) lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp (+28-25) ``diff diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index dadcde612614ba..30916853e6d0b2 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -97,24 +97,28 @@ struct InitializePythonRAII { InitializePythonRAII() { InitializePythonHome(); +// The table of built-in modules can only be extended before Python is +// initialized. +if (!Py_IsInitialized()) { #ifdef LLDB_USE_LIBEDIT_READLINE_COMPAT_MODULE -// Python's readline is incompatible with libedit being linked into lldb. -// Provide a patched version local to the embedded interpreter. -bool ReadlinePatched = false; -for (auto *p = PyImport_Inittab; p->name != nullptr; p++) { - if (strcmp(p->name, "readline") == 0) { -p->initfunc = initlldb_readline; -break; + // Python's readline is incompatible with libedit being linked into lldb. + // Provide a patched version local to the embedded interpreter. + bool ReadlinePatched = false; + for (auto *p = PyImport_Inittab; p->name != nullptr; p++) { +if (strcmp(p->name, "readline") == 0) { + p->initfunc = initlldb_readline; + break; +} + } + if (!ReadlinePatched) { +PyImport_AppendInittab("readline", initlldb_readline); +ReadlinePatched = true; } -} -if (!ReadlinePatched) { - PyImport_AppendInittab("readline", initlldb_readline); - ReadlinePatched = true; -} #endif -// Register _lldb as a built-in module. -PyImport_AppendInittab("_lldb", LLDBSwigPyInit); + // Register _lldb as a built-in module. + PyImport_AppendInittab("_lldb", LLDBSwigPyInit); +} // Python < 3.2 and Python >= 3.2 reversed the ordering requirements for // calling `Py_Initialize` and `PyEval_InitThreads`. < 3.2 requires that you @@ -2802,7 +2806,7 @@ bool ScriptInterpreterPythonImpl::RunScriptBasedParsedCommand( args_arr_sp->AddStringItem(entry.ref()); } StructuredDataImpl args_impl(args_arr_sp); - + ret_val = SWIGBridge::LLDBSwigPythonCallParsedCommandObject( static_cast(impl_obj_sp->GetValue()), debugger_sp, args_impl, cmd_retobj, exe_ctx_ref_sp); @@ -2936,7 +2940,7 @@ uint32_t ScriptInterpreterPythonImpl::GetFlagsForCommandObject( return result; } -StructuredData::ObjectSP +StructuredData::ObjectSP ScriptInterpreterPythonImpl::GetOptionsForCommandObject( StructuredData::GenericSP cmd_obj_sp) { StructuredData::ObjectSP result = {}; @@ -2984,7 +2988,7 @@ ScriptInterpreterPythonImpl::GetOptionsForCommandObject( return py_return.CreateStructuredObject(); } -StructuredData::ObjectSP +StructuredData::ObjectSP ScriptInterpreterPythonImpl::GetArgumentsForCommandObject( StructuredData::GenericSP cmd_obj_sp) { StructuredData::ObjectSP result = {}; @@ -3032,8 +3036,7 @@ ScriptInterpreterPythonImpl::GetArgumentsForCommandObject( return py_return.CreateStructuredObject(); } -void -ScriptInterpreterPythonImpl::OptionParsingStartedForCommandObject( +void ScriptInterpreterPythonImpl::OptionParsingStartedForCommandObject( StructuredData::GenericSP cmd_obj_sp) { Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock); @@ -3067,7 +3070,7 @@ ScriptInterpreterPythonImpl::OptionParsingStartedForCommandObject( if (PyErr_Occurred()) PyErr_Clear(); - // option_parsing_starting doesn't return anything, ignore anything but + // option_parsing_starting doesn't return anything, ignore anything but // python errors. unwrapOrSetPythonException( As(implementor.CallMethod(callee_name))); @@
[Lldb-commits] [lldb] [lldb] Call Import_AppendInittab exactly once before Py_Initialize (PR #82095)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/82095 The Python documentation [1] says that `PyImport_AppendInittab` should be called before `Py_Initialize()`. Starting with Python 3.12, this is enforced with a fatal error: Fatal Python error: PyImport_AppendInittab: PyImport_AppendInittab() may not be called after Py_Initialize() This commit ensures we only modify the table of built-in modules if Python hasn't been initialized. For Python embedded in LLDB, that means this happen exactly once, before the first call to `Py_Initialize`, which becomes a NO-OP after. However, when lldb is imported in an existing Python interpreter, Python will have already been initialized, but by definition, the lldb module will already have been loaded, so it's safe to skip adding it (again). This fixes #70453. [1] https://docs.python.org/3.12/c-api/import.html#c.PyImport_AppendInittab >From cf3ced835a1c6d05219a9a654ad880211f26e01b Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 16 Feb 2024 22:32:03 -0800 Subject: [PATCH] [lldb] Call Import_AppendInittab exactly once before Py_Initialize The Python documentation [1] says that `PyImport_AppendInittab` should be called before `Py_Initialize()`. Starting with Python 3.12, this is enforced with a fatal error: Fatal Python error: PyImport_AppendInittab: PyImport_AppendInittab() may not be called after Py_Initialize() This commit ensures we only modify the table of built-in modules if Python hasn't been initialized. For Python embedded in LLDB, that means this happen exactly once, before the first call to `Py_Initialize`, which becomes a NO-OP after. However, when lldb is imported in an existing Python interpreter, Python will have already been initialized, but by definition, the lldb module will already have been loaded, so it's safe to skip adding it (again). This fixes #70453. [1] https://docs.python.org/3.12/c-api/import.html#c.PyImport_AppendInittab --- .../Python/ScriptInterpreterPython.cpp| 53 ++- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index dadcde612614ba..30916853e6d0b2 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -97,24 +97,28 @@ struct InitializePythonRAII { InitializePythonRAII() { InitializePythonHome(); +// The table of built-in modules can only be extended before Python is +// initialized. +if (!Py_IsInitialized()) { #ifdef LLDB_USE_LIBEDIT_READLINE_COMPAT_MODULE -// Python's readline is incompatible with libedit being linked into lldb. -// Provide a patched version local to the embedded interpreter. -bool ReadlinePatched = false; -for (auto *p = PyImport_Inittab; p->name != nullptr; p++) { - if (strcmp(p->name, "readline") == 0) { -p->initfunc = initlldb_readline; -break; + // Python's readline is incompatible with libedit being linked into lldb. + // Provide a patched version local to the embedded interpreter. + bool ReadlinePatched = false; + for (auto *p = PyImport_Inittab; p->name != nullptr; p++) { +if (strcmp(p->name, "readline") == 0) { + p->initfunc = initlldb_readline; + break; +} + } + if (!ReadlinePatched) { +PyImport_AppendInittab("readline", initlldb_readline); +ReadlinePatched = true; } -} -if (!ReadlinePatched) { - PyImport_AppendInittab("readline", initlldb_readline); - ReadlinePatched = true; -} #endif -// Register _lldb as a built-in module. -PyImport_AppendInittab("_lldb", LLDBSwigPyInit); + // Register _lldb as a built-in module. + PyImport_AppendInittab("_lldb", LLDBSwigPyInit); +} // Python < 3.2 and Python >= 3.2 reversed the ordering requirements for // calling `Py_Initialize` and `PyEval_InitThreads`. < 3.2 requires that you @@ -2802,7 +2806,7 @@ bool ScriptInterpreterPythonImpl::RunScriptBasedParsedCommand( args_arr_sp->AddStringItem(entry.ref()); } StructuredDataImpl args_impl(args_arr_sp); - + ret_val = SWIGBridge::LLDBSwigPythonCallParsedCommandObject( static_cast(impl_obj_sp->GetValue()), debugger_sp, args_impl, cmd_retobj, exe_ctx_ref_sp); @@ -2936,7 +2940,7 @@ uint32_t ScriptInterpreterPythonImpl::GetFlagsForCommandObject( return result; } -StructuredData::ObjectSP +StructuredData::ObjectSP ScriptInterpreterPythonImpl::GetOptionsForCommandObject( StructuredData::GenericSP cmd_obj_sp) { StructuredData::ObjectSP result = {}; @@ -2984,7 +2988,7 @@ ScriptInterpreterPythonImpl::GetOptionsForCommandObject( return py_return.CreateStructuredObject(); } -StructuredData::ObjectSP
[Lldb-commits] [lldb] [lldb] Migrate distutils.version.LooseVersion to packaging (PR #82066)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/82066 >From 2e663a2e4a056529e2e17908fc39b90ea8c16eb9 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 16 Feb 2024 14:59:15 -0800 Subject: [PATCH] [lldb] Migrate distutils.version.LooseVersion to packaging The distutils package has been deprecated and was removed from Python 3.12. The migration page [1] advises to use the packaging module instead. Since Python 3.6 that's vendored into pkg_resources. [1] https://peps.python.org/pep-0632/#migration-advice --- .../Python/lldbsuite/test/decorators.py | 12 --- .../Python/lldbsuite/test/lldbplatformutil.py | 25 --- lldb/test/API/sanity/TestSettingSkipping.py | 31 +-- .../lldb-server/TestAppleSimulatorOSType.py | 4 +-- lldb/test/Shell/helper/build.py | 4 +-- 5 files changed, 40 insertions(+), 36 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index a5d7a7a25879df..b691f82b90652c 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -1,6 +1,6 @@ # System modules -from distutils.version import LooseVersion from functools import wraps +from pkg_resources import packaging import ctypes import locale import os @@ -65,10 +65,10 @@ def fn_neq(x, y): ">=": fn_geq, "<=": fn_leq, } -expected_str = ".".join([str(x) for x in expected]) -actual_str = ".".join([str(x) for x in actual]) -return op_lookup[comparison](LooseVersion(actual_str), LooseVersion(expected_str)) +return op_lookup[comparison]( +packaging.version.parse(actual), packaging.version.parse(expected) +) def _match_decorator_property(expected, actual): @@ -238,7 +238,9 @@ def fn(actual_debug_info=None): ) ) skip_for_py_version = (py_version is None) or _check_expected_version( -py_version[0], py_version[1], sys.version_info +py_version[0], +py_version[1], +"{}.{}".format(sys.version_info.major, sys.version_info.minor), ) skip_for_macos_version = (macos_version is None) or ( (platform.mac_ver()[0] != "") diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py index bd92d03e0e2212..a118aa61a6287d 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py @@ -7,8 +7,8 @@ import subprocess import sys import os -from distutils.version import LooseVersion from urllib.parse import urlparse +from pkg_resources import packaging # LLDB modules import lldb @@ -297,27 +297,30 @@ def expectedCompilerVersion(compiler_version): if compiler_version is None: return True operator = str(compiler_version[0]) -version = compiler_version[1] +version_str = str(compiler_version[1]) -if version is None: +if not version_str: return True -test_compiler_version = getCompilerVersion() -if test_compiler_version == "unknown": +test_compiler_version_str = getCompilerVersion() +if test_compiler_version_str == "unknown": # Assume the compiler version is at or near the top of trunk. return operator in [">", ">=", "!", "!=", "not"] +version = packaging.version.parse(version_str) +test_compiler_version = packaging.version.parse(test_compiler_version_str) + if operator == ">": -return LooseVersion(test_compiler_version) > LooseVersion(version) +return test_compiler_version < version if operator == ">=" or operator == "=>": -return LooseVersion(test_compiler_version) >= LooseVersion(version) +return test_compiler_version >= version if operator == "<": -return LooseVersion(test_compiler_version) < LooseVersion(version) +return test_compiler_version < version if operator == "<=" or operator == "=<": -return LooseVersion(test_compiler_version) <= LooseVersion(version) +return test_compiler_version <= version if operator == "!=" or operator == "!" or operator == "not": -return str(version) not in str(test_compiler_version) -return str(version) in str(test_compiler_version) +return version_str not in test_compiler_version_str +return version_str in test_compiler_version_str def expectedCompiler(compilers): diff --git a/lldb/test/API/sanity/TestSettingSkipping.py b/lldb/test/API/sanity/TestSettingSkipping.py index 5f58ec2638456d..f0d4d266073e03 100644 --- a/lldb/test/API/sanity/TestSettingSkipping.py +++ b/lldb/test/API/sanity/TestSettingSkipping.py @@ -1,8 +1,7 @@ """ -This is a sanity check that verifies that test can be sklipped based on settings. +This is a sanity check that verifies that test can be skipped based on
[Lldb-commits] [lldb] [lldb] Migrate distutils.version.LooseVersion to packaging (PR #82066)
@@ -1,33 +1,33 @@ """ -This is a sanity check that verifies that test can be sklipped based on settings. +This is a sanity check that verifies that test can be skipped based on settings. """ - import lldb from lldbsuite.test.lldbtest import * from lldbsuite.test.decorators import * class SettingSkipSanityTestCase(TestBase): NO_DEBUG_INFO_TESTCASE = True +REAL_PYTHON_VERSION = "3.0" +FUTURE_PYTHON_VERSION = "4.0" -@skipIf(py_version=(">=", (3, 0))) +@skipIf(py_version=(">=", REAL_PYTHON_VERSION)) def testSkip(self): -"""This setting is on by default""" -self.assertTrue(False, "This test should not run!") - -@skipIf(py_version=("<", (3, 0))) -def testNoMatch(self): -self.assertTrue(True, "This test should run!") +self.assertTrue(False, "This test should not run and fail (SKIPPED)") -@skipIf(setting=("target.i-made-this-one-up", "true")) -def testNotExisting(self): -self.assertTrue(True, "This test should run!") +@skipIf(py_version=("<", FUTURE_PYTHON_VERSION)) +def testNoSKip(self): +self.assertTrue(True, "This test should run and pass(PASS)") -@expectedFailureAll(py_version=(">=", (3, 0))) +@expectedFailureAll(py_version=("<", FUTURE_PYTHON_VERSION)) def testXFAIL(self): -self.assertTrue(False, "This test should run and fail!") +self.assertTrue(False, "This test should expectedly fail (XFAIL)") -@expectedFailureAll(py_version=("<", (3, 0))) +@expectedFailureAll(py_version=(">=", FUTURE_PYTHON_VERSION)) JDevlieghere wrote: We had a bug in the decorator and I messed around with the conditions to test a few more cases, but the original ones were easier to understand. I'll keep the original comparisons. https://github.com/llvm/llvm-project/pull/82066 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Replace assertRegexpMatches with assertRegex (NFC) (PR #82074)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/82074 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 737bc9f - [lldb] Replace assertRegexpMatches with assertRegex (NFC) (#82074)
Author: Jonas Devlieghere Date: 2024-02-16T21:45:08-08:00 New Revision: 737bc9f76a14b955bdfeb3811ce6c9156572be9f URL: https://github.com/llvm/llvm-project/commit/737bc9f76a14b955bdfeb3811ce6c9156572be9f DIFF: https://github.com/llvm/llvm-project/commit/737bc9f76a14b955bdfeb3811ce6c9156572be9f.diff LOG: [lldb] Replace assertRegexpMatches with assertRegex (NFC) (#82074) assertRegexpMatches is a deprecated alias for assertRegex and has been removed in Python 3.12. This wasn't an issue previously because we used a vendored version of the unittest module. Now that we use the built-in version this gets updated together with the Python version used to run the test suite. Added: Modified: lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py lldb/test/API/functionalities/memory-region/TestMemoryRegion.py lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py lldb/test/API/linux/aarch64/tagged_memory_access/TestAArch64LinuxTaggedMemoryAccess.py lldb/test/API/linux/aarch64/tagged_memory_region/TestAArch64LinuxTaggedMemoryRegion.py lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py lldb/test/API/tools/lldb-server/TestGdbRemoteLaunch.py lldb/test/API/tools/lldb-server/TestGdbRemoteModuleInfo.py Removed: diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 7436b9900e98b0..73bd037fd328cb 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -249,13 +249,13 @@ def continue_to_exception_breakpoint(self, filter_label): def continue_to_exit(self, exitCode=0): self.dap_server.request_continue() stopped_events = self.dap_server.wait_for_stopped() -self.assertEquals( +self.assertEqual( len(stopped_events), 1, "stopped_events = {}".format(stopped_events) ) -self.assertEquals( +self.assertEqual( stopped_events[0]["event"], "exited", "make sure program ran to completion" ) -self.assertEquals( +self.assertEqual( stopped_events[0]["body"]["exitCode"], exitCode, "exitCode == %i" % (exitCode), diff --git a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py index d90ae310ecf0e8..577411ebc1037d 100644 --- a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py +++ b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py @@ -2,7 +2,6 @@ Test the 'memory region' command. """ - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -62,7 +61,7 @@ def test_command(self): # We allow --all or an address argument, not both interp.HandleCommand("memory region --all 0", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( +self.assertRegex( result.GetError(), 'The "--all" option cannot be used when an address argument is given', ) @@ -81,7 +80,7 @@ def test_command(self): # Now let's print the memory region starting at 0 which should always work. interp.HandleCommand("memory region 0x0", result) self.assertTrue(result.Succeeded()) -self.assertRegexpMatches(result.GetOutput(), "\\[0x0+-") +self.assertRegex(result.GetOutput(), "\\[0x0+-") all_regions += result.GetOutput() # Keep printing memory regions until we printed all of them. @@ -94,7 +93,7 @@ def test_command(self): # Now that we reached the end, 'memory region' should again print the usage. interp.HandleCommand("memory region", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( +self.assertRegex( result.GetError(), "Usage: memory region \(or \-\-all\)", ) diff --git a/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py b/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py index 7a2e488a92ab4c..6d2ce2bb3e7092 100644 --- a/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py +++ b/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py @@ -2,7 +2,6 @@ Test how lldb reacts to wrong commands """ - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -18,11 +17,9 @@ def test_ambiguous_command(self): command_interpreter.HandleCommand("g", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( -result.GetError(), "Ambiguous command 'g'. Possible matches:" -) -
[Lldb-commits] [lldb] [lldb] Migrate distutils.version.LooseVersion to packaging (PR #82066)
@@ -1,33 +1,33 @@ """ -This is a sanity check that verifies that test can be sklipped based on settings. +This is a sanity check that verifies that test can be skipped based on settings. """ - import lldb from lldbsuite.test.lldbtest import * from lldbsuite.test.decorators import * class SettingSkipSanityTestCase(TestBase): NO_DEBUG_INFO_TESTCASE = True +REAL_PYTHON_VERSION = "3.0" +FUTURE_PYTHON_VERSION = "4.0" -@skipIf(py_version=(">=", (3, 0))) +@skipIf(py_version=(">=", REAL_PYTHON_VERSION)) def testSkip(self): -"""This setting is on by default""" -self.assertTrue(False, "This test should not run!") - -@skipIf(py_version=("<", (3, 0))) -def testNoMatch(self): -self.assertTrue(True, "This test should run!") +self.assertTrue(False, "This test should not run and fail (SKIPPED)") -@skipIf(setting=("target.i-made-this-one-up", "true")) -def testNotExisting(self): -self.assertTrue(True, "This test should run!") +@skipIf(py_version=("<", FUTURE_PYTHON_VERSION)) +def testNoSKip(self): +self.assertTrue(True, "This test should run and pass(PASS)") -@expectedFailureAll(py_version=(">=", (3, 0))) +@expectedFailureAll(py_version=("<", FUTURE_PYTHON_VERSION)) def testXFAIL(self): -self.assertTrue(False, "This test should run and fail!") +self.assertTrue(False, "This test should expectedly fail (XFAIL)") -@expectedFailureAll(py_version=("<", (3, 0))) +@expectedFailureAll(py_version=(">=", FUTURE_PYTHON_VERSION)) felipepiovezan wrote: is this right? what used to be <3.0 is now >=4.0? https://github.com/llvm/llvm-project/pull/82066 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Migrate distutils.version.LooseVersion to packaging (PR #82066)
@@ -308,13 +308,21 @@ def expectedCompilerVersion(compiler_version): return operator in [">", ">=", "!", "!=", "not"] if operator == ">": -return LooseVersion(test_compiler_version) > LooseVersion(version) +return packaging.version.parse(test_compiler_version) > packaging.version.parse( felipepiovezan wrote: all these would probably be easier to read if we factored out both parse calls into a variable, as they are repeated everywhere. Don't feel strongly about it though https://github.com/llvm/llvm-project/pull/82066 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Replace assertRegexpMatches with assertRegex (NFC) (PR #82074)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/82074 >From f78594900fa34cb9c96bfc6b2dedc2e86bce201f Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 16 Feb 2024 15:49:11 -0800 Subject: [PATCH] [lldb] Replace assertRegexpMatches with assertRegex (NFC) assertRegexpMatches is a deprecated alias for assertRegex and has been removed in Python 3.12. This wasn't an issue previously because we used a vendored version of the unittest module. Now that we use the built-in version this gets updated together with the Python version used to run the test suite. --- .../test/tools/lldb-dap/lldbdap_testcase.py| 6 +++--- .../memory-region/TestMemoryRegion.py | 7 +++ .../wrong_commands/TestWrongCommands.py| 11 --- .../TestAArch64LinuxTaggedMemoryAccess.py | 3 +-- .../TestAArch64LinuxTaggedMemoryRegion.py | 3 +-- .../lldb-dap/evaluate/TestDAP_evaluate.py | 18 +++--- .../tools/lldb-server/TestGdbRemoteLaunch.py | 2 +- .../lldb-server/TestGdbRemoteModuleInfo.py | 10 +- 8 files changed, 29 insertions(+), 31 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 7436b9900e98b0..73bd037fd328cb 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -249,13 +249,13 @@ def continue_to_exception_breakpoint(self, filter_label): def continue_to_exit(self, exitCode=0): self.dap_server.request_continue() stopped_events = self.dap_server.wait_for_stopped() -self.assertEquals( +self.assertEqual( len(stopped_events), 1, "stopped_events = {}".format(stopped_events) ) -self.assertEquals( +self.assertEqual( stopped_events[0]["event"], "exited", "make sure program ran to completion" ) -self.assertEquals( +self.assertEqual( stopped_events[0]["body"]["exitCode"], exitCode, "exitCode == %i" % (exitCode), diff --git a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py index d90ae310ecf0e8..577411ebc1037d 100644 --- a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py +++ b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py @@ -2,7 +2,6 @@ Test the 'memory region' command. """ - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -62,7 +61,7 @@ def test_command(self): # We allow --all or an address argument, not both interp.HandleCommand("memory region --all 0", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( +self.assertRegex( result.GetError(), 'The "--all" option cannot be used when an address argument is given', ) @@ -81,7 +80,7 @@ def test_command(self): # Now let's print the memory region starting at 0 which should always work. interp.HandleCommand("memory region 0x0", result) self.assertTrue(result.Succeeded()) -self.assertRegexpMatches(result.GetOutput(), "\\[0x0+-") +self.assertRegex(result.GetOutput(), "\\[0x0+-") all_regions += result.GetOutput() # Keep printing memory regions until we printed all of them. @@ -94,7 +93,7 @@ def test_command(self): # Now that we reached the end, 'memory region' should again print the usage. interp.HandleCommand("memory region", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( +self.assertRegex( result.GetError(), "Usage: memory region \(or \-\-all\)", ) diff --git a/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py b/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py index 83900a307f52e0..d8210b74dd7064 100644 --- a/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py +++ b/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py @@ -2,7 +2,6 @@ Test how lldb reacts to wrong commands """ - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -18,12 +17,10 @@ def test_ambiguous_command(self): command_interpreter.HandleCommand("g", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( -result.GetError(), "Ambiguous command 'g'. Possible matches:" -) -self.assertRegexpMatches(result.GetError(), "gui") -self.assertRegexpMatches(result.GetError(), "gdb-remote") -self.assertEquals(1, result.GetError().count("gdb-remote")) +self.assertRegex(result.GetError(), "Ambiguous command 'g'.
[Lldb-commits] [lldb] [lldb] Replace assertRegexpMatches with assertRegex (NFC) (PR #82074)
https://github.com/felipepiovezan approved this pull request. https://github.com/llvm/llvm-project/pull/82074 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Replace assertEquals with assertEqual (NFC) (PR #82073)
https://github.com/JDevlieghere closed https://github.com/llvm/llvm-project/pull/82073 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Centralize the handling of completion for simple argument lists. (PR #82085)
@@ -1139,6 +1097,15 @@ class CommandObjectPlatformProcessLaunch : public CommandObjectParsed { m_arguments.push_back({run_arg_arg}); } + void + HandleArgumentCompletion(CompletionRequest , + OptionElementVector _element_vector) override { bulbazord wrote: Any way you could move this to the generic CommandObject implementation? https://github.com/llvm/llvm-project/pull/82085 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Centralize the handling of completion for simple argument lists. (PR #82085)
@@ -305,6 +305,42 @@ void CommandObject::HandleCompletion(CompletionRequest ) { } } +void +CommandObject::HandleArgumentCompletion(CompletionRequest , + OptionElementVector _element_vector) { + size_t num_arg_entries = GetNumArgumentEntries(); + if (num_arg_entries != 1) +return; + + CommandArgumentEntry *entry_ptr = GetArgumentEntryAtIndex(0); + if (!entry_ptr) +return; // Maybe this should be an assert, this shouldn't be possible. bulbazord wrote: If it shouldn't be possible, I think an assert is warranted here. I would say add the assertion above the early return (and keep the early return since the assertion will be compiled out in release builds). https://github.com/llvm/llvm-project/pull/82085 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Centralize the handling of completion for simple argument lists. (PR #82085)
@@ -243,7 +243,7 @@ static constexpr CommandObject::ArgumentTableEntry g_argument_table[] = { { lldb::eArgTypeLogCategory, "log-category", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "The name of a category within a log channel, e.g. all (try \"log list\" to see a list of all channels and their categories." }, { lldb::eArgTypeLogChannel, "log-channel", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "The name of a log channel, e.g. process.gdb-remote (try \"log list\" to see a list of all channels and their categories)." }, { lldb::eArgTypeMethod, "method", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "A C++ method name." }, -{ lldb::eArgTypeName, "name", lldb::eTypeCategoryNameCompletion, {}, { nullptr, false }, "Help text goes here." }, bulbazord wrote: Help text DOES go here! :) https://github.com/llvm/llvm-project/pull/82085 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Centralize the handling of completion for simple argument lists. (PR #82085)
jimingham wrote: I didn't add any new tests, the TestCompletion.py is pretty thorough already. https://github.com/llvm/llvm-project/pull/82085 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Centralize the handling of completion for simple argument lists. (PR #82085)
jimingham wrote: BTW, in case this is confusing, the completers that were returning if the cursor was not in the first argument slot was preventing: (lldb) command arg1 from starting another completion when the argument was eArgTypePlain (only one arg). I moved that check to the CommandObject::HandleArgumentCompletion so that's no longer required. Also, I on purpose didn't change any argument completions that I had to think hard about. I'll do those on subsequent passes. https://github.com/llvm/llvm-project/pull/82085 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Centralize the handling of completion for simple argument lists. (PR #82085)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 6ce03ff3fef8fb6fa9afe8eb22c6d98bced26d48 d08b2b0f10fd449a2b47252aa0da75d515a68664 -- lldb/include/lldb/Interpreter/CommandObject.h lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h lldb/include/lldb/lldb-enumerations.h lldb/source/Commands/CommandObjectCommands.cpp lldb/source/Commands/CommandObjectDWIMPrint.cpp lldb/source/Commands/CommandObjectDWIMPrint.h lldb/source/Commands/CommandObjectFrame.cpp lldb/source/Commands/CommandObjectPlatform.cpp lldb/source/Commands/CommandObjectPlugin.cpp lldb/source/Commands/CommandObjectProcess.cpp lldb/source/Commands/CommandObjectRegister.cpp lldb/source/Commands/CommandObjectSession.cpp lldb/source/Commands/CommandObjectSettings.cpp lldb/source/Commands/CommandObjectTarget.cpp lldb/source/Commands/CommandObjectThread.cpp lldb/source/Commands/CommandObjectType.cpp lldb/source/Commands/CommandObjectWatchpoint.cpp lldb/source/Interpreter/CommandObject.cpp `` View the diff from clang-format here. ``diff diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h index 537acb4502..6f058c5628 100644 --- a/lldb/include/lldb/Interpreter/CommandObject.h +++ b/lldb/include/lldb/Interpreter/CommandObject.h @@ -241,11 +241,11 @@ public: /// The default version handles argument definitions that have only one /// argument type, and use one of the argument types that have an entry in - /// the CommonCompletions. Override this if you have a more complex - /// argument setup. - /// FIXME: we should be able to extend this to more complex argument + /// the CommonCompletions. Override this if you have a more complex + /// argument setup. + /// FIXME: we should be able to extend this to more complex argument /// definitions provided we have completers for all the argument types. - /// + /// /// The input array contains a parsed version of the line. /// /// We've constructed the map of options and their arguments as well if that diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp index 7b960029d3..b25c391bd4 100644 --- a/lldb/source/Commands/CommandObjectPlatform.cpp +++ b/lldb/source/Commands/CommandObjectPlatform.cpp @@ -1103,7 +1103,8 @@ public: // I didn't make a type for RemoteRunArgs, but since we're going to run // this on the remote system we should use the remote completer. lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks( -GetCommandInterpreter(), lldb::eRemoteDiskFileCompletion, request, nullptr); +GetCommandInterpreter(), lldb::eRemoteDiskFileCompletion, request, +nullptr); } ~CommandObjectPlatformProcessLaunch() override = default; diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index 50e6a78d31..1abc3bf45f 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -305,9 +305,8 @@ void CommandObject::HandleCompletion(CompletionRequest ) { } } -void -CommandObject::HandleArgumentCompletion(CompletionRequest , - OptionElementVector _element_vector) { +void CommandObject::HandleArgumentCompletion( +CompletionRequest , OptionElementVector _element_vector) { size_t num_arg_entries = GetNumArgumentEntries(); if (num_arg_entries != 1) return; @@ -315,32 +314,30 @@ CommandObject::HandleArgumentCompletion(CompletionRequest , CommandArgumentEntry *entry_ptr = GetArgumentEntryAtIndex(0); if (!entry_ptr) return; // Maybe this should be an assert, this shouldn't be possible. - + CommandArgumentEntry = *entry_ptr; // For now, we only handle the simple case of one homogenous argument type. if (entry.size() != 1) return; // Look up the completion type, and if it has one, invoke it: - const CommandObject::ArgumentTableEntry *arg_entry - = FindArgumentDataByType(entry[0].arg_type); + const CommandObject::ArgumentTableEntry *arg_entry = + FindArgumentDataByType(entry[0].arg_type); const ArgumentRepetitionType repeat = entry[0].arg_repetition; - + if (arg_entry == nullptr || arg_entry->completion_type == lldb::eNoCompletion) return; - + // FIXME: This should be handled higher in the Command Parser. // Check the case where this command only takes one argument, and don't do // the completion if we aren't on the first entry: if (repeat == eArgRepeatPlain && request.GetCursorIndex() != 0) return; - - lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks( -GetCommandInterpreter(), arg_entry->completion_type, request, nullptr); +
[Lldb-commits] [lldb] Centralize the handling of completion for simple argument lists. (PR #82085)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: None (jimingham) Changes Most commands were adding argument completion handling by themselves, resulting in a lot of unnecessary boilerplate. In many cases, this could be done generically given the argument definition and the entries in the g_argument_table. I'm going to address this in a couple passes. In this first pass, I added handling of commands that have only one argument list, with one argument type, either single or repeated, and changed all the commands that are of this sort (and don't have other bits of business in their completers.) I also added some missing connections between arg types and completions to the table, and added a RemoteFilename and RemotePath to use in places where we were using the Remote completers. Those arguments used to say they were "files" but they were in fact remote files. I also added a module arg type to use where we were using the module completer. In that case, we should call the argument module. --- Patch is 39.50 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/82085.diff 19 Files Affected: - (modified) lldb/include/lldb/Interpreter/CommandObject.h (+8-1) - (modified) lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h (+12-9) - (modified) lldb/include/lldb/lldb-enumerations.h (+3) - (modified) lldb/source/Commands/CommandObjectCommands.cpp (-14) - (modified) lldb/source/Commands/CommandObjectDWIMPrint.cpp (-6) - (modified) lldb/source/Commands/CommandObjectDWIMPrint.h (-4) - (modified) lldb/source/Commands/CommandObjectFrame.cpp (-19) - (modified) lldb/source/Commands/CommandObjectPlatform.cpp (+17-57) - (modified) lldb/source/Commands/CommandObjectPlugin.cpp (-7) - (modified) lldb/source/Commands/CommandObjectProcess.cpp (+1-18) - (modified) lldb/source/Commands/CommandObjectRegister.cpp (+2-5) - (modified) lldb/source/Commands/CommandObjectSession.cpp (-7) - (modified) lldb/source/Commands/CommandObjectSettings.cpp (-8) - (modified) lldb/source/Commands/CommandObjectTarget.cpp (+3-26) - (modified) lldb/source/Commands/CommandObjectThread.cpp (+1-12) - (modified) lldb/source/Commands/CommandObjectType.cpp (-32) - (modified) lldb/source/Commands/CommandObjectWatchpoint.cpp (-10) - (modified) lldb/source/Interpreter/CommandObject.cpp (+36) - (modified) lldb/test/API/commands/help/TestHelp.py (+1-1) ``diff diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h index 7b427de0264f75..537acb450296b5 100644 --- a/lldb/include/lldb/Interpreter/CommandObject.h +++ b/lldb/include/lldb/Interpreter/CommandObject.h @@ -239,6 +239,13 @@ class CommandObject : public std::enable_shared_from_this { ///The completion request that needs to be answered. virtual void HandleCompletion(CompletionRequest ); + /// The default version handles argument definitions that have only one + /// argument type, and use one of the argument types that have an entry in + /// the CommonCompletions. Override this if you have a more complex + /// argument setup. + /// FIXME: we should be able to extend this to more complex argument + /// definitions provided we have completers for all the argument types. + /// /// The input array contains a parsed version of the line. /// /// We've constructed the map of options and their arguments as well if that @@ -248,7 +255,7 @@ class CommandObject : public std::enable_shared_from_this { ///The completion request that needs to be answered. virtual void HandleArgumentCompletion(CompletionRequest , - OptionElementVector _element_vector) {} + OptionElementVector _element_vector); bool HelpTextContainsWord(llvm::StringRef search_word, bool search_short_help = true, diff --git a/lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h b/lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h index d0cf54c31ca73f..ab5eff699b4cf0 100644 --- a/lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h +++ b/lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h @@ -243,7 +243,7 @@ static constexpr CommandObject::ArgumentTableEntry g_argument_table[] = { { lldb::eArgTypeLogCategory, "log-category", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "The name of a category within a log channel, e.g. all (try \"log list\" to see a list of all channels and their categories." }, { lldb::eArgTypeLogChannel, "log-channel", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "The name of a log channel, e.g. process.gdb-remote (try \"log list\" to see a list of all channels and their categories)." }, { lldb::eArgTypeMethod, "method", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "A C++ method name." }, -{ lldb::eArgTypeName, "name", lldb::eTypeCategoryNameCompletion,
[Lldb-commits] [lldb] Centralize the handling of completion for simple argument lists. (PR #82085)
https://github.com/jimingham created https://github.com/llvm/llvm-project/pull/82085 Most commands were adding argument completion handling by themselves, resulting in a lot of unnecessary boilerplate. In many cases, this could be done generically given the argument definition and the entries in the g_argument_table. I'm going to address this in a couple passes. In this first pass, I added handling of commands that have only one argument list, with one argument type, either single or repeated, and changed all the commands that are of this sort (and don't have other bits of business in their completers.) I also added some missing connections between arg types and completions to the table, and added a RemoteFilename and RemotePath to use in places where we were using the Remote completers. Those arguments used to say they were "files" but they were in fact remote files. I also added a module arg type to use where we were using the module completer. In that case, we should call the argument module. >From d08b2b0f10fd449a2b47252aa0da75d515a68664 Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Fri, 16 Feb 2024 16:58:35 -0800 Subject: [PATCH] Centralize the handling of completion for simple argument lists. Most commands were adding argument completion handling by themselves, resulting in a lot of unnecessary boilerplate. In many cases, this could be done generically given the argument definition and the entries in the g_argument_table. I'm going to address this in a couple passes. In this first pass, I added handling of commands that have only one argument list, with one argument type, either single or repeated, and changed all the commands that are of this sort (and don't have other bits of business in their completers.) I also added some missing connections between arg types and completions to the table, and added a RemoteFilename and RemotePath to use in places where we were using the Remote completers. Those arguments used to say they were "files" but they were in fact remote files. I also added a module arg type to use where we were using the module completer. In that case, we should call the argument module. --- lldb/include/lldb/Interpreter/CommandObject.h | 9 ++- .../Interpreter/CommandOptionArgumentTable.h | 21 +++--- lldb/include/lldb/lldb-enumerations.h | 3 + .../source/Commands/CommandObjectCommands.cpp | 14 .../Commands/CommandObjectDWIMPrint.cpp | 6 -- lldb/source/Commands/CommandObjectDWIMPrint.h | 4 - lldb/source/Commands/CommandObjectFrame.cpp | 19 - .../source/Commands/CommandObjectPlatform.cpp | 74 +-- lldb/source/Commands/CommandObjectPlugin.cpp | 7 -- lldb/source/Commands/CommandObjectProcess.cpp | 19 + .../source/Commands/CommandObjectRegister.cpp | 7 +- lldb/source/Commands/CommandObjectSession.cpp | 7 -- .../source/Commands/CommandObjectSettings.cpp | 8 -- lldb/source/Commands/CommandObjectTarget.cpp | 29 +--- lldb/source/Commands/CommandObjectThread.cpp | 13 +--- lldb/source/Commands/CommandObjectType.cpp| 32 .../Commands/CommandObjectWatchpoint.cpp | 10 --- lldb/source/Interpreter/CommandObject.cpp | 36 + lldb/test/API/commands/help/TestHelp.py | 2 +- 19 files changed, 84 insertions(+), 236 deletions(-) diff --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h index 7b427de0264f75..537acb450296b5 100644 --- a/lldb/include/lldb/Interpreter/CommandObject.h +++ b/lldb/include/lldb/Interpreter/CommandObject.h @@ -239,6 +239,13 @@ class CommandObject : public std::enable_shared_from_this { ///The completion request that needs to be answered. virtual void HandleCompletion(CompletionRequest ); + /// The default version handles argument definitions that have only one + /// argument type, and use one of the argument types that have an entry in + /// the CommonCompletions. Override this if you have a more complex + /// argument setup. + /// FIXME: we should be able to extend this to more complex argument + /// definitions provided we have completers for all the argument types. + /// /// The input array contains a parsed version of the line. /// /// We've constructed the map of options and their arguments as well if that @@ -248,7 +255,7 @@ class CommandObject : public std::enable_shared_from_this { ///The completion request that needs to be answered. virtual void HandleArgumentCompletion(CompletionRequest , - OptionElementVector _element_vector) {} + OptionElementVector _element_vector); bool HelpTextContainsWord(llvm::StringRef search_word, bool search_short_help = true, diff --git a/lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h b/lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h index d0cf54c31ca73f..ab5eff699b4cf0 100644 ---
[Lldb-commits] [lldb] [lldb] Replace assertEquals with assertEqual (NFC) (PR #82073)
https://github.com/felipepiovezan approved this pull request. nice! https://github.com/llvm/llvm-project/pull/82073 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Replace assertRegexpMatches with assertRegex (NFC) (PR #82074)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes assertRegexpMatches is a deprecated alias for assertRegex and has been removed in Python 3.12. This wasn't an issue previously because we used a vendored version of the unittest module. Now that we use the built-in version this gets updated together with the Python version used to run the test suite. --- Full diff: https://github.com/llvm/llvm-project/pull/82074.diff 8 Files Affected: - (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py (+3-3) - (modified) lldb/test/API/functionalities/memory-region/TestMemoryRegion.py (+3-4) - (modified) lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py (+4-7) - (modified) lldb/test/API/linux/aarch64/tagged_memory_access/TestAArch64LinuxTaggedMemoryAccess.py (+1-2) - (modified) lldb/test/API/linux/aarch64/tagged_memory_region/TestAArch64LinuxTaggedMemoryRegion.py (+1-2) - (modified) lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py (+11-7) - (modified) lldb/test/API/tools/lldb-server/TestGdbRemoteLaunch.py (+1-1) - (modified) lldb/test/API/tools/lldb-server/TestGdbRemoteModuleInfo.py (+5-5) ``diff diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 7436b9900e98b0..73bd037fd328cb 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -249,13 +249,13 @@ def continue_to_exception_breakpoint(self, filter_label): def continue_to_exit(self, exitCode=0): self.dap_server.request_continue() stopped_events = self.dap_server.wait_for_stopped() -self.assertEquals( +self.assertEqual( len(stopped_events), 1, "stopped_events = {}".format(stopped_events) ) -self.assertEquals( +self.assertEqual( stopped_events[0]["event"], "exited", "make sure program ran to completion" ) -self.assertEquals( +self.assertEqual( stopped_events[0]["body"]["exitCode"], exitCode, "exitCode == %i" % (exitCode), diff --git a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py index d90ae310ecf0e8..577411ebc1037d 100644 --- a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py +++ b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py @@ -2,7 +2,6 @@ Test the 'memory region' command. """ - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -62,7 +61,7 @@ def test_command(self): # We allow --all or an address argument, not both interp.HandleCommand("memory region --all 0", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( +self.assertRegex( result.GetError(), 'The "--all" option cannot be used when an address argument is given', ) @@ -81,7 +80,7 @@ def test_command(self): # Now let's print the memory region starting at 0 which should always work. interp.HandleCommand("memory region 0x0", result) self.assertTrue(result.Succeeded()) -self.assertRegexpMatches(result.GetOutput(), "\\[0x0+-") +self.assertRegex(result.GetOutput(), "\\[0x0+-") all_regions += result.GetOutput() # Keep printing memory regions until we printed all of them. @@ -94,7 +93,7 @@ def test_command(self): # Now that we reached the end, 'memory region' should again print the usage. interp.HandleCommand("memory region", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( +self.assertRegex( result.GetError(), "Usage: memory region \(or \-\-all\)", ) diff --git a/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py b/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py index 83900a307f52e0..d8210b74dd7064 100644 --- a/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py +++ b/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py @@ -2,7 +2,6 @@ Test how lldb reacts to wrong commands """ - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -18,12 +17,10 @@ def test_ambiguous_command(self): command_interpreter.HandleCommand("g", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( -result.GetError(), "Ambiguous command 'g'. Possible matches:" -) -self.assertRegexpMatches(result.GetError(), "gui") -self.assertRegexpMatches(result.GetError(), "gdb-remote") -self.assertEquals(1,
[Lldb-commits] [lldb] [lldb] Replace assertRegexpMatches with assertRegex (NFC) (PR #82074)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/82074 assertRegexpMatches is a deprecated alias for assertRegex and has been removed in Python 3.12. This wasn't an issue previously because we used a vendored version of the unittest module. Now that we use the built-in version this gets updated together with the Python version used to run the test suite. >From f78594900fa34cb9c96bfc6b2dedc2e86bce201f Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 16 Feb 2024 15:49:11 -0800 Subject: [PATCH] [lldb] Replace assertRegexpMatches with assertRegex (NFC) assertRegexpMatches is a deprecated alias for assertRegex and has been removed in Python 3.12. This wasn't an issue previously because we used a vendored version of the unittest module. Now that we use the built-in version this gets updated together with the Python version used to run the test suite. --- .../test/tools/lldb-dap/lldbdap_testcase.py| 6 +++--- .../memory-region/TestMemoryRegion.py | 7 +++ .../wrong_commands/TestWrongCommands.py| 11 --- .../TestAArch64LinuxTaggedMemoryAccess.py | 3 +-- .../TestAArch64LinuxTaggedMemoryRegion.py | 3 +-- .../lldb-dap/evaluate/TestDAP_evaluate.py | 18 +++--- .../tools/lldb-server/TestGdbRemoteLaunch.py | 2 +- .../lldb-server/TestGdbRemoteModuleInfo.py | 10 +- 8 files changed, 29 insertions(+), 31 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 7436b9900e98b0..73bd037fd328cb 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -249,13 +249,13 @@ def continue_to_exception_breakpoint(self, filter_label): def continue_to_exit(self, exitCode=0): self.dap_server.request_continue() stopped_events = self.dap_server.wait_for_stopped() -self.assertEquals( +self.assertEqual( len(stopped_events), 1, "stopped_events = {}".format(stopped_events) ) -self.assertEquals( +self.assertEqual( stopped_events[0]["event"], "exited", "make sure program ran to completion" ) -self.assertEquals( +self.assertEqual( stopped_events[0]["body"]["exitCode"], exitCode, "exitCode == %i" % (exitCode), diff --git a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py index d90ae310ecf0e8..577411ebc1037d 100644 --- a/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py +++ b/lldb/test/API/functionalities/memory-region/TestMemoryRegion.py @@ -2,7 +2,6 @@ Test the 'memory region' command. """ - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -62,7 +61,7 @@ def test_command(self): # We allow --all or an address argument, not both interp.HandleCommand("memory region --all 0", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( +self.assertRegex( result.GetError(), 'The "--all" option cannot be used when an address argument is given', ) @@ -81,7 +80,7 @@ def test_command(self): # Now let's print the memory region starting at 0 which should always work. interp.HandleCommand("memory region 0x0", result) self.assertTrue(result.Succeeded()) -self.assertRegexpMatches(result.GetOutput(), "\\[0x0+-") +self.assertRegex(result.GetOutput(), "\\[0x0+-") all_regions += result.GetOutput() # Keep printing memory regions until we printed all of them. @@ -94,7 +93,7 @@ def test_command(self): # Now that we reached the end, 'memory region' should again print the usage. interp.HandleCommand("memory region", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( +self.assertRegex( result.GetError(), "Usage: memory region \(or \-\-all\)", ) diff --git a/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py b/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py index 83900a307f52e0..d8210b74dd7064 100644 --- a/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py +++ b/lldb/test/API/functionalities/wrong_commands/TestWrongCommands.py @@ -2,7 +2,6 @@ Test how lldb reacts to wrong commands """ - import lldb from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -18,12 +17,10 @@ def test_ambiguous_command(self): command_interpreter.HandleCommand("g", result) self.assertFalse(result.Succeeded()) -self.assertRegexpMatches( -result.GetError(), "Ambiguous
[Lldb-commits] [lldb] [lldb] Replace assertEquals with assertEqual (NFC) (PR #82073)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes assertEquals is a deprecated alias for assertEqual and has been removed in Python 3.12. This wasn't an issue previously because we used a vendored version of the unittest module. Now that we use the built-in version this gets updated together with the Python version used to run the test suite. --- Patch is 165.12 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/82073.diff 111 Files Affected: - (modified) lldb/packages/Python/lldbsuite/test/lldbutil.py (+6-6) - (modified) lldb/test/API/commands/disassemble/basic/TestFrameDisassemble.py (+1-1) - (modified) lldb/test/API/commands/expression/call-restarts/TestCallThatRestarts.py (+4-4) - (modified) lldb/test/API/commands/expression/call-throws/TestCallThatThrows.py (+2-2) - (modified) lldb/test/API/commands/expression/completion/TestExprCompletion.py (+1-1) - (modified) lldb/test/API/commands/expression/fixits/TestFixIts.py (+5-5) - (modified) lldb/test/API/commands/expression/save_jit_objects/TestSaveJITObjects.py (+1-1) - (modified) lldb/test/API/commands/expression/test/TestExprs.py (+4-4) - (modified) lldb/test/API/commands/expression/timeout/TestCallWithTimeout.py (+2-2) - (modified) lldb/test/API/commands/expression/unwind_expression/TestUnwindExpression.py (+1-1) - (modified) lldb/test/API/commands/frame/language/TestGuessLanguage.py (+1-1) - (modified) lldb/test/API/commands/frame/var/TestFrameVar.py (+1-1) - (modified) lldb/test/API/commands/log/basic/TestLogging.py (+2-2) - (modified) lldb/test/API/commands/memory/read/TestMemoryRead.py (+2-2) - (modified) lldb/test/API/commands/watchpoints/step_over_watchpoint/TestStepOverWatchpoint.py (+5-5) - (modified) lldb/test/API/driver/job_control/TestJobControl.py (+1-1) - (modified) lldb/test/API/functionalities/breakpoint/address_breakpoints/TestAddressBreakpoints.py (+2-2) - (modified) lldb/test/API/functionalities/breakpoint/address_breakpoints/TestBadAddressBreakpoints.py (+1-1) - (modified) lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py (+7-7) - (modified) lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommandsFromPython.py (+7-7) - (modified) lldb/test/API/functionalities/breakpoint/breakpoint_ids/TestBreakpointIDs.py (+3-3) - (modified) lldb/test/API/functionalities/breakpoint/breakpoint_locations/TestBreakpointLocations.py (+1-1) - (modified) lldb/test/API/functionalities/breakpoint/breakpoint_names/TestBreakpointNames.py (+5-5) - (modified) lldb/test/API/functionalities/breakpoint/consecutive_breakpoints/TestConsecutiveBreakpoints.py (+4-4) - (modified) lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py (+4-4) - (modified) lldb/test/API/functionalities/breakpoint/cpp_exception/TestCPPExceptionBreakpoint.py (+2-2) - (modified) lldb/test/API/functionalities/breakpoint/source_regexp/TestSourceRegexBreakpoints.py (+1-1) - (modified) lldb/test/API/functionalities/breakpoint/step_over_breakpoint/TestStepOverBreakpoint.py (+7-7) - (modified) lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/TestThreadPlanUserBreakpoint.py (+2-2) - (modified) lldb/test/API/functionalities/data-formatter/format-propagation/TestFormatPropagation.py (+7-7) - (modified) lldb/test/API/functionalities/diagnostic_reporting/TestDiagnosticReporting.py (+2-2) - (modified) lldb/test/API/functionalities/dynamic_value_child_count/TestDynamicValueChildCount.py (+2-2) - (modified) lldb/test/API/functionalities/gdb_remote_client/TestGDBRemoteClient.py (+6-6) - (modified) lldb/test/API/functionalities/gdb_remote_client/TestGdbClientModuleLoad.py (+1-1) - (modified) lldb/test/API/functionalities/gdb_remote_client/TestWasm.py (+36-36) - (modified) lldb/test/API/functionalities/gdb_remote_client/TestqOffsets.py (+2-2) - (modified) lldb/test/API/functionalities/limit-debug-info/TestLimitDebugInfo.py (+1-1) - (modified) lldb/test/API/functionalities/load_lazy/TestLoadUsingLazyBind.py (+1-1) - (modified) lldb/test/API/functionalities/memory/cache/TestMemoryCache.py (+2-2) - (modified) lldb/test/API/functionalities/plugins/python_os_plugin/TestPythonOSPlugin.py (+1-1) - (modified) lldb/test/API/functionalities/process_group/TestChangeProcessGroup.py (+1-1) - (modified) lldb/test/API/functionalities/return-value/TestReturnValue.py (+11-11) - (modified) lldb/test/API/functionalities/signal/TestSendSignal.py (+2-2) - (modified) lldb/test/API/functionalities/source-map/TestTargetSourceMap.py (+7-7) - (modified) lldb/test/API/functionalities/step-avoids-no-debug/TestStepNoDebug.py (+1-1) - (modified) lldb/test/API/functionalities/tail_call_frames/unambiguous_sequence/main.cpp (+1-1) - (modified) lldb/test/API/functionalities/thread/main_thread_exit/TestMainThreadExit.py (+1-1) - (modified)
[Lldb-commits] [lldb] [lldb] Migrate distutils.version.LooseVersion to packaging (PR #82066)
https://github.com/JDevlieghere edited https://github.com/llvm/llvm-project/pull/82066 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Migrate distutils.version.LooseVersion to packaging.LooseVersion (PR #82066)
https://github.com/JDevlieghere updated https://github.com/llvm/llvm-project/pull/82066 >From dad7c2a49f118d11b213b9691c8b01733040a510 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 16 Feb 2024 14:59:15 -0800 Subject: [PATCH] [lldb] Migrate distutils.version.LooseVersion to packaging The distutils package has been deprecated and was removed from Python 3.12. The migration page [1] advises to use the packaging module instead. Since Python 3.6 that's vendored into pkg_resources. [1] https://peps.python.org/pep-0632/#migration-advice --- .../Python/lldbsuite/test/decorators.py | 12 --- .../Python/lldbsuite/test/lldbplatformutil.py | 18 --- lldb/test/API/sanity/TestSettingSkipping.py | 32 +-- .../lldb-server/TestAppleSimulatorOSType.py | 4 +-- lldb/test/Shell/helper/build.py | 4 +-- 5 files changed, 40 insertions(+), 30 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index a5d7a7a25879df..b691f82b90652c 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -1,6 +1,6 @@ # System modules -from distutils.version import LooseVersion from functools import wraps +from pkg_resources import packaging import ctypes import locale import os @@ -65,10 +65,10 @@ def fn_neq(x, y): ">=": fn_geq, "<=": fn_leq, } -expected_str = ".".join([str(x) for x in expected]) -actual_str = ".".join([str(x) for x in actual]) -return op_lookup[comparison](LooseVersion(actual_str), LooseVersion(expected_str)) +return op_lookup[comparison]( +packaging.version.parse(actual), packaging.version.parse(expected) +) def _match_decorator_property(expected, actual): @@ -238,7 +238,9 @@ def fn(actual_debug_info=None): ) ) skip_for_py_version = (py_version is None) or _check_expected_version( -py_version[0], py_version[1], sys.version_info +py_version[0], +py_version[1], +"{}.{}".format(sys.version_info.major, sys.version_info.minor), ) skip_for_macos_version = (macos_version is None) or ( (platform.mac_ver()[0] != "") diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py index bd92d03e0e2212..f159e53a98429e 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py @@ -7,8 +7,8 @@ import subprocess import sys import os -from distutils.version import LooseVersion from urllib.parse import urlparse +from pkg_resources import packaging # LLDB modules import lldb @@ -308,13 +308,21 @@ def expectedCompilerVersion(compiler_version): return operator in [">", ">=", "!", "!=", "not"] if operator == ">": -return LooseVersion(test_compiler_version) > LooseVersion(version) +return packaging.version.parse(test_compiler_version) > packaging.version.parse( +version +) if operator == ">=" or operator == "=>": -return LooseVersion(test_compiler_version) >= LooseVersion(version) +return packaging.version.parse( +test_compiler_version +) >= packaging.version.parse(version) if operator == "<": -return LooseVersion(test_compiler_version) < LooseVersion(version) +return packaging.version.parse(test_compiler_version) < packaging.version.parse( +version +) if operator == "<=" or operator == "=<": -return LooseVersion(test_compiler_version) <= LooseVersion(version) +return packaging.version.parse( +test_compiler_version +) <= packaging.version.parse(version) if operator == "!=" or operator == "!" or operator == "not": return str(version) not in str(test_compiler_version) return str(version) in str(test_compiler_version) diff --git a/lldb/test/API/sanity/TestSettingSkipping.py b/lldb/test/API/sanity/TestSettingSkipping.py index 5f58ec2638456d..369948b2b49463 100644 --- a/lldb/test/API/sanity/TestSettingSkipping.py +++ b/lldb/test/API/sanity/TestSettingSkipping.py @@ -1,8 +1,7 @@ """ -This is a sanity check that verifies that test can be sklipped based on settings. +This is a sanity check that verifies that test can be skipped based on settings. """ - import lldb from lldbsuite.test.lldbtest import * from lldbsuite.test.decorators import * @@ -10,24 +9,25 @@ class SettingSkipSanityTestCase(TestBase): NO_DEBUG_INFO_TESTCASE = True +REAL_PYTHON_VERSION = "3.0" +FUTURE_PYTHON_VERSION = "4.0" -@skipIf(py_version=(">=", (3, 0))) +@skipIf(py_version=(">=", REAL_PYTHON_VERSION)) def testSkip(self): -"""This setting is on by default""" -self.assertTrue(False, "This test should not run!") -
[Lldb-commits] [lldb] [lldb] Migrate distutils.version.LooseVersion to packaging.LooseVersion (PR #82066)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) Changes The distutils package has been deprecated and was removed from Python 3.12. The migration page [1] advises to use the packaging module instead. Since Python 3.6 that's vendored into pkg_resources. [1] https://peps.python.org/pep-0632/#migration-advice --- Full diff: https://github.com/llvm/llvm-project/pull/82066.diff 5 Files Affected: - (modified) lldb/packages/Python/lldbsuite/test/decorators.py (+7-5) - (modified) lldb/packages/Python/lldbsuite/test/lldbplatformutil.py (+13-5) - (modified) lldb/test/API/sanity/TestSettingSkipping.py (+16-16) - (modified) lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py (+2-2) - (modified) lldb/test/Shell/helper/build.py (+2-2) ``diff diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index a5d7a7a25879df..b691f82b90652c 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -1,6 +1,6 @@ # System modules -from distutils.version import LooseVersion from functools import wraps +from pkg_resources import packaging import ctypes import locale import os @@ -65,10 +65,10 @@ def fn_neq(x, y): ">=": fn_geq, "<=": fn_leq, } -expected_str = ".".join([str(x) for x in expected]) -actual_str = ".".join([str(x) for x in actual]) -return op_lookup[comparison](LooseVersion(actual_str), LooseVersion(expected_str)) +return op_lookup[comparison]( +packaging.version.parse(actual), packaging.version.parse(expected) +) def _match_decorator_property(expected, actual): @@ -238,7 +238,9 @@ def fn(actual_debug_info=None): ) ) skip_for_py_version = (py_version is None) or _check_expected_version( -py_version[0], py_version[1], sys.version_info +py_version[0], +py_version[1], +"{}.{}".format(sys.version_info.major, sys.version_info.minor), ) skip_for_macos_version = (macos_version is None) or ( (platform.mac_ver()[0] != "") diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py index bd92d03e0e2212..f159e53a98429e 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py @@ -7,8 +7,8 @@ import subprocess import sys import os -from distutils.version import LooseVersion from urllib.parse import urlparse +from pkg_resources import packaging # LLDB modules import lldb @@ -308,13 +308,21 @@ def expectedCompilerVersion(compiler_version): return operator in [">", ">=", "!", "!=", "not"] if operator == ">": -return LooseVersion(test_compiler_version) > LooseVersion(version) +return packaging.version.parse(test_compiler_version) > packaging.version.parse( +version +) if operator == ">=" or operator == "=>": -return LooseVersion(test_compiler_version) >= LooseVersion(version) +return packaging.version.parse( +test_compiler_version +) >= packaging.version.parse(version) if operator == "<": -return LooseVersion(test_compiler_version) < LooseVersion(version) +return packaging.version.parse(test_compiler_version) < packaging.version.parse( +version +) if operator == "<=" or operator == "=<": -return LooseVersion(test_compiler_version) <= LooseVersion(version) +return packaging.version.parse( +test_compiler_version +) <= packaging.version.parse(version) if operator == "!=" or operator == "!" or operator == "not": return str(version) not in str(test_compiler_version) return str(version) in str(test_compiler_version) diff --git a/lldb/test/API/sanity/TestSettingSkipping.py b/lldb/test/API/sanity/TestSettingSkipping.py index 5f58ec2638456d..369948b2b49463 100644 --- a/lldb/test/API/sanity/TestSettingSkipping.py +++ b/lldb/test/API/sanity/TestSettingSkipping.py @@ -1,8 +1,7 @@ """ -This is a sanity check that verifies that test can be sklipped based on settings. +This is a sanity check that verifies that test can be skipped based on settings. """ - import lldb from lldbsuite.test.lldbtest import * from lldbsuite.test.decorators import * @@ -10,24 +9,25 @@ class SettingSkipSanityTestCase(TestBase): NO_DEBUG_INFO_TESTCASE = True +REAL_PYTHON_VERSION = "3.0" +FUTURE_PYTHON_VERSION = "4.0" -@skipIf(py_version=(">=", (3, 0))) +@skipIf(py_version=(">=", REAL_PYTHON_VERSION)) def testSkip(self): -"""This setting is on by default""" -self.assertTrue(False, "This test should not run!") - -@skipIf(py_version=("<", (3, 0))) -def testNoMatch(self): -self.assertTrue(True, "This test
[Lldb-commits] [lldb] [lldb] Migrate distutils.version.LooseVersion to packaging.LooseVersion (PR #82066)
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/82066 The distutils package has been deprecated and was removed from Python 3.12. The migration page [1] advises to use the packaging module instead. Since Python 3.6 that's vendored into pkg_resources. [1] https://peps.python.org/pep-0632/#migration-advice >From ba71b5d70df8c3ba240a86f29f31a78c55ed91d1 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Fri, 16 Feb 2024 14:59:15 -0800 Subject: [PATCH] [lldb] Migrate distutils.version.LooseVersion to packaging.LooseVersion The distutils package has been deprecated and was removed from Python 3.12. The migration page [1] advises to use the packaging module instead. Since Python 3.6 that's vendored into pkg_resources. [1] https://peps.python.org/pep-0632/#migration-advice --- .../Python/lldbsuite/test/decorators.py | 12 --- .../Python/lldbsuite/test/lldbplatformutil.py | 18 --- lldb/test/API/sanity/TestSettingSkipping.py | 32 +-- .../lldb-server/TestAppleSimulatorOSType.py | 4 +-- lldb/test/Shell/helper/build.py | 4 +-- 5 files changed, 40 insertions(+), 30 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index a5d7a7a25879df..b691f82b90652c 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -1,6 +1,6 @@ # System modules -from distutils.version import LooseVersion from functools import wraps +from pkg_resources import packaging import ctypes import locale import os @@ -65,10 +65,10 @@ def fn_neq(x, y): ">=": fn_geq, "<=": fn_leq, } -expected_str = ".".join([str(x) for x in expected]) -actual_str = ".".join([str(x) for x in actual]) -return op_lookup[comparison](LooseVersion(actual_str), LooseVersion(expected_str)) +return op_lookup[comparison]( +packaging.version.parse(actual), packaging.version.parse(expected) +) def _match_decorator_property(expected, actual): @@ -238,7 +238,9 @@ def fn(actual_debug_info=None): ) ) skip_for_py_version = (py_version is None) or _check_expected_version( -py_version[0], py_version[1], sys.version_info +py_version[0], +py_version[1], +"{}.{}".format(sys.version_info.major, sys.version_info.minor), ) skip_for_macos_version = (macos_version is None) or ( (platform.mac_ver()[0] != "") diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py index bd92d03e0e2212..f159e53a98429e 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py @@ -7,8 +7,8 @@ import subprocess import sys import os -from distutils.version import LooseVersion from urllib.parse import urlparse +from pkg_resources import packaging # LLDB modules import lldb @@ -308,13 +308,21 @@ def expectedCompilerVersion(compiler_version): return operator in [">", ">=", "!", "!=", "not"] if operator == ">": -return LooseVersion(test_compiler_version) > LooseVersion(version) +return packaging.version.parse(test_compiler_version) > packaging.version.parse( +version +) if operator == ">=" or operator == "=>": -return LooseVersion(test_compiler_version) >= LooseVersion(version) +return packaging.version.parse( +test_compiler_version +) >= packaging.version.parse(version) if operator == "<": -return LooseVersion(test_compiler_version) < LooseVersion(version) +return packaging.version.parse(test_compiler_version) < packaging.version.parse( +version +) if operator == "<=" or operator == "=<": -return LooseVersion(test_compiler_version) <= LooseVersion(version) +return packaging.version.parse( +test_compiler_version +) <= packaging.version.parse(version) if operator == "!=" or operator == "!" or operator == "not": return str(version) not in str(test_compiler_version) return str(version) in str(test_compiler_version) diff --git a/lldb/test/API/sanity/TestSettingSkipping.py b/lldb/test/API/sanity/TestSettingSkipping.py index 5f58ec2638456d..369948b2b49463 100644 --- a/lldb/test/API/sanity/TestSettingSkipping.py +++ b/lldb/test/API/sanity/TestSettingSkipping.py @@ -1,8 +1,7 @@ """ -This is a sanity check that verifies that test can be sklipped based on settings. +This is a sanity check that verifies that test can be skipped based on settings. """ - import lldb from lldbsuite.test.lldbtest import * from lldbsuite.test.decorators import * @@ -10,24 +9,25 @@ class SettingSkipSanityTestCase(TestBase): NO_DEBUG_INFO_TESTCASE = True +REAL_PYTHON_VERSION =
[Lldb-commits] [lldb] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. (PR #82051)
ashgti wrote: > Needs a test and this will be good to go. Done, added tests https://github.com/llvm/llvm-project/pull/82051 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. (PR #82051)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/82051 >From 61224ee2642e7fa2723e48e4a32c90f5ec04759a Mon Sep 17 00:00:00 2001 From: John Harrison Date: Fri, 16 Feb 2024 14:11:10 -0800 Subject: [PATCH] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. This fixes an issue where the error is lost if a command while executing `launchCommands` when launching the debugger. --- .../test/tools/lldb-dap/lldbdap_testcase.py | 2 + .../tools/lldb-dap/launch/TestDAP_launch.py | 44 ++- lldb/tools/lldb-dap/lldb-dap.cpp | 4 +- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 7436b9900e98b0..8092341a449b9f 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -122,6 +122,8 @@ def verify_commands(self, flavor, output, commands): for cmd in commands: found = False for line in lines: +if len(cmd) > 0 and (cmd[0] == "!" or cmd[0] == "?"): +cmd = cmd[1:] if line.startswith(prefix) and cmd in line: found = True break diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py index 78958612253691..8ae82a01652d3b 100644 --- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py +++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py @@ -2,7 +2,6 @@ Test lldb-dap setBreakpoints request """ - import dap_server from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * @@ -398,7 +397,7 @@ def test_extra_launch_commands(self): # Verify all "preRunCommands" were found in console output self.verify_commands("preRunCommands", output, preRunCommands) -# Verify all "launchCommands" were founc in console output +# Verify all "launchCommands" were found in console output # After execution, program should launch self.verify_commands("launchCommands", output, launchCommands) # Verify the "stopCommands" here @@ -420,6 +419,47 @@ def test_extra_launch_commands(self): output = self.get_console(timeout=1.0) self.verify_commands("exitCommands", output, exitCommands) +@skipIfWindows +@skipIfRemote +def test_failing_launch_commands(self): +""" +Tests "launchCommands" failures prevents a launch. +""" +self.build_and_create_debug_adaptor() +program = self.getBuildArtifact("a.out") + +# Run an invalid launch command, in this case a bad path. +launchCommands = ['!target create "/bad/path%s"' % (program)] + +initCommands = ["target list", "platform list"] +preRunCommands = ["image list a.out", "image dump sections a.out"] +response = self.launch( +program, +initCommands=initCommands, +preRunCommands=preRunCommands, +launchCommands=launchCommands, +expectFailure=True, +) + +self.assertFalse(response["success"]) +self.assertRegex( +response["message"], +r"Failed to run launch commands\. See the Debug Console for more details", +) + +# Get output from the console. This should contain both the +# "initCommands" and the "preRunCommands". +output = self.get_console() +# Verify all "initCommands" were found in console output +self.verify_commands("initCommands", output, initCommands) +# Verify all "preRunCommands" were found in console output +self.verify_commands("preRunCommands", output, preRunCommands) + +# Verify all "launchCommands" were founc in console output +# The launch should fail due to the invalid command. +self.verify_commands("launchCommands", output, launchCommands) +self.assertRegex(output, r"unable to find executable for '/bad/path/") + @skipIfWindows @skipIfNetBSD # Hangs on NetBSD as well @skipIf(archs=["arm", "aarch64"], oslist=["linux"]) diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index 67022347e6d624..78b0b4078706aa 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -1779,8 +1779,10 @@ lldb::SBError LaunchProcess(const llvm::json::Object ) { // Set the launch info so that run commands can access the configured // launch details. g_dap.target.SetLaunchInfo(launch_info); -if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) +if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) {
[Lldb-commits] [lldb] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. (PR #82051)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/82051 >From 465abea7e445271681f5107ccbd306f63ccd0956 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Fri, 16 Feb 2024 14:11:10 -0800 Subject: [PATCH] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. This fixes an issue where the error is lost if a command while executing `launchCommands` when launching the debugger. --- .../test/tools/lldb-dap/lldbdap_testcase.py | 2 + .../tools/lldb-dap/launch/TestDAP_launch.py | 48 ++- lldb/tools/lldb-dap/lldb-dap.cpp | 4 +- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 7436b9900e98b0..264e66d7e0dab8 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -122,6 +122,8 @@ def verify_commands(self, flavor, output, commands): for cmd in commands: found = False for line in lines: +if len(cmd) > 0 and (cmd[0] == '!' or cmd[0] == '?'): +cmd = cmd[1:] if line.startswith(prefix) and cmd in line: found = True break diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py index 78958612253691..1f9cfecf1d952a 100644 --- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py +++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py @@ -398,7 +398,7 @@ def test_extra_launch_commands(self): # Verify all "preRunCommands" were found in console output self.verify_commands("preRunCommands", output, preRunCommands) -# Verify all "launchCommands" were founc in console output +# Verify all "launchCommands" were found in console output # After execution, program should launch self.verify_commands("launchCommands", output, launchCommands) # Verify the "stopCommands" here @@ -420,6 +420,52 @@ def test_extra_launch_commands(self): output = self.get_console(timeout=1.0) self.verify_commands("exitCommands", output, exitCommands) +@skipIfWindows +@skipIfRemote +def test_failing_launch_commands(self): +""" +Tests "launchCommands" failures prevents a launch. +""" +self.build_and_create_debug_adaptor() +program = self.getBuildArtifact("a.out") + +# Run an invalid launch command, in this case a bad path. +launchCommands = [ +'!target create "/bad/path%s"' % (program) +] + +initCommands = ["target list", "platform list"] +preRunCommands = ["image list a.out", "image dump sections a.out"] +response = self.launch( +program, +initCommands=initCommands, +preRunCommands=preRunCommands, +launchCommands=launchCommands, +expectFailure=True, +) + +self.assertFalse(response["success"]) +self.assertRegex( +response["message"], +r"Failed to run launch commands\. See the Debug Console for more details" +) + +# Get output from the console. This should contain both the +# "initCommands" and the "preRunCommands". +output = self.get_console() +# Verify all "initCommands" were found in console output +self.verify_commands("initCommands", output, initCommands) +# Verify all "preRunCommands" were found in console output +self.verify_commands("preRunCommands", output, preRunCommands) + +# Verify all "launchCommands" were founc in console output +# The launch should fail due to the invalid command. +self.verify_commands("launchCommands", output, launchCommands) +self.assertRegex( +output, +r"unable to find executable for '/bad/path/" +) + @skipIfWindows @skipIfNetBSD # Hangs on NetBSD as well @skipIf(archs=["arm", "aarch64"], oslist=["linux"]) diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index 67022347e6d624..78b0b4078706aa 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -1779,8 +1779,10 @@ lldb::SBError LaunchProcess(const llvm::json::Object ) { // Set the launch info so that run commands can access the configured // launch details. g_dap.target.SetLaunchInfo(launch_info); -if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) +if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) { error.SetErrorString(llvm::toString(std::move(err)).c_str()); + return error; +} // The custom commands might have created a
[Lldb-commits] [lldb] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. (PR #82051)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r 2de269a641e4ffbb7a44e559c4c0a91bb66df823...f76dbe10e30c84aadaf33c597fe81bc0a285c995 lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py `` View the diff from darker here. ``diff --- packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py 2024-02-16 23:15:51.00 + +++ packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py 2024-02-16 23:18:32.138239 + @@ -120,11 +120,11 @@ lines = output.splitlines() prefix = "(lldb) " for cmd in commands: found = False for line in lines: -if len(cmd) > 0 and (cmd[0] == '!' or cmd[0] == '?'): +if len(cmd) > 0 and (cmd[0] == "!" or cmd[0] == "?"): cmd = cmd[1:] if line.startswith(prefix) and cmd in line: found = True break self.assertTrue( --- test/API/tools/lldb-dap/launch/TestDAP_launch.py2024-02-16 23:15:51.00 + +++ test/API/tools/lldb-dap/launch/TestDAP_launch.py2024-02-16 23:18:32.288817 + @@ -425,13 +425,11 @@ """ self.build_and_create_debug_adaptor() program = self.getBuildArtifact("a.out") # Run an invalid launch command, in this case a bad path. -launchCommands = [ -'!target create "/bad/path%s"' % (program) -] +launchCommands = ['!target create "/bad/path%s"' % (program)] initCommands = ["target list", "platform list"] preRunCommands = ["image list a.out", "image dump sections a.out"] response = self.launch( program, @@ -441,12 +439,12 @@ expectFailure=True, ) self.assertFalse(response["success"]) self.assertRegex( -response["message"], -r"Failed to run launch commands\. See the Debug Console for more details" +response["message"], +r"Failed to run launch commands\. See the Debug Console for more details", ) # Get output from the console. This should contain both the # "initCommands" and the "preRunCommands". output = self.get_console() `` https://github.com/llvm/llvm-project/pull/82051 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. (PR #82051)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/82051 >From f76dbe10e30c84aadaf33c597fe81bc0a285c995 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Fri, 16 Feb 2024 14:11:10 -0800 Subject: [PATCH] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. This fixes an issue where the error is lost if a command while executing `launchCommands` when launching the debugger. --- .../test/tools/lldb-dap/lldbdap_testcase.py | 2 + .../tools/lldb-dap/launch/TestDAP_launch.py | 47 +-- lldb/tools/lldb-dap/lldb-dap.cpp | 4 +- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py index 7436b9900e98b0..264e66d7e0dab8 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py @@ -122,6 +122,8 @@ def verify_commands(self, flavor, output, commands): for cmd in commands: found = False for line in lines: +if len(cmd) > 0 and (cmd[0] == '!' or cmd[0] == '?'): +cmd = cmd[1:] if line.startswith(prefix) and cmd in line: found = True break diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py index 78958612253691..d0d09c5ac74b31 100644 --- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py +++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py @@ -272,9 +272,6 @@ def test_environment(self): @skipIfWindows @skipIfRemote -@skipIf( -archs=["arm", "aarch64"] -) # failed run https://lab.llvm.org/buildbot/#/builders/96/builds/6933 def test_commands(self): """ Tests the "initCommands", "preRunCommands", "stopCommands", @@ -398,7 +395,7 @@ def test_extra_launch_commands(self): # Verify all "preRunCommands" were found in console output self.verify_commands("preRunCommands", output, preRunCommands) -# Verify all "launchCommands" were founc in console output +# Verify all "launchCommands" were found in console output # After execution, program should launch self.verify_commands("launchCommands", output, launchCommands) # Verify the "stopCommands" here @@ -420,6 +417,48 @@ def test_extra_launch_commands(self): output = self.get_console(timeout=1.0) self.verify_commands("exitCommands", output, exitCommands) +@skipIfWindows +@skipIfRemote +def test_failing_launch_commands(self): +""" +Tests the "launchCommands" failing to launch a target. +""" +self.build_and_create_debug_adaptor() +program = self.getBuildArtifact("a.out") + +# Run an invalid launch command, in this case a bad path. +launchCommands = [ +'!target create "/bad/path%s"' % (program) +] + +initCommands = ["target list", "platform list"] +preRunCommands = ["image list a.out", "image dump sections a.out"] +response = self.launch( +program, +initCommands=initCommands, +preRunCommands=preRunCommands, +launchCommands=launchCommands, +expectFailure=True, +) + +self.assertFalse(response["success"]) +self.assertRegex( +response["message"], +r"Failed to run launch commands\. See the Debug Console for more details" +) + +# Get output from the console. This should contain both the +# "initCommands" and the "preRunCommands". +output = self.get_console() +# Verify all "initCommands" were found in console output +self.verify_commands("initCommands", output, initCommands) +# Verify all "preRunCommands" were found in console output +self.verify_commands("preRunCommands", output, preRunCommands) + +# Verify all "launchCommands" were founc in console output +# The launch should fail due to the invalid command. +self.verify_commands("launchCommands", output, launchCommands) + @skipIfWindows @skipIfNetBSD # Hangs on NetBSD as well @skipIf(archs=["arm", "aarch64"], oslist=["linux"]) diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index 67022347e6d624..78b0b4078706aa 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -1779,8 +1779,10 @@ lldb::SBError LaunchProcess(const llvm::json::Object ) { // Set the launch info so that run commands can access the configured // launch details. g_dap.target.SetLaunchInfo(launch_info); -if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) +
[Lldb-commits] [lldb] [lldb] Add more ways to find the .dwp file. (PR #81067)
clayborg wrote: Is there a website or something that details how to correctly save symbols for split DWARF? Is there an existing tool people use? If the answer is no, I would like to support all variations for now. I am happy to emit a warning with a URL for best practices when it comes to emitting and archiving split DWARF if a user is doing something we don't want them to. But if we have no enforcements anywhere and no website that details how to do it correctly, just saying "well you should know to do it the right way but we don't provide any documentation on how to do i t right and our debuggers or symbolizers won't load your info" doesn't make for a great user experience. The _only_ contentious think in this patch seems to be allowing `.debug` + `.debug.dwp`. https://github.com/llvm/llvm-project/pull/81067 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Add more ways to find the .dwp file. (PR #81067)
ayermolo wrote: Just my 2 cents as a "random dude who works on DWARF". The interoperability of various gnu extensions and DWARF spec is not well defined. Which leads to situations like this. If binary is A then DWP is A.dwp no direct link between binary and dwp file. If binary has gnulink than it has a section that points to an elf file with rest of the debuginfo. Most people name it as binary.debuglink. If binary has split dwarf and gnulink not well defined I think. It would be great if tools took an option away from the user that "create" debug information or at least restricted so that all of this was standardized, but currently they are not. Even if we change them there are still legacy builds that is a free for all. I think we are already at a "people are confused" point, and DWARF consumer (LLDB) being more permissive doesn't really contribute to it. Because people who use LLDB by and large are not the people who are responsible for build systems that produce debug information. Users of LLDB just want things to work, and have no clue what split-dwarf is or gnulink. They download a coredump launch lldb and then wonder why it is not working. https://github.com/llvm/llvm-project/pull/81067 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. (PR #82051)
https://github.com/clayborg commented: Needs a test and this will be good to go. https://github.com/llvm/llvm-project/pull/82051 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. (PR #82051)
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/82051 >From 300d2959e510f41607ce2487264a98814d0a1700 Mon Sep 17 00:00:00 2001 From: John Harrison Date: Fri, 16 Feb 2024 14:11:10 -0800 Subject: [PATCH] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. This fixes an issue where the error is lost if a command while executing `launchCommands` when launching the debugger. --- lldb/tools/lldb-dap/lldb-dap.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index 67022347e6d624..78b0b4078706aa 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -1779,8 +1779,10 @@ lldb::SBError LaunchProcess(const llvm::json::Object ) { // Set the launch info so that run commands can access the configured // launch details. g_dap.target.SetLaunchInfo(launch_info); -if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) +if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) { error.SetErrorString(llvm::toString(std::move(err)).c_str()); + return error; +} // The custom commands might have created a new target so we should use the // selected target after these commands are run. g_dap.target = g_dap.debugger.GetSelectedTarget(); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. (PR #82051)
llvmbot wrote: @llvm/pr-subscribers-lldb Author: John Harrison (ashgti) Changes This fixes an issue where the error is lost if a command while executing `launchCommands` when launching the debugger. This should fix #82048 --- Full diff: https://github.com/llvm/llvm-project/pull/82051.diff 1 Files Affected: - (modified) lldb/tools/lldb-dap/lldb-dap.cpp (+4-2) ``diff diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index 67022347e6d624..cc555d33b48b53 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -22,7 +22,7 @@ // We also need to #undef GetObject (which is defined to GetObjectW) because // the JSON code we use also has methods named `GetObject()` and we conflict // against these. -#define NOMINMAX +#define NOMINMAXf #include #undef GetObject #include @@ -1779,8 +1779,10 @@ lldb::SBError LaunchProcess(const llvm::json::Object ) { // Set the launch info so that run commands can access the configured // launch details. g_dap.target.SetLaunchInfo(launch_info); -if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) +if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) { error.SetErrorString(llvm::toString(std::move(err)).c_str()); + return error; +} // The custom commands might have created a new target so we should use the // selected target after these commands are run. g_dap.target = g_dap.debugger.GetSelectedTarget(); `` https://github.com/llvm/llvm-project/pull/82051 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. (PR #82051)
https://github.com/ashgti created https://github.com/llvm/llvm-project/pull/82051 This fixes an issue where the error is lost if a command while executing `launchCommands` when launching the debugger. This should fix #82048 >From 5e3787a61c92f002746f2437e2fc8509d787a0ce Mon Sep 17 00:00:00 2001 From: John Harrison Date: Fri, 16 Feb 2024 14:11:10 -0800 Subject: [PATCH] [lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. This fixes an issue where the error is lost if a command while executing `launchCommands` when launching the debugger. --- lldb/tools/lldb-dap/lldb-dap.cpp | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp index 67022347e6d624..cc555d33b48b53 100644 --- a/lldb/tools/lldb-dap/lldb-dap.cpp +++ b/lldb/tools/lldb-dap/lldb-dap.cpp @@ -22,7 +22,7 @@ // We also need to #undef GetObject (which is defined to GetObjectW) because // the JSON code we use also has methods named `GetObject()` and we conflict // against these. -#define NOMINMAX +#define NOMINMAXf #include #undef GetObject #include @@ -1779,8 +1779,10 @@ lldb::SBError LaunchProcess(const llvm::json::Object ) { // Set the launch info so that run commands can access the configured // launch details. g_dap.target.SetLaunchInfo(launch_info); -if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) +if (llvm::Error err = g_dap.RunLaunchCommands(launchCommands)) { error.SetErrorString(llvm::toString(std::move(err)).c_str()); + return error; +} // The custom commands might have created a new target so we should use the // selected target after these commands are run. g_dap.target = g_dap.debugger.GetSelectedTarget(); ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Report only loaded debug info in statistics dump (PR #81706)
https://github.com/clayborg approved this pull request. https://github.com/llvm/llvm-project/pull/81706 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 4214f25 - Re-land "[lldb] Fix `FindDirectNestedType` not working with class templates (#81666)"
Author: Vlad Serebrennikov Date: 2024-02-16T22:47:09+03:00 New Revision: 4214f25dccba36472c9666f1395eef894dca1bba URL: https://github.com/llvm/llvm-project/commit/4214f25dccba36472c9666f1395eef894dca1bba DIFF: https://github.com/llvm/llvm-project/commit/4214f25dccba36472c9666f1395eef894dca1bba.diff LOG: Re-land "[lldb] Fix `FindDirectNestedType` not working with class templates (#81666)" This patch attempts to fix lookup in class template specialization. The first fixed problem is that during type lookup `DeclContextGetName` have been dropping template arguments. So when such a name was compared against a name in `DW_AT_name`, which contains template arguments, false mismatches have been occurring. The second fixed problem is that LLDB's printing policy hasn't been matching Clang's printing policy when it comes to integral non-type template arguments. This again caused some false mismatches during type lookup, because Clang puts e.g. `3U` in debug info for class specializations, but LLDB has been expecting just `3`. This patch brings printing policy in line with what Clang does. Added: Modified: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp lldb/test/API/python_api/type/TestTypeList.py lldb/test/API/python_api/type/main.cpp Removed: diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index a41e2c690853d2..51ab13108feb3a 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -9265,8 +9265,14 @@ ConstString TypeSystemClang::DeclContextGetName(void *opaque_decl_ctx) { if (opaque_decl_ctx) { clang::NamedDecl *named_decl = llvm::dyn_cast((clang::DeclContext *)opaque_decl_ctx); -if (named_decl) - return ConstString(named_decl->getName()); +if (named_decl) { + std::string name; + llvm::raw_string_ostream stream{name}; + auto policy = GetTypePrintingPolicy(); + policy.AlwaysIncludeTypeForTemplateArgument = true; + named_decl->getNameForDiagnostic(stream, policy, /*qualified=*/false); + return ConstString(name); +} } return ConstString(); } diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py index c267defb58edf9..63ab958193574b 100644 --- a/lldb/test/API/python_api/type/TestTypeList.py +++ b/lldb/test/API/python_api/type/TestTypeList.py @@ -150,6 +150,23 @@ def test(self): invalid_type = task_type.FindDirectNestedType(None) self.assertFalse(invalid_type) +# Check that FindDirectNestedType works with types from AST +pointer = frame0.FindVariable("pointer") +pointer_type = pointer.GetType() +self.assertTrue(pointer_type) +self.DebugSBType(pointer_type) +pointer_info_type = pointer_type.template_args[1] +self.assertTrue(pointer_info_type) +self.DebugSBType(pointer_info_type) + +pointer_masks1_type = pointer_info_type.FindDirectNestedType("Masks1") +self.assertTrue(pointer_masks1_type) +self.DebugSBType(pointer_masks1_type) + +pointer_masks2_type = pointer_info_type.FindDirectNestedType("Masks2") +self.assertTrue(pointer_masks2_type) +self.DebugSBType(pointer_masks2_type) + # We'll now get the child member 'id' from 'task_head'. id = task_head.GetChildMemberWithName("id") self.DebugSBValue(id) diff --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp index 98de9707d88654..391f58e3e5871c 100644 --- a/lldb/test/API/python_api/type/main.cpp +++ b/lldb/test/API/python_api/type/main.cpp @@ -34,6 +34,14 @@ class Task { {} }; +template struct PointerInfo { + enum Masks1 { pointer_mask }; + enum class Masks2 { pointer_mask }; +}; + +template > +struct Pointer {}; + enum EnumType {}; enum class ScopedEnumType {}; enum class EnumUChar : unsigned char {}; @@ -71,5 +79,9 @@ int main (int argc, char const *argv[]) ScopedEnumType scoped_enum_type; EnumUChar scoped_enum_type_uchar; +Pointer<3> pointer; +PointerInfo<3>::Masks1 mask1 = PointerInfo<3>::Masks1::pointer_mask; +PointerInfo<3>::Masks2 mask2 = PointerInfo<3>::Masks2::pointer_mask; + return 0; // Break at this line } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix `FindDirectNestedType` not working with class templates (PR #81666)
Endilll wrote: I'd appreciate if you gave me a slightly bit more time, because I've been testing the fix locally in the meantime. https://github.com/llvm/llvm-project/pull/81666 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix `FindDirectNestedType` not working with class templates (PR #81666)
rastogishubham wrote: Hi @Endilll this patch has been reverted with 831ba9540089350b740c5db61159fe23ab6872d3 to make sure the lldb bots are green. https://github.com/llvm/llvm-project/pull/81666 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 831ba95 - Revert "[lldb] Fix `FindDirectNestedType` not working with class templates (#81666)"
Author: Shubham Sandeep Rastogi Date: 2024-02-16T11:00:35-08:00 New Revision: 831ba9540089350b740c5db61159fe23ab6872d3 URL: https://github.com/llvm/llvm-project/commit/831ba9540089350b740c5db61159fe23ab6872d3 DIFF: https://github.com/llvm/llvm-project/commit/831ba9540089350b740c5db61159fe23ab6872d3.diff LOG: Revert "[lldb] Fix `FindDirectNestedType` not working with class templates (#81666)" This reverts commit 7b7d411de9f731d2bcf6b093f6cee2cf57a5196e. Added: Modified: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp lldb/test/API/python_api/type/TestTypeList.py lldb/test/API/python_api/type/main.cpp Removed: diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index 0652ac0e134f53..a41e2c690853d2 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -2165,7 +2165,6 @@ PrintingPolicy TypeSystemClang::GetTypePrintingPolicy() { // (and we then would have suppressed them from the type name) and also setups // where LLDB wasn't able to reconstruct the default arguments. printing_policy.SuppressDefaultTemplateArgs = false; - printing_policy.AlwaysIncludeTypeForTemplateArgument = true; return printing_policy; } @@ -9266,13 +9265,8 @@ ConstString TypeSystemClang::DeclContextGetName(void *opaque_decl_ctx) { if (opaque_decl_ctx) { clang::NamedDecl *named_decl = llvm::dyn_cast((clang::DeclContext *)opaque_decl_ctx); -if (named_decl) { - std::string name; - llvm::raw_string_ostream stream{name}; - named_decl->getNameForDiagnostic(stream, GetTypePrintingPolicy(), - /*qualified=*/false); - return ConstString(name); -} +if (named_decl) + return ConstString(named_decl->getName()); } return ConstString(); } diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py index 63ab958193574b..c267defb58edf9 100644 --- a/lldb/test/API/python_api/type/TestTypeList.py +++ b/lldb/test/API/python_api/type/TestTypeList.py @@ -150,23 +150,6 @@ def test(self): invalid_type = task_type.FindDirectNestedType(None) self.assertFalse(invalid_type) -# Check that FindDirectNestedType works with types from AST -pointer = frame0.FindVariable("pointer") -pointer_type = pointer.GetType() -self.assertTrue(pointer_type) -self.DebugSBType(pointer_type) -pointer_info_type = pointer_type.template_args[1] -self.assertTrue(pointer_info_type) -self.DebugSBType(pointer_info_type) - -pointer_masks1_type = pointer_info_type.FindDirectNestedType("Masks1") -self.assertTrue(pointer_masks1_type) -self.DebugSBType(pointer_masks1_type) - -pointer_masks2_type = pointer_info_type.FindDirectNestedType("Masks2") -self.assertTrue(pointer_masks2_type) -self.DebugSBType(pointer_masks2_type) - # We'll now get the child member 'id' from 'task_head'. id = task_head.GetChildMemberWithName("id") self.DebugSBValue(id) diff --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp index 391f58e3e5871c..98de9707d88654 100644 --- a/lldb/test/API/python_api/type/main.cpp +++ b/lldb/test/API/python_api/type/main.cpp @@ -34,14 +34,6 @@ class Task { {} }; -template struct PointerInfo { - enum Masks1 { pointer_mask }; - enum class Masks2 { pointer_mask }; -}; - -template > -struct Pointer {}; - enum EnumType {}; enum class ScopedEnumType {}; enum class EnumUChar : unsigned char {}; @@ -79,9 +71,5 @@ int main (int argc, char const *argv[]) ScopedEnumType scoped_enum_type; EnumUChar scoped_enum_type_uchar; -Pointer<3> pointer; -PointerInfo<3>::Masks1 mask1 = PointerInfo<3>::Masks1::pointer_mask; -PointerInfo<3>::Masks2 mask2 = PointerInfo<3>::Masks2::pointer_mask; - return 0; // Break at this line } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix `FindDirectNestedType` not working with class templates (PR #81666)
rastogishubham wrote: I am going to revert this patch for now, to make sure that green dragon is up and running again https://github.com/llvm/llvm-project/pull/81666 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix `FindDirectNestedType` not working with class templates (PR #81666)
JDevlieghere wrote: Great. Let me know if you need help reproducing stuff on macOS. https://github.com/llvm/llvm-project/pull/81666 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix `FindDirectNestedType` not working with class templates (PR #81666)
Endilll wrote: @JDevlieghere I have an idea what have caused this failure, but I guess I have to enable libcxx to replicate it locally. https://github.com/llvm/llvm-project/pull/81666 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix `FindDirectNestedType` not working with class templates (PR #81666)
JDevlieghere wrote: This is what the failure looks like: ``` == FAIL: test_with_run_command_dsym (TestDataFormatterLibcxxChrono.LibcxxChronoDataFormatterTestCase) Test that that file and class static variables display correctly. -- Traceback (most recent call last): File "/Users/jonas/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1676, in test_method return attrvalue(self) File "/Users/jonas/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py", line 150, in wrapper return func(*args, **kwargs) File "/Users/jonas/llvm/llvm-project/lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/chrono/TestDataFormatterLibcxxChrono.py", line 35, in test_with_run_command self.expect( File "/Users/jonas/llvm/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 2447, in expect self.fail(log_msg) AssertionError: Ran command: "frame variable ss_tp" Got output: (std::chrono::time_point >) ss_tp = { __d_ = (__rep_ = 0) } Expecting sub string: "ss_tp = date/time=1970-01-01T00:00:00Z timestamp=0 s" (was not found) ``` https://github.com/llvm/llvm-project/pull/81666 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix `FindDirectNestedType` not working with class templates (PR #81666)
Endilll wrote: Trying to take a look, but https://green.lab.llvm.org is extraordinary slow for me. https://github.com/llvm/llvm-project/pull/81666 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] [lldb] Fix `FindDirectNestedType` not working with class templates (PR #81666)
JDevlieghere wrote: This breaks `TestDataFormatterLibcxxChrono.py` on macOS: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/66400/ https://green.lab.llvm.org/green/view/LLDB/job/as-lldb-cmake/16178/ CC @rastogishubham https://github.com/llvm/llvm-project/pull/81666 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] Report only loaded debug info in statistics dump (PR #81706)
https://github.com/kusmour updated https://github.com/llvm/llvm-project/pull/81706 >From 70d3c80aa73ef10284c6615ac9e5e73ff38a5245 Mon Sep 17 00:00:00 2001 From: Wanyi Ye Date: Mon, 5 Feb 2024 11:33:03 -0800 Subject: [PATCH 1/4] Only report total currently loaded debug info --- lldb/include/lldb/Symbol/SymbolFile.h | 14 +++--- lldb/include/lldb/Symbol/SymbolFileOnDemand.h | 2 +- .../SymbolFile/Breakpad/SymbolFileBreakpad.cpp | 2 +- .../SymbolFile/Breakpad/SymbolFileBreakpad.h | 2 +- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp | 5 +++-- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h | 2 +- .../Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp | 4 ++-- .../Plugins/SymbolFile/DWARF/SymbolFileDWARF.h | 14 +- .../SymbolFile/DWARF/SymbolFileDWARFDwo.cpp| 2 +- .../Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h | 2 +- .../SymbolFile/NativePDB/SymbolFileNativePDB.cpp | 2 +- .../SymbolFile/NativePDB/SymbolFileNativePDB.h | 2 +- lldb/source/Symbol/SymbolFile.cpp | 2 +- lldb/source/Symbol/SymbolFileOnDemand.cpp | 4 ++-- 14 files changed, 40 insertions(+), 19 deletions(-) diff --git a/lldb/include/lldb/Symbol/SymbolFile.h b/lldb/include/lldb/Symbol/SymbolFile.h index f356f7b789fa38..13a4d146d651ec 100644 --- a/lldb/include/lldb/Symbol/SymbolFile.h +++ b/lldb/include/lldb/Symbol/SymbolFile.h @@ -381,7 +381,8 @@ class SymbolFile : public PluginInterface { /// Metrics gathering functions - /// Return the size in bytes of all debug information in the symbol file. + /// Return the size in bytes of all loaded debug information or total possible + /// debug info in the symbol file. /// /// If the debug information is contained in sections of an ObjectFile, then /// this call should add the size of all sections that contain debug @@ -391,7 +392,14 @@ class SymbolFile : public PluginInterface { /// entire file should be returned. The default implementation of this /// function will iterate over all sections in a module and add up their /// debug info only section byte sizes. - virtual uint64_t GetDebugInfoSize() = 0; + /// + /// \param load_if_needed + /// If true, force loading any symbol files if they are not yet loaded and + /// add to the total size + /// + /// \returns + /// Total currently loaded debug info size in bytes + virtual uint64_t GetDebugInfoSize(bool load_if_needed = false) = 0; /// Return the time taken to parse the debug information. /// @@ -534,7 +542,7 @@ class SymbolFileCommon : public SymbolFile { void Dump(Stream ) override; - uint64_t GetDebugInfoSize() override; + uint64_t GetDebugInfoSize(bool load_if_needed = false) override; bool GetDebugInfoIndexWasLoadedFromCache() const override { return m_index_was_loaded_from_cache; diff --git a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h index 4e3009941aa7d6..9b3512aa85cdd6 100644 --- a/lldb/include/lldb/Symbol/SymbolFileOnDemand.h +++ b/lldb/include/lldb/Symbol/SymbolFileOnDemand.h @@ -178,7 +178,7 @@ class SymbolFileOnDemand : public lldb_private::SymbolFile { void PreloadSymbols() override; - uint64_t GetDebugInfoSize() override; + uint64_t GetDebugInfoSize(bool load_if_needed = false) override; lldb_private::StatsDuration::Duration GetDebugInfoParseTime() override; lldb_private::StatsDuration::Duration GetDebugInfoIndexTime() override; diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp index b1f7397d6b0f00..ff0bba7bcab10c 100644 --- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp +++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp @@ -918,7 +918,7 @@ void SymbolFileBreakpad::ParseUnwindData() { m_unwind_data->win.Sort(); } -uint64_t SymbolFileBreakpad::GetDebugInfoSize() { +uint64_t SymbolFileBreakpad::GetDebugInfoSize(bool load_if_needed) { // Breakpad files are all debug info. return m_objfile_sp->GetByteSize(); } diff --git a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h index 41e4e3b258014c..609ed6ffc9ff96 100644 --- a/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h +++ b/lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.h @@ -141,7 +141,7 @@ class SymbolFileBreakpad : public SymbolFileCommon { llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } - uint64_t GetDebugInfoSize() override; + uint64_t GetDebugInfoSize(bool load_if_needed = false) override; private: // A class representing a position in the breakpad file. Useful for diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp index 23e0b8a7f2c06b..4e822742780f8d 100644 ---
[Lldb-commits] [lldb] [llvm] LLDB Debuginfod usage tests (with fixes) (PR #79181)
https://github.com/kevinfrei converted_to_draft https://github.com/llvm/llvm-project/pull/79181 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 0da0966 - [lldb] Don't overwrite the dynamic loader library path for "driver tests"
Author: Jonas Devlieghere Date: 2024-02-16T08:47:38-08:00 New Revision: 0da0966da4b813386a85cf70ae0d0efc7cb2eaea URL: https://github.com/llvm/llvm-project/commit/0da0966da4b813386a85cf70ae0d0efc7cb2eaea DIFF: https://github.com/llvm/llvm-project/commit/0da0966da4b813386a85cf70ae0d0efc7cb2eaea.diff LOG: [lldb] Don't overwrite the dynamic loader library path for "driver tests" We have a handful of tests that build a driver which links against LLDB. When running those binaries, we overwrite the dynamic loader library path to point to the build directory's libs dir, presumably to make sure we load LLDB from there. This above becomes an issue when you have libc++ enabled and the driver is linked against the system's libc++, but the dynamic loader flag forces it to pick up libc++ from the libs dir. We could try to make the logic for building the driver smarter and have it pick up the just-built libc++ like we do for our test binaries, but I don't think we need to overwrite the library path in the first place. The build logic to build these drivers already takes care to set the correct RPATH in the linker. This patch removes the logic and simplifies the tests. Added: Modified: lldb/packages/Python/lldbsuite/test/lldbtest.py lldb/test/API/api/check_public_api_headers/TestPublicAPIHeaders.py lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py lldb/test/API/api/multiple-targets/TestMultipleTargets.py lldb/test/API/api/multithreaded/TestMultithreaded.py Removed: diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index 018f2a06980a88..493152166094e8 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -1594,21 +1594,6 @@ def invoke(self, obj, name, trace=False): print(str(method) + ":", result, file=sbuf) return result -def getLLDBLibraryEnvVal(self): -"""Returns the path that the OS-specific library search environment variable -(self.dylibPath) should be set to in order for a program to find the LLDB -library. If an environment variable named self.dylibPath is already set, -the new path is appended to it and returned. -""" -existing_library_path = ( -os.environ[self.dylibPath] if self.dylibPath in os.environ else None -) -if existing_library_path: -return "%s:%s" % (existing_library_path, configuration.lldb_libs_dir) -if sys.platform.startswith("darwin") and configuration.lldb_framework_path: -return configuration.lldb_framework_path -return configuration.lldb_libs_dir - def getLibcPlusPlusLibs(self): if self.getPlatform() in ("freebsd", "linux", "netbsd", "openbsd"): return ["libc++.so.1"] diff --git a/lldb/test/API/api/check_public_api_headers/TestPublicAPIHeaders.py b/lldb/test/API/api/check_public_api_headers/TestPublicAPIHeaders.py index f2cd2eaef604f9..60ca8557d60b97 100644 --- a/lldb/test/API/api/check_public_api_headers/TestPublicAPIHeaders.py +++ b/lldb/test/API/api/check_public_api_headers/TestPublicAPIHeaders.py @@ -39,14 +39,6 @@ def sanity_check_executable(self, exe_name): self.getBuildArtifact(self.source), "// Set breakpoint here." ) -env_cmd = "settings set target.env-vars %s=%s" % ( -self.dylibPath, -self.getLLDBLibraryEnvVal(), -) -if self.TraceOn(): -print("Set environment to: ", env_cmd) -self.runCmd(env_cmd) - lldbutil.run_break_set_by_file_and_line( self, self.source, self.line_to_break, num_expected_locations=-1 ) diff --git a/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py b/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py index e992f62ba91441..f2dbbbd7b4d428 100644 --- a/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py +++ b/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py @@ -1,5 +1,7 @@ """Test the lldb public C++ api for returning SBCommandReturnObject.""" +import subprocess + from lldbsuite.test.decorators import * from lldbsuite.test.lldbtest import * from lldbsuite.test import lldbutil @@ -14,20 +16,11 @@ class TestSBCommandReturnObject(TestBase): ) @skipIfHostIncompatibleWithTarget def test_sb_command_return_object(self): -env = {self.dylibPath: self.getLLDBLibraryEnvVal()} - self.driver_exe = self.getBuildArtifact("command-return-object") self.buildDriver("main.cpp", self.driver_exe) self.addTearDownHook(lambda: os.remove(self.driver_exe)) -if self.TraceOn(): -print("Running test %s" %
[Lldb-commits] [lldb] [lldb] Fix `FindDirectNestedType` not working with class templates (PR #81666)
https://github.com/Endilll closed https://github.com/llvm/llvm-project/pull/81666 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] 7b7d411 - [lldb] Fix `FindDirectNestedType` not working with class templates (#81666)
Author: Vlad Serebrennikov Date: 2024-02-16T20:40:27+04:00 New Revision: 7b7d411de9f731d2bcf6b093f6cee2cf57a5196e URL: https://github.com/llvm/llvm-project/commit/7b7d411de9f731d2bcf6b093f6cee2cf57a5196e DIFF: https://github.com/llvm/llvm-project/commit/7b7d411de9f731d2bcf6b093f6cee2cf57a5196e.diff LOG: [lldb] Fix `FindDirectNestedType` not working with class templates (#81666) This patch attempts to fix lookup in class template specialization. The first fixed problem is that during type lookup `DeclContextGetName` have been dropping template arguments. So when such a name was compared against a name in `DW_AT_name`, which contains template arguments, false mismatches have been occurring. The second fixed problem is that LLDB's printing policy hasn't been matching Clang's printing policy when it comes to integral non-type template arguments. This again caused some false mismatches during type lookup, because Clang puts e.g. `3U` in debug info for class specializations, but LLDB has been expecting just `3`. This patch brings printing policy in line with what Clang does. Added: Modified: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp lldb/test/API/python_api/type/TestTypeList.py lldb/test/API/python_api/type/main.cpp Removed: diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index a41e2c690853d2..0652ac0e134f53 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -2165,6 +2165,7 @@ PrintingPolicy TypeSystemClang::GetTypePrintingPolicy() { // (and we then would have suppressed them from the type name) and also setups // where LLDB wasn't able to reconstruct the default arguments. printing_policy.SuppressDefaultTemplateArgs = false; + printing_policy.AlwaysIncludeTypeForTemplateArgument = true; return printing_policy; } @@ -9265,8 +9266,13 @@ ConstString TypeSystemClang::DeclContextGetName(void *opaque_decl_ctx) { if (opaque_decl_ctx) { clang::NamedDecl *named_decl = llvm::dyn_cast((clang::DeclContext *)opaque_decl_ctx); -if (named_decl) - return ConstString(named_decl->getName()); +if (named_decl) { + std::string name; + llvm::raw_string_ostream stream{name}; + named_decl->getNameForDiagnostic(stream, GetTypePrintingPolicy(), + /*qualified=*/false); + return ConstString(name); +} } return ConstString(); } diff --git a/lldb/test/API/python_api/type/TestTypeList.py b/lldb/test/API/python_api/type/TestTypeList.py index c267defb58edf9..63ab958193574b 100644 --- a/lldb/test/API/python_api/type/TestTypeList.py +++ b/lldb/test/API/python_api/type/TestTypeList.py @@ -150,6 +150,23 @@ def test(self): invalid_type = task_type.FindDirectNestedType(None) self.assertFalse(invalid_type) +# Check that FindDirectNestedType works with types from AST +pointer = frame0.FindVariable("pointer") +pointer_type = pointer.GetType() +self.assertTrue(pointer_type) +self.DebugSBType(pointer_type) +pointer_info_type = pointer_type.template_args[1] +self.assertTrue(pointer_info_type) +self.DebugSBType(pointer_info_type) + +pointer_masks1_type = pointer_info_type.FindDirectNestedType("Masks1") +self.assertTrue(pointer_masks1_type) +self.DebugSBType(pointer_masks1_type) + +pointer_masks2_type = pointer_info_type.FindDirectNestedType("Masks2") +self.assertTrue(pointer_masks2_type) +self.DebugSBType(pointer_masks2_type) + # We'll now get the child member 'id' from 'task_head'. id = task_head.GetChildMemberWithName("id") self.DebugSBValue(id) diff --git a/lldb/test/API/python_api/type/main.cpp b/lldb/test/API/python_api/type/main.cpp index 98de9707d88654..391f58e3e5871c 100644 --- a/lldb/test/API/python_api/type/main.cpp +++ b/lldb/test/API/python_api/type/main.cpp @@ -34,6 +34,14 @@ class Task { {} }; +template struct PointerInfo { + enum Masks1 { pointer_mask }; + enum class Masks2 { pointer_mask }; +}; + +template > +struct Pointer {}; + enum EnumType {}; enum class ScopedEnumType {}; enum class EnumUChar : unsigned char {}; @@ -71,5 +79,9 @@ int main (int argc, char const *argv[]) ScopedEnumType scoped_enum_type; EnumUChar scoped_enum_type_uchar; +Pointer<3> pointer; +PointerInfo<3>::Masks1 mask1 = PointerInfo<3>::Masks1::pointer_mask; +PointerInfo<3>::Masks2 mask2 = PointerInfo<3>::Masks2::pointer_mask; + return 0; // Break at this line } ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [lldb] bf93f4b - [lldb] Fix and rename skipIfHostIncompatibleWithRemote
Author: Jonas Devlieghere Date: 2024-02-16T07:59:03-08:00 New Revision: bf93f4b85fd4efbd7a3083935a2ddbbb00f1a35f URL: https://github.com/llvm/llvm-project/commit/bf93f4b85fd4efbd7a3083935a2ddbbb00f1a35f DIFF: https://github.com/llvm/llvm-project/commit/bf93f4b85fd4efbd7a3083935a2ddbbb00f1a35f.diff LOG: [lldb] Fix and rename skipIfHostIncompatibleWithRemote Fix and rename the broken and confusingly named decorator skipIfHostIncompatibleWithRemote. The decorator is meant to skip test which uses the inferior test build system (i.e. to build test inferiors) to build host binaries (e.g. lldb drivers). The decorator was broken on macOS, where the host and target platform report macosx, but the decorator overwrote it with Darwin, resulting in tests incorrectly being skipped. The decorator was also missing on a handful of tests that use the buildDriver helper, which this commit fixes as well. Added: Modified: lldb/packages/Python/lldbsuite/test/decorators.py lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py lldb/test/API/api/multiple-targets/TestMultipleTargets.py lldb/test/API/api/multithreaded/TestMultithreaded.py lldb/test/API/functionalities/plugins/command_plugin/TestPluginCommands.py Removed: diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index 86594c2b409e79..a5d7a7a25879df 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -746,18 +746,14 @@ def skipUnlessTargetAndroid(func): )(func) -def skipIfHostIncompatibleWithRemote(func): -"""Decorate the item to skip tests if binaries built on this host are incompatible.""" +def skipIfHostIncompatibleWithTarget(func): +"""Decorate the item to skip tests when the host and target are incompatible.""" def is_host_incompatible_with_remote(): host_arch = lldbplatformutil.getLLDBArchitecture() host_platform = lldbplatformutil.getHostPlatform() target_arch = lldbplatformutil.getArchitecture() -target_platform = ( -"darwin" -if lldbplatformutil.platformIsDarwin() -else lldbplatformutil.getPlatform() -) +target_platform = lldbplatformutil.getPlatform() if ( not (target_arch == "x86_64" and host_arch == "i386") and host_arch != target_arch diff --git a/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py b/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py index 98f08937736349..e992f62ba91441 100644 --- a/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py +++ b/lldb/test/API/api/command-return-object/TestSBCommandReturnObject.py @@ -12,6 +12,7 @@ class TestSBCommandReturnObject(TestBase): @expectedFailureAll( oslist=["windows"], archs=["i[3-6]86", "x86_64"], bugnumber="llvm.org/pr43570" ) +@skipIfHostIncompatibleWithTarget def test_sb_command_return_object(self): env = {self.dylibPath: self.getLLDBLibraryEnvVal()} diff --git a/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py b/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py index 15b2012eee13b6..b818268f2efa80 100644 --- a/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py +++ b/lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py @@ -13,6 +13,7 @@ class TestMultipleSimultaneousDebuggers(TestBase): @skipIfNoSBHeaders @skipIfWindows +@skipIfHostIncompatibleWithTarget def test_multiple_debuggers(self): env = {self.dylibPath: self.getLLDBLibraryEnvVal()} diff --git a/lldb/test/API/api/multiple-targets/TestMultipleTargets.py b/lldb/test/API/api/multiple-targets/TestMultipleTargets.py index 4fb9279e978d7b..a2e0f08d3b3bc7 100644 --- a/lldb/test/API/api/multiple-targets/TestMultipleTargets.py +++ b/lldb/test/API/api/multiple-targets/TestMultipleTargets.py @@ -13,11 +13,11 @@ class TestMultipleTargets(TestBase): @skipIf(oslist=["linux"], archs=["arm", "aarch64"]) @skipIfNoSBHeaders -@skipIfHostIncompatibleWithRemote @expectedFailureAll( oslist=["windows"], archs=["i[3-6]86", "x86_64"], bugnumber="llvm.org/pr20282" ) @expectedFlakeyNetBSD +@skipIfHostIncompatibleWithTarget def test_multiple_targets(self): env = {self.dylibPath: self.getLLDBLibraryEnvVal()} diff --git a/lldb/test/API/api/multithreaded/TestMultithreaded.py b/lldb/test/API/api/multithreaded/TestMultithreaded.py index 1eeff12da4920d..9f2756fcd46fc9 100644 --- a/lldb/test/API/api/multithreaded/TestMultithreaded.py +++ b/lldb/test/API/api/multithreaded/TestMultithreaded.py @@ -27,6 +27,7 @@ def setUp(self): @skipIfRemote # clang-cl