Add formattors for libc++ std::optional and tests to verify the new Formattors.
Details
- Reviewers
jingham friss jasonmolenda EricWF JDevlieghere davide - Commits
- rGc53d36847ebd: Add libc++ data formatters for std::optional.
rG1d44c46539fa: Recommit [DataFormatters] Add formatter for C++17 std::optional.
rG1d4a78ef0422: [DataFormatters] Add formatter for C++17 std::optional.
rLLDB339828: Add libc++ data formatters for std::optional.
rL339828: Add libc++ data formatters for std::optional.
rLLDB338156: Recommit [DataFormatters] Add formatter for C++17 std::optional.
rLLDB337959: [DataFormatters] Add formatter for C++17 std::optional.
rL338156: Recommit [DataFormatters] Add formatter for C++17 std::optional.
rL337959: [DataFormatters] Add formatter for C++17 std::optional.
Diff Detail
Event Timeline
Some comments. Jonas looked at many formatters recently so he's in a good position to take a look.
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/Makefile | ||
---|---|---|
10 | commented out code? | |
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py | ||
22–23 | ditto | |
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp | ||
15–39 | You don't really need to se all these breakpoints. | |
source/Plugins/Language/CPlusPlus/CMakeLists.txt | ||
15–16 | Please sort this. | |
source/Plugins/Language/CPlusPlus/LibCxx.cpp | ||
48–51 | Can you use StringRef? | |
source/Plugins/Language/CPlusPlus/LibCxx.h | ||
30–33 | Please clang-format this patch. | |
source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp | ||
60 | Please remove this commented out code. | |
64 | if you want to log diagnostics, you might consider using the LOG facility and then add these to the data formatters channel. |
It seems a little odd to choose to represent this as an array with 1 element. I think I would be confused by that. You can maybe choose a better name like "value" for your cloned object. But it looks like it is also possible to make a Synthetic Child Provider that just replaces the value of the object with the value provided by the synthetic child provider. That's done in the Python front end by saying you have no children and then providing a the "get_value" method. It must be possible to do this from C++ as well, but it will take a little thought to figure out how that works. But that would be the most natural way to present this, I think.
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py | ||
---|---|---|
27–39 | you can do this more cleanly with: (self.target, _, _, bkpt) = lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.cpp")) | |
40–49 | I don't think you need this cleanup, you aren't adding any formatters, you're just testing built-in ones. | |
source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp | ||
64 | If you want to log this, get the formatters log channel and put the text there. Then somebody will see this when they turn on the log. An fprintf like this won't help anybody. |
Address comments
- Applying clang-formt
- Refactoring OptionalFrontEnd to produce out that makes the underlying data look like an array
- Removing commented out code and left in debugging
- Using StringRef instead of const char *
Looks good to me, modulo the inline test (or the current comments addressed). Thanks Shafik!
Probably last round of comments. Thanks for your patience!
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/Makefile | ||
---|---|---|
8 | you don't need this, it's implicit (-O0) | |
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py | ||
9 | I do wonder if you need a decorator to indicate that this is a libcxx only test (and skip everywhere the library isn't supported). | |
source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp | ||
495 | I'm a little nervous about this regex, but I think it's fine and I'll let Jim take another look in case I missed something. | |
source/Plugins/Language/CPlusPlus/LibCxx.cpp | ||
42–51 | This is really obscure to somebody who doesn't understand the type internally. Can you add a comment explaining the structure? (here or in the synthetic) |
This looks fine. I agree with Davide that putting some description of the type you are formatting in comments somewhere would be make things easier for somebody else who might have to fix this (or to you when you've totally forgotten how this worked a year from now...)
I'm okay with this if you fix the things Davide asked about (except the regex, that looks right to me.)
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py | ||
---|---|---|
9 | Yes, you do need to mark this or you will get spurious failures at least on Windows, which turns off the libcxx category. | |
source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp | ||
495 | That looks right to me, it's catching the type or a reference to it. |
Addressing comments
- -O0 is not needed in Makefile
- engaged is not friendly terminology so switching to "Has Value"
- Switching test away from lldbinline style due to bug w/ .categories files which does not work on these tests
@davide One more pass
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py | ||
---|---|---|
9 | Switched back to the old style tests due to the .categories bug we discussed earlier. | |
source/Plugins/Language/CPlusPlus/LibCxx.cpp | ||
42–51 | That is a good point, I am looking at the cppreference page for it and I think maybe has_value might be an improvement. |
Your latest update doesn't contain CMakeList.txt files and the Xcode project changes. That's why it failed to apply. Please upload a correct version and I'll commit it for you.
Recommitted:
a11963323fc Recommit [DataFormatters] Add formatter for C++17 std::optional.
Authentication realm: https://llvm.org:443 LLVM Subversion repository
Password for 'davide': ***
Sending lldb/trunk/lldb.xcodeproj/project.pbxproj
Adding lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional
Adding lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/Makefile
Adding lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py
Adding lldb/trunk/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp
Sending lldb/trunk/source/Plugins/Language/CPlusPlus/CMakeLists.txt
Sending lldb/trunk/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
Sending lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.cpp
Sending lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxx.h
Adding lldb/trunk/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp
Transmitting file data .........done
Committing transaction...
Committed revision 338156.
Committed a11963323fc to svn.
I'm afraid I had to revert this again. It broke an ubuntu lldb-cmake bot which builds with clang-3.5 (which has no -std=c++17 support flag, as 17 wasn't there yet).
I'd recommend to update this patch with another decorator to skip places where -std=c++17 is not available doesn't work, and then we'll try again.
Bot logs for completeness:
Session logs for test failures/errors/unexpected successes will go into directory 'logs-clang-3.5-i386' Command invoked: /lldb-buildbot/lldbSlave/buildWorkingDir/scripts/../llvm/tools/lldb/test/dotest.py -A i386 -C clang-3.5 -v -s logs-clang-3.5-i386 -u CXXFLAGS -u CFLAGS --env ARCHIVER=ar --env OBJCOPY=objcopy --executable /lldb-buildbot/lldbSlave/buildWorkingDir/scripts/../build/bin/lldb --channel gdb-remote packets --channel lldb all --skip-category watchpoint --skip-category lldb-mi --results-port 43584 -S fnmac --inferior -p TestDataFormatterLibcxxOptional.py /lldb-buildbot/lldbSlave/buildWorkingDir/llvm/tools/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional --event-add-entries worker_index=4:int Configuration: arch=i386 compiler=/usr/bin/clang-3.5 ---------------------------------------------------------------------- Collected 4 tests 1: test_with_run_command_dsym (TestDataFormatterLibcxxOptional.LibcxxOptionalDataFormatterTestCase) Test that that file and class static variables display correctly. ... skipped 'test case does not fall in any category of interest for this run' 2: test_with_run_command_dwarf (TestDataFormatterLibcxxOptional.LibcxxOptionalDataFormatterTestCase) Test that that file and class static variables display correctly. ... 3: test_with_run_command_dwo (TestDataFormatterLibcxxOptional.LibcxxOptionalDataFormatterTestCase) Test that that file and class static variables display correctly. ... 4: test_with_run_command_gmodules (TestDataFormatterLibcxxOptional.LibcxxOptionalDataFormatterTestCase) Test that that file and class static variables display correctly. ... skipped 'test case does not fall in any category of interest for this run' ====================================================================== ERROR: test_with_run_command_dwarf (TestDataFormatterLibcxxOptional.LibcxxOptionalDataFormatterTestCase) Test that that file and class static variables display correctly. ---------------------------------------------------------------------- Error when building test subject. Build Command: make VPATH=/lldb-buildbot/lldbSlave/buildWorkingDir/llvm/tools/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional -C /lldb-buildbot/lldbSlave/buildWorkingDir/scripts/lldb-test-build.noindex/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.test_with_run_command_dwarf -I /lldb-buildbot/lldbSlave/buildWorkingDir/llvm/tools/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional -f /lldb-buildbot/lldbSlave/buildWorkingDir/llvm/tools/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/Makefile MAKE_DSYM=NO ARCH=i386 CC="/usr/bin/clang-3.5" Build Command Output: error: invalid value 'c++17' in '-std=c++17' error: invalid value 'c++17' in '-std=c++17' make: *** [main.o] Error 1
Thanks for looking out for the bots.
I am afraid the compiler check will not be enough here. After that, you'll run into the issue of the system libc++ not being recent enough to contain std::optional. I suppose this could be handled by including some other header first (to make sure __config is evaluated) and then checking the _LIBCPP_VERSION macro.
I am sorry that this is so annoying. It's surprising that this is the first time we're running into this, but I guess this is the first data formatter for something that hasn't been implemented in libc++ since forever.
Adjust test to filter on clang version and libc++ version to precent build bots from failing due to lack of C++17 or lack of optional support
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py | ||
---|---|---|
22 | Could you add another line for gcc here? The -std=c++17 flag seems to be supported starting with gcc-5.1. Also a comment that this is due to the -std flag would be helpful to people looking at this in the future. | |
45 | Replace by self.skipTest(...). This way, the test will be properly marked as skipped. | |
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp | ||
16–18 | these need to be guarded by the #if too (i'd just move then into the main function). |
- Adding comments
- Changing from exit to self.skipTest
- Adding skip for gcc
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py | ||
---|---|---|
22 | Adding a comment makes sense. So @add_test_categories(["libc++"]) won't skip for gcc bots then? |
Thanks for the patience. I've tried the patch out on our end. You shouldn't have any problems now.
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py | ||
---|---|---|
22 | It won't because it doesn't make sense to do that. Gcc is perfectly capable of using libc++. The only tricky thing is that it doesn't have the magic -stdlib argument, so you have to specify the include paths and libraries explicitly (which our makefiles do). | |
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp | ||
18–21 | This could be simplified to bool has_optional = HAVE_OPTIONAL; |
@labath Addressed comment, thank you for helping out.
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/TestDataFormatterLibcxxOptional.py | ||
---|---|---|
22 | Good point I did not realize this before! | |
packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/optional/main.cpp | ||
18–21 | Good catch! |
I see this test failing on Linux right now (bots are down, so I can't confirm that the official bots fail as well). The failure is because of the last decorator which was not part of the review:
@skipIf(macos_version=["<", "10.14"])
It looks like this only works correctly when mac_ver returns a meaningful result (a.k.a. on mac platforms), so linux is broken.
Another thing that I noticed is that the name of the test class (LibcxxOptionalDataFormatterTestCase) was re-used from another test. This has caused problems in the past with test overriding each other's results because they share the same class and test name (as these do).
@stella.stamenova Thank you for catching this. I fixed the test names, I am looking into the best way to fix the skipif now.
@shafik I send a change for review this morning that I think should do the trick: https://reviews.llvm.org/D53208. The other option is to change the skipIf to include the os like some of the other ones.
commented out code?