This is an archive of the discontinued LLVM Phabricator instance.

[lldb][CPlusPlus] Add abi_tag support to the CPlusPlusNameParser
ClosedPublic

Authored by Michael137 on Oct 19 2022, 5:17 PM.

Details

Summary

This patch teaches the CPlusPlusNameParser to parse the
demangled/prettified [[gnu::abi_tag(...)]] attribute. The demangled format
isn't standardized and the additions to the parser were mainly driven
using Clang (and the limited information on this from the official
Clang docs).

This change is motivated by multiple failures around step-in
behaviour for libcxx APIs (many of which have ABI tags as of recently).
LLDB determines whether the step-avoid-regexp matches the current
frame by parsing the scope-qualified name out of the demangled
function symbol. On failure, the CPlusPlusNameParser will simply
return the fully demangled name (which can include the return type)
to the caller, which in FrameMatchesAvoidCriteria means we will
not correctly decide whether we should stop at a frame or not if
the function has an abi_tag.

Ideally we wouldn't want to rely on the non-standard format
of demangled attributes. Alternatives would be:

  1. Use the mangle tree API to do the parsing for us
  2. Reconstruct the scope-qualified name from DWARF instead of parsing the demangled name

(1) isn't feasible without a significant refactor of lldb_private::Mangled,
if we want to do this efficiently.

(2) could be feasible in cases where debug-info for a frame is
available. But it does mean we certain operations (such as step-in regexp,
and frame function names) won't work with/won't show ABI tags.

Testing

  • Un-XFAILed step-in API test
  • Added parser unit-tests

Diff Detail

Event Timeline

Michael137 created this revision.Oct 19 2022, 5:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 5:17 PM
Michael137 requested review of this revision.Oct 19 2022, 5:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 5:17 PM

Would really be nice not to have to do this. Especially because it looks like only the LLVM demangler prints out the ABI tags (though other vendors may start doing the same at some point)

This is partly educational to see what we'd have to do to support demangled names with abi-tags

Michael137 planned changes to this revision.Oct 20 2022, 4:12 AM

Wonder if we should skip the tags rather than consume them. Depends on what DW_AT_name says. Also I suspect there are cases where we would want to include tags and others where we dont

Will need to handle special characters in the tags too (currently it just handles simple identifiers)

  • Support certain special tokens
Michael137 retitled this revision from [WIP][lldb][CPlusPlus] Add abi_tag support to the CPlusPlusNameParser to [lldb][CPlusPlus] Add abi_tag support to the CPlusPlusNameParser.Oct 20 2022, 9:58 AM
Michael137 edited the summary of this revision. (Show Details)
  • Add test case
aprantl accepted this revision.Oct 20 2022, 1:55 PM

As much as I dislike expanding our hand-rolled parser, this does seem small and important enough to warrant doing it!

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp
260

nit: the function is inconsistent about whether to use curly braces on single statements. LLVM style says don't.

This revision is now accepted and ready to land.Oct 20 2022, 1:55 PM
  • Docs fixes
  • Add more test cases
  • Handle operator overloads
labath accepted this revision.Oct 21 2022, 5:56 AM