DebugUtils.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===----- DebugUtils.h - Utilities for debugging ORC JITs ------*- 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. //
  14. // Utilities for debugging ORC-based JITs.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H
  18. #define LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H
  19. #include "llvm/ADT/ArrayRef.h"
  20. #include "llvm/ExecutionEngine/Orc/Core.h"
  21. #include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
  22. #include "llvm/Support/Error.h"
  23. #include "llvm/Support/raw_ostream.h"
  24. #include <memory>
  25. #include <string>
  26. namespace llvm {
  27. class MemoryBuffer;
  28. namespace orc {
  29. // --raw_ostream operators for ORC types--
  30. /// Render a SymbolStringPtr.
  31. raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPtr &Sym);
  32. /// Render a SymbolNameSet.
  33. raw_ostream &operator<<(raw_ostream &OS, const SymbolNameSet &Symbols);
  34. /// Render a SymbolNameVector.
  35. raw_ostream &operator<<(raw_ostream &OS, const SymbolNameVector &Symbols);
  36. /// Render an array of SymbolStringPtrs.
  37. raw_ostream &operator<<(raw_ostream &OS, ArrayRef<SymbolStringPtr> Symbols);
  38. /// Render JITSymbolFlags.
  39. raw_ostream &operator<<(raw_ostream &OS, const JITSymbolFlags &Flags);
  40. /// Render a SymbolFlagsMap entry.
  41. raw_ostream &operator<<(raw_ostream &OS, const SymbolFlagsMap::value_type &KV);
  42. /// Render a SymbolMap entry.
  43. raw_ostream &operator<<(raw_ostream &OS, const SymbolMap::value_type &KV);
  44. /// Render a SymbolFlagsMap.
  45. raw_ostream &operator<<(raw_ostream &OS, const SymbolFlagsMap &SymbolFlags);
  46. /// Render a SymbolMap.
  47. raw_ostream &operator<<(raw_ostream &OS, const SymbolMap &Symbols);
  48. /// Render a SymbolDependenceMap entry.
  49. raw_ostream &operator<<(raw_ostream &OS,
  50. const SymbolDependenceMap::value_type &KV);
  51. /// Render a SymbolDependendeMap.
  52. raw_ostream &operator<<(raw_ostream &OS, const SymbolDependenceMap &Deps);
  53. /// Render a MaterializationUnit.
  54. raw_ostream &operator<<(raw_ostream &OS, const MaterializationUnit &MU);
  55. //// Render a JITDylibLookupFlags instance.
  56. raw_ostream &operator<<(raw_ostream &OS,
  57. const JITDylibLookupFlags &JDLookupFlags);
  58. /// Rendar a SymbolLookupFlags instance.
  59. raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupFlags &LookupFlags);
  60. /// Render a SymbolLookupSet entry.
  61. raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupSet::value_type &KV);
  62. /// Render a SymbolLookupSet.
  63. raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupSet &LookupSet);
  64. /// Render a JITDylibSearchOrder.
  65. raw_ostream &operator<<(raw_ostream &OS,
  66. const JITDylibSearchOrder &SearchOrder);
  67. /// Render a SymbolAliasMap.
  68. raw_ostream &operator<<(raw_ostream &OS, const SymbolAliasMap &Aliases);
  69. /// Render a SymbolState.
  70. raw_ostream &operator<<(raw_ostream &OS, const SymbolState &S);
  71. /// Render a LookupKind.
  72. raw_ostream &operator<<(raw_ostream &OS, const LookupKind &K);
  73. /// Dump a SymbolStringPool. Useful for debugging dangling-pointer crashes.
  74. raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPool &SSP);
  75. /// A function object that can be used as an ObjectTransformLayer transform
  76. /// to dump object files to disk at a specified path.
  77. class DumpObjects {
  78. public:
  79. /// Construct a DumpObjects transform that will dump objects to disk.
  80. ///
  81. /// @param DumpDir specifies the path to write dumped objects to. DumpDir may
  82. /// be empty, in which case files will be dumped to the working directory. If
  83. /// DumpDir is non-empty then any trailing separators will be discarded.
  84. ///
  85. /// @param IdentifierOverride specifies a file name stem to use when dumping
  86. /// objects. If empty, each MemoryBuffer's identifier will be used (with a .o
  87. /// suffix added if not already present). If an identifier override is
  88. /// supplied it will be used instead (since all buffers will use the same
  89. /// identifier, the resulting files will be named <ident>.o, <ident>.2.o,
  90. /// <ident>.3.o, and so on). IdentifierOverride should not contain an
  91. /// extension, as a .o suffix will be added by DumpObjects.
  92. DumpObjects(std::string DumpDir = "", std::string IdentifierOverride = "");
  93. /// Dumps the given buffer to disk.
  94. Expected<std::unique_ptr<MemoryBuffer>>
  95. operator()(std::unique_ptr<MemoryBuffer> Obj);
  96. private:
  97. StringRef getBufferIdentifier(MemoryBuffer &B);
  98. std::string DumpDir;
  99. std::string IdentifierOverride;
  100. };
  101. } // End namespace orc
  102. } // End namespace llvm
  103. #endif // LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H
  104. #ifdef __GNUC__
  105. #pragma GCC diagnostic pop
  106. #endif