diff --git a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h --- a/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h +++ b/mlir/include/mlir/ExecutionEngine/ExecutionEngine.h @@ -26,6 +26,7 @@ template class Expected; class Module; class ExecutionEngine; +class JITEventListener; class MemoryBuffer; } // namespace llvm @@ -97,15 +98,18 @@ void dumpToObjectFile(StringRef filename); private: - // Ordering of llvmContext and jit is important for destruction purposes: the - // jit must be destroyed before the context. + /// Ordering of llvmContext and jit is important for destruction purposes: the + /// jit must be destroyed before the context. llvm::LLVMContext llvmContext; - // Underlying LLJIT. + /// Underlying LLJIT. std::unique_ptr jit; - // Underlying cache. + /// Underlying cache. std::unique_ptr cache; + + /// GDB notification listener. + llvm::JITEventListener *gdbListener; }; template diff --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp --- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp @@ -18,6 +18,7 @@ #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/Bitcode/BitcodeWriter.h" +#include "llvm/ExecutionEngine/JITEventListener.h" #include "llvm/ExecutionEngine/ObjectCache.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h" @@ -182,7 +183,8 @@ } ExecutionEngine::ExecutionEngine(bool enableObjectCache) - : cache(enableObjectCache ? nullptr : new SimpleObjectCache()) {} + : cache(enableObjectCache ? nullptr : new SimpleObjectCache()), + gdbListener(llvm::JITEventListener::createGDBRegistrationListener()) {} Expected> ExecutionEngine::create( ModuleOp m, std::function transformer, @@ -221,6 +223,14 @@ const Triple &TT) { auto objectLayer = std::make_unique( session, []() { return std::make_unique(); }); + objectLayer->setNotifyLoaded( + [engine = engine.get()]( + llvm::orc::VModuleKey, const llvm::object::ObjectFile &object, + const llvm::RuntimeDyld::LoadedObjectInfo &objectInfo) { + uint64_t key = static_cast( + reinterpret_cast(object.getData().data())); + engine->gdbListener->notifyObjectLoaded(key, object, objectInfo); + }); auto dataLayout = deserModule->getDataLayout(); llvm::orc::JITDylib *mainJD = session.getJITDylibByName("
"); if (!mainJD)