This is an archive of the discontinued LLVM Phabricator instance.

[lldb] add SBSection.alignment to python bindings
ClosedPublic

Authored by dmlary on Jun 17 2022, 9:49 AM.

Details

Summary

This commit adds SBSection.GetAlignment(), and SBSection.alignment as a python property to lldb.

Diff Detail

Event Timeline

dmlary created this revision.Jun 17 2022, 9:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 17 2022, 9:49 AM
dmlary requested review of this revision.Jun 17 2022, 9:49 AM

Is this something we could add a test for?

I went through the existing tests for SBSection, and there is only one test case for all the getters & props, and that is for target_byte_size. Based on that lack, and the simplicity of the getter, I didn't think a test case was warranted here.

If the reviewers feel a test is necessary here, I can definitely add one.

JDevlieghere added a comment.EditedJun 17 2022, 12:32 PM

I went through the existing tests for SBSection, and there is only one test case for all the getters & props, and that is for target_byte_size. Based on that lack, and the simplicity of the getter, I didn't think a test case was warranted here.

I'm less concerned about the getter and the property and more about the underlying functionality. It doesn't look like it's being tested, and adding it to the SB API allows us to change that.

If the reviewers feel a test is necessary here, I can definitely add one.

Yes, unless there's a good reason not too, every change should be accompanied by a test.

labath added a subscriber: labath.Jun 20 2022, 2:10 AM

For the underlying functionality, I think it'd be best to extend lldb-test to print section alignment (dumpSectionList in lldb/tools/lldb-test/lldb-test.cpp) and then write (or extend) some test in test/Shell/ObjectFile/ELF (or your favourite object format).

That won't test the code added here though, as lldb-test does not use the SB API.

Sent this via email, but doesn't look like it showed up here:

I'm less concerned about the getter and the property and more about the underlying functionality. It doesn't look like it's being tested, and adding it to the SB API allows to change that.

Just to clarify, are you asking me to add a test for the underlying
functionality, Section.GetLog2Align()? Or is the goal to add the
test at the SBSection level to ensure we detect if someone ever
changes the underlying api?

Sent this via email, but doesn't look like it showed up here:

I'm less concerned about the getter and the property and more about the underlying functionality. It doesn't look like it's being tested, and adding it to the SB API allows to change that.

Just to clarify, are you asking me to add a test for the underlying
functionality, Section.GetLog2Align()? Or is the goal to add the
test at the SBSection level to ensure we detect if someone ever
changes the underlying api?

We should test any APIs we add in a python test IMHO. Also testing that the ".alignment" property works

We should test any APIs we add in a python test IMHO. Also testing that the ".alignment" property works

Ok, I'll add tests for the added python function and property.

Now for the hard part, what's the recommended way to access elf section details within python without using the function added in this commit? I do not think it is safe to hard code the expected alignment in the test case as the default alignment may vary across architectures. Shelling out to readelf and parsing is possible, but feels clunky; is there an existing function to get this data?

We should test any APIs we add in a python test IMHO. Also testing that the ".alignment" property works

Ok, I'll add tests for the added python function and property.

Now for the hard part, what's the recommended way to access elf section details within python without using the function added in this commit? I do not think it is safe to hard code the expected alignment in the test case as the default alignment may vary across architectures. Shelling out to readelf and parsing is possible, but feels clunky; is there an existing function to get this data?

You can use yaml2obj to create sections with known alignments. You should be able to find examples of that in the existing tests (just grep for yaml2obj).

dmlary updated this revision to Diff 441073.Jun 29 2022, 10:32 AM

updated to include test cases for SBSection.GetAlignment() and SBSection.alignment property.

@labath Thanks for the yaml2obj pointer.

labath accepted this revision.Jun 30 2022, 1:16 AM

updated to include test cases for SBSection.GetAlignment() and SBSection.alignment property.

Cool. Looks good, just a couple of small comments inline.

lldb/test/API/python_api/section/TestSectionAPI.py
43

we normally use the .yaml extension.

59

I don't think this is worth a separate test, I'd just move it next to the other check.

This revision is now accepted and ready to land.Jun 30 2022, 1:16 AM
dmlary updated this revision to Diff 441429.Jun 30 2022, 9:10 AM

merge tests, rename yml to yaml

clayborg accepted this revision.Jun 30 2022, 11:59 AM

Looks good, thanks for the revisions

dmlary marked 2 inline comments as done.Jul 8 2022, 1:48 PM

@JDevlieghere if I'm reading this right, yours is the last approval this review needs. Is there anything else you would like to be updated in this diff?

I do not have commit access; could someone merge this patch as time allows?

This revision was automatically updated to reflect the committed changes.