blob: ac75f7d0cb29e572d225cef38ebf49805588cd2a [file] [log] [blame]
Sterling Augustine2e9018a2020-03-10 12:03:24 -07001// The other libunwind tests don't test internal interfaces, so the include path
2// is a little wonky.
3#include "../src/config.h"
4
5// Only run this test under supported configurations.
6// This #if chain is ugly, but see the comments in AddressSpace.hpp for
7// the reasoning.
8
9#ifdef __APPLE__
10int main() { return 0; }
11#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL)
12int main() { return 0; }
13#elif defined(_LIBUNWIND_ARM_EHABI) && defined(_LIBUNWIND_IS_BAREMETAL)
14int main() { return 0; }
15#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32)
16int main() { return 0; }
17#elif defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)
18int main() { return 0; }
19#elif defined(_LIBUNWIND_ARM_EHABI) && defined(__BIONIC__)
20int main() { return 0; }
21#elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
22
23#include <link.h>
24#include <stdio.h>
25
26// This file defines several of the data structures needed here,
27// and includes FrameHeaderCache.hpp as well.
28#include "../src/AddressSpace.hpp"
29
30#define kBaseAddr 0xFFF000
31#define kDwarfSectionLength 0xFF
32
33using namespace libunwind;
34
35int main() {
36 FrameHeaderCache FHC;
37 struct dl_phdr_info PInfo;
38 memset(&PInfo, 0, sizeof(PInfo));
39 // The cache itself should only care about these two fields--they
40 // tell the cache to invalidate or not; everything else is handled
41 // by AddressSpace.hpp.
42 PInfo.dlpi_adds = 6;
43 PInfo.dlpi_subs = 7;
44
45 UnwindInfoSections UIS;
46 UIS.dso_base = kBaseAddr;
47 UIS.dwarf_section_length = kDwarfSectionLength;
48 dl_iterate_cb_data CBData;
49 // Unused by the cache.
50 CBData.addressSpace = nullptr;
51 CBData.sects = &UIS;
52 CBData.targetAddr = kBaseAddr + 1;
53
54 // Nothing present, shouldn't find.
55 if (FHC.find(&PInfo, 0, &CBData))
56 abort();
57 FHC.add(&UIS);
58 // Just added. Should find.
59 if (!FHC.find(&PInfo, 0, &CBData))
60 abort();
61 // Cache is invalid. Shouldn't find.
62 PInfo.dlpi_adds++;
63 if (FHC.find(&PInfo, 0, &CBData))
64 abort();
65
66 FHC.add(&UIS);
67 CBData.targetAddr = kBaseAddr - 1;
68 // Shouldn't find something outside of the addresses.
69 if (FHC.find(&PInfo, 0, &CBData))
70 abort();
71 // Add enough things to the cache that the entry is evicted.
72 for (int i = 0; i < 9; i++) {
73 UIS.dso_base = kBaseAddr + (kDwarfSectionLength * i);
74 FHC.add(&UIS);
75 }
76 CBData.targetAddr = kBaseAddr;
77 // Should have been evicted.
78 if (FHC.find(&PInfo, 0, &CBData))
79 abort();
80 return 0;
81}
82#endif