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) && \ |
| 8 | defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) && \ |
| 9 | defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 10 | |
| 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 Prichard | 0cff857 | 2020-09-16 01:22:55 -0700 | [diff] [blame^] | 19 | #define kTextSegmentLength 0xFF |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 20 | |
| 21 | using namespace libunwind; |
| 22 | |
| 23 | int 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 Prichard | 0cff857 | 2020-09-16 01:22:55 -0700 | [diff] [blame^] | 35 | UIS.text_segment_length = kTextSegmentLength; |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 36 | 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 Prichard | 0cff857 | 2020-09-16 01:22:55 -0700 | [diff] [blame^] | 61 | UIS.dso_base = kBaseAddr + (kTextSegmentLength * i); |
Sterling Augustine | 2e9018a | 2020-03-10 12:03:24 -0700 | [diff] [blame] | 62 | 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 Prichard | 7629c30 | 2020-08-27 23:46:49 -0700 | [diff] [blame] | 70 | |
Sterling Augustine | 157d5f8 | 2020-03-12 18:12:52 -0700 | [diff] [blame] | 71 | #else |
| 72 | int main() { return 0;} |
| 73 | #endif |