Add ability to import std module into expression parser to improve C++ debugging
authorRaphael Isemann <teemperor@gmail.com>
Tue, 12 Mar 2019 17:09:33 +0000 (17:09 +0000)
committerRaphael Isemann <teemperor@gmail.com>
Tue, 12 Mar 2019 17:09:33 +0000 (17:09 +0000)
commit6c0bbfc0c94b24bfe52745323656e81beb8334e7
tree09896c5a4425b475b6187214ca293b7ace988fdc
parent9bc817a0ae7d629417e369c0612b6312b7437dfa
Add ability to import std module into expression parser to improve C++ debugging

Summary:
This patch is the MVP version of importing the std module into the expression parser to improve C++ debugging.

What happens in this patch is that we inject a `@import std` into our expression source code. We also
modify our internal Clang instance for parsing this expression to work with modules and debug info
at the same time (which is the main change in terms of LOC). We implicitly build the `std` module on the first use. The
C++ include paths for building are extracted from the debug info, which means that this currently only
works if the program is compiled with `-glldb -fmodules` and uses the std module. The C include paths
are currently specified by LLDB.

I enabled the tests currently only for libc++ and Linux because I could test this locally. I'll enable the tests
for other platforms once this has landed and doesn't break any bots (and I implemented the platform-specific
C include paths for them).

With this patch we can now:
* Build a libc++ as a module and import it into the expression parser.
* Read from the module while also referencing declarations from the debug info. E.g. `std::abs(local_variable)`.

What doesn't work (yet):
* Merging debug info and C++ module declarations. E.g. `std::vector<CustomClass>` doesn't work.
* Pretty much anything that involves the ASTImporter and templated code. As the ASTImporter is used for saving the result declaration, this means that we can't
call yet any function that returns a non-trivial type.
* Use libstdc++ for this, as it requires multiple include paths and Clang only emits one include path per module. Also libstdc++ doesn't support Clang modules without patches.

Reviewers: aprantl, jingham, shafik, friss, davide, serge-sans-paille

Reviewed By: aprantl

Subscribers: labath, mgorny, abidh, jdoerfert, lldb-commits

Tags: #c_modules_in_lldb, #lldb

Differential Revision: https://reviews.llvm.org/D58125

llvm-svn: 355939
31 files changed:
lldb/include/lldb/Expression/ExpressionSourceCode.h
lldb/include/lldb/Target/Platform.h
lldb/include/lldb/Target/Target.h
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/Makefile [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/TestImportStdModule.py [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/basic/main.cpp [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/Makefile [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/TestStdModuleWithConflicts.py [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/conflicts/main.cpp [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/Makefile [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/TestMissingStdModule.py [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/no-std-module/main.cpp [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/Makefile [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/TestStdModuleSysroot.py [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/main.cpp [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/c++/include/algorithm [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/c++/include/module.modulemap [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/expression_command/import-std-module/sysroot/root/usr/include/libc_header.h [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/make/Makefile.rules
lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.cpp [new file with mode: 0644]
lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h [new file with mode: 0644]
lldb/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
lldb/source/Plugins/Platform/Linux/PlatformLinux.h
lldb/source/Target/Target.cpp