DwarfTransformer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- DwarfTransformer.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_DWARFTRANSFORMER_H
  14. #define LLVM_DEBUGINFO_GSYM_DWARFTRANSFORMER_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/DebugInfo/GSYM/ExtractRanges.h"
  17. #include "llvm/Support/Error.h"
  18. namespace llvm {
  19. class raw_ostream;
  20. namespace gsym {
  21. struct CUInfo;
  22. struct FunctionInfo;
  23. class GsymCreator;
  24. /// A class that transforms the DWARF in a DWARFContext into GSYM information
  25. /// by populating the GsymCreator object that it is constructed with. This
  26. /// class supports converting all DW_TAG_subprogram DIEs into
  27. /// gsym::FunctionInfo objects that includes line table information and inline
  28. /// function information. Creating a separate class to transform this data
  29. /// allows this class to be unit tested.
  30. class DwarfTransformer {
  31. public:
  32. /// Create a DWARF transformer.
  33. ///
  34. /// \param D The DWARF to use when converting to GSYM.
  35. ///
  36. /// \param OS The stream to log warnings and non fatal issues to.
  37. ///
  38. /// \param G The GSYM creator to populate with the function information
  39. /// from the debug info.
  40. DwarfTransformer(DWARFContext &D, raw_ostream &OS, GsymCreator &G) :
  41. DICtx(D), Log(OS), Gsym(G) {}
  42. /// Extract the DWARF from the supplied object file and convert it into the
  43. /// Gsym format in the GsymCreator object that is passed in. Returns an
  44. /// error if something fatal is encountered.
  45. ///
  46. /// \returns An error indicating any fatal issues that happen when parsing
  47. /// the DWARF, or Error::success() if all goes well.
  48. llvm::Error convert(uint32_t NumThreads);
  49. llvm::Error verify(StringRef GsymPath);
  50. private:
  51. /// Parse the DWARF in the object file and convert it into the GsymCreator.
  52. Error parse();
  53. /// Handle any DIE (debug info entry) from the DWARF.
  54. ///
  55. /// This function will find all DW_TAG_subprogram DIEs that convert them into
  56. /// GSYM FuntionInfo objects and add them to the GsymCreator supplied during
  57. /// construction. The DIE and all its children will be recursively parsed
  58. /// with calls to this function.
  59. ///
  60. /// \param Strm The thread specific log stream for any non fatal errors and
  61. /// warnings. Once a thread has finished parsing an entire compile unit, all
  62. /// information in this temporary stream will be forwarded to the member
  63. /// variable log. This keeps logging thread safe.
  64. ///
  65. /// \param CUI The compile unit specific information that contains the DWARF
  66. /// line table, cached file list, and other compile unit specific
  67. /// information.
  68. ///
  69. /// \param Die The DWARF debug info entry to parse.
  70. void handleDie(raw_ostream &Strm, CUInfo &CUI, DWARFDie Die);
  71. DWARFContext &DICtx;
  72. raw_ostream &Log;
  73. GsymCreator &Gsym;
  74. friend class DwarfTransformerTest;
  75. };
  76. } // namespace gsym
  77. } // namespace llvm
  78. #endif // LLVM_DEBUGINFO_GSYM_DWARFTRANSFORMER_H
  79. #ifdef __GNUC__
  80. #pragma GCC diagnostic pop
  81. #endif