This is an archive of the discontinued LLVM Phabricator instance.

Make partial function name matching match on context boundaries
ClosedPublic

Authored by jingham on Apr 27 2022, 5:33 PM.

Details

Summary

We don't require users to type out the full context of a function, for symbol name matches. Instead, we extract the incoming path's base name, look up all the symbols with that base name, and then compare the rest of the context that the user provided to make sure it matches. However, we do this comparison using just a strstr. So for instance:

break set -n foo::bar

will match not only "a::foo::bar" but "notherfoo::bar". The former is pretty clearly the user's intent, but I don't think the latter is, and results in breakpoints picking up too many matches.

This change adds a Language::DemangledNameContainsPath API which can do a language aware match against the path provided. If the language doesn't provide this we fall back to the strstr (though that's changed to StringRef::contains in the patch).

Diff Detail

Event Timeline

jingham created this revision.Apr 27 2022, 5:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 5:33 PM
Herald added a subscriber: mgorny. · View Herald Transcript
jingham requested review of this revision.Apr 27 2022, 5:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 5:33 PM

You might want to try fun cases like operator< and operator()() from a lambda. They should work but might be worth throwing them in.

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
324

dead code?

lldb/tools/CMakeLists.txt
11 ↗(On Diff #425658)

Did you mean to delete this line?

Yeah, this was very surprising.

The fact that we're still doing substring matches on the context is suspicious, and might cause false positives, but given that we first verify that the context is valid, I was not able to come up with counterexamples.

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
293–309
StringRef haystack = m_context;
if (!haystack.consume_back(context))
  return false;
if (haystack.empty() || !isalnum(haystack.back()))
  return true;
return false;
lldb/unittests/Language/CPlusPlus/CPlusPlusLanguageTest.cpp
151–155

what about these?

157

This saves very little compared to spelling out the individual checks (EXPECT_TRUE/FALSE(reference_1.ContainsPath("whatever"))), and makes the error messages a lot more cryptic.

clayborg requested changes to this revision.Apr 29 2022, 11:48 AM
clayborg added inline comments.
lldb/include/lldb/Target/Language.h
225

The comment should be adding something extra to "A" right? See suggested code change

lldb/source/Core/Module.cpp
753–754

Remove this, SymbolContext::GetFunctionName() already returns the symbol name if there is no block with inlined function name or concrete function name.

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
324–353

delete commented out code

This revision now requires changes to proceed.Apr 29 2022, 11:48 AM
jingham updated this revision to Diff 426170.Apr 29 2022, 2:51 PM

Address review comments.

jingham marked 6 inline comments as done.Apr 29 2022, 2:59 PM
jingham added inline comments.
lldb/include/lldb/Target/Language.h
225

Yes, the comment was wrong. I had a fancier example that was taking too many characters and I didn't delete enough when simplifying. But I'm not sure what code change you are referring to? I don't see how this is related to GetFunctionName.

lldb/source/Core/Module.cpp
753–754

Yeah, I swear I saw a case debugging through this where GetFunctionName was returning a null string but going to the Symbol worked, but reading through GetFunctionName I don't see how that could be and I can't reproduce the problem, so I must have been seeing some unrelated error.

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
293–309

Much nicer, thanks!

324

Yup, that was the not very good (but much easier to implement) first try. It's gone...

clayborg accepted this revision.May 2 2022, 4:19 PM
clayborg added inline comments.
lldb/include/lldb/Target/Language.h
225

It isn't related to GetFunctionName, I have a code change that you can see on the web page that suggests the edit to make to fix the comment. I see you fixed the comment, so nothing more needed for this.

This revision is now accepted and ready to land.May 2 2022, 4:19 PM
labath accepted this revision.May 4 2022, 8:43 AM
This revision was automatically updated to reflect the committed changes.
jingham marked 4 inline comments as done.