blob: 9abff5e8cda9a429ffef3c3b313c6238e5109446 [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) && \
Ryan Prichard7629c302020-08-27 23:46:49 -07008 defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
Sterling Augustine2e9018a2020-03-10 12:03:24 -07009
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
Ryan Prichard0cff8572020-09-16 01:22:55 -070018#define kTextSegmentLength 0xFF
Sterling Augustine2e9018a2020-03-10 12:03:24 -070019
20using namespace libunwind;
21
Louis Dionnecbfe0172020-10-08 13:36:33 -040022int main(int, char**) {
Sterling Augustine2e9018a2020-03-10 12:03:24 -070023 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;
Ryan Prichard0cff8572020-09-16 01:22:55 -070034 UIS.text_segment_length = kTextSegmentLength;
Sterling Augustine2e9018a2020-03-10 12:03:24 -070035 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++) {
Ryan Prichard0cff8572020-09-16 01:22:55 -070060 UIS.dso_base = kBaseAddr + (kTextSegmentLength * i);
Sterling Augustine2e9018a2020-03-10 12:03:24 -070061 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}
Ryan Prichard7629c302020-08-27 23:46:49 -070069
Sterling Augustine157d5f82020-03-12 18:12:52 -070070#else
Louis Dionnecbfe0172020-10-08 13:36:33 -040071int main(int, char**) { return 0;}
Sterling Augustine157d5f82020-03-12 18:12:52 -070072#endif