This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add support for recognizing swift mangled names
ClosedPublic

Authored by bulbazord on Aug 21 2023, 5:23 PM.

Details

Summary

Apple maintains a downstream fork of lldb in order to support swift
debugging. Much of that support is isolated to its own plugins, but some
of it is exposed in more generic code. I would like to take some of
the swift support we have downstream and move it upstream to llvm.org in
an effort to 1) reduce downstream maintenance burden, and 2) work
towards solidifying the process of adding new language support to lldb.

Diff Detail

Event Timeline

bulbazord created this revision.Aug 21 2023, 5:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 21 2023, 5:23 PM
bulbazord requested review of this revision.Aug 21 2023, 5:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 21 2023, 5:23 PM
bulbazord edited the summary of this revision. (Show Details)Aug 21 2023, 5:23 PM
JDevlieghere accepted this revision.Aug 21 2023, 8:51 PM

Given support for other languages like Rust and D, I think this is reasonable. LGTM.

This revision is now accepted and ready to land.Aug 21 2023, 8:51 PM
kastiglione accepted this revision.Aug 21 2023, 8:57 PM
mib accepted this revision.Aug 22 2023, 2:51 AM
aprantl accepted this revision.Aug 22 2023, 8:54 AM
fdeazeve accepted this revision.Aug 22 2023, 8:55 AM
aprantl added inline comments.Aug 22 2023, 8:57 AM
lldb/source/Core/Mangled.cpp
61

Feel free to completely ignore this, it's a pointless micro optimization.

I'm curious if it would be more efficient to write this as

switch (name[0]) {
  case '?':     return Mangled::eManglingSchemeMSVC;
  case '_': 
     switch(name[1]) {
        ...
     }
  case '$': 
     switch(name[1]) {
        ...
     }

or if it would actually be slower than the chain of "vector" comparisons we have right now?

JDevlieghere added inline comments.Aug 22 2023, 9:04 AM
lldb/source/Core/Mangled.cpp
61

I actually started writing a similar comment before discarding it. Even if this code is as hot as I expect it to be, I don't think it would outweigh the complexity and the potential for bugs. I really like how you can glance at the code and see the different mangling schemes and that's the first thing we'd lose. Anyway happy to be proven wrong too.

fdeazeve added inline comments.Aug 22 2023, 9:23 AM
lldb/source/Core/Mangled.cpp
61

Honestly the optimizer is pretty good at doing those, look at the IR: https://godbolt.org/z/PY3TeadbM

aprantl added inline comments.Aug 22 2023, 9:40 AM
lldb/source/Core/Mangled.cpp
61

Sounds good, let's leave it!

Just trolling now: should we use some crazy #ifdef magic to flip the order based on the host platform, such the ? comes first on windows and $ comes first on Darwin?

JDevlieghere added inline comments.Aug 22 2023, 10:10 AM
lldb/source/Core/Mangled.cpp
61

Did someone say tablegen?

bulbazord marked 4 inline comments as done.Aug 22 2023, 10:18 AM
bulbazord added inline comments.
lldb/source/Core/Mangled.cpp
61

As much as I love micro-optimizations, let's do all of that in a follow-up. ;)

This revision was automatically updated to reflect the committed changes.