Skip to content

Commit 1e3ee76

Browse files
dmlarylabath
authored andcommitted
[lldb] add SBSection.alignment to python bindings
This commit adds SBSection.GetAlignment(), and SBSection.alignment as a python property to lldb. Reviewed By: clayborg, JDevlieghere, labath Differential Revision: https://reviews.llvm.org/D128069
1 parent 918b1e7 commit 1e3ee76

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

lldb/bindings/interface/SBSection.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public:
105105
uint32_t
106106
GetTargetByteSize ();
107107

108+
uint32_t
109+
GetAlignment ();
110+
108111
bool
109112
GetDescription (lldb::SBStream &description);
110113

@@ -138,6 +141,7 @@ public:
138141
data = property(GetSectionData, None, doc='''A read only property that returns an lldb object that represents the bytes for this section (lldb.SBData) for this section.''')
139142
type = property(GetSectionType, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eSectionType") that represents the type of this section (code, data, etc.).''')
140143
target_byte_size = property(GetTargetByteSize, None, doc='''A read only property that returns the size of a target byte represented by this section as a number of host bytes.''')
144+
alignment = property(GetAlignment, None, doc='''A read only property that returns the alignment of this section as a number of host bytes.''')
141145
%}
142146
#endif
143147

lldb/include/lldb/API/SBSection.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ class LLDB_API SBSection {
7676
/// The number of host (8-bit) bytes needed to hold a target byte
7777
uint32_t GetTargetByteSize();
7878

79+
/// Return the alignment of the section in bytes
80+
///
81+
/// \return
82+
/// The alignment of the section in bytes
83+
uint32_t GetAlignment();
84+
7985
bool operator==(const lldb::SBSection &rhs);
8086

8187
bool operator!=(const lldb::SBSection &rhs);

lldb/source/API/SBSection.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,15 @@ uint32_t SBSection::GetTargetByteSize() {
242242
return 0;
243243
}
244244

245+
uint32_t SBSection::GetAlignment() {
246+
LLDB_INSTRUMENT_VA(this);
247+
248+
SectionSP section_sp(GetSP());
249+
if (section_sp.get())
250+
return (1 << section_sp->GetLog2Align());
251+
return 0;
252+
}
253+
245254
bool SBSection::operator==(const SBSection &rhs) {
246255
LLDB_INSTRUMENT_VA(this, rhs);
247256

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,14 @@ def test_get_target_byte_size(self):
3737

3838
self.assertIsNotNone(data_section)
3939
self.assertEqual(data_section.target_byte_size, 1)
40+
41+
def test_get_alignment(self):
42+
exe = self.getBuildArtifact("aligned.out")
43+
self.yaml2obj("aligned.yaml", exe)
44+
target = self.dbg.CreateTarget(exe)
45+
self.assertTrue(target, VALID_TARGET)
46+
47+
# exe contains a single section aligned to 0x1000
48+
section = target.modules[0].sections[0]
49+
self.assertEqual(section.GetAlignment(), 0x1000)
50+
self.assertEqual(section.alignment, 0x1000)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_EXEC
6+
Machine: EM_X86_64
7+
Entry: 0x0000000000400000
8+
Sections:
9+
- Name: .text1
10+
Type: SHT_PROGBITS
11+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
12+
Address: 0x0000000000400000
13+
AddressAlign: 0x0000000000001000
14+
Size: 0xb0

0 commit comments

Comments
 (0)