ExtractRanges.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ExtractRanges.h ------------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_DEBUGINFO_GSYM_EXTRACTRANGES_H
  14. #define LLVM_DEBUGINFO_GSYM_EXTRACTRANGES_H
  15. #include "llvm/ADT/AddressRanges.h"
  16. #include "llvm/Support/Format.h"
  17. #include "llvm/Support/raw_ostream.h"
  18. #include <stdint.h>
  19. #include <vector>
  20. #define HEX8(v) llvm::format_hex(v, 4)
  21. #define HEX16(v) llvm::format_hex(v, 6)
  22. #define HEX32(v) llvm::format_hex(v, 10)
  23. #define HEX64(v) llvm::format_hex(v, 18)
  24. namespace llvm {
  25. class DataExtractor;
  26. class raw_ostream;
  27. namespace gsym {
  28. class FileWriter;
  29. /// AddressRange objects are encoded and decoded to be relative to a base
  30. /// address. This will be the FunctionInfo's start address if the AddressRange
  31. /// is directly contained in a FunctionInfo, or a base address of the
  32. /// containing parent AddressRange or AddressRanges. This allows address
  33. /// ranges to be efficiently encoded using ULEB128 encodings as we encode the
  34. /// offset and size of each range instead of full addresses. This also makes
  35. /// encoded addresses easy to relocate as we just need to relocate one base
  36. /// address.
  37. /// @{
  38. AddressRange decodeRange(DataExtractor &Data, uint64_t BaseAddr,
  39. uint64_t &Offset);
  40. void encodeRange(const AddressRange &Range, FileWriter &O, uint64_t BaseAddr);
  41. /// @}
  42. /// Skip an address range object in the specified data a the specified
  43. /// offset.
  44. ///
  45. /// \param Data The binary stream to read the data from.
  46. ///
  47. /// \param Offset The byte offset within \a Data.
  48. void skipRange(DataExtractor &Data, uint64_t &Offset);
  49. /// Address ranges are decoded and encoded to be relative to a base address.
  50. /// See the AddressRange comment for the encode and decode methods for full
  51. /// details.
  52. /// @{
  53. void decodeRanges(AddressRanges &Ranges, DataExtractor &Data, uint64_t BaseAddr,
  54. uint64_t &Offset);
  55. void encodeRanges(const AddressRanges &Ranges, FileWriter &O,
  56. uint64_t BaseAddr);
  57. /// @}
  58. /// Skip an address range object in the specified data a the specified
  59. /// offset.
  60. ///
  61. /// \param Data The binary stream to read the data from.
  62. ///
  63. /// \param Offset The byte offset within \a Data.
  64. ///
  65. /// \returns The number of address ranges that were skipped.
  66. uint64_t skipRanges(DataExtractor &Data, uint64_t &Offset);
  67. } // namespace gsym
  68. raw_ostream &operator<<(raw_ostream &OS, const AddressRange &R);
  69. raw_ostream &operator<<(raw_ostream &OS, const AddressRanges &AR);
  70. } // namespace llvm
  71. #endif // LLVM_DEBUGINFO_GSYM_EXTRACTRANGES_H
  72. #ifdef __GNUC__
  73. #pragma GCC diagnostic pop
  74. #endif