From 94ec0b6c5ab8b5cd2f418f872ae2bbb2be3c550e Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Mon, 7 Mar 2022 16:38:52 -0800 Subject: Change "target.save-jit-objects" to "target.save-jit-objects-dir". The old command wrote to CWD, which doesn't always work, and if it didn't, there was no workaround (and it crashed on failure). This patch changed the setting to provide a directory to save the objects to. Differential Revision: https://reviews.llvm.org/D121036 --- lldb/source/Expression/IRExecutionUnit.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'lldb/source/Expression/IRExecutionUnit.cpp') diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index 92c91deb46e9..91b92f1ba300 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -21,6 +21,7 @@ #include "lldb/Core/Module.h" #include "lldb/Core/Section.h" #include "lldb/Expression/IRExecutionUnit.h" +#include "lldb/Host/HostInfo.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/SymbolFile.h" @@ -306,27 +307,37 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr, class ObjectDumper : public llvm::ObjectCache { public: + ObjectDumper(FileSpec output_dir) : m_out_dir(output_dir) {} void notifyObjectCompiled(const llvm::Module *module, llvm::MemoryBufferRef object) override { int fd = 0; llvm::SmallVector result_path; std::string object_name_model = "jit-object-" + module->getModuleIdentifier() + "-%%%.o"; - (void)llvm::sys::fs::createUniqueFile(object_name_model, fd, result_path); - llvm::raw_fd_ostream fds(fd, true); - fds.write(object.getBufferStart(), object.getBufferSize()); + FileSpec model_spec + = m_out_dir.CopyByAppendingPathComponent(object_name_model); + std::string model_path = model_spec.GetPath(); + + std::error_code result + = llvm::sys::fs::createUniqueFile(model_path, fd, result_path); + if (!result) { + llvm::raw_fd_ostream fds(fd, true); + fds.write(object.getBufferStart(), object.getBufferSize()); + } } - std::unique_ptr - getObject(const llvm::Module *module) override { + getObject(const llvm::Module *module) override { // Return nothing - we're just abusing the object-cache mechanism to dump // objects. return nullptr; - } + } + private: + FileSpec m_out_dir; }; - if (process_sp->GetTarget().GetEnableSaveObjects()) { - m_object_cache_up = std::make_unique(); + FileSpec save_objects_dir = process_sp->GetTarget().GetSaveJITObjectsDir(); + if (save_objects_dir) { + m_object_cache_up = std::make_unique(save_objects_dir); m_execution_engine_up->setObjectCache(m_object_cache_up.get()); } -- cgit v1.2.3