This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Accept negative indexes in __getitem__
ClosedPublic

Authored by kastiglione on Feb 3 2023, 9:40 AM.

Details

Summary

To the Python bindings, add support for Python-like indexing with negative indexes.

While was using script, I tried to access a thread's bottom frame with thread.frame[-1], but that failed. This change updates the __getitem__ implementations to support negative indexes as one would expect in Python.

Diff Detail

Event Timeline

kastiglione created this revision.Feb 3 2023, 9:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 3 2023, 9:40 AM
Herald added a subscriber: arphaman. · View Herald Transcript
kastiglione requested review of this revision.Feb 3 2023, 9:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 3 2023, 9:40 AM
mib accepted this revision.EditedFeb 3 2023, 9:54 AM

This is nice although I wish there was a builtin way to do it. LGTM with a test :)

This revision is now accepted and ready to land.Feb 3 2023, 9:54 AM

I wondered what to do about tests. Should I pick one of these to test? Just
doesn't seem worth tests for each…

mib added a comment.Feb 3 2023, 10:56 AM

I wondered what to do about tests. Should I pick one of these to test? Just
doesn't seem worth tests for each…

Yeah, that sounds good to me :)

A simple test would be what you did in your commit summary, trying to get thread.frame[-1] and verifying that it's the correct frame. LGTM with a test.

Add a couple tests

This revision was automatically updated to reflect the committed changes.