[lldb][CPlusPlusLanguage] Respect the step-avoid-regex for functions with auto return...
authorMichael Buch <michaelbuch12@gmail.com>
Thu, 6 Oct 2022 23:35:05 +0000 (00:35 +0100)
committerMichael Buch <michaelbuch12@gmail.com>
Mon, 10 Oct 2022 11:50:15 +0000 (12:50 +0100)
commita4561d934877fbba5cfb3cac3195a41707ba6043
tree907ad67b2786b0e0eae9357e6607cabb9e53fd60
parentb3d4d9ced17c5b3ebd6bf5b61731ddcdde3cbca5
[lldb][CPlusPlusLanguage] Respect the step-avoid-regex for functions with auto return types

**Summary**

The primary motivation for this patch is to make sure we handle
the step-in behaviour for functions in the `std` namespace which
have an `auto` return type. Currently the default `step-avoid-regex`
setting is `^std::` but LLDB will still step into template functions
with `auto` return types in the `std` namespace.

**Details**
When we hit a breakpoint and check whether we should stop, we call
into `ThreadPlanStepInRange::FrameMatchesAvoidCriteria`. We then ask
for the frame function name via `SymbolContext::GetFunctionName(Mangled::ePreferDemangledWithoutArguments)`.
This ends up trying to parse the function name using `CPlusPlusLanguage::MethodName::GetBasename` which
parses the raw demangled name string.

`CPlusPlusNameParser::ParseFunctionImpl` calls `ConsumeTypename` to skip
the (in our case auto) return type of the demangled name (according to the
Itanium ABI this is a valid thing to encode into the mangled name). However,
`ConsumeTypename` doesn't strip out a plain `auto` identifier
(it will strip a `decltype(auto) return type though). So we are now left with
a basename that still has the return type in it, thus failing to match the `^std::`
regex.

Example frame where the return type is still part of the function name:
```
Process 1234 stopped
* thread #1, stop reason = step in
    frame #0: 0x12345678 repro`auto std::test_return_auto<int>() at main.cpp:12:5
   9
   10   template <class>
   11   auto test_return_auto() {
-> 12       return 42;
   13   }
```

This is another case where the `CPlusPlusNameParser` breaks us in subtle ways
due to evolving C++ syntax. There are longer-term plans of replacing the hand-rolled
C++ parser with an alternative that uses the mangle tree API to do the parsing for us.

**Testing**

* Added API and unit-tests
* Adding support for ABI tags into the parser is a larger undertaking
  which we would rather solve properly by using libcxxabi's mangle tree
  parser

Differential Revision: https://reviews.llvm.org/D135413
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp
lldb/test/API/functionalities/step-avoids-regexp/Makefile [new file with mode: 0644]
lldb/test/API/functionalities/step-avoids-regexp/TestStepAvoidsRegexp.py [new file with mode: 0644]
lldb/test/API/functionalities/step-avoids-regexp/main.cpp [new file with mode: 0644]
lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp