1 //===----- DebugUtils.h - Utilities for debugging ORC JITs ------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Utilities for debugging ORC-based JITs. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H 14 #define LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H 15 16 #include "llvm/Support/Error.h" 17 #include <memory> 18 #include <string> 19 20 namespace llvm { 21 22 class MemoryBuffer; 23 24 namespace orc { 25 26 /// A function object that can be used as an ObjectTransformLayer transform 27 /// to dump object files to disk at a specified path. 28 class DumpObjects { 29 public: 30 /// Construct a DumpObjects transform that will dump objects to disk. 31 /// 32 /// @param DumpDir specifies the path to write dumped objects to. DumpDir may 33 /// be empty, in which case files will be dumped to the working directory. If 34 /// DumpDir is non-empty then any trailing separators will be discarded. 35 /// 36 /// @param IdentifierOverride specifies a file name stem to use when dumping 37 /// objects. If empty, each MemoryBuffer's identifier will be used (with a .o 38 /// suffix added if not already present). If an identifier override is 39 /// supplied it will be used instead (since all buffers will use the same 40 /// identifier, the resulting files will be named <ident>.o, <ident>.2.o, 41 /// <ident>.3.o, and so on). IdentifierOverride should not contain an 42 /// extension, as a .o suffix will be added by DumpObjects. 43 DumpObjects(std::string DumpDir = "", std::string IdentifierOverride = ""); 44 45 /// Dumps the given buffer to disk. 46 Expected<std::unique_ptr<MemoryBuffer>> 47 operator()(std::unique_ptr<MemoryBuffer> Obj); 48 49 private: 50 StringRef getBufferIdentifier(MemoryBuffer &B); 51 std::string DumpDir; 52 std::string IdentifierOverride; 53 }; 54 55 } // End namespace orc 56 } // End namespace llvm 57 58 #endif // LLVM_EXECUTIONENGINE_ORC_DEBUGUTILS_H 59