diff options
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/Expression/IRExecutionUnit.cpp | 27 | ||||
-rw-r--r-- | lldb/source/Target/Target.cpp | 9 |
2 files changed, 36 insertions, 0 deletions
diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index 3500530ae34..dbc9b03fd19 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/ObjectCache.h" #include "llvm/IR/Constants.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" @@ -306,6 +307,32 @@ void IRExecutionUnit::GetRunnableInfo(Error &error, lldb::addr_t &func_addr, return; } + class ObjectDumper : public llvm::ObjectCache { + public: + 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()); + } + + std::unique_ptr<llvm::MemoryBuffer> + getObject(const llvm::Module *module) override { + // Return nothing - we're just abusing the object-cache mechanism to dump + // objects. + return nullptr; + } + }; + + if (process_sp->GetTarget().GetEnableSaveObjects()) { + m_object_cache_ap = llvm::make_unique<ObjectDumper>(); + m_execution_engine_ap->setObjectCache(m_object_cache_ap.get()); + } + // Make sure we see all sections, including ones that don't have // relocations... m_execution_engine_ap->setProcessAllSections(true); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index ee7eab71c6a..f4a91192cfd 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -3246,6 +3246,8 @@ static PropertyDefinition g_properties[] = { nullptr, "Automatically apply fix-it hints to expressions."}, {"notify-about-fixits", OptionValue::eTypeBoolean, false, true, nullptr, nullptr, "Print the fixed expression text."}, + {"save-jit-objects", OptionValue::eTypeBoolean, false, false, nullptr, + nullptr, "Save intermediate object files generated by the LLVM JIT"}, {"max-children-count", OptionValue::eTypeSInt64, false, 256, nullptr, nullptr, "Maximum number of children to expand in any level of depth."}, {"max-string-summary-length", OptionValue::eTypeSInt64, false, 1024, @@ -3370,6 +3372,7 @@ enum { ePropertyAutoImportClangModules, ePropertyAutoApplyFixIts, ePropertyNotifyAboutFixIts, + ePropertySaveObjects, ePropertyMaxChildrenCount, ePropertyMaxSummaryLength, ePropertyMaxMemReadSize, @@ -3788,6 +3791,12 @@ bool TargetProperties::GetEnableNotifyAboutFixIts() const { nullptr, idx, g_properties[idx].default_uint_value != 0); } +bool TargetProperties::GetEnableSaveObjects() const { + const uint32_t idx = ePropertySaveObjects; + return m_collection_sp->GetPropertyAtIndexAsBoolean( + nullptr, idx, g_properties[idx].default_uint_value != 0); +} + bool TargetProperties::GetEnableSyntheticValue() const { const uint32_t idx = ePropertyEnableSynthetic; return m_collection_sp->GetPropertyAtIndexAsBoolean( |