blob: ebbc00464e0727b63d7e556acb82f448c41a1d23 [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.
Sterling Augustine157d5f82020-03-12 18:12:52 -07006// The frame header cache should work fine for other architectures,
7// but the #ifdefs end up being even more complicated than this.
8
Sterling Augustineb778c912020-08-18 12:05:07 -07009#if defined(__x86_64__) && defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
Sterling Augustine157d5f82020-03-12 18:12:52 -070010
Sterling Augustine2e9018a2020-03-10 12:03:24 -070011// This #if chain is ugly, but see the comments in AddressSpace.hpp for
12// the reasoning.
13
14#ifdef __APPLE__
15int main() { return 0; }
16#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL)
17int main() { return 0; }
18#elif defined(_LIBUNWIND_ARM_EHABI) && defined(_LIBUNWIND_IS_BAREMETAL)
19int main() { return 0; }
20#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_WIN32)
21int main() { return 0; }
22#elif defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)
23int main() { return 0; }
24#elif defined(_LIBUNWIND_ARM_EHABI) && defined(__BIONIC__)
25int main() { return 0; }
26#elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
27
28#include <link.h>
29#include <stdio.h>
30
31// This file defines several of the data structures needed here,
32// and includes FrameHeaderCache.hpp as well.
33#include "../src/AddressSpace.hpp"
34
35#define kBaseAddr 0xFFF000
36#define kDwarfSectionLength 0xFF
37
38using namespace libunwind;
39
40int main() {
41 FrameHeaderCache FHC;
42 struct dl_phdr_info PInfo;
43 memset(&PInfo, 0, sizeof(PInfo));
44 // The cache itself should only care about these two fields--they
45 // tell the cache to invalidate or not; everything else is handled
46 // by AddressSpace.hpp.
47 PInfo.dlpi_adds = 6;
48 PInfo.dlpi_subs = 7;
49
50 UnwindInfoSections UIS;
51 UIS.dso_base = kBaseAddr;
52 UIS.dwarf_section_length = kDwarfSectionLength;
53 dl_iterate_cb_data CBData;
54 // Unused by the cache.
55 CBData.addressSpace = nullptr;
56 CBData.sects = &UIS;
57 CBData.targetAddr = kBaseAddr + 1;
58
59 // Nothing present, shouldn't find.
60 if (FHC.find(&PInfo, 0, &CBData))
61 abort();
62 FHC.add(&UIS);
63 // Just added. Should find.
64 if (!FHC.find(&PInfo, 0, &CBData))
65 abort();
66 // Cache is invalid. Shouldn't find.
67 PInfo.dlpi_adds++;
68 if (FHC.find(&PInfo, 0, &CBData))
69 abort();
70
71 FHC.add(&UIS);
72 CBData.targetAddr = kBaseAddr - 1;
73 // Shouldn't find something outside of the addresses.
74 if (FHC.find(&PInfo, 0, &CBData))
75 abort();
76 // Add enough things to the cache that the entry is evicted.
77 for (int i = 0; i < 9; i++) {
78 UIS.dso_base = kBaseAddr + (kDwarfSectionLength * i);
79 FHC.add(&UIS);
80 }
81 CBData.targetAddr = kBaseAddr;
82 // Should have been evicted.
83 if (FHC.find(&PInfo, 0, &CBData))
84 abort();
85 return 0;
86}
Sterling Augustine4ee0e982020-03-12 11:52:13 -070087#else
88int main() { return 0; }
Sterling Augustine2e9018a2020-03-10 12:03:24 -070089#endif
Sterling Augustine157d5f82020-03-12 18:12:52 -070090#else
91int main() { return 0;}
92#endif