DWARFDebugAbbrev.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- DWARFDebugAbbrev.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_DWARF_DWARFDEBUGABBREV_H
  14. #define LLVM_DEBUGINFO_DWARF_DWARFDEBUGABBREV_H
  15. #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
  16. #include "llvm/Support/DataExtractor.h"
  17. #include <cstdint>
  18. #include <map>
  19. #include <vector>
  20. namespace llvm {
  21. class raw_ostream;
  22. class DWARFAbbreviationDeclarationSet {
  23. uint64_t Offset;
  24. /// Code of the first abbreviation, if all abbreviations in the set have
  25. /// consecutive codes. UINT32_MAX otherwise.
  26. uint32_t FirstAbbrCode;
  27. std::vector<DWARFAbbreviationDeclaration> Decls;
  28. using const_iterator =
  29. std::vector<DWARFAbbreviationDeclaration>::const_iterator;
  30. public:
  31. DWARFAbbreviationDeclarationSet();
  32. uint64_t getOffset() const { return Offset; }
  33. void dump(raw_ostream &OS) const;
  34. bool extract(DataExtractor Data, uint64_t *OffsetPtr);
  35. const DWARFAbbreviationDeclaration *
  36. getAbbreviationDeclaration(uint32_t AbbrCode) const;
  37. const_iterator begin() const {
  38. return Decls.begin();
  39. }
  40. const_iterator end() const {
  41. return Decls.end();
  42. }
  43. std::string getCodeRange() const;
  44. private:
  45. void clear();
  46. };
  47. class DWARFDebugAbbrev {
  48. using DWARFAbbreviationDeclarationSetMap =
  49. std::map<uint64_t, DWARFAbbreviationDeclarationSet>;
  50. mutable DWARFAbbreviationDeclarationSetMap AbbrDeclSets;
  51. mutable DWARFAbbreviationDeclarationSetMap::const_iterator PrevAbbrOffsetPos;
  52. mutable Optional<DataExtractor> Data;
  53. public:
  54. DWARFDebugAbbrev();
  55. const DWARFAbbreviationDeclarationSet *
  56. getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
  57. void dump(raw_ostream &OS) const;
  58. void parse() const;
  59. void extract(DataExtractor Data);
  60. DWARFAbbreviationDeclarationSetMap::const_iterator begin() const {
  61. parse();
  62. return AbbrDeclSets.begin();
  63. }
  64. DWARFAbbreviationDeclarationSetMap::const_iterator end() const {
  65. return AbbrDeclSets.end();
  66. }
  67. private:
  68. void clear();
  69. };
  70. } // end namespace llvm
  71. #endif // LLVM_DEBUGINFO_DWARF_DWARFDEBUGABBREV_H
  72. #ifdef __GNUC__
  73. #pragma GCC diagnostic pop
  74. #endif