Skip to content

Commit 98581d9

Browse files
committed
Added a new yaml to test equality by creating a different value to compare against instead of needing to inspect files.
1 parent ae18f13 commit 98581d9

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

lldb/test/API/python_api/unified_section_list/TestModuleUnifiedSectionList.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import os
6+
import shutil
67

78
import lldb
89
from lldbsuite.test.decorators import *
@@ -230,3 +231,55 @@ def test_unified_section_list_overwrite_mixed_merge(self):
230231

231232
self.assertTrue(error.Success())
232233
self.assertEqual(comment_content_after_merge, bytes.fromhex("BAADF00DF00DBAAD"))
234+
235+
def test_unified_section_list_overwrite_equal_size(self):
236+
"""
237+
Test the merging of an ELF file with an ELF file with sections of the same size with different values
238+
.text
239+
"""
240+
exe = self.getBuildArtifact("a.out")
241+
self.yaml2obj("main.yaml", exe)
242+
243+
target = self.dbg.CreateTarget(exe)
244+
self.assertTrue(target, VALID_TARGET)
245+
main_exe_module = target.GetModuleAtIndex(0)
246+
247+
# First we verify out .text section is the expected BEC0FFEE
248+
text_before_merge = main_exe_module.FindSection(".text")
249+
self.assertTrue(text_before_merge.IsValid())
250+
error = lldb.SBError()
251+
section_content = text_before_merge.data.ReadRawData(
252+
error, 0, text_before_merge.data.size
253+
)
254+
self.assertTrue(error.Success())
255+
self.assertEqual(section_content, bytes.fromhex("BEC0FFEE"))
256+
257+
# .comment in main.yaml should be SHT_NOBITS, and size 0
258+
comment_before_merge = main_exe_module.FindSection(".comment")
259+
self.assertTrue(comment_before_merge.IsValid())
260+
self.assertEqual(comment_before_merge.data.size, 0)
261+
262+
# yamlize the main with the .text reversed from BEC0FFEE
263+
# to EEFF0CEB. We should still keep our .text with BEC0FFEE
264+
debug_info = self.getBuildArtifact("a.out.debug")
265+
self.yaml2obj("main.reversedtext.yaml", debug_info)
266+
267+
ci = self.dbg.GetCommandInterpreter()
268+
res = lldb.SBCommandReturnObject()
269+
ci.HandleCommand(f"target symbols add {debug_info}", res)
270+
self.assertTrue(res.Succeeded())
271+
272+
# verify .text did not change
273+
main_exe_module_after_merge = target.GetModuleAtIndex(0)
274+
text_after_merge = main_exe_module_after_merge.FindSection(".text")
275+
self.assertTrue(text_after_merge.IsValid())
276+
section_content_after_merge = text_after_merge.data.ReadRawData(
277+
error, 0, text_after_merge.data.size
278+
)
279+
self.assertTrue(error.Success())
280+
self.assertEqual(section_content_after_merge, bytes.fromhex("BEC0FFEE"))
281+
282+
# verify comment did not change
283+
comment_afer_merge = main_exe_module_after_merge.FindSection(".comment")
284+
self.assertTrue(comment_afer_merge.IsValid())
285+
self.assertEqual(comment_afer_merge.data.size, 0)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_DYN
6+
Machine: EM_X86_64
7+
Entry: 0x1040
8+
ProgramHeaders:
9+
- Type: PT_PHDR
10+
Flags: [ PF_R ]
11+
VAddr: 0x40
12+
Align: 0x8
13+
Offset: 0x40
14+
- Type: PT_LOAD
15+
Flags: [ PF_R ]
16+
FirstSec: .text
17+
LastSec: .fini
18+
Align: 0x1000
19+
Offset: 0x0
20+
Sections:
21+
- Name: .text
22+
Type: SHT_PROGBITS
23+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
24+
Address: 0x1040
25+
AddressAlign: 0x10
26+
Content: BEC0FFEE
27+
- Name: .fini
28+
Type: SHT_PROGBITS
29+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
30+
Address: 0x1140
31+
AddressAlign: 0x4
32+
Content: DEADBEEF
33+
- Name: .comment
34+
Type: SHT_NOBITS
35+
Flags: [ SHF_ALLOC ]
36+
Address: 0x3140
37+
AddressAlign: 0x4
38+
Symbols:
39+
- Name: main
40+
Type: STT_FUNC
41+
Section: .text
42+
Binding: STB_GLOBAL
43+
Value: 0x1130
44+
Size: 0xF
45+
...

0 commit comments

Comments
 (0)