blob: 6b648e72849149ef23f4bf2bbb9142a949b3edd6 [file] [log] [blame]
Louis Dionnecb96c632022-04-03 08:55:57 -04001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
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
7//
8//===----------------------------------------------------------------------===//
9
Sterling Augustine2e9018a2020-03-10 12:03:24 -070010// The other libunwind tests don't test internal interfaces, so the include path
11// is a little wonky.
12#include "../src/config.h"
13
14// Only run this test under supported configurations.
Sterling Augustine157d5f82020-03-12 18:12:52 -070015
Ryan Prichard7629c302020-08-27 23:46:49 -070016#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \
Ryan Prichard7629c302020-08-27 23:46:49 -070017 defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
Sterling Augustine2e9018a2020-03-10 12:03:24 -070018
19#include <link.h>
20#include <stdio.h>
21
22// This file defines several of the data structures needed here,
23// and includes FrameHeaderCache.hpp as well.
24#include "../src/AddressSpace.hpp"
25
26#define kBaseAddr 0xFFF000
Ryan Prichard0cff8572020-09-16 01:22:55 -070027#define kTextSegmentLength 0xFF
Sterling Augustine2e9018a2020-03-10 12:03:24 -070028
29using namespace libunwind;
30
Louis Dionnecbfe0172020-10-08 13:36:33 -040031int main(int, char**) {
Sterling Augustine2e9018a2020-03-10 12:03:24 -070032 FrameHeaderCache FHC;
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.
38 PInfo.dlpi_adds = 6;
39 PInfo.dlpi_subs = 7;
40
41 UnwindInfoSections UIS;
42 UIS.dso_base = kBaseAddr;
Ryan Prichard0cff8572020-09-16 01:22:55 -070043 UIS.text_segment_length = kTextSegmentLength;
Sterling Augustine2e9018a2020-03-10 12:03:24 -070044 dl_iterate_cb_data CBData;
45 // Unused by the cache.
46 CBData.addressSpace = nullptr;
47 CBData.sects = &UIS;
48 CBData.targetAddr = kBaseAddr + 1;
49
50 // Nothing present, shouldn't find.
51 if (FHC.find(&PInfo, 0, &CBData))
52 abort();
53 FHC.add(&UIS);
54 // Just added. Should find.
55 if (!FHC.find(&PInfo, 0, &CBData))
56 abort();
57 // Cache is invalid. Shouldn't find.
58 PInfo.dlpi_adds++;
59 if (FHC.find(&PInfo, 0, &CBData))
60 abort();
61
62 FHC.add(&UIS);
63 CBData.targetAddr = kBaseAddr - 1;
64 // Shouldn't find something outside of the addresses.
65 if (FHC.find(&PInfo, 0, &CBData))
66 abort();
67 // Add enough things to the cache that the entry is evicted.
68 for (int i = 0; i < 9; i++) {
Ryan Prichard0cff8572020-09-16 01:22:55 -070069 UIS.dso_base = kBaseAddr + (kTextSegmentLength * i);
Sterling Augustine2e9018a2020-03-10 12:03:24 -070070 FHC.add(&UIS);
71 }
72 CBData.targetAddr = kBaseAddr;
73 // Should have been evicted.
74 if (FHC.find(&PInfo, 0, &CBData))
75 abort();
76 return 0;
77}
Ryan Prichard7629c302020-08-27 23:46:49 -070078
Sterling Augustine157d5f82020-03-12 18:12:52 -070079#else
Louis Dionnecbfe0172020-10-08 13:36:33 -040080int main(int, char**) { return 0;}
Sterling Augustine157d5f82020-03-12 18:12:52 -070081#endif