1 //===-- IRExecutionUnit.cpp -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ExecutionEngine/ExecutionEngine.h"
11 #include "llvm/IR/LLVMContext.h"
12 #include "llvm/IR/Module.h"
13 #include "llvm/Support/SourceMgr.h"
14 #include "llvm/Support/raw_ostream.h"
16 #include "lldb/Core/DataBufferHeap.h"
17 #include "lldb/Core/DataExtractor.h"
18 #include "lldb/Core/Debugger.h"
19 #include "lldb/Core/Disassembler.h"
20 #include "lldb/Core/Log.h"
21 #include "lldb/Core/Module.h"
22 #include "lldb/Core/Section.h"
23 #include "lldb/Symbol/SymbolContext.h"
24 #include "lldb/Expression/IRExecutionUnit.h"
25 #include "lldb/Target/ExecutionContext.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Target/ObjCLanguageRuntime.h"
29 using namespace lldb_private;
31 IRExecutionUnit::IRExecutionUnit (std::unique_ptr<llvm::LLVMContext> &context_ap,
32 std::unique_ptr<llvm::Module> &module_ap,
34 const lldb::TargetSP &target_sp,
35 std::vector<std::string> &cpu_features) :
36 IRMemoryMap(target_sp),
37 m_context_ap(context_ap.release()),
38 m_module_ap(module_ap.release()),
39 m_module(m_module_ap.get()),
40 m_cpu_features(cpu_features),
43 m_function_load_addr(LLDB_INVALID_ADDRESS),
44 m_function_end_load_addr(LLDB_INVALID_ADDRESS)
49 IRExecutionUnit::WriteNow (const uint8_t *bytes,
53 lldb::addr_t allocation_process_addr = Malloc (size,
55 lldb::ePermissionsWritable | lldb::ePermissionsReadable,
56 eAllocationPolicyMirror,
60 return LLDB_INVALID_ADDRESS;
62 WriteMemory(allocation_process_addr, bytes, size, error);
67 Free (allocation_process_addr, err);
69 return LLDB_INVALID_ADDRESS;
72 if (Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS))
74 DataBufferHeap my_buffer(size, 0);
76 ReadMemory(my_buffer.GetBytes(), allocation_process_addr, size, err);
80 DataExtractor my_extractor(my_buffer.GetBytes(), my_buffer.GetByteSize(), lldb::eByteOrderBig, 8);
81 my_extractor.PutToLog(log, 0, my_buffer.GetByteSize(), allocation_process_addr, 16, DataExtractor::TypeUInt8);
85 return allocation_process_addr;
89 IRExecutionUnit::FreeNow (lldb::addr_t allocation)
91 if (allocation == LLDB_INVALID_ADDRESS)
96 Free(allocation, err);
100 IRExecutionUnit::DisassembleFunction (Stream &stream,
101 lldb::ProcessSP &process_wp)
103 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
105 ExecutionContext exe_ctx(process_wp);
111 lldb::addr_t func_local_addr = LLDB_INVALID_ADDRESS;
112 lldb::addr_t func_remote_addr = LLDB_INVALID_ADDRESS;
114 for (JittedFunction &function : m_jitted_functions)
116 if (strstr(function.m_name.c_str(), m_name.AsCString()))
118 func_local_addr = function.m_local_addr;
119 func_remote_addr = function.m_remote_addr;
123 if (func_local_addr == LLDB_INVALID_ADDRESS)
125 ret.SetErrorToGenericError();
126 ret.SetErrorStringWithFormat("Couldn't find function %s for disassembly", m_name.AsCString());
131 log->Printf("Found function, has local address 0x%" PRIx64 " and remote address 0x%" PRIx64, (uint64_t)func_local_addr, (uint64_t)func_remote_addr);
133 std::pair <lldb::addr_t, lldb::addr_t> func_range;
135 func_range = GetRemoteRangeForLocal(func_local_addr);
137 if (func_range.first == 0 && func_range.second == 0)
139 ret.SetErrorToGenericError();
140 ret.SetErrorStringWithFormat("Couldn't find code range for function %s", m_name.AsCString());
145 log->Printf("Function's code range is [0x%" PRIx64 "+0x%" PRIx64 "]", func_range.first, func_range.second);
147 Target *target = exe_ctx.GetTargetPtr();
150 ret.SetErrorToGenericError();
151 ret.SetErrorString("Couldn't find the target");
155 lldb::DataBufferSP buffer_sp(new DataBufferHeap(func_range.second, 0));
157 Process *process = exe_ctx.GetProcessPtr();
159 process->ReadMemory(func_remote_addr, buffer_sp->GetBytes(), buffer_sp->GetByteSize(), err);
163 ret.SetErrorToGenericError();
164 ret.SetErrorStringWithFormat("Couldn't read from process: %s", err.AsCString("unknown error"));
168 ArchSpec arch(target->GetArchitecture());
170 const char *plugin_name = NULL;
171 const char *flavor_string = NULL;
172 lldb::DisassemblerSP disassembler_sp = Disassembler::FindPlugin(arch, flavor_string, plugin_name);
174 if (!disassembler_sp)
176 ret.SetErrorToGenericError();
177 ret.SetErrorStringWithFormat("Unable to find disassembler plug-in for %s architecture.", arch.GetArchitectureName());
183 ret.SetErrorToGenericError();
184 ret.SetErrorString("Couldn't find the process");
188 DataExtractor extractor(buffer_sp,
189 process->GetByteOrder(),
190 target->GetArchitecture().GetAddressByteSize());
194 log->Printf("Function data has contents:");
195 extractor.PutToLog (log,
197 extractor.GetByteSize(),
200 DataExtractor::TypeUInt8);
203 disassembler_sp->DecodeInstructions (Address (func_remote_addr), extractor, 0, UINT32_MAX, false, false);
205 InstructionList &instruction_list = disassembler_sp->GetInstructionList();
206 instruction_list.Dump(&stream, true, true, &exe_ctx);
208 // FIXME: The DisassemblerLLVMC has a reference cycle and won't go away if it has any active instructions.
209 // I'll fix that but for now, just clear the list and it will go away nicely.
210 disassembler_sp->GetInstructionList().Clear();
214 static void ReportInlineAsmError(const llvm::SMDiagnostic &diagnostic, void *Context, unsigned LocCookie)
216 Error *err = static_cast<Error*>(Context);
218 if (err && err->Success())
220 err->SetErrorToGenericError();
221 err->SetErrorStringWithFormat("Inline assembly error: %s", diagnostic.getMessage().str().c_str());
226 IRExecutionUnit::ReportSymbolLookupError(const ConstString &name)
228 m_failed_lookups.push_back(name);
232 IRExecutionUnit::GetRunnableInfo(Error &error,
233 lldb::addr_t &func_addr,
234 lldb::addr_t &func_end)
236 lldb::ProcessSP process_sp(GetProcessWP().lock());
238 static Mutex s_runnable_info_mutex(Mutex::Type::eMutexTypeRecursive);
240 func_addr = LLDB_INVALID_ADDRESS;
241 func_end = LLDB_INVALID_ADDRESS;
245 error.SetErrorToGenericError();
246 error.SetErrorString("Couldn't write the JIT compiled code into the process because the process is invalid");
252 func_addr = m_function_load_addr;
253 func_end = m_function_end_load_addr;
258 Mutex::Locker runnable_info_mutex_locker(s_runnable_info_mutex);
262 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
264 std::string error_string;
269 llvm::raw_string_ostream oss(s);
271 m_module->print(oss, NULL);
275 log->Printf ("Module being sent to JIT: \n%s", s.c_str());
278 llvm::Triple triple(m_module->getTargetTriple());
279 llvm::Function *function = m_module->getFunction (m_name.AsCString());
280 llvm::Reloc::Model relocModel;
281 llvm::CodeModel::Model codeModel;
283 if (triple.isOSBinFormatELF())
285 relocModel = llvm::Reloc::Static;
286 // This will be small for 32-bit and large for 64-bit.
287 codeModel = llvm::CodeModel::JITDefault;
291 relocModel = llvm::Reloc::PIC_;
292 codeModel = llvm::CodeModel::Small;
295 m_module_ap->getContext().setInlineAsmDiagnosticHandler(ReportInlineAsmError, &error);
297 llvm::EngineBuilder builder(std::move(m_module_ap));
299 builder.setEngineKind(llvm::EngineKind::JIT)
300 .setErrorStr(&error_string)
301 .setRelocationModel(relocModel)
302 .setMCJITMemoryManager(std::unique_ptr<MemoryManager>(new MemoryManager(*this)))
303 .setCodeModel(codeModel)
304 .setOptLevel(llvm::CodeGenOpt::Less);
306 llvm::StringRef mArch;
307 llvm::StringRef mCPU;
308 llvm::SmallVector<std::string, 0> mAttrs;
310 for (std::string &feature : m_cpu_features)
311 mAttrs.push_back(feature);
313 llvm::TargetMachine *target_machine = builder.selectTarget(triple,
318 m_execution_engine_ap.reset(builder.create(target_machine));
320 if (!m_execution_engine_ap.get())
322 error.SetErrorToGenericError();
323 error.SetErrorStringWithFormat("Couldn't JIT the function: %s", error_string.c_str());
327 // Make sure we see all sections, including ones that don't have relocations...
328 m_execution_engine_ap->setProcessAllSections(true);
330 m_execution_engine_ap->DisableLazyCompilation();
332 // We don't actually need the function pointer here, this just forces it to get resolved.
334 void *fun_ptr = m_execution_engine_ap->getPointerToFunction(function);
336 if (!error.Success())
338 // We got an error through our callback!
344 error.SetErrorToGenericError();
345 error.SetErrorStringWithFormat("Couldn't find '%s' in the JITted module", m_name.AsCString());
351 error.SetErrorToGenericError();
352 error.SetErrorStringWithFormat("'%s' was in the JITted module but wasn't lowered", m_name.AsCString());
356 m_jitted_functions.push_back (JittedFunction(m_name.AsCString(), (lldb::addr_t)fun_ptr));
358 CommitAllocations(process_sp);
359 ReportAllocations(*m_execution_engine_ap);
360 WriteData(process_sp);
362 if (m_failed_lookups.size())
366 ss.PutCString("Couldn't lookup symbols:\n");
368 bool emitNewLine = false;
370 for (const ConstString &failed_lookup : m_failed_lookups)
376 ss.PutCString(Mangled(failed_lookup).GetDemangledName(lldb::eLanguageTypeObjC_plus_plus).AsCString());
379 m_failed_lookups.clear();
381 error.SetErrorString(ss.GetData());
386 m_function_load_addr = LLDB_INVALID_ADDRESS;
387 m_function_end_load_addr = LLDB_INVALID_ADDRESS;
389 for (JittedFunction &jitted_function : m_jitted_functions)
391 jitted_function.m_remote_addr = GetRemoteAddressForLocal (jitted_function.m_local_addr);
393 if (!jitted_function.m_name.compare(m_name.AsCString()))
395 AddrRange func_range = GetRemoteRangeForLocal(jitted_function.m_local_addr);
396 m_function_end_load_addr = func_range.first + func_range.second;
397 m_function_load_addr = jitted_function.m_remote_addr;
403 log->Printf("Code can be run in the target.");
405 StreamString disassembly_stream;
407 Error err = DisassembleFunction(disassembly_stream, process_sp);
411 log->Printf("Couldn't disassemble function : %s", err.AsCString("unknown error"));
415 log->Printf("Function disassembly:\n%s", disassembly_stream.GetData());
418 log->Printf("Sections: ");
419 for (AllocationRecord &record : m_records)
421 if (record.m_process_address != LLDB_INVALID_ADDRESS)
425 DataBufferHeap my_buffer(record.m_size, 0);
427 ReadMemory(my_buffer.GetBytes(), record.m_process_address, record.m_size, err);
431 DataExtractor my_extractor(my_buffer.GetBytes(), my_buffer.GetByteSize(), lldb::eByteOrderBig, 8);
432 my_extractor.PutToLog(log, 0, my_buffer.GetByteSize(), record.m_process_address, 16, DataExtractor::TypeUInt8);
438 func_addr = m_function_load_addr;
439 func_end = m_function_end_load_addr;
444 IRExecutionUnit::~IRExecutionUnit ()
447 m_execution_engine_ap.reset();
448 m_context_ap.reset();
451 IRExecutionUnit::MemoryManager::MemoryManager (IRExecutionUnit &parent) :
452 m_default_mm_ap (new llvm::SectionMemoryManager()),
457 IRExecutionUnit::MemoryManager::~MemoryManager ()
462 IRExecutionUnit::GetSectionTypeFromSectionName (const llvm::StringRef &name, IRExecutionUnit::AllocationKind alloc_kind)
464 lldb::SectionType sect_type = lldb::eSectionTypeCode;
467 case AllocationKind::Stub: sect_type = lldb::eSectionTypeCode; break;
468 case AllocationKind::Code: sect_type = lldb::eSectionTypeCode; break;
469 case AllocationKind::Data: sect_type = lldb::eSectionTypeData; break;
470 case AllocationKind::Global:sect_type = lldb::eSectionTypeData; break;
471 case AllocationKind::Bytes: sect_type = lldb::eSectionTypeOther; break;
476 if (name.equals("__text") || name.equals(".text"))
477 sect_type = lldb::eSectionTypeCode;
478 else if (name.equals("__data") || name.equals(".data"))
479 sect_type = lldb::eSectionTypeCode;
480 else if (name.startswith("__debug_") || name.startswith(".debug_"))
482 const uint32_t name_idx = name[0] == '_' ? 8 : 7;
483 llvm::StringRef dwarf_name(name.substr(name_idx));
484 switch (dwarf_name[0])
487 if (dwarf_name.equals("abbrev"))
488 sect_type = lldb::eSectionTypeDWARFDebugAbbrev;
489 else if (dwarf_name.equals("aranges"))
490 sect_type = lldb::eSectionTypeDWARFDebugAranges;
494 if (dwarf_name.equals("frame"))
495 sect_type = lldb::eSectionTypeDWARFDebugFrame;
499 if (dwarf_name.equals("info"))
500 sect_type = lldb::eSectionTypeDWARFDebugInfo;
504 if (dwarf_name.equals("line"))
505 sect_type = lldb::eSectionTypeDWARFDebugLine;
506 else if (dwarf_name.equals("loc"))
507 sect_type = lldb::eSectionTypeDWARFDebugLoc;
511 if (dwarf_name.equals("macinfo"))
512 sect_type = lldb::eSectionTypeDWARFDebugMacInfo;
516 if (dwarf_name.equals("pubnames"))
517 sect_type = lldb::eSectionTypeDWARFDebugPubNames;
518 else if (dwarf_name.equals("pubtypes"))
519 sect_type = lldb::eSectionTypeDWARFDebugPubTypes;
523 if (dwarf_name.equals("str"))
524 sect_type = lldb::eSectionTypeDWARFDebugStr;
528 if (dwarf_name.equals("ranges"))
529 sect_type = lldb::eSectionTypeDWARFDebugRanges;
536 else if (name.startswith("__apple_") || name.startswith(".apple_"))
539 const uint32_t name_idx = name[0] == '_' ? 8 : 7;
540 llvm::StringRef apple_name(name.substr(name_idx));
541 switch (apple_name[0])
544 if (apple_name.equals("names"))
545 sect_type = lldb::eSectionTypeDWARFAppleNames;
546 else if (apple_name.equals("namespac") || apple_name.equals("namespaces"))
547 sect_type = lldb::eSectionTypeDWARFAppleNamespaces;
550 if (apple_name.equals("types"))
551 sect_type = lldb::eSectionTypeDWARFAppleTypes;
554 if (apple_name.equals("objc"))
555 sect_type = lldb::eSectionTypeDWARFAppleObjC;
561 sect_type = lldb::eSectionTypeInvalid;
564 else if (name.equals("__objc_imageinfo"))
565 sect_type = lldb::eSectionTypeOther;
571 IRExecutionUnit::MemoryManager::allocateCodeSection(uintptr_t Size,
574 llvm::StringRef SectionName)
576 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
578 uint8_t *return_value = m_default_mm_ap->allocateCodeSection(Size, Alignment, SectionID, SectionName);
580 m_parent.m_records.push_back(AllocationRecord((uintptr_t)return_value,
581 lldb::ePermissionsReadable | lldb::ePermissionsExecutable,
582 GetSectionTypeFromSectionName (SectionName, AllocationKind::Code),
586 SectionName.str().c_str()));
590 log->Printf("IRExecutionUnit::allocateCodeSection(Size=0x%" PRIx64 ", Alignment=%u, SectionID=%u) = %p",
591 (uint64_t)Size, Alignment, SectionID, (void *)return_value);
598 IRExecutionUnit::MemoryManager::allocateDataSection(uintptr_t Size,
601 llvm::StringRef SectionName,
604 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
606 uint8_t *return_value = m_default_mm_ap->allocateDataSection(Size, Alignment, SectionID, SectionName, IsReadOnly);
608 uint32_t permissions = lldb::ePermissionsReadable;
610 permissions |= lldb::ePermissionsWritable;
611 m_parent.m_records.push_back(AllocationRecord((uintptr_t)return_value,
613 GetSectionTypeFromSectionName (SectionName, AllocationKind::Data),
617 SectionName.str().c_str()));
620 log->Printf("IRExecutionUnit::allocateDataSection(Size=0x%" PRIx64 ", Alignment=%u, SectionID=%u) = %p",
621 (uint64_t)Size, Alignment, SectionID, (void *)return_value);
628 IRExecutionUnit::MemoryManager::getSymbolAddress(const std::string &Name)
630 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
632 SymbolContextList sc_list;
634 ExecutionContextScope *exe_scope = m_parent.GetBestExecutionContextScope();
636 lldb::TargetSP target_sp = exe_scope->CalculateTarget();
638 const char *name = Name.c_str();
640 ConstString bare_name_cs(name);
644 name_cs = ConstString(name + 1);
649 log->Printf("IRExecutionUnit::getSymbolAddress(Name=\"%s\") = <no target>",
652 m_parent.ReportSymbolLookupError(name_cs);
657 uint32_t num_matches = 0;
658 lldb::ProcessSP process_sp = exe_scope->CalculateProcess();
660 if (!name_cs.IsEmpty())
662 target_sp->GetImages().FindSymbolsWithNameAndType(name_cs, lldb::eSymbolTypeAny, sc_list);
663 num_matches = sc_list.GetSize();
668 target_sp->GetImages().FindSymbolsWithNameAndType(bare_name_cs, lldb::eSymbolTypeAny, sc_list);
669 num_matches = sc_list.GetSize();
672 lldb::addr_t symbol_load_addr = LLDB_INVALID_ADDRESS;
674 for (uint32_t i=0; i<num_matches && (symbol_load_addr == 0 || symbol_load_addr == LLDB_INVALID_ADDRESS); i++)
676 SymbolContext sym_ctx;
677 sc_list.GetContextAtIndex(i, sym_ctx);
679 symbol_load_addr = sym_ctx.symbol->ResolveCallableAddress(*target_sp);
681 if (symbol_load_addr == LLDB_INVALID_ADDRESS)
682 symbol_load_addr = sym_ctx.symbol->GetAddress().GetLoadAddress(target_sp.get());
685 if (symbol_load_addr == LLDB_INVALID_ADDRESS && process_sp && name_cs)
687 // Try the Objective-C language runtime.
689 ObjCLanguageRuntime *runtime = process_sp->GetObjCLanguageRuntime();
692 symbol_load_addr = runtime->LookupRuntimeSymbol(name_cs);
695 if (symbol_load_addr == LLDB_INVALID_ADDRESS)
698 log->Printf("IRExecutionUnit::getSymbolAddress(Name=\"%s\") = <not found>",
701 m_parent.ReportSymbolLookupError(bare_name_cs);
707 log->Printf("IRExecutionUnit::getSymbolAddress(Name=\"%s\") = %" PRIx64,
711 if (symbol_load_addr == 0)
714 return symbol_load_addr;
718 IRExecutionUnit::MemoryManager::getPointerToNamedFunction(const std::string &Name,
719 bool AbortOnFailure) {
720 assert (sizeof(void *) == 8);
722 return (void*)getSymbolAddress(Name);
726 IRExecutionUnit::GetRemoteAddressForLocal (lldb::addr_t local_address)
728 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
730 for (AllocationRecord &record : m_records)
732 if (local_address >= record.m_host_address &&
733 local_address < record.m_host_address + record.m_size)
735 if (record.m_process_address == LLDB_INVALID_ADDRESS)
736 return LLDB_INVALID_ADDRESS;
738 lldb::addr_t ret = record.m_process_address + (local_address - record.m_host_address);
742 log->Printf("IRExecutionUnit::GetRemoteAddressForLocal() found 0x%" PRIx64 " in [0x%" PRIx64 "..0x%" PRIx64 "], and returned 0x%" PRIx64 " from [0x%" PRIx64 "..0x%" PRIx64 "].",
744 (uint64_t)record.m_host_address,
745 (uint64_t)record.m_host_address + (uint64_t)record.m_size,
747 record.m_process_address,
748 record.m_process_address + record.m_size);
755 return LLDB_INVALID_ADDRESS;
758 IRExecutionUnit::AddrRange
759 IRExecutionUnit::GetRemoteRangeForLocal (lldb::addr_t local_address)
761 for (AllocationRecord &record : m_records)
763 if (local_address >= record.m_host_address &&
764 local_address < record.m_host_address + record.m_size)
766 if (record.m_process_address == LLDB_INVALID_ADDRESS)
767 return AddrRange(0, 0);
769 return AddrRange(record.m_process_address, record.m_size);
773 return AddrRange (0, 0);
777 IRExecutionUnit::CommitAllocations (lldb::ProcessSP &process_sp)
781 lldb_private::Error err;
783 for (AllocationRecord &record : m_records)
785 if (record.m_process_address != LLDB_INVALID_ADDRESS)
788 switch (record.m_sect_type)
790 case lldb::eSectionTypeInvalid:
791 case lldb::eSectionTypeDWARFDebugAbbrev:
792 case lldb::eSectionTypeDWARFDebugAranges:
793 case lldb::eSectionTypeDWARFDebugFrame:
794 case lldb::eSectionTypeDWARFDebugInfo:
795 case lldb::eSectionTypeDWARFDebugLine:
796 case lldb::eSectionTypeDWARFDebugLoc:
797 case lldb::eSectionTypeDWARFDebugMacInfo:
798 case lldb::eSectionTypeDWARFDebugPubNames:
799 case lldb::eSectionTypeDWARFDebugPubTypes:
800 case lldb::eSectionTypeDWARFDebugRanges:
801 case lldb::eSectionTypeDWARFDebugStr:
802 case lldb::eSectionTypeDWARFAppleNames:
803 case lldb::eSectionTypeDWARFAppleTypes:
804 case lldb::eSectionTypeDWARFAppleNamespaces:
805 case lldb::eSectionTypeDWARFAppleObjC:
809 record.m_process_address = Malloc (record.m_size,
811 record.m_permissions,
812 eAllocationPolicyProcessOnly,
826 for (AllocationRecord &record : m_records)
828 if (record.m_process_address != LLDB_INVALID_ADDRESS)
830 Free(record.m_process_address, err);
831 record.m_process_address = LLDB_INVALID_ADDRESS;
840 IRExecutionUnit::ReportAllocations (llvm::ExecutionEngine &engine)
842 for (AllocationRecord &record : m_records)
844 if (record.m_process_address == LLDB_INVALID_ADDRESS)
847 if (record.m_section_id == eSectionIDInvalid)
850 engine.mapSectionAddress((void*)record.m_host_address, record.m_process_address);
853 // Trigger re-application of relocations.
854 engine.finalizeObject();
858 IRExecutionUnit::WriteData (lldb::ProcessSP &process_sp)
860 bool wrote_something = false;
861 for (AllocationRecord &record : m_records)
863 if (record.m_process_address != LLDB_INVALID_ADDRESS)
865 lldb_private::Error err;
866 WriteMemory (record.m_process_address, (uint8_t*)record.m_host_address, record.m_size, err);
868 wrote_something = true;
871 return wrote_something;
875 IRExecutionUnit::AllocationRecord::dump (Log *log)
880 log->Printf("[0x%llx+0x%llx]->0x%llx (alignment %d, section ID %d)",
881 (unsigned long long)m_host_address,
882 (unsigned long long)m_size,
883 (unsigned long long)m_process_address,
884 (unsigned)m_alignment,
885 (unsigned)m_section_id);
890 IRExecutionUnit::GetByteOrder () const
892 ExecutionContext exe_ctx (GetBestExecutionContextScope());
893 return exe_ctx.GetByteOrder();
897 IRExecutionUnit::GetAddressByteSize () const
899 ExecutionContext exe_ctx (GetBestExecutionContextScope());
900 return exe_ctx.GetAddressByteSize();
904 IRExecutionUnit::PopulateSymtab (lldb_private::ObjectFile *obj_file,
905 lldb_private::Symtab &symtab)
912 IRExecutionUnit::PopulateSectionList (lldb_private::ObjectFile *obj_file,
913 lldb_private::SectionList §ion_list)
915 for (AllocationRecord &record : m_records)
917 if (record.m_size > 0)
919 lldb::SectionSP section_sp (new lldb_private::Section (obj_file->GetModule(),
922 ConstString(record.m_name),
924 record.m_process_address,
926 record.m_host_address, // file_offset (which is the host address for the data)
927 record.m_size, // file_size
929 record.m_permissions)); // flags
930 section_list.AddSection (section_sp);
936 IRExecutionUnit::GetArchitecture (lldb_private::ArchSpec &arch)
938 ExecutionContext exe_ctx (GetBestExecutionContextScope());
939 Target *target = exe_ctx.GetTargetPtr();
941 arch = target->GetArchitecture();
944 return arch.IsValid();
948 IRExecutionUnit::GetJITModule ()
950 ExecutionContext exe_ctx (GetBestExecutionContextScope());
951 Target *target = exe_ctx.GetTargetPtr();
954 lldb::ModuleSP jit_module_sp = lldb_private::Module::CreateJITModule (std::static_pointer_cast<lldb_private::ObjectFileJITDelegate>(shared_from_this()));
957 bool changed = false;
958 jit_module_sp->SetLoadAddress(*target, 0, true, changed);
960 return jit_module_sp;
962 return lldb::ModuleSP();