This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Expose a const iterator for SymbolContextList
ClosedPublic

Authored by bulbazord on May 4 2023, 1:30 PM.

Details

Summary

There are many situations where we'll iterate over a SymbolContextList
with the pattern:

SymbolContextList sc_list;
// Fill in sc_list here
for (auto i = 0; i < sc_list.GetSize(); i++) {
  SymbolContext sc;
  sc_list.GetSymbolAtContext(i, sc);

  // Do work with sc
}

Adding an iterator to iterate over the instances directly means we don't
have to do bounds checking or create a copy of every element of the
SymbolContextList.

Diff Detail

Event Timeline

bulbazord created this revision.May 4 2023, 1:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2023, 1:30 PM
bulbazord requested review of this revision.May 4 2023, 1:30 PM
Herald added a project: Restricted Project. · View Herald Transcript
aprantl accepted this revision.May 4 2023, 2:03 PM

Please do more of this!
I haven't checked all the replacements for correctness but the direction is good.

This revision is now accepted and ready to land.May 4 2023, 2:03 PM
mib added a comment.May 4 2023, 2:17 PM

LGTM but I'd prefer if we kept the type in the for loop

for (const SymbolContext &sym_ctx : sc_list)
bulbazord updated this revision to Diff 519690.May 4 2023, 4:37 PM

Explicitly write out type

This revision was landed with ongoing or failed builds.May 4 2023, 4:39 PM
This revision was automatically updated to reflect the committed changes.

Looks like this may have broken the Debian buildbot: https://lab.llvm.org/buildbot/#/builders/68/builds/52162/steps/6/logs/stdio

I'm taking a look and will try to fix forward. If I can't figure it out quickly, I will revert.