This is an archive of the discontinued LLVM Phabricator instance.

[lldb/API] Add SBCompileUnit::GetIndexForLineEntry method to SB API
ClosedPublic

Authored by mib on May 11 2022, 5:15 PM.

Details

Summary

This patch adds a new GetIndexForLineEntry method to the SBCompileUnit
class. As the name suggests, given an SBLineEntry object, this will
return the line entry index within a specific compile unit.

This method can take a exact boolean that will make sure that the
provided line entry matches perfectly another line entry in the compile unit.

rdar://47450887

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.May 11 2022, 5:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2022, 5:15 PM
Herald added a subscriber: arphaman. · View Herald Transcript
mib requested review of this revision.May 11 2022, 5:15 PM
jingham requested changes to this revision.May 11 2022, 5:37 PM

This needs a doctoring for the API and some test.

lldb/source/API/SBCompileUnit.cpp
86

llvm would prefer an early return here.

94

Why do you have to do this Compare? You already passed exact to FindLineEntry, does FindLineEntry really return line entries that fail your Compare test when exact is passed in as true? That doesn't seem right.

This revision now requires changes to proceed.May 11 2022, 5:37 PM
mib added inline comments.May 11 2022, 5:41 PM
lldb/source/API/SBCompileUnit.cpp
94

exact could be false, in which case the line entry index returned by FindLineEntry will be different from the one provided by the user.

But if the user really wants the exact line entry index, we need to compare the returned line entry and the one provided by the user.

mib marked 2 inline comments as done.May 11 2022, 6:28 PM
mib updated this revision to Diff 428829.May 11 2022, 6:32 PM

Addressed @jingham comments:

  • Use early returns
  • Remove LineEntry::Compare call since it's already handled by CompileUnit::FindLineEntry
  • Add docstring
mib updated this revision to Diff 428841.May 11 2022, 7:34 PM

I forgot to add the test in the previous diffs --'

mib added a comment.May 12 2022, 10:45 AM

Address @jingham feedbacks

This revision is now accepted and ready to land.May 12 2022, 12:42 PM
JDevlieghere added inline comments.May 13 2022, 11:18 AM
lldb/include/lldb/API/SBCompileUnit.h
37

How's this different from FindLineEntryIndex? In other words why not make this an FindLineEntryIndex overload? It would be good to document this here (too).

mib closed this revision.EditedMay 13 2022, 11:27 AM
mib marked an inline comment as done.

Actually, landed this yesterday in a6926d576131c9ad849fef6f1d43134caab5025e

lldb/include/lldb/API/SBCompileUnit.h
37

We already have a line entry but we just want to get the index in the compile unit, so it made sense to have a separate method for this.

JDevlieghere added inline comments.May 13 2022, 11:50 AM
lldb/include/lldb/API/SBCompileUnit.h
37

I was referring to the name. It seems weird to have a few overloads of FindLineEntryIndex and then a totally different function GetIndexForLineEntry. Are they conceptually different enough to have different names? Don't they both return the line entry index?