2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 // The other libunwind tests don't test internal interfaces, so the include path
12 #include "../src/config.h"
14 // Only run this test under supported configurations.
16 #if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \
17 defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
22 // This file defines several of the data structures needed here,
23 // and includes FrameHeaderCache.hpp as well.
24 #include "../src/AddressSpace.hpp"
26 #define kBaseAddr 0xFFF000
27 #define kTextSegmentLength 0xFF
29 using namespace libunwind
;
31 int main(int, char**) {
33 struct dl_phdr_info PInfo
;
34 memset(&PInfo
, 0, sizeof(PInfo
));
35 // The cache itself should only care about these two fields--they
36 // tell the cache to invalidate or not; everything else is handled
37 // by AddressSpace.hpp.
41 UnwindInfoSections UIS
;
42 UIS
.dso_base
= kBaseAddr
;
43 UIS
.text_segment_length
= kTextSegmentLength
;
44 dl_iterate_cb_data CBData
;
45 // Unused by the cache.
46 CBData
.addressSpace
= nullptr;
48 CBData
.targetAddr
= kBaseAddr
+ 1;
50 // Nothing present, shouldn't find.
51 if (FHC
.find(&PInfo
, 0, &CBData
))
54 // Just added. Should find.
55 if (!FHC
.find(&PInfo
, 0, &CBData
))
57 // Cache is invalid. Shouldn't find.
59 if (FHC
.find(&PInfo
, 0, &CBData
))
63 CBData
.targetAddr
= kBaseAddr
- 1;
64 // Shouldn't find something outside of the addresses.
65 if (FHC
.find(&PInfo
, 0, &CBData
))
67 // Add enough things to the cache that the entry is evicted.
68 for (int i
= 0; i
< 9; i
++) {
69 UIS
.dso_base
= kBaseAddr
+ (kTextSegmentLength
* i
);
72 CBData
.targetAddr
= kBaseAddr
;
73 // Should have been evicted.
74 if (FHC
.find(&PInfo
, 0, &CBData
))
80 int main(int, char**) { return 0;}