This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add support for negative integer to {SB,}StructuredData
ClosedPublic

Authored by mib on May 12 2023, 2:37 PM.

Details

Summary

This patch refactors the StructuredData::Integer class to make it
templated, makes it private and adds 2 public specialization for both
int64_t & uint64_t with a public type aliases, respectively
SignedInteger & UnsignedInteger.

It adds new getter for signed and unsigned interger values to the
StructuredData::Object base class and changes the implementation of
StructuredData::Array::GetItemAtIndexAsInteger and
StructuredData::Dictionary::GetValueForKeyAsInteger to support signed
and unsigned integers.

This patch also adds 2 new Get{Signed,Unsigned}IntegerValue to the
SBStructuredData class and marks GetIntegerValue as deprecated.

Finally, this patch audits all the caller of StructuredData::Integer
or StructuredData::GetIntegerValue to use the proper type as well the
various tests that uses SBStructuredData.GetIntegerValue.

rdar://105575764

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>

Diff Detail

Event Timeline

mib created this revision.May 12 2023, 2:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2023, 2:37 PM
mib requested review of this revision.May 12 2023, 2:37 PM

This is going to need some tests... And because you're adding templates to the SBAPI we'll need multiple tests -- Not just on the python side but I think we should add some actual C++ tests here in test/API/api/

lldb/include/lldb/API/SBStructuredData.h
12–13

You can't include a private header in a public header.

77–78

All the SB API classes are non-virtual, single inheritance classes. They should only include SBDefines.h or other SB headers as needed. There should be no inlined method implementations in the header files, they should all be in the implementation files. And there should be no direct ivar access.

Emphasis mine, from: https://lldb.llvm.org/design/sbapi.html

We should be able to move this into the implementation file.

78–79

This implementation allows us to generate GetIntegerValue for things like const char * and will just return a fail_value for those things. I think the interface would be better if it could give users feedback when they accidentally do something wrong with types instead of just giving them back whatever they want the failure value to be. Is there a way we can use SFINAE to only generate GetIntegerValue for things that are integral type? Would such a thing be compatible with SWIG?

lldb/include/lldb/Core/StructuredDataImpl.h
131

Not related to your change, we should probably move StructuredDataImpl to Utility :P

lldb/include/lldb/Utility/StructuredData.h
313–314

Check for floating type here in addition, just like below.

lldb/include/lldb/lldb-enumerations.h
819–820

Is it a good idea to insert these in the middle? Not that people should do this, but I assume some people hardcode these values in their script....

JDevlieghere added inline comments.May 15 2023, 1:48 PM
lldb/include/lldb/API/SBStructuredData.h
77

I'm open to the idea of adding templates to the SB API, but I think that will require careful considerations in terms of impact on the ABI, the bindings, etc. I'm not convinced this use case really warrants that: it looks like there's only really two meaningful instantiations.

mib updated this revision to Diff 524083.May 21 2023, 12:48 AM
mib marked 2 inline comments as done.
mib edited the summary of this revision. (Show Details)

Many changes:

  • Change SBAPI templated specialization for 2 distinct methods GetUnsignedIntegerValue & GetSignedIntegerValue
  • Add new tests
  • Update previous tests

Ok, this is a pretty big patch so we probably don't want to leave it in review for a long time or it just gets harder to land correctly.

I've looked over most of this patch and it looks fine to me. A lot of is rather mechanical: Changing things like GetIntegerValue to GetUnsignedIntegerValue and using GetSignedIntegerValue where it makes sense. There are lots of little cleanups as well, like correcting the type of some variables (e.g. addr_t -> offset_t) and these are fine too. I don't have much of a problem with any of that.

2 small things though and I think this should probably be good after that.

lldb/include/lldb/API/SBStructuredData.h
81–84

Did you mean to remove the deprecated attribute and use LLDB_DEPRECATED directly?

lldb/include/lldb/Utility/StructuredData.h
105–106

Could you add a small note here specifying why eStructuredDataTypeInteger corresponds to UnsignedInteger and not SignedInteger?

mib marked 5 inline comments as done.May 22 2023, 1:26 PM
mib updated this revision to Diff 524476.May 22 2023, 1:55 PM
mib marked 2 inline comments as done.

Address @bulbazord comments.

bulbazord accepted this revision.May 22 2023, 1:58 PM

Alright, looks good to me. Let's see what the bots think!

This revision is now accepted and ready to land.May 22 2023, 1:58 PM