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