File: TestMultipleSlides.py

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,634,792 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (79 lines) | stat: -rw-r--r-- 3,690 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
Test that a binary can be slid to different load addresses correctly
"""



import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class MultipleSlidesTestCase(TestBase):

    NO_DEBUG_INFO_TESTCASE = True
    def test_mulitple_slides(self):
        """Test that a binary can be slid multiple times correctly."""
        self.build()
        exe = self.getBuildArtifact("a.out")
        err = lldb.SBError()
        load_dependent_modules = False
        target = self.dbg.CreateTarget(exe, '', '', load_dependent_modules, err)
        self.assertTrue(target.IsValid())
        module = target.GetModuleAtIndex(0)
        self.assertTrue(module.IsValid())

        first_sym = target.FindSymbols("first").GetContextAtIndex(0).GetSymbol()
        second_sym = target.FindSymbols("second").GetContextAtIndex(0).GetSymbol()
        first_size = first_sym.GetEndAddress().GetOffset() - first_sym.GetStartAddress().GetOffset()
        second_size = second_sym.GetEndAddress().GetOffset() - second_sym.GetStartAddress().GetOffset()

        # View the first element of `first` and `second` while
        # they have no load address set.
        self.expect("p/d ((int*)&first)[0]", substrs=['= 5'])
        self.expect("p/d ((int*)&second)[0]", substrs=['= 6'])
        self.assertEqual(first_sym.GetStartAddress().GetLoadAddress(target), lldb.LLDB_INVALID_ADDRESS)
        self.assertEqual(second_sym.GetStartAddress().GetLoadAddress(target), lldb.LLDB_INVALID_ADDRESS)


        # View the first element of `first` and `second` with
        # no slide applied, but with load address set.
        #
        # In memory, we have something like
        #    0x1000 - 0x17ff  first[]
        #    0x1800 - 0x1fff  second[]
        target.SetModuleLoadAddress(module, 0)
        self.expect("p/d ((int*)&first)[0]", substrs=['= 5'])
        self.expect("p/d ((int*)&second)[0]", substrs=['= 6'])
        self.assertEqual(first_sym.GetStartAddress().GetLoadAddress(target), 
                         first_sym.GetStartAddress().GetFileAddress())
        self.assertEqual(second_sym.GetStartAddress().GetLoadAddress(target),
                         second_sym.GetStartAddress().GetFileAddress())

        # Slide it a little bit less than the size of the first array.
        #
        # In memory, we have something like
        #    0xfc0 - 0x17bf  first[]
        #    0x17c0 - 0x1fbf second[]
        #
        # but if the original entries are still present in lldb, 
        # the beginning address of second[] will get a load address
        # of 0x1800, instead of 0x17c0 (0x1800-64) as we need to get.
        target.SetModuleLoadAddress(module, first_size - 64)
        self.expect("p/d ((int*)&first)[0]", substrs=['= 5'])
        self.expect("p/d ((int*)&second)[0]", substrs=['= 6'])
        self.assertNotEqual(first_sym.GetStartAddress().GetLoadAddress(target), 
                         first_sym.GetStartAddress().GetFileAddress())
        self.assertNotEqual(second_sym.GetStartAddress().GetLoadAddress(target),
                         second_sym.GetStartAddress().GetFileAddress())

        # Slide it back to the original vmaddr.
        target.SetModuleLoadAddress(module, 0)
        self.expect("p/d ((int*)&first)[0]", substrs=['= 5'])
        self.expect("p/d ((int*)&second)[0]", substrs=['= 6'])
        self.assertEqual(first_sym.GetStartAddress().GetLoadAddress(target), 
                         first_sym.GetStartAddress().GetFileAddress())
        self.assertEqual(second_sym.GetStartAddress().GetLoadAddress(target),
                         second_sym.GetStartAddress().GetFileAddress())