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. 6 7 #if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \ 8 defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) && \ 9 defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE) 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 19 #define kDwarfSectionLength 0xFF 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; 35 UIS.dwarf_section_length = kDwarfSectionLength; 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++) { 61 UIS.dso_base = kBaseAddr + (kDwarfSectionLength * i); 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 } 70 71 #else 72 int main() { return 0;} 73 #endif 74