This is an archive of the discontinued LLVM Phabricator instance.

[lldb][Breakpoint] Fix setting breakpoints on templates by basename
ClosedPublic

Authored by Michael137 on Oct 13 2022, 2:34 PM.

Details

Summary

This patch fixes a regression with setting breakpoints on template
functions by name. E.g.,:

$ cat main.cpp
template<typename T>
struct Foo {
  template<typename U>
  void func() {}
};

int main() {
  Foo<int> f;
  f.func<double>();
}

(lldb) br se -n func

This has regressed since 3339000e0bda696c2e29173d15958c0a4978a143
where we started using the CPlusPlusNameParser for getting the
basename of the function symbol and match it exactly against
the name in the breakpoint command. The parser will include template
parameters in the basename, so the exact match will always fail

Testing

  • Added API tests
  • Added unit-tests

Diff Detail

Event Timeline

Michael137 created this revision.Oct 13 2022, 2:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 13 2022, 2:34 PM
Michael137 requested review of this revision.Oct 13 2022, 2:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 13 2022, 2:34 PM
Michael137 added inline comments.Oct 13 2022, 3:09 PM
lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py
63

These didn't work before this patch (or in lldb-14) either. So may xfail them for now

  • Fix comment
Michael137 added inline comments.Oct 14 2022, 3:07 AM
lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py
63

This turns out to be a discrepancy between how we parse basenames for templates and the DW_AT_name that gets generated for these nested templates. In DWARF, the name contains a space between angle brackets (i.e., func<ns::Foo<int> >). So setting a breakpoint without the space fails to find the function name in the DWARF index. However, adding the space still doesn't work because it trips over something around the parser, haven't checked what exactly yet. Will try address this in a separate patch

Michael137 added inline comments.Oct 14 2022, 3:14 AM
lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py
63

Ah, the demangler gives us back a string without the space between angle brackets. So we don't match.

labath added inline comments.Oct 14 2022, 3:43 AM
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
280

I think this should return basename here. Otherwise, all non-templated names will match the empty string.

lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
170

Is this actually expected? Like, I don't think it's completely wrong, but I definitely did not expect it to do that.

Michael137 added inline comments.Oct 14 2022, 3:47 AM
lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
170

I agree, it's not intuitive. This happens because operator is a reserved keyword in the eyes of the CPlusPlusNameParser. It will just consume the entire token and return an empty string.

This won't work for the breakpoint matching logic. I thought we'd just test it here in case the someone ever decides to change this behaviour

Michael137 added inline comments.Oct 14 2022, 3:50 AM
lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
170

This won't work for the breakpoint matching logic.

I.e., we don't allow matching breakpoints on just operator. IIRC something else in the breakpoint resolver accounts for this. Seems fragile though

Michael137 added inline comments.Oct 14 2022, 4:06 AM
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
280

Very true

  • Add more test cases
  • Remove FIXMEs
  • Add docs
  • Don't return empty string for non-templates
Michael137 marked an inline comment as done.Oct 14 2022, 4:51 AM
Michael137 retitled this revision from [WIP][lldb][Breakpoint] Fix setting breakpoints on templates by basename to [lldb][Breakpoint] Fix setting breakpoints on templates by basename.
aprantl accepted this revision.Oct 14 2022, 10:16 AM
This revision is now accepted and ready to land.Oct 14 2022, 10:16 AM