This is an archive of the discontinued LLVM Phabricator instance.

[lldb/Plugins] Improve error reporting when reading memory in Scripted Process
ClosedPublic

Authored by mib on Sep 16 2022, 6:05 AM.

Details

Summary

This patch improves the ScriptedPythonInterface::Dispatch method to
support passing lldb_private types to the python implementation.

This will allow, for instance, the Scripted Process python implementation
to report errors, when reading memory, back to lldb.

To do so, the Dispatch method will transform the private types in the
parameter pack into PythonObjects to be able to pass them down to the
python methods.

Then, if the call succeeded, the transformed arguments will be converted
back to their original type and re-assigned in the parameter pack, to
ensure pointers and references behaviours are preserved.

This patch also updates various scripted process python class and tests
to reflect this change.

rdar://100030995

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.Sep 16 2022, 6:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 16 2022, 6:05 AM
mib requested review of this revision.Sep 16 2022, 6:05 AM
mib added inline comments.Sep 16 2022, 6:18 AM
lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
152

@labath In order to pass down the Status& to python, I create a StatusSP (to avoid leaking the lldb_private::Status type to python), and turn that into a python::PyObject by calling ToSWIGWrapper. This is why I moved its declaration to SWIGPythonBridge.h.

Finally, the python::PyObject is wrapped into another PythonObject* so it can be passed to GetPythonValueFormatString and PyObject_CallMethod in ScriptedPythonInterface::Dispatch

I tried to follow the logic explained in 7f09ab0, however, when ToSWIGWrapper is called at runtime, it crashes in Python:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
    frame #0: 0x00000001056f3c3c Python`PyTuple_New + 212
    frame #1: 0x0000000135524720 liblldb.16.0.0git.dylib`SWIG_Python_NewShadowInstance(data=0x00006000011d6340, swig_this=0x0000000105ec5d70) at LLDBWrapPython.cpp:2284:28
  * frame #2: 0x0000000135515a00 liblldb.16.0.0git.dylib`SWIG_Python_NewPointerObj(self=0x0000000000000000, ptr=0x0000600001dc4040, type=0x000000014448c140, flags=1) at LLDBWrapPython.cpp:2395:22
    frame #3: 0x00000001355157f4 liblldb.16.0.0git.dylib`lldb_private::python::ToSWIGHelper(obj=0x0000600001dc4040, info=0x000000014448c140) at python-swigsafecast.swig:5:29
    frame #4: 0x0000000135515e14 liblldb.16.0.0git.dylib`lldb_private::python::ToSWIGWrapper(status_sp=std::__1::shared_ptr<lldb_private::Status>::element_type @ 0x0000600000ac9a18 strong=3 weak=1) at python-swigsafecast.swig:37:10
    frame #5: 0x00000001367383c4 liblldb.16.0.0git.dylib`lldb_private::ScriptedProcessPythonInterface::ReadMemoryAtAddress(this=0x00006000011cd2c0, address=8034160640, size=512, error=0x000000016b35c650) at ScriptedProcessPythonInterface.cpp:161:45

Am I doing something wrong or maybe I'm missing something ?

labath added inline comments.Sep 19 2022, 7:19 AM
lldb/include/lldb/API/SBError.h
99

This is technically an ABI break (changes sizeof(SBError)). I don't care, but someone might.

lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.cpp
27 ↗(On Diff #460711)

Yes, it should.

lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
35

we don't indent namespaces

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
152

Well.. I'm not sure if this is the cause of the crash, but one problem I see is the passing of PythonObject* to the Dispatch function, which forwards it unmodified to the PyObject_CallMethod function. Python clearly does not know anything about our lldb_private::python::PythonObject wrappers. You'll either need to pass a PyObject here, or teach Dispatch how to unwrap a PythonObject.

I also don't think that it was necessary to move all of this code around. I don't see why would Status be any different from say StructuredDataImpl, which is already passed as a plain reference (no smart pointers). Using an lldb-private object inside python-swigsafecast.swig is still ok, as that code is still part of liblldb. We already include some internal headers from the swig files, but I think that in this case a forward declaration should be enough as well (you may need to add a SBError(const Status &) constructor). The opposite (moving this code to "regular" files) is not ideal as well, as you've needed to add a bunch of SB forward declarations into SWIGPythonBridge, and split the implementation of ToSWIGWrapper into two files.

I also don't think the shared_ptr transition is helping with anything (and it is an ABI break). It might be necessary if the problem was that the SBError object was being copied, and you couldn't get a hold of the copy which the user code has modified, but in that case you'd also have to modify the objects copy constructors to do a shallow (instead of a deep) copy (which in turn could break other code which was relying on this).

mib updated this revision to Diff 476019.EditedNov 16 2022, 11:06 PM
mib marked 2 inline comments as done.
mib retitled this revision from [lldb/Plugins] Improve error reporting with reading/writing memory in a Scripted Process (WIP) to [lldb/Plugins] Improve error reporting with reading memory in Scripted Process.
mib edited the summary of this revision. (Show Details)
mib added a reviewer: kastiglione.

Re-did the whole patch (taking into account @labath's previous comments)

It makes use of:

  • Generic Variadic Lambdas
  • Fold Expressions
  • Index Sequences
  • Template Partial Specializations
  • Variadic template parameters and tuples

...

mib retitled this revision from [lldb/Plugins] Improve error reporting with reading memory in Scripted Process to [lldb/Plugins] Improve error reporting when reading memory in Scripted Process.Nov 16 2022, 11:15 PM
mib edited the summary of this revision. (Show Details)

I kinda like it. One thing that I think would help with the readability is if the "transformation" methods were grouped according to the type of the object being transformed, rather than according to the direction. So something like:

// general transform
// general reverse
// Status transform
// Status reverse

instead of

// general transform
// Status transform
// general reverse
// Status reverse

Also I don't think that these structs (transformation, reverse_transformation) wrapping the transformation functions are really necessary. It's true that one cannot partially specialize functions, but one of the reasons for that is this is normally not necessary -- regular function overloading can do most of that as well.

lldb/bindings/python/python-swigsafecast.swig
36

add const ?

lldb/source/API/SBError.cpp
29

That's cute, but you can just call the copy constructor (new Status(status))

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
125

or assign it to the error argument instead?

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
11–22

move this inside #if LLDB_ENABLE_PYTHON

103–132

Can this be a call to PythonObject::CallMethod (via std::apply and everything). If not, why not?

184

PythonObject::CallMethod knows how to unwrap a PythonObject argument, so ideally, we'd return py_obj directly here.

mib updated this revision to Diff 476292.Nov 17 2022, 5:13 PM
mib marked 8 inline comments as done.
mib edited the summary of this revision. (Show Details)

Address @labath comments.

mib added a comment.Nov 17 2022, 5:14 PM

I kinda like it. One thing that I think would help with the readability is if the "transformation" methods were grouped according to the type of the object being transformed, rather than according to the direction. So something like:

// general transform
// general reverse
// Status transform
// Status reverse

instead of

// general transform
// Status transform
// general reverse
// Status reverse

Also I don't think that these structs (transformation, reverse_transformation) wrapping the transformation functions are really necessary. It's true that one cannot partially specialize functions, but one of the reasons for that is this is normally not necessary -- regular function overloading can do most of that as well.

Thanks for the feedback! I really appreciate it :) For now I reordered the structs as you suggested but I'm thinking of moving all the transformation related code to an anonymous namespace above the class. I'll do that in a follow-up patch :)

lldb/include/lldb/API/SBError.h
99

Luckily, I didn't have to change this.

mib updated this revision to Diff 476299.Nov 17 2022, 5:45 PM

Fix failure when building PythonScriptInterpreter unit test libraries

labath accepted this revision.Nov 17 2022, 11:03 PM

Cool. Thanks.

I kinda like it. One thing that I think would help with the readability is if the "transformation" methods were grouped according to the type of the object being transformed, rather than according to the direction. So something like:

// general transform
// general reverse
// Status transform
// Status reverse

instead of

// general transform
// Status transform
// general reverse
// Status reverse

Also I don't think that these structs (transformation, reverse_transformation) wrapping the transformation functions are really necessary. It's true that one cannot partially specialize functions, but one of the reasons for that is this is normally not necessary -- regular function overloading can do most of that as well.

Thanks for the feedback! I really appreciate it :) For now I reordered the structs as you suggested but I'm thinking of moving all the transformation related code to an anonymous namespace above the class. I'll do that in a follow-up patch :)

You can't have an anonymous namespace in a header (well.. you can, but it will break in very interesting ways). You can put it inside some detail or internal namespace, if you think it helps.

lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h
167–168

this could be a static_assert

This revision is now accepted and ready to land.Nov 17 2022, 11:03 PM
mgorny added a subscriber: mgorny.Nov 19 2022, 7:00 AM

LLDB no longer builds for me after this change (could be related to swig 4.1.0):

[1/5] Building CXX object tools/lldb/source/Plugins/ScriptInterpre...ldbPluginScriptInterpreterPython.dir/ScriptedPythonInterface.cpp.o
FAILED: tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedPythonInterface.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -DLLDB_PYTHON_EXE_RELATIVE_PATH=\"bin/python3.10\" -DLLDB_PYTHON_RELATIVE_LIBDIR=\"lib/python3.10/site-packages\" -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/mgorny/git/llvm-project/build/tools/lldb/source/Plugins/ScriptInterpreter/Python -I/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python -I/home/mgorny/git/llvm-project/lldb/include -I/home/mgorny/git/llvm-project/build/tools/lldb/include -I/home/mgorny/git/llvm-project/build/include -I/home/mgorny/git/llvm-project/llvm/include -I/usr/include/python3.10 -I/home/mgorny/git/llvm-project/llvm/../clang/include -I/home/mgorny/git/llvm-project/build/tools/lldb/../clang/include -I/home/mgorny/git/llvm-project/lldb/source -I/home/mgorny/git/llvm-project/build/tools/lldb/source -isystem /usr/include/libxml2 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-stringop-truncation -Os -DNDEBUG  -fno-exceptions -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedPythonInterface.cpp.o -MF tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedPythonInterface.cpp.o.d -o tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedPythonInterface.cpp.o -c /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp
In file included from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp:20:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:113:13: error: explicit specialization in non-namespace scope ‘class lldb_private::ScriptedPythonInterface’
  113 |   template <> struct transformation<Status> {
      |             ^
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:113:22: error: too few template-parameter-lists
  113 |   template <> struct transformation<Status> {
      |                      ^~~~~~~~~~~~~~~~~~~~~~
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:129:13: error: explicit specialization in non-namespace scope ‘class lldb_private::ScriptedPythonInterface’
  129 |   template <> typename transformation<Status>::type Transform(Status arg) {
      |             ^
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h: In member function ‘lldb_private::ScriptedPythonInterface::transformation<lldb_private::Status>::type lldb_private::ScriptedPythonInterface::Transform(lldb_private::Status)’:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:131:33: error: could not convert ‘lldb_private::python::ToSWIGWrapper(const lldb_private::Status&)()’ from ‘lldb_private::python::PythonObject’ to ‘lldb_private::ScriptedPythonInterface::transformation<lldb_private::Status>::type’ {aka ‘lldb_private::Status’}
  131 |     return python::ToSWIGWrapper(arg);
      |            ~~~~~~~~~~~~~~~~~~~~~^~~~~
      |                                 |
      |                                 lldb_private::python::PythonObject
In file included from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.cpp:16:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h: At global scope:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h:16:30: warning: ‘g_fcxx_modules_workaround’ defined but not used [-Wunused-variable]
   16 | static llvm::Expected<bool> *g_fcxx_modules_workaround;
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~
[2/5] Building CXX object tools/lldb/source/Plugins/ScriptInterpre...ginScriptInterpreterPython.dir/ScriptedThreadPythonInterface.cpp.o
FAILED: tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedThreadPythonInterface.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -DLLDB_PYTHON_EXE_RELATIVE_PATH=\"bin/python3.10\" -DLLDB_PYTHON_RELATIVE_LIBDIR=\"lib/python3.10/site-packages\" -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/mgorny/git/llvm-project/build/tools/lldb/source/Plugins/ScriptInterpreter/Python -I/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python -I/home/mgorny/git/llvm-project/lldb/include -I/home/mgorny/git/llvm-project/build/tools/lldb/include -I/home/mgorny/git/llvm-project/build/include -I/home/mgorny/git/llvm-project/llvm/include -I/usr/include/python3.10 -I/home/mgorny/git/llvm-project/llvm/../clang/include -I/home/mgorny/git/llvm-project/build/tools/lldb/../clang/include -I/home/mgorny/git/llvm-project/lldb/source -I/home/mgorny/git/llvm-project/build/tools/lldb/source -isystem /usr/include/libxml2 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-stringop-truncation -Os -DNDEBUG  -fno-exceptions -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedThreadPythonInterface.cpp.o -MF tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedThreadPythonInterface.cpp.o.d -o tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedThreadPythonInterface.cpp.o -c /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp
In file included from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.h:16,
                 from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp:20:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:113:13: error: explicit specialization in non-namespace scope ‘class lldb_private::ScriptedPythonInterface’
  113 |   template <> struct transformation<Status> {
      |             ^
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:113:22: error: too few template-parameter-lists
  113 |   template <> struct transformation<Status> {
      |                      ^~~~~~~~~~~~~~~~~~~~~~
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:129:13: error: explicit specialization in non-namespace scope ‘class lldb_private::ScriptedPythonInterface’
  129 |   template <> typename transformation<Status>::type Transform(Status arg) {
      |             ^
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h: In member function ‘lldb_private::ScriptedPythonInterface::transformation<lldb_private::Status>::type lldb_private::ScriptedPythonInterface::Transform(lldb_private::Status)’:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:131:33: error: could not convert ‘lldb_private::python::ToSWIGWrapper(const lldb_private::Status&)()’ from ‘lldb_private::python::PythonObject’ to ‘lldb_private::ScriptedPythonInterface::transformation<lldb_private::Status>::type’ {aka ‘lldb_private::Status’}
  131 |     return python::ToSWIGWrapper(arg);
      |            ~~~~~~~~~~~~~~~~~~~~~^~~~~
      |                                 |
      |                                 lldb_private::python::PythonObject
In file included from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedThreadPythonInterface.cpp:16:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h: At global scope:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h:16:30: warning: ‘g_fcxx_modules_workaround’ defined but not used [-Wunused-variable]
   16 | static llvm::Expected<bool> *g_fcxx_modules_workaround;
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~
[3/5] Building CXX object tools/lldb/source/Plugins/ScriptInterpre...inScriptInterpreterPython.dir/ScriptedProcessPythonInterface.cpp.o
FAILED: tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedProcessPythonInterface.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -DLLDB_PYTHON_EXE_RELATIVE_PATH=\"bin/python3.10\" -DLLDB_PYTHON_RELATIVE_LIBDIR=\"lib/python3.10/site-packages\" -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/mgorny/git/llvm-project/build/tools/lldb/source/Plugins/ScriptInterpreter/Python -I/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python -I/home/mgorny/git/llvm-project/lldb/include -I/home/mgorny/git/llvm-project/build/tools/lldb/include -I/home/mgorny/git/llvm-project/build/include -I/home/mgorny/git/llvm-project/llvm/include -I/usr/include/python3.10 -I/home/mgorny/git/llvm-project/llvm/../clang/include -I/home/mgorny/git/llvm-project/build/tools/lldb/../clang/include -I/home/mgorny/git/llvm-project/lldb/source -I/home/mgorny/git/llvm-project/build/tools/lldb/source -isystem /usr/include/libxml2 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-stringop-truncation -Os -DNDEBUG  -fno-exceptions -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedProcessPythonInterface.cpp.o -MF tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedProcessPythonInterface.cpp.o.d -o tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptedProcessPythonInterface.cpp.o -c /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp
In file included from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h:16,
                 from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp:21:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:113:13: error: explicit specialization in non-namespace scope ‘class lldb_private::ScriptedPythonInterface’
  113 |   template <> struct transformation<Status> {
      |             ^
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:113:22: error: too few template-parameter-lists
  113 |   template <> struct transformation<Status> {
      |                      ^~~~~~~~~~~~~~~~~~~~~~
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:129:13: error: explicit specialization in non-namespace scope ‘class lldb_private::ScriptedPythonInterface’
  129 |   template <> typename transformation<Status>::type Transform(Status arg) {
      |             ^
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h: In member function ‘lldb_private::ScriptedPythonInterface::transformation<lldb_private::Status>::type lldb_private::ScriptedPythonInterface::Transform(lldb_private::Status)’:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:131:33: error: could not convert ‘lldb_private::python::ToSWIGWrapper(const lldb_private::Status&)()’ from ‘lldb_private::python::PythonObject’ to ‘lldb_private::ScriptedPythonInterface::transformation<lldb_private::Status>::type’ {aka ‘lldb_private::Status’}
  131 |     return python::ToSWIGWrapper(arg);
      |            ~~~~~~~~~~~~~~~~~~~~~^~~~~
      |                                 |
      |                                 lldb_private::python::PythonObject
In file included from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h:21,
                 from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp:19:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h: In instantiation of ‘llvm::Expected<lldb_private::python::PythonObject> lldb_private::python::PythonObject::CallMethod(const char*, const T& ...) const [with T = {long unsigned int, long unsigned int, lldb_private::Status}]’:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:72:34:   required from ‘lldb_private::ScriptedPythonInterface::Dispatch<std::shared_ptr<lldb_private::DataExtractor>, long unsigned int&, long unsigned int&, lldb_private::Status&>(llvm::StringRef, lldb_private::Status&, long unsigned int&, long unsigned int&, lldb_private::Status&)::<lambda(auto:32&& ...)> [with auto:32 = {long unsigned int&, long unsigned int&, lldb_private::Status&}]’
/usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/type_traits:2565:26:   required by substitution of ‘template<class _Fn, class ... _Args> static std::__result_of_success<decltype (declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn = lldb_private::ScriptedPythonInterface::Dispatch<std::shared_ptr<lldb_private::DataExtractor>, long unsigned int&, long unsigned int&, lldb_private::Status&>(llvm::StringRef, lldb_private::Status&, long unsigned int&, long unsigned int&, lldb_private::Status&)::<lambda(auto:32&& ...)>; _Args = {long unsigned int&, long unsigned int&, lldb_private::Status&}]’
/usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/type_traits:2576:55:   required from ‘struct std::__result_of_impl<false, false, lldb_private::ScriptedPythonInterface::Dispatch<std::shared_ptr<lldb_private::DataExtractor>, long unsigned int&, long unsigned int&, lldb_private::Status&>(llvm::StringRef, lldb_private::Status&, long unsigned int&, long unsigned int&, lldb_private::Status&)::<lambda(auto:32&& ...)>, long unsigned int&, long unsigned int&, lldb_private::Status&>’
/usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/type_traits:167:12:   recursively required by substitution of ‘template<class _Result, class _Ret> struct std::__is_invocable_impl<_Result, _Ret, true, std::__void_t<typename _CTp::type> > [with _Result = std::__invoke_result<lldb_private::ScriptedPythonInterface::Dispatch<std::shared_ptr<lldb_private::DataExtractor>, long unsigned int&, long unsigned int&, lldb_private::Status&>(llvm::StringRef, lldb_private::Status&, long unsigned int&, long unsigned int&, lldb_private::Status&)::<lambda(auto:32&& ...)>, long unsigned int&, long unsigned int&, lldb_private::Status&>; _Ret = void]’
/usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/type_traits:167:12:   required from ‘struct std::__and_<std::__is_invocable_impl<std::__invoke_result<lldb_private::ScriptedPythonInterface::Dispatch<std::shared_ptr<lldb_private::DataExtractor>, long unsigned int&, long unsigned int&, lldb_private::Status&>(llvm::StringRef, lldb_private::Status&, long unsigned int&, long unsigned int&, lldb_private::Status&)::<lambda(auto:32&& ...)>, long unsigned int&, long unsigned int&, lldb_private::Status&>, void, true, void>, std::__call_is_nothrow<std::__invoke_result<lldb_private::ScriptedPythonInterface::Dispatch<std::shared_ptr<lldb_private::DataExtractor>, long unsigned int&, long unsigned int&, lldb_private::Status&>(llvm::StringRef, lldb_private::Status&, long unsigned int&, long unsigned int&, lldb_private::Status&)::<lambda(auto:32&& ...)>, long unsigned int&, long unsigned int&, lldb_private::Status&>, lldb_private::ScriptedPythonInterface::Dispatch<std::shared_ptr<lldb_private::DataExtractor>, long unsigned int&, long unsigned int&, lldb_private::Status&>(llvm::StringRef, lldb_private::Status&, long unsigned int&, long unsigned int&, lldb_private::Status&)::<lambda(auto:32&& ...)>, long unsigned int&, long unsigned int&, lldb_private::Status&> >’
/usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/type_traits:3064:12:   required from ‘struct std::is_nothrow_invocable<lldb_private::ScriptedPythonInterface::Dispatch<std::shared_ptr<lldb_private::DataExtractor>, long unsigned int&, long unsigned int&, lldb_private::Status&>(llvm::StringRef, lldb_private::Status&, long unsigned int&, long unsigned int&, lldb_private::Status&)::<lambda(auto:32&& ...)>, long unsigned int&, long unsigned int&, lldb_private::Status&>’
/usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/tuple:1836:31:   required from ‘constexpr const bool std::__unpack_std_tuple<template<class _Fn, class ... _ArgTypes> struct std::is_nothrow_invocable, lldb_private::ScriptedPythonInterface::Dispatch<std::shared_ptr<lldb_private::DataExtractor>, long unsigned int&, long unsigned int&, lldb_private::Status&>(llvm::StringRef, lldb_private::Status&, long unsigned int&, long unsigned int&, lldb_private::Status&)::<lambda(auto:32&& ...)>, std::tuple<long unsigned int, long unsigned int, lldb_private::Status>&>’
/usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/tuple:1859:14:   required from ‘constexpr decltype(auto) std::apply(_Fn&&, _Tuple&&) [with _Fn = lldb_private::ScriptedPythonInterface::Dispatch<std::shared_ptr<lldb_private::DataExtractor>, long unsigned int&, long unsigned int&, lldb_private::Status&>(llvm::StringRef, lldb_private::Status&, long unsigned int&, long unsigned int&, lldb_private::Status&)::<lambda(auto:32&& ...)>; _Tuple = tuple<long unsigned int, long unsigned int, lldb_private::Status>&]’
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:69:15:   required from ‘T lldb_private::ScriptedPythonInterface::Dispatch(llvm::StringRef, lldb_private::Status&, Args&& ...) [with T = std::shared_ptr<lldb_private::DataExtractor>; Args = {long unsigned int&, long unsigned int&, lldb_private::Status&}]’
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp:125:66:   required from here
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h:317:50: error: incomplete type ‘lldb_private::python::PythonFormat<lldb_private::Status, void>’ used in nested name specifier
  317 |     const char format[] = {'(', PythonFormat<T>::format..., ')', 0};
      |                                                  ^~~~~~
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h:320:73: error: incomplete type ‘lldb_private::python::PythonFormat<lldb_private::Status, void>’ used in nested name specifier
  320 |                             py2_const_cast(format), PythonFormat<T>::get(t)...);
      |                                                     ~~~~~~~~~~~~~~~~~~~~^~~
In file included from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp:17:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h: At global scope:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h:16:30: warning: ‘g_fcxx_modules_workaround’ defined but not used [-Wunused-variable]
   16 | static llvm::Expected<bool> *g_fcxx_modules_workaround;
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~
[4/5] Building CXX object tools/lldb/source/Plugins/ScriptInterpre...ldbPluginScriptInterpreterPython.dir/ScriptInterpreterPython.cpp.o
FAILED: tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptInterpreterPython.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -DLLDB_PYTHON_EXE_RELATIVE_PATH=\"bin/python3.10\" -DLLDB_PYTHON_RELATIVE_LIBDIR=\"lib/python3.10/site-packages\" -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/mgorny/git/llvm-project/build/tools/lldb/source/Plugins/ScriptInterpreter/Python -I/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python -I/home/mgorny/git/llvm-project/lldb/include -I/home/mgorny/git/llvm-project/build/tools/lldb/include -I/home/mgorny/git/llvm-project/build/include -I/home/mgorny/git/llvm-project/llvm/include -I/usr/include/python3.10 -I/home/mgorny/git/llvm-project/llvm/../clang/include -I/home/mgorny/git/llvm-project/build/tools/lldb/../clang/include -I/home/mgorny/git/llvm-project/lldb/source -I/home/mgorny/git/llvm-project/build/tools/lldb/source -isystem /usr/include/libxml2 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-strict-aliasing -Wno-stringop-truncation -Os -DNDEBUG  -fno-exceptions -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptInterpreterPython.cpp.o -MF tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptInterpreterPython.cpp.o.d -o tools/lldb/source/Plugins/ScriptInterpreter/Python/CMakeFiles/lldbPluginScriptInterpreterPython.dir/ScriptInterpreterPython.cpp.o -c /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
In file included from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h:16,
                 from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp:21:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:113:13: error: explicit specialization in non-namespace scope ‘class lldb_private::ScriptedPythonInterface’
  113 |   template <> struct transformation<Status> {
      |             ^
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:113:22: error: too few template-parameter-lists
  113 |   template <> struct transformation<Status> {
      |                      ^~~~~~~~~~~~~~~~~~~~~~
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:129:13: error: explicit specialization in non-namespace scope ‘class lldb_private::ScriptedPythonInterface’
  129 |   template <> typename transformation<Status>::type Transform(Status arg) {
      |             ^
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h: In member function ‘lldb_private::ScriptedPythonInterface::transformation<lldb_private::Status>::type lldb_private::ScriptedPythonInterface::Transform(lldb_private::Status)’:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptedPythonInterface.h:131:33: error: could not convert ‘lldb_private::python::ToSWIGWrapper(const lldb_private::Status&)()’ from ‘lldb_private::python::PythonObject’ to ‘lldb_private::ScriptedPythonInterface::transformation<lldb_private::Status>::type’ {aka ‘lldb_private::Status’}
  131 |     return python::ToSWIGWrapper(arg);
      |            ~~~~~~~~~~~~~~~~~~~~~^~~~~
      |                                 |
      |                                 lldb_private::python::PythonObject
In file included from /home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp:15:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h: At global scope:
/home/mgorny/git/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/lldb-python.h:16:30: warning: ‘g_fcxx_modules_workaround’ defined but not used [-Wunused-variable]
   16 | static llvm::Expected<bool> *g_fcxx_modules_workaround;
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: cannot make progress due to previous errors.
dyung added a subscriber: dyung.Nov 19 2022, 8:49 AM

This seems to have broken the cross-project-test buildbot as well: https://lab.llvm.org/buildbot/#/builders/217/builds/15302

mib added a comment.Nov 19 2022, 9:23 AM

@mgorny @dyung error: too few template-parameter-lists this seems to be a g++ error. Could you try building with clang to confirm my theory ? I'll try to fix the issue but I have no way to reproduce it

@mgorny @dyung error: too few template-parameter-lists this seems to be a g++ error. Could you try building with clang to confirm my theory ? I'll try to fix the issue but I have no way to reproduce it

I'm going to try. Can we revert the change in the meantime?

mib added a comment.Nov 19 2022, 10:17 AM

@mgorny @dyung error: too few template-parameter-lists this seems to be a g++ error. Could you try building with clang to confirm my theory ? I'll try to fix the issue but I have no way to reproduce it

I'm going to try. Can we revert the change in the meantime?

I was able to get my hands on a linux box, if I can reproduce the build failure I'll try to fix it otherwise I'll revert my patches.

I can confirm that it doesn't fail with clang.

mib added a comment.Nov 19 2022, 1:13 PM

I can confirm that it doesn't fail with clang.

I think I have a fix!

Thanks, it builds fine for me now!