frameheadercache_test.pass.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // Only run this test under supported configurations.
  5. #if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && \
  6. defined(_LIBUNWIND_USE_FRAME_HEADER_CACHE)
  7. #include <link.h>
  8. #include <stdio.h>
  9. // This file defines several of the data structures needed here,
  10. // and includes FrameHeaderCache.hpp as well.
  11. #include "../src/AddressSpace.hpp"
  12. #define kBaseAddr 0xFFF000
  13. #define kTextSegmentLength 0xFF
  14. using namespace libunwind;
  15. int main(int, char**) {
  16. FrameHeaderCache FHC;
  17. struct dl_phdr_info PInfo;
  18. memset(&PInfo, 0, sizeof(PInfo));
  19. // The cache itself should only care about these two fields--they
  20. // tell the cache to invalidate or not; everything else is handled
  21. // by AddressSpace.hpp.
  22. PInfo.dlpi_adds = 6;
  23. PInfo.dlpi_subs = 7;
  24. UnwindInfoSections UIS;
  25. UIS.dso_base = kBaseAddr;
  26. UIS.text_segment_length = kTextSegmentLength;
  27. dl_iterate_cb_data CBData;
  28. // Unused by the cache.
  29. CBData.addressSpace = nullptr;
  30. CBData.sects = &UIS;
  31. CBData.targetAddr = kBaseAddr + 1;
  32. // Nothing present, shouldn't find.
  33. if (FHC.find(&PInfo, 0, &CBData))
  34. abort();
  35. FHC.add(&UIS);
  36. // Just added. Should find.
  37. if (!FHC.find(&PInfo, 0, &CBData))
  38. abort();
  39. // Cache is invalid. Shouldn't find.
  40. PInfo.dlpi_adds++;
  41. if (FHC.find(&PInfo, 0, &CBData))
  42. abort();
  43. FHC.add(&UIS);
  44. CBData.targetAddr = kBaseAddr - 1;
  45. // Shouldn't find something outside of the addresses.
  46. if (FHC.find(&PInfo, 0, &CBData))
  47. abort();
  48. // Add enough things to the cache that the entry is evicted.
  49. for (int i = 0; i < 9; i++) {
  50. UIS.dso_base = kBaseAddr + (kTextSegmentLength * i);
  51. FHC.add(&UIS);
  52. }
  53. CBData.targetAddr = kBaseAddr;
  54. // Should have been evicted.
  55. if (FHC.find(&PInfo, 0, &CBData))
  56. abort();
  57. return 0;
  58. }
  59. #else
  60. int main(int, char**) { return 0;}
  61. #endif