Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 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. |
Sterling Augustine | 157d5f8 | 2020-03-12 18:12:52 -0700 | [diff] [blame] | 6 | |
Ryan Prichard | 7629c30 | 2020-08-27 23:46:49 -0700 | [diff] [blame] | 7 | #if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \ |
Ryan Prichard | 7629c30 | 2020-08-27 23:46:49 -0700 | [diff] [blame] | 8 | defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 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 |
Ryan Prichard | 0cff857 | 2020-09-16 01:22:55 -0700 | [diff] [blame] | 18 | #define kTextSegmentLength 0xFF |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 19 | |
| 20 | using namespace libunwind; |
| 21 | |
Louis Dionne | cbfe017 | 2020-10-08 13:36:33 -0400 | [diff] [blame] | 22 | int main(int, char**) { |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 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; |
Ryan Prichard | 0cff857 | 2020-09-16 01:22:55 -0700 | [diff] [blame] | 34 | UIS.text_segment_length = kTextSegmentLength; |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 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++) { |
Ryan Prichard | 0cff857 | 2020-09-16 01:22:55 -0700 | [diff] [blame] | 60 | UIS.dso_base = kBaseAddr + (kTextSegmentLength * i); |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 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 | } |
Ryan Prichard | 7629c30 | 2020-08-27 23:46:49 -0700 | [diff] [blame] | 69 | |
Sterling Augustine | 157d5f8 | 2020-03-12 18:12:52 -0700 | [diff] [blame] | 70 | #else |
Louis Dionne | cbfe017 | 2020-10-08 13:36:33 -0400 | [diff] [blame] | 71 | int main(int, char**) { return 0;} |
Sterling Augustine | 157d5f8 | 2020-03-12 18:12:52 -0700 | [diff] [blame] | 72 | #endif |