1 // 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
7 #if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \
8 defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
9
10 #include <link.h>
11 #include <stdio.h>
12
13 // This file defines several of the data structures needed here,
14 // and includes FrameHeaderCache.hpp as well.
15 #include "../src/AddressSpace.hpp"
16
17 #define kBaseAddr 0xFFF000
18 #define kTextSegmentLength 0xFF
19
20 using namespace libunwind;
21
main(int,char **)22 int main(int, char**) {
23 FrameHeaderCache FHC;
24 struct dl_phdr_info PInfo;
25 memset(&PInfo, 0, sizeof(PInfo));
26 // The cache itself should only care about these two fields--they
27 // tell the cache to invalidate or not; everything else is handled
28 // by AddressSpace.hpp.
29 PInfo.dlpi_adds = 6;
30 PInfo.dlpi_subs = 7;
31
32 UnwindInfoSections UIS;
33 UIS.dso_base = kBaseAddr;
34 UIS.text_segment_length = kTextSegmentLength;
35 dl_iterate_cb_data CBData;
36 // Unused by the cache.
37 CBData.addressSpace = nullptr;
38 CBData.sects = &UIS;
39 CBData.targetAddr = kBaseAddr + 1;
40
41 // Nothing present, shouldn't find.
42 if (FHC.find(&PInfo, 0, &CBData))
43 abort();
44 FHC.add(&UIS);
45 // Just added. Should find.
46 if (!FHC.find(&PInfo, 0, &CBData))
47 abort();
48 // Cache is invalid. Shouldn't find.
49 PInfo.dlpi_adds++;
50 if (FHC.find(&PInfo, 0, &CBData))
51 abort();
52
53 FHC.add(&UIS);
54 CBData.targetAddr = kBaseAddr - 1;
55 // Shouldn't find something outside of the addresses.
56 if (FHC.find(&PInfo, 0, &CBData))
57 abort();
58 // Add enough things to the cache that the entry is evicted.
59 for (int i = 0; i < 9; i++) {
60 UIS.dso_base = kBaseAddr + (kTextSegmentLength * i);
61 FHC.add(&UIS);
62 }
63 CBData.targetAddr = kBaseAddr;
64 // Should have been evicted.
65 if (FHC.find(&PInfo, 0, &CBData))
66 abort();
67 return 0;
68 }
69
70 #else
main(int,char **)71 int main(int, char**) { return 0;}
72 #endif
73