diff options
| author | Jim Ingham <jingham@apple.com> | 2022-03-07 16:38:52 -0800 |
|---|---|---|
| committer | Jim Ingham <jingham@apple.com> | 2022-03-07 17:44:51 -0800 |
| commit | 94ec0b6c5ab8b5cd2f418f872ae2bbb2be3c550e (patch) | |
| tree | 2ec191e18ee79574ec5266b1666898b32689e5c1 /lldb/source/Expression/IRExecutionUnit.cpp | |
| parent | a7adf7b9e9ffa7de9d90152ecf6430b800d2ca11 (diff) | |
| download | llvm-94ec0b6c5ab8b5cd2f418f872ae2bbb2be3c550e.tar.gz llvm-94ec0b6c5ab8b5cd2f418f872ae2bbb2be3c550e.tar.bz2 llvm-94ec0b6c5ab8b5cd2f418f872ae2bbb2be3c550e.zip | |
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
Diffstat (limited to 'lldb/source/Expression/IRExecutionUnit.cpp')
| -rw-r--r-- | lldb/source/Expression/IRExecutionUnit.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
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<char, 256> 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<llvm::MemoryBuffer> - 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<ObjectDumper>(); + FileSpec save_objects_dir = process_sp->GetTarget().GetSaveJITObjectsDir(); + if (save_objects_dir) { + m_object_cache_up = std::make_unique<ObjectDumper>(save_objects_dir); m_execution_engine_up->setObjectCache(m_object_cache_up.get()); } |
