LLDB  mainline
IRExecutionUnit.cpp
Go to the documentation of this file.
1 //===-- IRExecutionUnit.cpp -----------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/ExecutionEngine/ExecutionEngine.h"
10 #include "llvm/ExecutionEngine/ObjectCache.h"
11 #include "llvm/IR/Constants.h"
12 #include "llvm/IR/DiagnosticHandler.h"
13 #include "llvm/IR/DiagnosticInfo.h"
14 #include "llvm/IR/LLVMContext.h"
15 #include "llvm/IR/Module.h"
16 #include "llvm/Support/SourceMgr.h"
17 #include "llvm/Support/raw_ostream.h"
18 
19 #include "lldb/Core/Debugger.h"
20 #include "lldb/Core/Disassembler.h"
21 #include "lldb/Core/Module.h"
22 #include "lldb/Core/Section.h"
24 #include "lldb/Host/HostInfo.h"
27 #include "lldb/Symbol/SymbolFile.h"
30 #include "lldb/Target/Language.h"
32 #include "lldb/Target/Target.h"
36 #include "lldb/Utility/LLDBLog.h"
37 #include "lldb/Utility/Log.h"
38 
39 #include "lldb/../../source/Plugins/ObjectFile/JIT/ObjectFileJIT.h"
40 
41 using namespace lldb_private;
42 
43 IRExecutionUnit::IRExecutionUnit(std::unique_ptr<llvm::LLVMContext> &context_up,
44  std::unique_ptr<llvm::Module> &module_up,
45  ConstString &name,
46  const lldb::TargetSP &target_sp,
47  const SymbolContext &sym_ctx,
48  std::vector<std::string> &cpu_features)
49  : IRMemoryMap(target_sp), m_context_up(context_up.release()),
50  m_module_up(module_up.release()), m_module(m_module_up.get()),
51  m_cpu_features(cpu_features), m_name(name), m_sym_ctx(sym_ctx),
52  m_did_jit(false), m_function_load_addr(LLDB_INVALID_ADDRESS),
53  m_function_end_load_addr(LLDB_INVALID_ADDRESS),
54  m_reported_allocations(false) {}
55 
56 lldb::addr_t IRExecutionUnit::WriteNow(const uint8_t *bytes, size_t size,
57  Status &error) {
58  const bool zero_memory = false;
59  lldb::addr_t allocation_process_addr =
60  Malloc(size, 8, lldb::ePermissionsWritable | lldb::ePermissionsReadable,
61  eAllocationPolicyMirror, zero_memory, error);
62 
63  if (!error.Success())
64  return LLDB_INVALID_ADDRESS;
65 
66  WriteMemory(allocation_process_addr, bytes, size, error);
67 
68  if (!error.Success()) {
69  Status err;
70  Free(allocation_process_addr, err);
71 
72  return LLDB_INVALID_ADDRESS;
73  }
74 
75  if (Log *log = GetLog(LLDBLog::Expressions)) {
76  DataBufferHeap my_buffer(size, 0);
77  Status err;
78  ReadMemory(my_buffer.GetBytes(), allocation_process_addr, size, err);
79 
80  if (err.Success()) {
81  DataExtractor my_extractor(my_buffer.GetBytes(), my_buffer.GetByteSize(),
83  my_extractor.PutToLog(log, 0, my_buffer.GetByteSize(),
84  allocation_process_addr, 16,
86  }
87  }
88 
89  return allocation_process_addr;
90 }
91 
93  if (allocation == LLDB_INVALID_ADDRESS)
94  return;
95 
96  Status err;
97 
98  Free(allocation, err);
99 }
100 
102  lldb::ProcessSP &process_wp) {
104 
105  ExecutionContext exe_ctx(process_wp);
106 
107  Status ret;
108 
109  ret.Clear();
110 
111  lldb::addr_t func_local_addr = LLDB_INVALID_ADDRESS;
112  lldb::addr_t func_remote_addr = LLDB_INVALID_ADDRESS;
113 
114  for (JittedFunction &function : m_jitted_functions) {
115  if (function.m_name == m_name) {
116  func_local_addr = function.m_local_addr;
117  func_remote_addr = function.m_remote_addr;
118  }
119  }
120 
121  if (func_local_addr == LLDB_INVALID_ADDRESS) {
123  ret.SetErrorStringWithFormat("Couldn't find function %s for disassembly",
124  m_name.AsCString());
125  return ret;
126  }
127 
128  LLDB_LOGF(log,
129  "Found function, has local address 0x%" PRIx64
130  " and remote address 0x%" PRIx64,
131  (uint64_t)func_local_addr, (uint64_t)func_remote_addr);
132 
133  std::pair<lldb::addr_t, lldb::addr_t> func_range;
134 
135  func_range = GetRemoteRangeForLocal(func_local_addr);
136 
137  if (func_range.first == 0 && func_range.second == 0) {
139  ret.SetErrorStringWithFormat("Couldn't find code range for function %s",
140  m_name.AsCString());
141  return ret;
142  }
143 
144  LLDB_LOGF(log, "Function's code range is [0x%" PRIx64 "+0x%" PRIx64 "]",
145  func_range.first, func_range.second);
146 
147  Target *target = exe_ctx.GetTargetPtr();
148  if (!target) {
150  ret.SetErrorString("Couldn't find the target");
151  return ret;
152  }
153 
154  lldb::WritableDataBufferSP buffer_sp(
155  new DataBufferHeap(func_range.second, 0));
156 
157  Process *process = exe_ctx.GetProcessPtr();
158  Status err;
159  process->ReadMemory(func_remote_addr, buffer_sp->GetBytes(),
160  buffer_sp->GetByteSize(), err);
161 
162  if (!err.Success()) {
164  ret.SetErrorStringWithFormat("Couldn't read from process: %s",
165  err.AsCString("unknown error"));
166  return ret;
167  }
168 
169  ArchSpec arch(target->GetArchitecture());
170 
171  const char *plugin_name = nullptr;
172  const char *flavor_string = nullptr;
173  lldb::DisassemblerSP disassembler_sp =
174  Disassembler::FindPlugin(arch, flavor_string, plugin_name);
175 
176  if (!disassembler_sp) {
179  "Unable to find disassembler plug-in for %s architecture.",
180  arch.GetArchitectureName());
181  return ret;
182  }
183 
184  if (!process) {
186  ret.SetErrorString("Couldn't find the process");
187  return ret;
188  }
189 
190  DataExtractor extractor(buffer_sp, process->GetByteOrder(),
191  target->GetArchitecture().GetAddressByteSize());
192 
193  if (log) {
194  LLDB_LOGF(log, "Function data has contents:");
195  extractor.PutToLog(log, 0, extractor.GetByteSize(), func_remote_addr, 16,
197  }
198 
199  disassembler_sp->DecodeInstructions(Address(func_remote_addr), extractor, 0,
200  UINT32_MAX, false, false);
201 
202  InstructionList &instruction_list = disassembler_sp->GetInstructionList();
203  instruction_list.Dump(&stream, true, true, &exe_ctx);
204  return ret;
205 }
206 
207 namespace {
208 struct IRExecDiagnosticHandler : public llvm::DiagnosticHandler {
209  Status *err;
210  IRExecDiagnosticHandler(Status *err) : err(err) {}
211  bool handleDiagnostics(const llvm::DiagnosticInfo &DI) override {
212  if (DI.getKind() == llvm::DK_SrcMgr) {
213  const auto &DISM = llvm::cast<llvm::DiagnosticInfoSrcMgr>(DI);
214  if (err && err->Success()) {
215  err->SetErrorToGenericError();
217  "Inline assembly error: %s",
218  DISM.getSMDiag().getMessage().str().c_str());
219  }
220  return true;
221  }
222 
223  return false;
224  }
225 };
226 } // namespace
227 
229  m_failed_lookups.push_back(name);
230 }
231 
233  lldb::addr_t &func_end) {
234  lldb::ProcessSP process_sp(GetProcessWP().lock());
235 
236  static std::recursive_mutex s_runnable_info_mutex;
237 
238  func_addr = LLDB_INVALID_ADDRESS;
239  func_end = LLDB_INVALID_ADDRESS;
240 
241  if (!process_sp) {
242  error.SetErrorToGenericError();
243  error.SetErrorString("Couldn't write the JIT compiled code into the "
244  "process because the process is invalid");
245  return;
246  }
247 
248  if (m_did_jit) {
249  func_addr = m_function_load_addr;
250  func_end = m_function_end_load_addr;
251 
252  return;
253  };
254 
255  std::lock_guard<std::recursive_mutex> guard(s_runnable_info_mutex);
256 
257  m_did_jit = true;
258 
260 
261  std::string error_string;
262 
263  if (log) {
264  std::string s;
265  llvm::raw_string_ostream oss(s);
266 
267  m_module->print(oss, nullptr);
268 
269  oss.flush();
270 
271  LLDB_LOGF(log, "Module being sent to JIT: \n%s", s.c_str());
272  }
273 
274  m_module_up->getContext().setDiagnosticHandler(
275  std::make_unique<IRExecDiagnosticHandler>(&error));
276 
277  llvm::EngineBuilder builder(std::move(m_module_up));
278  llvm::Triple triple(m_module->getTargetTriple());
279 
280  builder.setEngineKind(llvm::EngineKind::JIT)
281  .setErrorStr(&error_string)
282  .setRelocationModel(triple.isOSBinFormatMachO() ? llvm::Reloc::PIC_
283  : llvm::Reloc::Static)
284  .setMCJITMemoryManager(std::make_unique<MemoryManager>(*this))
285  .setOptLevel(llvm::CodeGenOpt::Less);
286 
287  llvm::StringRef mArch;
288  llvm::StringRef mCPU;
289  llvm::SmallVector<std::string, 0> mAttrs;
290 
291  for (std::string &feature : m_cpu_features)
292  mAttrs.push_back(feature);
293 
294  llvm::TargetMachine *target_machine =
295  builder.selectTarget(triple, mArch, mCPU, mAttrs);
296 
297  m_execution_engine_up.reset(builder.create(target_machine));
298 
299  if (!m_execution_engine_up) {
300  error.SetErrorToGenericError();
301  error.SetErrorStringWithFormat("Couldn't JIT the function: %s",
302  error_string.c_str());
303  return;
304  }
305 
307  (m_execution_engine_up->getDataLayout().getGlobalPrefix() == '_');
308 
309  class ObjectDumper : public llvm::ObjectCache {
310  public:
311  ObjectDumper(FileSpec output_dir) : m_out_dir(output_dir) {}
312  void notifyObjectCompiled(const llvm::Module *module,
313  llvm::MemoryBufferRef object) override {
314  int fd = 0;
315  llvm::SmallVector<char, 256> result_path;
316  std::string object_name_model =
317  "jit-object-" + module->getModuleIdentifier() + "-%%%.o";
318  FileSpec model_spec
319  = m_out_dir.CopyByAppendingPathComponent(object_name_model);
320  std::string model_path = model_spec.GetPath();
321 
322  std::error_code result
323  = llvm::sys::fs::createUniqueFile(model_path, fd, result_path);
324  if (!result) {
325  llvm::raw_fd_ostream fds(fd, true);
326  fds.write(object.getBufferStart(), object.getBufferSize());
327  }
328  }
329  std::unique_ptr<llvm::MemoryBuffer>
330  getObject(const llvm::Module *module) override {
331  // Return nothing - we're just abusing the object-cache mechanism to dump
332  // objects.
333  return nullptr;
334  }
335  private:
336  FileSpec m_out_dir;
337  };
338 
339  FileSpec save_objects_dir = process_sp->GetTarget().GetSaveJITObjectsDir();
340  if (save_objects_dir) {
341  m_object_cache_up = std::make_unique<ObjectDumper>(save_objects_dir);
342  m_execution_engine_up->setObjectCache(m_object_cache_up.get());
343  }
344 
345  // Make sure we see all sections, including ones that don't have
346  // relocations...
347  m_execution_engine_up->setProcessAllSections(true);
348 
349  m_execution_engine_up->DisableLazyCompilation();
350 
351  for (llvm::Function &function : *m_module) {
352  if (function.isDeclaration() || function.hasPrivateLinkage())
353  continue;
354 
355  const bool external = !function.hasLocalLinkage();
356 
357  void *fun_ptr = m_execution_engine_up->getPointerToFunction(&function);
358 
359  if (!error.Success()) {
360  // We got an error through our callback!
361  return;
362  }
363 
364  if (!fun_ptr) {
365  error.SetErrorToGenericError();
366  error.SetErrorStringWithFormat(
367  "'%s' was in the JITted module but wasn't lowered",
368  function.getName().str().c_str());
369  return;
370  }
372  function.getName().str().c_str(), external, reinterpret_cast<uintptr_t>(fun_ptr)));
373  }
374 
375  CommitAllocations(process_sp);
377 
378  // We have to do this after calling ReportAllocations because for the MCJIT,
379  // getGlobalValueAddress will cause the JIT to perform all relocations. That
380  // can only be done once, and has to happen after we do the remapping from
381  // local -> remote. That means we don't know the local address of the
382  // Variables, but we don't need that for anything, so that's okay.
383 
384  std::function<void(llvm::GlobalValue &)> RegisterOneValue = [this](
385  llvm::GlobalValue &val) {
386  if (val.hasExternalLinkage() && !val.isDeclaration()) {
387  uint64_t var_ptr_addr =
388  m_execution_engine_up->getGlobalValueAddress(val.getName().str());
389 
390  lldb::addr_t remote_addr = GetRemoteAddressForLocal(var_ptr_addr);
391 
392  // This is a really unfortunae API that sometimes returns local addresses
393  // and sometimes returns remote addresses, based on whether the variable
394  // was relocated during ReportAllocations or not.
395 
396  if (remote_addr == LLDB_INVALID_ADDRESS) {
397  remote_addr = var_ptr_addr;
398  }
399 
400  if (var_ptr_addr != 0)
402  val.getName().str().c_str(), LLDB_INVALID_ADDRESS, remote_addr));
403  }
404  };
405 
406  for (llvm::GlobalVariable &global_var : m_module->getGlobalList()) {
407  RegisterOneValue(global_var);
408  }
409 
410  for (llvm::GlobalAlias &global_alias : m_module->getAliasList()) {
411  RegisterOneValue(global_alias);
412  }
413 
414  WriteData(process_sp);
415 
416  if (m_failed_lookups.size()) {
417  StreamString ss;
418 
419  ss.PutCString("Couldn't lookup symbols:\n");
420 
421  bool emitNewLine = false;
422 
423  for (ConstString failed_lookup : m_failed_lookups) {
424  if (emitNewLine)
425  ss.PutCString("\n");
426  emitNewLine = true;
427  ss.PutCString(" ");
428  ss.PutCString(Mangled(failed_lookup).GetDemangledName().GetStringRef());
429  }
430 
431  m_failed_lookups.clear();
432 
433  error.SetErrorString(ss.GetString());
434 
435  return;
436  }
437 
440 
441  for (JittedFunction &jitted_function : m_jitted_functions) {
442  jitted_function.m_remote_addr =
443  GetRemoteAddressForLocal(jitted_function.m_local_addr);
444 
445  if (!m_name.IsEmpty() && jitted_function.m_name == m_name) {
446  AddrRange func_range =
447  GetRemoteRangeForLocal(jitted_function.m_local_addr);
448  m_function_end_load_addr = func_range.first + func_range.second;
449  m_function_load_addr = jitted_function.m_remote_addr;
450  }
451  }
452 
453  if (log) {
454  LLDB_LOGF(log, "Code can be run in the target.");
455 
456  StreamString disassembly_stream;
457 
458  Status err = DisassembleFunction(disassembly_stream, process_sp);
459 
460  if (!err.Success()) {
461  LLDB_LOGF(log, "Couldn't disassemble function : %s",
462  err.AsCString("unknown error"));
463  } else {
464  LLDB_LOGF(log, "Function disassembly:\n%s", disassembly_stream.GetData());
465  }
466 
467  LLDB_LOGF(log, "Sections: ");
468  for (AllocationRecord &record : m_records) {
469  if (record.m_process_address != LLDB_INVALID_ADDRESS) {
470  record.dump(log);
471 
472  DataBufferHeap my_buffer(record.m_size, 0);
473  Status err;
474  ReadMemory(my_buffer.GetBytes(), record.m_process_address,
475  record.m_size, err);
476 
477  if (err.Success()) {
478  DataExtractor my_extractor(my_buffer.GetBytes(),
479  my_buffer.GetByteSize(),
481  my_extractor.PutToLog(log, 0, my_buffer.GetByteSize(),
482  record.m_process_address, 16,
484  }
485  } else {
486  record.dump(log);
487 
488  DataExtractor my_extractor((const void *)record.m_host_address,
489  record.m_size, lldb::eByteOrderBig, 8);
490  my_extractor.PutToLog(log, 0, record.m_size, record.m_host_address, 16,
492  }
493  }
494  }
495 
496  func_addr = m_function_load_addr;
497  func_end = m_function_end_load_addr;
498 }
499 
501  m_module_up.reset();
502  m_execution_engine_up.reset();
503  m_context_up.reset();
504 }
505 
507  : m_default_mm_up(new llvm::SectionMemoryManager()), m_parent(parent) {}
508 
510 
512  const llvm::StringRef &name, IRExecutionUnit::AllocationKind alloc_kind) {
514  switch (alloc_kind) {
516  sect_type = lldb::eSectionTypeCode;
517  break;
519  sect_type = lldb::eSectionTypeCode;
520  break;
522  sect_type = lldb::eSectionTypeData;
523  break;
525  sect_type = lldb::eSectionTypeData;
526  break;
528  sect_type = lldb::eSectionTypeOther;
529  break;
530  }
531 
532  if (!name.empty()) {
533  if (name.equals("__text") || name.equals(".text"))
534  sect_type = lldb::eSectionTypeCode;
535  else if (name.equals("__data") || name.equals(".data"))
536  sect_type = lldb::eSectionTypeCode;
537  else if (name.startswith("__debug_") || name.startswith(".debug_")) {
538  const uint32_t name_idx = name[0] == '_' ? 8 : 7;
539  llvm::StringRef dwarf_name(name.substr(name_idx));
540  switch (dwarf_name[0]) {
541  case 'a':
542  if (dwarf_name.equals("abbrev"))
544  else if (dwarf_name.equals("aranges"))
546  else if (dwarf_name.equals("addr"))
548  break;
549 
550  case 'f':
551  if (dwarf_name.equals("frame"))
553  break;
554 
555  case 'i':
556  if (dwarf_name.equals("info"))
558  break;
559 
560  case 'l':
561  if (dwarf_name.equals("line"))
563  else if (dwarf_name.equals("loc"))
565  else if (dwarf_name.equals("loclists"))
567  break;
568 
569  case 'm':
570  if (dwarf_name.equals("macinfo"))
572  break;
573 
574  case 'p':
575  if (dwarf_name.equals("pubnames"))
577  else if (dwarf_name.equals("pubtypes"))
579  break;
580 
581  case 's':
582  if (dwarf_name.equals("str"))
584  else if (dwarf_name.equals("str_offsets"))
586  break;
587 
588  case 'r':
589  if (dwarf_name.equals("ranges"))
591  break;
592 
593  default:
594  break;
595  }
596  } else if (name.startswith("__apple_") || name.startswith(".apple_"))
597  sect_type = lldb::eSectionTypeInvalid;
598  else if (name.equals("__objc_imageinfo"))
599  sect_type = lldb::eSectionTypeOther;
600  }
601  return sect_type;
602 }
603 
605  uintptr_t Size, unsigned Alignment, unsigned SectionID,
606  llvm::StringRef SectionName) {
608 
609  uint8_t *return_value = m_default_mm_up->allocateCodeSection(
610  Size, Alignment, SectionID, SectionName);
611 
612  m_parent.m_records.push_back(AllocationRecord(
613  (uintptr_t)return_value,
614  lldb::ePermissionsReadable | lldb::ePermissionsExecutable,
616  Alignment, SectionID, SectionName.str().c_str()));
617 
618  LLDB_LOGF(log,
619  "IRExecutionUnit::allocateCodeSection(Size=0x%" PRIx64
620  ", Alignment=%u, SectionID=%u) = %p",
621  (uint64_t)Size, Alignment, SectionID, (void *)return_value);
622 
623  if (m_parent.m_reported_allocations) {
624  Status err;
625  lldb::ProcessSP process_sp =
626  m_parent.GetBestExecutionContextScope()->CalculateProcess();
627 
628  m_parent.CommitOneAllocation(process_sp, err, m_parent.m_records.back());
629  }
630 
631  return return_value;
632 }
633 
635  uintptr_t Size, unsigned Alignment, unsigned SectionID,
636  llvm::StringRef SectionName, bool IsReadOnly) {
638 
639  uint8_t *return_value = m_default_mm_up->allocateDataSection(
640  Size, Alignment, SectionID, SectionName, IsReadOnly);
641 
642  uint32_t permissions = lldb::ePermissionsReadable;
643  if (!IsReadOnly)
644  permissions |= lldb::ePermissionsWritable;
645  m_parent.m_records.push_back(AllocationRecord(
646  (uintptr_t)return_value, permissions,
648  Alignment, SectionID, SectionName.str().c_str()));
649  LLDB_LOGF(log,
650  "IRExecutionUnit::allocateDataSection(Size=0x%" PRIx64
651  ", Alignment=%u, SectionID=%u) = %p",
652  (uint64_t)Size, Alignment, SectionID, (void *)return_value);
653 
654  if (m_parent.m_reported_allocations) {
655  Status err;
656  lldb::ProcessSP process_sp =
657  m_parent.GetBestExecutionContextScope()->CalculateProcess();
658 
659  m_parent.CommitOneAllocation(process_sp, err, m_parent.m_records.back());
660  }
661 
662  return return_value;
663 }
664 
665 void IRExecutionUnit::CollectCandidateCNames(std::vector<ConstString> &C_names,
666  ConstString name) {
667  if (m_strip_underscore && name.AsCString()[0] == '_')
668  C_names.insert(C_names.begin(), ConstString(&name.AsCString()[1]));
669  C_names.push_back(name);
670 }
671 
673  std::vector<ConstString> &CPP_names,
674  const std::vector<ConstString> &C_names, const SymbolContext &sc) {
676  for (const ConstString &name : C_names) {
677  Mangled mangled(name);
678  if (cpp_lang->SymbolNameFitsToLanguage(mangled)) {
679  if (ConstString best_alternate =
680  cpp_lang->FindBestAlternateFunctionMangledName(mangled, sc)) {
681  CPP_names.push_back(best_alternate);
682  }
683  }
684 
685  std::vector<ConstString> alternates =
686  cpp_lang->GenerateAlternateFunctionManglings(name);
687  CPP_names.insert(CPP_names.end(), alternates.begin(), alternates.end());
688 
689  // As a last-ditch fallback, try the base name for C++ names. It's
690  // terrible, but the DWARF doesn't always encode "extern C" correctly.
691  ConstString basename =
692  cpp_lang->GetDemangledFunctionNameWithoutArguments(mangled);
693  CPP_names.push_back(basename);
694  }
695  }
696 }
697 
699 public:
700  LoadAddressResolver(Target *target, bool &symbol_was_missing_weak)
701  : m_target(target), m_symbol_was_missing_weak(symbol_was_missing_weak) {}
702 
703  llvm::Optional<lldb::addr_t> Resolve(SymbolContextList &sc_list) {
704  if (sc_list.IsEmpty())
705  return llvm::None;
706 
707  lldb::addr_t load_address = LLDB_INVALID_ADDRESS;
708 
709  // Missing_weak_symbol will be true only if we found only weak undefined
710  // references to this symbol.
711  m_symbol_was_missing_weak = true;
712 
713  for (auto candidate_sc : sc_list.SymbolContexts()) {
714  // Only symbols can be weak undefined.
715  if (!candidate_sc.symbol ||
716  candidate_sc.symbol->GetType() != lldb::eSymbolTypeUndefined ||
717  !candidate_sc.symbol->IsWeak())
718  m_symbol_was_missing_weak = false;
719 
720  // First try the symbol.
721  if (candidate_sc.symbol) {
722  load_address = candidate_sc.symbol->ResolveCallableAddress(*m_target);
723  if (load_address == LLDB_INVALID_ADDRESS) {
724  Address addr = candidate_sc.symbol->GetAddress();
725  load_address = m_target->GetProcessSP()
726  ? addr.GetLoadAddress(m_target)
727  : addr.GetFileAddress();
728  }
729  }
730 
731  // If that didn't work, try the function.
732  if (load_address == LLDB_INVALID_ADDRESS && candidate_sc.function) {
733  Address addr =
734  candidate_sc.function->GetAddressRange().GetBaseAddress();
735  load_address = m_target->GetProcessSP() ? addr.GetLoadAddress(m_target)
736  : addr.GetFileAddress();
737  }
738 
739  // We found a load address.
740  if (load_address != LLDB_INVALID_ADDRESS) {
741  // If the load address is external, we're done.
742  const bool is_external =
743  (candidate_sc.function) ||
744  (candidate_sc.symbol && candidate_sc.symbol->IsExternal());
745  if (is_external)
746  return load_address;
747 
748  // Otherwise, remember the best internal load address.
749  if (m_best_internal_load_address == LLDB_INVALID_ADDRESS)
750  m_best_internal_load_address = load_address;
751  }
752  }
753 
754  // You test the address of a weak symbol against NULL to see if it is
755  // present. So we should return 0 for a missing weak symbol.
756  if (m_symbol_was_missing_weak)
757  return 0;
758 
759  return llvm::None;
760  }
761 
763  return m_best_internal_load_address;
764  }
765 
766 private:
769  lldb::addr_t m_best_internal_load_address = LLDB_INVALID_ADDRESS;
770 };
771 
773 IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
774  const lldb_private::SymbolContext &sc,
775  bool &symbol_was_missing_weak) {
776  symbol_was_missing_weak = false;
777 
778  Target *target = sc.target_sp.get();
779  if (!target) {
780  // We shouldn't be doing any symbol lookup at all without a target.
781  return LLDB_INVALID_ADDRESS;
782  }
783 
784  LoadAddressResolver resolver(target, symbol_was_missing_weak);
785 
786  ModuleFunctionSearchOptions function_options;
787  function_options.include_symbols = true;
788  function_options.include_inlines = false;
789 
790  for (const ConstString &name : names) {
791  if (sc.module_sp) {
792  SymbolContextList sc_list;
793  sc.module_sp->FindFunctions(name, CompilerDeclContext(),
794  lldb::eFunctionNameTypeFull, function_options,
795  sc_list);
796  if (auto load_addr = resolver.Resolve(sc_list))
797  return *load_addr;
798  }
799 
800  if (sc.target_sp) {
801  SymbolContextList sc_list;
802  sc.target_sp->GetImages().FindFunctions(name, lldb::eFunctionNameTypeFull,
803  function_options, sc_list);
804  if (auto load_addr = resolver.Resolve(sc_list))
805  return *load_addr;
806  }
807 
808  if (sc.target_sp) {
809  SymbolContextList sc_list;
810  sc.target_sp->GetImages().FindSymbolsWithNameAndType(
811  name, lldb::eSymbolTypeAny, sc_list);
812  if (auto load_addr = resolver.Resolve(sc_list))
813  return *load_addr;
814  }
815 
816  lldb::addr_t best_internal_load_address =
817  resolver.GetBestInternalLoadAddress();
818  if (best_internal_load_address != LLDB_INVALID_ADDRESS)
819  return best_internal_load_address;
820  }
821 
822  return LLDB_INVALID_ADDRESS;
823 }
824 
826 IRExecutionUnit::FindInRuntimes(const std::vector<ConstString> &names,
827  const lldb_private::SymbolContext &sc) {
828  lldb::TargetSP target_sp = sc.target_sp;
829 
830  if (!target_sp) {
831  return LLDB_INVALID_ADDRESS;
832  }
833 
834  lldb::ProcessSP process_sp = sc.target_sp->GetProcessSP();
835 
836  if (!process_sp) {
837  return LLDB_INVALID_ADDRESS;
838  }
839 
840  for (const ConstString &name : names) {
841  for (LanguageRuntime *runtime : process_sp->GetLanguageRuntimes()) {
842  lldb::addr_t symbol_load_addr = runtime->LookupRuntimeSymbol(name);
843 
844  if (symbol_load_addr != LLDB_INVALID_ADDRESS)
845  return symbol_load_addr;
846  }
847  }
848 
849  return LLDB_INVALID_ADDRESS;
850 }
851 
853  const std::vector<ConstString> &names,
854  const lldb_private::SymbolContext &sc) {
855  lldb::TargetSP target_sp = sc.target_sp;
856 
857  for (const ConstString &name : names) {
858  lldb::addr_t symbol_load_addr = target_sp->GetPersistentSymbol(name);
859 
860  if (symbol_load_addr != LLDB_INVALID_ADDRESS)
861  return symbol_load_addr;
862  }
863 
864  return LLDB_INVALID_ADDRESS;
865 }
866 
868  bool &missing_weak) {
869  std::vector<ConstString> candidate_C_names;
870  std::vector<ConstString> candidate_CPlusPlus_names;
871 
872  CollectCandidateCNames(candidate_C_names, name);
873 
874  lldb::addr_t ret = FindInSymbols(candidate_C_names, m_sym_ctx, missing_weak);
875  if (ret != LLDB_INVALID_ADDRESS)
876  return ret;
877 
878  // If we find the symbol in runtimes or user defined symbols it can't be
879  // a missing weak symbol.
880  missing_weak = false;
881  ret = FindInRuntimes(candidate_C_names, m_sym_ctx);
882  if (ret != LLDB_INVALID_ADDRESS)
883  return ret;
884 
885  ret = FindInUserDefinedSymbols(candidate_C_names, m_sym_ctx);
886  if (ret != LLDB_INVALID_ADDRESS)
887  return ret;
888 
889  CollectCandidateCPlusPlusNames(candidate_CPlusPlus_names, candidate_C_names,
890  m_sym_ctx);
891  ret = FindInSymbols(candidate_CPlusPlus_names, m_sym_ctx, missing_weak);
892  return ret;
893 }
894 
896  std::vector<lldb::addr_t> &static_initializers) {
898 
899  llvm::GlobalVariable *global_ctors =
900  m_module->getNamedGlobal("llvm.global_ctors");
901  if (!global_ctors) {
902  LLDB_LOG(log, "Couldn't find llvm.global_ctors.");
903  return;
904  }
905  auto *ctor_array =
906  llvm::dyn_cast<llvm::ConstantArray>(global_ctors->getInitializer());
907  if (!ctor_array) {
908  LLDB_LOG(log, "llvm.global_ctors not a ConstantArray.");
909  return;
910  }
911 
912  for (llvm::Use &ctor_use : ctor_array->operands()) {
913  auto *ctor_struct = llvm::dyn_cast<llvm::ConstantStruct>(ctor_use);
914  if (!ctor_struct)
915  continue;
916  // this is standardized
917  lldbassert(ctor_struct->getNumOperands() == 3);
918  auto *ctor_function =
919  llvm::dyn_cast<llvm::Function>(ctor_struct->getOperand(1));
920  if (!ctor_function) {
921  LLDB_LOG(log, "global_ctor doesn't contain an llvm::Function");
922  continue;
923  }
924 
925  ConstString ctor_function_name(ctor_function->getName().str());
926  LLDB_LOG(log, "Looking for callable jitted function with name {0}.",
927  ctor_function_name);
928 
929  for (JittedFunction &jitted_function : m_jitted_functions) {
930  if (ctor_function_name != jitted_function.m_name)
931  continue;
932  if (jitted_function.m_remote_addr == LLDB_INVALID_ADDRESS) {
933  LLDB_LOG(log, "Found jitted function with invalid address.");
934  continue;
935  }
936  static_initializers.push_back(jitted_function.m_remote_addr);
937  LLDB_LOG(log, "Calling function at address {0:x}.",
938  jitted_function.m_remote_addr);
939  break;
940  }
941  }
942 }
943 
944 llvm::JITSymbol
946  bool missing_weak = false;
947  uint64_t addr = GetSymbolAddressAndPresence(Name, missing_weak);
948  // This is a weak symbol:
949  if (missing_weak)
950  return llvm::JITSymbol(addr,
951  llvm::JITSymbolFlags::Exported | llvm::JITSymbolFlags::Weak);
952  else
953  return llvm::JITSymbol(addr, llvm::JITSymbolFlags::Exported);
954 }
955 
956 uint64_t
958  bool missing_weak = false;
959  return GetSymbolAddressAndPresence(Name, missing_weak);
960 }
961 
962 uint64_t
964  const std::string &Name, bool &missing_weak) {
966 
967  ConstString name_cs(Name.c_str());
968 
969  lldb::addr_t ret = m_parent.FindSymbol(name_cs, missing_weak);
970 
971  if (ret == LLDB_INVALID_ADDRESS) {
972  LLDB_LOGF(log,
973  "IRExecutionUnit::getSymbolAddress(Name=\"%s\") = <not found>",
974  Name.c_str());
975 
976  m_parent.ReportSymbolLookupError(name_cs);
977  return 0;
978  } else {
979  LLDB_LOGF(log, "IRExecutionUnit::getSymbolAddress(Name=\"%s\") = %" PRIx64,
980  Name.c_str(), ret);
981  return ret;
982  }
983 }
984 
986  const std::string &Name, bool AbortOnFailure) {
987  return (void *)getSymbolAddress(Name);
988 }
989 
993 
994  for (AllocationRecord &record : m_records) {
995  if (local_address >= record.m_host_address &&
996  local_address < record.m_host_address + record.m_size) {
997  if (record.m_process_address == LLDB_INVALID_ADDRESS)
998  return LLDB_INVALID_ADDRESS;
999 
1000  lldb::addr_t ret =
1001  record.m_process_address + (local_address - record.m_host_address);
1002 
1003  LLDB_LOGF(log,
1004  "IRExecutionUnit::GetRemoteAddressForLocal() found 0x%" PRIx64
1005  " in [0x%" PRIx64 "..0x%" PRIx64 "], and returned 0x%" PRIx64
1006  " from [0x%" PRIx64 "..0x%" PRIx64 "].",
1007  local_address, (uint64_t)record.m_host_address,
1008  (uint64_t)record.m_host_address + (uint64_t)record.m_size, ret,
1009  record.m_process_address,
1010  record.m_process_address + record.m_size);
1011 
1012  return ret;
1013  }
1014  }
1015 
1016  return LLDB_INVALID_ADDRESS;
1017 }
1018 
1021  for (AllocationRecord &record : m_records) {
1022  if (local_address >= record.m_host_address &&
1023  local_address < record.m_host_address + record.m_size) {
1024  if (record.m_process_address == LLDB_INVALID_ADDRESS)
1025  return AddrRange(0, 0);
1026 
1027  return AddrRange(record.m_process_address, record.m_size);
1028  }
1029  }
1030 
1031  return AddrRange(0, 0);
1032 }
1033 
1034 bool IRExecutionUnit::CommitOneAllocation(lldb::ProcessSP &process_sp,
1035  Status &error,
1036  AllocationRecord &record) {
1037  if (record.m_process_address != LLDB_INVALID_ADDRESS) {
1038  return true;
1039  }
1040 
1041  switch (record.m_sect_type) {
1063  error.Clear();
1064  break;
1065  default:
1066  const bool zero_memory = false;
1067  record.m_process_address =
1068  Malloc(record.m_size, record.m_alignment, record.m_permissions,
1069  eAllocationPolicyProcessOnly, zero_memory, error);
1070  break;
1071  }
1072 
1073  return error.Success();
1074 }
1075 
1076 bool IRExecutionUnit::CommitAllocations(lldb::ProcessSP &process_sp) {
1077  bool ret = true;
1078 
1080 
1081  for (AllocationRecord &record : m_records) {
1082  ret = CommitOneAllocation(process_sp, err, record);
1083 
1084  if (!ret) {
1085  break;
1086  }
1087  }
1088 
1089  if (!ret) {
1090  for (AllocationRecord &record : m_records) {
1091  if (record.m_process_address != LLDB_INVALID_ADDRESS) {
1092  Free(record.m_process_address, err);
1093  record.m_process_address = LLDB_INVALID_ADDRESS;
1094  }
1095  }
1096  }
1097 
1098  return ret;
1099 }
1100 
1101 void IRExecutionUnit::ReportAllocations(llvm::ExecutionEngine &engine) {
1102  m_reported_allocations = true;
1103 
1104  for (AllocationRecord &record : m_records) {
1105  if (record.m_process_address == LLDB_INVALID_ADDRESS)
1106  continue;
1107 
1108  if (record.m_section_id == eSectionIDInvalid)
1109  continue;
1110 
1111  engine.mapSectionAddress((void *)record.m_host_address,
1112  record.m_process_address);
1113  }
1114 
1115  // Trigger re-application of relocations.
1116  engine.finalizeObject();
1117 }
1118 
1119 bool IRExecutionUnit::WriteData(lldb::ProcessSP &process_sp) {
1120  bool wrote_something = false;
1121  for (AllocationRecord &record : m_records) {
1122  if (record.m_process_address != LLDB_INVALID_ADDRESS) {
1124  WriteMemory(record.m_process_address, (uint8_t *)record.m_host_address,
1125  record.m_size, err);
1126  if (err.Success())
1127  wrote_something = true;
1128  }
1129  }
1130  return wrote_something;
1131 }
1132 
1134  if (!log)
1135  return;
1136 
1137  LLDB_LOGF(log,
1138  "[0x%llx+0x%llx]->0x%llx (alignment %d, section ID %d, name %s)",
1139  (unsigned long long)m_host_address, (unsigned long long)m_size,
1140  (unsigned long long)m_process_address, (unsigned)m_alignment,
1141  (unsigned)m_section_id, m_name.c_str());
1142 }
1143 
1146  return exe_ctx.GetByteOrder();
1147 }
1148 
1151  return exe_ctx.GetAddressByteSize();
1152 }
1153 
1155  lldb_private::Symtab &symtab) {
1156  // No symbols yet...
1157 }
1158 
1160  lldb_private::ObjectFile *obj_file,
1161  lldb_private::SectionList &section_list) {
1162  for (AllocationRecord &record : m_records) {
1163  if (record.m_size > 0) {
1164  lldb::SectionSP section_sp(new lldb_private::Section(
1165  obj_file->GetModule(), obj_file, record.m_section_id,
1166  ConstString(record.m_name), record.m_sect_type,
1167  record.m_process_address, record.m_size,
1168  record.m_host_address, // file_offset (which is the host address for
1169  // the data)
1170  record.m_size, // file_size
1171  0,
1172  record.m_permissions)); // flags
1173  section_list.AddSection(section_sp);
1174  }
1175  }
1176 }
1177 
1180  if(Target *target = exe_ctx.GetTargetPtr())
1181  return target->GetArchitecture();
1182  return ArchSpec();
1183 }
1184 
1187  Target *target = exe_ctx.GetTargetPtr();
1188  if (!target)
1189  return nullptr;
1190 
1191  auto Delegate = std::static_pointer_cast<lldb_private::ObjectFileJITDelegate>(
1192  shared_from_this());
1193 
1194  lldb::ModuleSP jit_module_sp =
1195  lldb_private::Module::CreateModuleFromObjectFile<ObjectFileJIT>(Delegate);
1196  if (!jit_module_sp)
1197  return nullptr;
1198 
1199  bool changed = false;
1200  jit_module_sp->SetLoadAddress(*target, 0, true, changed);
1201  return jit_module_sp;
1202 }
lldb_private::IRExecutionUnit
Definition: IRExecutionUnit.h:56
lldb_private::IRExecutionUnit::FindInUserDefinedSymbols
lldb::addr_t FindInUserDefinedSymbols(const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc)
Definition: IRExecutionUnit.cpp:852
lldb_private::IRExecutionUnit::m_jitted_global_variables
std::vector< JittedGlobalVariable > m_jitted_global_variables
A vector of all functions that have been JITted into machine code.
Definition: IRExecutionUnit.h:376
lldb::eSectionTypeDWARFDebugLoc
@ eSectionTypeDWARFDebugLoc
Definition: lldb-enumerations.h:676
lldb_private::DataExtractor::PutToLog
lldb::offset_t PutToLog(Log *log, lldb::offset_t offset, lldb::offset_t length, uint64_t base_addr, uint32_t num_per_line, Type type) const
Dumps the binary data as type objects to stream s (or to Log() if s is nullptr) starting offset bytes...
Definition: DataExtractor.cpp:902
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::IRExecutionUnit::GetRunnableInfo
void GetRunnableInfo(Status &error, lldb::addr_t &func_addr, lldb::addr_t &func_end)
Definition: IRExecutionUnit.cpp:232
lldb_private::DataBufferHeap::GetByteSize
lldb::offset_t GetByteSize() const override
Definition: DataBufferHeap.cpp:43
llvm
Definition: Debugger.h:50
lldb::eSectionTypeDWARFAppleNamespaces
@ eSectionTypeDWARFAppleNamespaces
Definition: lldb-enumerations.h:686
lldb_private::IRExecutionUnit::GetAddressByteSize
uint32_t GetAddressByteSize() const override
Definition: IRExecutionUnit.cpp:1149
lldb::eSectionTypeDWARFAppleObjC
@ eSectionTypeDWARFAppleObjC
Definition: lldb-enumerations.h:687
lldb_private::IRExecutionUnit::m_strip_underscore
bool m_strip_underscore
True for platforms where global symbols have a _ prefix.
Definition: IRExecutionUnit.h:390
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::IRExecutionUnit::DisassembleFunction
Status DisassembleFunction(Stream &stream, lldb::ProcessSP &process_sp)
Definition: IRExecutionUnit.cpp:101
lldb_private::Process::ReadMemory
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition: Process.cpp:1921
CompileUnit.h
lldb_private::ExecutionContext::GetProcessPtr
Process * GetProcessPtr() const
Returns a pointer to the process object.
Definition: ExecutionContext.cpp:206
lldb_private::IRExecutionUnit::AllocationRecord::dump
void dump(Log *log)
Definition: IRExecutionUnit.cpp:1133
lldb_private::IRExecutionUnit::AddrRange
std::pair< lldb::addr_t, uintptr_t > AddrRange
Definition: IRExecutionUnit.h:176
lldb_private::SymbolContext::target_sp
lldb::TargetSP target_sp
The Target for a given query.
Definition: SymbolContext.h:317
lldb::eSectionTypeDWARFDebugAranges
@ eSectionTypeDWARFDebugAranges
Definition: lldb-enumerations.h:671
lldb_private::ExecutionContext::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Definition: ExecutionContext.cpp:182
lldb_private::Disassembler::FindPlugin
static lldb::DisassemblerSP FindPlugin(const ArchSpec &arch, const char *flavor, const char *plugin_name)
Definition: Disassembler.cpp:58
lldb_private::IRExecutionUnit::~IRExecutionUnit
~IRExecutionUnit() override
Destructor.
Definition: IRExecutionUnit.cpp:500
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:343
lldb::eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugRanges
Definition: lldb-enumerations.h:681
lldb_private::Process
Definition: Process.h:338
lldb_private::IRMemoryMap::Malloc
lldb::addr_t Malloc(size_t size, uint8_t alignment, uint32_t permissions, AllocationPolicy policy, bool zero_memory, Status &error)
Definition: IRMemoryMap.cpp:289
lldb::eSectionTypeDWARFDebugFrame
@ eSectionTypeDWARFDebugFrame
Definition: lldb-enumerations.h:673
Module.h
lldb::eSectionTypeDWARFDebugLine
@ eSectionTypeDWARFDebugLine
Definition: lldb-enumerations.h:675
lldb_private::IRExecutionUnit::JittedGlobalVariable
Definition: IRExecutionUnit.h:149
lldb_private::IRExecutionUnit::m_sym_ctx
SymbolContext m_sym_ctx
Used for symbol lookups.
Definition: IRExecutionUnit.h:382
lldb_private::SymbolContextList
Definition: SymbolContext.h:379
lldb::eSectionTypeDWARFDebugAddr
@ eSectionTypeDWARFDebugAddr
Definition: lldb-enumerations.h:670
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:193
lldb_private::SectionList
Definition: Section.h:34
lldb_private::IRMemoryMap::GetProcessWP
lldb::ProcessWP & GetProcessWP()
Definition: IRMemoryMap.h:86
Disassembler.h
lldb_private::IRExecutionUnit::WriteData
bool WriteData(lldb::ProcessSP &process_sp)
Write the contents of all allocations to the process.
Definition: IRExecutionUnit.cpp:1119
lldb_private::IRExecutionUnit::FindSymbol
lldb::addr_t FindSymbol(ConstString name, bool &missing_weak)
Definition: IRExecutionUnit.cpp:867
lldb_private::Stream
Definition: Stream.h:28
lldb_private::IRExecutionUnit::FindInSymbols
lldb::addr_t FindInSymbols(const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc, bool &symbol_was_missing_weak)
Definition: IRExecutionUnit.cpp:773
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
Language.h
lldb_private::ModuleFunctionSearchOptions::include_symbols
bool include_symbols
Include the symbol table.
Definition: Module.h:65
lldb_private::Status::SetErrorToGenericError
void SetErrorToGenericError()
Set the current error to a generic error.
Definition: Status.cpp:231
lldb::eSectionTypeDWARFDebugStrOffsets
@ eSectionTypeDWARFDebugStrOffsets
Definition: lldb-enumerations.h:683
Debugger.h
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::Target
Definition: Target.h:473
Section.h
lldb_private::IRExecutionUnit::MemoryManager::allocateDataSection
uint8_t * allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, llvm::StringRef SectionName, bool IsReadOnly) override
Allocate space for data, and add it to the m_spaceBlocks map.
Definition: IRExecutionUnit.cpp:634
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
lldb_private::ModuleFunctionSearchOptions::include_inlines
bool include_inlines
Include inlined functions.
Definition: Module.h:67
lldb_private::IRMemoryMap::Free
void Free(lldb::addr_t process_address, Status &error)
Definition: IRMemoryMap.cpp:446
lldb_private::IRExecutionUnit::AllocationRecord::m_size
size_t m_size
Definition: IRExecutionUnit.h:343
Target.h
lldb_private::IRExecutionUnit::MemoryManager::MemoryManager
MemoryManager(IRExecutionUnit &parent)
Definition: IRExecutionUnit.cpp:506
lldb_private::SectionList::AddSection
size_t AddSection(const lldb::SectionSP &section_sp)
Definition: Section.cpp:469
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb::eSymbolTypeAny
@ eSymbolTypeAny
Definition: lldb-enumerations.h:619
lldb_private::IRExecutionUnit::m_failed_lookups
std::vector< ConstString > m_failed_lookups
Definition: IRExecutionUnit.h:383
lldb_private::Status::Success
bool Success() const
Test for success condition.
Definition: Status.cpp:287
lldb_private::IRExecutionUnit::PopulateSectionList
void PopulateSectionList(lldb_private::ObjectFile *obj_file, lldb_private::SectionList &section_list) override
Definition: IRExecutionUnit.cpp:1159
lldb_private::ExecutionContext::GetAddressByteSize
uint32_t GetAddressByteSize() const
Definition: ExecutionContext.cpp:174
lldb_private::IRExecutionUnit::ReportAllocations
void ReportAllocations(llvm::ExecutionEngine &engine)
Report all committed allocations to the execution engine.
Definition: IRExecutionUnit.cpp:1101
lldb_private::IRExecutionUnit::GetRemoteAddressForLocal
lldb::addr_t GetRemoteAddressForLocal(lldb::addr_t local_address)
Look up the object in m_address_map that contains a given address, find where it was copied to,...
Definition: IRExecutionUnit.cpp:991
lldb_private::IRExecutionUnit::CollectCandidateCNames
void CollectCandidateCNames(std::vector< ConstString > &C_names, ConstString name)
Definition: IRExecutionUnit.cpp:665
lldb_private::InstructionList
Definition: Disassembler.h:267
lldb_private::IRExecutionUnit::m_module
llvm::Module * m_module
Owned by the execution engine.
Definition: IRExecutionUnit.h:371
LLDBAssert.h
lldb::eSectionTypeDWARFDebugAbbrev
@ eSectionTypeDWARFDebugAbbrev
Definition: lldb-enumerations.h:669
lldb_private::IRExecutionUnit::m_function_end_load_addr
lldb::addr_t m_function_end_load_addr
Definition: IRExecutionUnit.h:388
lldb_private::DataExtractor
Definition: DataExtractor.h:48
Log.h
lldb::eSymbolTypeUndefined
@ eSymbolTypeUndefined
Definition: lldb-enumerations.h:645
lldb_private::ConstString::IsEmpty
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:304
lldb_private::IRExecutionUnit::m_reported_allocations
bool m_reported_allocations
True after allocations have been reported.
Definition: IRExecutionUnit.h:392
lldb::eSectionTypeDWARFDebugStr
@ eSectionTypeDWARFDebugStr
Definition: lldb-enumerations.h:682
LoadAddressResolver::Resolve
llvm::Optional< lldb::addr_t > Resolve(SymbolContextList &sc_list)
Definition: IRExecutionUnit.cpp:703
lldb_private::IRExecutionUnit::AllocationKind::Stub
@ Stub
lldb_private::IRExecutionUnit::IRExecutionUnit
IRExecutionUnit(std::unique_ptr< llvm::LLVMContext > &context_up, std::unique_ptr< llvm::Module > &module_up, ConstString &name, const lldb::TargetSP &target_sp, const SymbolContext &sym_ctx, std::vector< std::string > &cpu_features)
Constructor.
Definition: IRExecutionUnit.cpp:43
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
lldb_private::IRExecutionUnit::MemoryManager::findSymbol
llvm::JITSymbol findSymbol(const std::string &Name) override
Definition: IRExecutionUnit.cpp:945
lldb_private::Status::SetErrorStringWithFormat
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:255
lldb_private::Address::GetFileAddress
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:291
lldb_private::IRExecutionUnit::JittedFunction
Definition: IRExecutionUnit.h:141
lldb_private::IRMemoryMap::eAllocationPolicyMirror
@ eAllocationPolicyMirror
The intent is that this allocation exist both in the host and the process and have the same content i...
Definition: IRMemoryMap.h:46
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::StreamString
Definition: StreamString.h:23
lldb::eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugInfo
Definition: lldb-enumerations.h:674
LoadAddressResolver
Definition: IRExecutionUnit.cpp:698
lldb_private::IRExecutionUnit::eSectionIDInvalid
static const unsigned eSectionIDInvalid
Definition: IRExecutionUnit.h:325
lldb_private::IRExecutionUnit::AllocationKind::Code
@ Code
lldb::eSectionTypeDWARFAppleTypes
@ eSectionTypeDWARFAppleTypes
Definition: lldb-enumerations.h:685
lldb::eSectionTypeDWARFAppleNames
@ eSectionTypeDWARFAppleNames
Definition: lldb-enumerations.h:684
lldb_private::IRExecutionUnit::MemoryManager::getPointerToNamedFunction
void * getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure=true) override
Definition: IRExecutionUnit.cpp:985
lldb::eSectionTypeDWARFGNUDebugAltLink
@ eSectionTypeDWARFGNUDebugAltLink
Definition: lldb-enumerations.h:700
lldb_private::LanguageRuntime
Definition: LanguageRuntime.h:60
IRExecutionUnit.h
HostInfo.h
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::IRExecutionUnit::MemoryManager::~MemoryManager
~MemoryManager() override
lldb_private::FileSpec::CopyByAppendingPathComponent
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
Definition: FileSpec.cpp:399
lldb_private::IRExecutionUnit::AllocationRecord::m_alignment
unsigned m_alignment
Definition: IRExecutionUnit.h:344
lldb::eSectionTypeDWARFDebugCuIndex
@ eSectionTypeDWARFDebugCuIndex
Definition: lldb-enumerations.h:672
lldb_private::IRExecutionUnit::AllocationKind
AllocationKind
Definition: IRExecutionUnit.h:327
lldb_private::IRExecutionUnit::GetSectionTypeFromSectionName
static lldb::SectionType GetSectionTypeFromSectionName(const llvm::StringRef &name, AllocationKind alloc_kind)
Definition: IRExecutionUnit.cpp:511
lldb_private::CompilerDeclContext
Represents a generic declaration context in a program.
Definition: CompilerDeclContext.h:30
lldb_private::Language::FindPlugin
static Language * FindPlugin(lldb::LanguageType language)
Definition: Language.cpp:53
lldb_private::ArchSpec::GetAddressByteSize
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:684
lldb_private::IRExecutionUnit::m_did_jit
std::atomic< bool > m_did_jit
Definition: IRExecutionUnit.h:385
lldb::eSectionTypeData
@ eSectionTypeData
Definition: lldb-enumerations.h:656
lldb_private::IRExecutionUnit::PopulateSymtab
void PopulateSymtab(lldb_private::ObjectFile *obj_file, lldb_private::Symtab &symtab) override
Definition: IRExecutionUnit.cpp:1154
lldb_private::ModuleFunctionSearchOptions
Options used by Module::FindFunctions.
Definition: Module.h:63
lldb_private::IRMemoryMap::ReadMemory
void ReadMemory(uint8_t *bytes, lldb::addr_t process_address, size_t size, Status &error)
Definition: IRMemoryMap.cpp:621
lldb_private::IRExecutionUnit::ReportSymbolLookupError
void ReportSymbolLookupError(ConstString name)
Definition: IRExecutionUnit.cpp:228
lldb_private::IRExecutionUnit::CommitAllocations
bool CommitAllocations(lldb::ProcessSP &process_sp)
Commit all allocations to the process and record where they were stored.
Definition: IRExecutionUnit.cpp:1076
lldb_private::Section
Definition: Section.h:102
lldb_private::IRExecutionUnit::MemoryManager::allocateCodeSection
uint8_t * allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, llvm::StringRef SectionName) override
Allocate space for executable code, and add it to the m_spaceBlocks map.
Definition: IRExecutionUnit.cpp:604
lldb::eSectionTypeOther
@ eSectionTypeOther
Definition: lldb-enumerations.h:703
lldb::eSectionTypeCode
@ eSectionTypeCode
Definition: lldb-enumerations.h:654
lldb_private::IRExecutionUnit::m_cpu_features
std::vector< std::string > m_cpu_features
Definition: IRExecutionUnit.h:372
lldbassert
#define lldbassert(x)
Definition: LLDBAssert.h:15
lldb_private::IRExecutionUnit::m_module_up
std::unique_ptr< llvm::Module > m_module_up
Holder for the module until it's been handed off.
Definition: IRExecutionUnit.h:370
lldb_private::IRExecutionUnit::GetStaticInitializers
void GetStaticInitializers(std::vector< lldb::addr_t > &static_initializers)
Definition: IRExecutionUnit.cpp:895
lldb_private::Target::GetArchitecture
const ArchSpec & GetArchitecture() const
Definition: Target.h:989
lldb_private::IRExecutionUnit::AllocationRecord
Encapsulates a single allocation request made by the JIT.
Definition: IRExecutionUnit.h:337
lldb_private::Status
Definition: Status.h:44
lldb_private::ArchSpec::GetArchitectureName
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition: ArchSpec.cpp:539
lldb_private::IRMemoryMap::WriteMemory
void WriteMemory(lldb::addr_t process_address, const uint8_t *bytes, size_t size, Status &error)
Definition: IRMemoryMap.cpp:512
lldb_private::IRExecutionUnit::AllocationKind::Data
@ Data
lldb_private::Symtab
Definition: Symtab.h:22
uint32_t
lldb::SectionType
SectionType
Definition: lldb-enumerations.h:652
lldb_private::IRExecutionUnit::AllocationKind::Bytes
@ Bytes
lldb_private::IRExecutionUnit::FreeNow
void FreeNow(lldb::addr_t allocation)
Definition: IRExecutionUnit.cpp:92
lldb_private::SymbolContextList::SymbolContexts
SymbolContextIterable SymbolContexts()
Definition: SymbolContext.h:474
lldb_private::Address
Definition: Address.h:59
lldb_private::IRExecutionUnit::AllocationRecord::m_process_address
lldb::addr_t m_process_address
Definition: IRExecutionUnit.h:339
lldb::eSectionTypeDWARFDebugPubTypes
@ eSectionTypeDWARFDebugPubTypes
Definition: lldb-enumerations.h:680
lldb_private::IRExecutionUnit::m_jitted_functions
std::vector< JittedFunction > m_jitted_functions
A vector of all functions that have been JITted into machine code.
Definition: IRExecutionUnit.h:373
lldb_private::IRExecutionUnit::m_records
RecordVector m_records
Definition: IRExecutionUnit.h:364
lldb_private::IRExecutionUnit::CollectCandidateCPlusPlusNames
void CollectCandidateCPlusPlusNames(std::vector< ConstString > &CPP_names, const std::vector< ConstString > &C_names, const SymbolContext &sc)
Definition: IRExecutionUnit.cpp:672
lldb_private::IRExecutionUnit::GetRemoteRangeForLocal
AddrRange GetRemoteRangeForLocal(lldb::addr_t local_address)
Look up the object in m_address_map that contains a given address, find where it was copied to,...
Definition: IRExecutionUnit.cpp:1020
lldb::eSectionTypeDWARFDebugPubNames
@ eSectionTypeDWARFDebugPubNames
Definition: lldb-enumerations.h:679
lldb_private::IRExecutionUnit::m_context_up
std::unique_ptr< llvm::LLVMContext > m_context_up
Definition: IRExecutionUnit.h:366
lldb::eSectionTypeInvalid
@ eSectionTypeInvalid
Definition: lldb-enumerations.h:653
lldb_private::Status::SetErrorString
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
lldb_private::Address::GetLoadAddress
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:311
LoadAddressResolver::LoadAddressResolver
LoadAddressResolver(Target *target, bool &symbol_was_missing_weak)
Definition: IRExecutionUnit.cpp:700
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:19
lldb_private::IRExecutionUnit::m_function_load_addr
lldb::addr_t m_function_load_addr
Definition: IRExecutionUnit.h:387
lldb_private::ModuleChild::GetModule
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
lldb_private::SymbolContext::module_sp
lldb::ModuleSP module_sp
The Module for a given query.
Definition: SymbolContext.h:318
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
lldb_private::IRExecutionUnit::AllocationRecord::m_sect_type
lldb::SectionType m_sect_type
Definition: IRExecutionUnit.h:342
lldb_private::IRExecutionUnit::GetByteOrder
lldb::ByteOrder GetByteOrder() const override
ObjectFileJITDelegate overrides.
Definition: IRExecutionUnit.cpp:1144
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:336
lldb_private::IRExecutionUnit::GetArchitecture
ArchSpec GetArchitecture() override
Definition: IRExecutionUnit.cpp:1178
DataExtractor.h
LanguageRuntime.h
lldb_private::SymbolContextList::IsEmpty
bool IsEmpty() const
Definition: SymbolContext.cpp:1278
SymbolContext.h
lldb_private::IRMemoryMap::GetBestExecutionContextScope
ExecutionContextScope * GetBestExecutionContextScope() const
Definition: IRMemoryMap.cpp:256
lldb_private::IRExecutionUnit::FindInRuntimes
lldb::addr_t FindInRuntimes(const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc)
Definition: IRExecutionUnit.cpp:826
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
LoadAddressResolver::m_target
Target * m_target
Definition: IRExecutionUnit.cpp:767
lldb_private::IRExecutionUnit::MemoryManager::GetSymbolAddressAndPresence
uint64_t GetSymbolAddressAndPresence(const std::string &Name, bool &missing_weak)
Definition: IRExecutionUnit.cpp:963
lldb_private::IRExecutionUnit::AllocationKind::Global
@ Global
lldb_private::IRExecutionUnit::WriteNow
lldb::addr_t WriteNow(const uint8_t *bytes, size_t size, Status &error)
Accessors for IRForTarget and other clients that may want binary data placed on their behalf.
Definition: IRExecutionUnit.cpp:56
lldb_private::IRExecutionUnit::m_name
const ConstString m_name
Definition: IRExecutionUnit.h:381
lldb::eByteOrderBig
@ eByteOrderBig
Definition: lldb-enumerations.h:140
lldb_private::Status::Clear
void Clear()
Clear the object state.
Definition: Status.cpp:167
LoadAddressResolver::m_symbol_was_missing_weak
bool & m_symbol_was_missing_weak
Definition: IRExecutionUnit.cpp:768
lldb_private::IRExecutionUnit::m_execution_engine_up
std::unique_ptr< llvm::ExecutionEngine > m_execution_engine_up
Definition: IRExecutionUnit.h:367
lldb_private::InstructionList::Dump
void Dump(Stream *s, bool show_address, bool show_bytes, const ExecutionContext *exe_ctx)
Definition: Disassembler.cpp:959
lldb_private::IRExecutionUnit::MemoryManager::getSymbolAddress
uint64_t getSymbolAddress(const std::string &Name) override
Definition: IRExecutionUnit.cpp:957
lldb_private::IRMemoryMap::eAllocationPolicyProcessOnly
@ eAllocationPolicyProcessOnly
The intent is that this allocation exist only in the process.
Definition: IRMemoryMap.h:49
lldb_private::Process::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3341
lldb_private::Log
Definition: Log.h:115
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb_private::IRExecutionUnit::GetJITModule
lldb::ModuleSP GetJITModule()
Definition: IRExecutionUnit.cpp:1185
lldb::eSectionTypeDWARFDebugMacInfo
@ eSectionTypeDWARFDebugMacInfo
Definition: lldb-enumerations.h:677
SymbolVendor.h
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:308
lldb_private::FileSpec::GetPath
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:347
lldb_private::IRExecutionUnit::AllocationRecord::m_permissions
uint32_t m_permissions
Definition: IRExecutionUnit.h:341
lldb_private::DataExtractor::GetByteSize
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
Definition: DataExtractor.h:270
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb_private::LLDBLog::Expressions
@ Expressions
lldb_private::IRMemoryMap
Definition: IRMemoryMap.h:34
lldb_private::DataExtractor::TypeUInt8
@ TypeUInt8
Format output as unsigned 8 bit integers.
Definition: DataExtractor.h:53
lldb::eSectionTypeDWARFDebugLocLists
@ eSectionTypeDWARFDebugLocLists
DWARF v5 .debug_loclists.
Definition: lldb-enumerations.h:706
LLDBLog.h
SymbolFile.h
lldb_private::ExecutionContext::GetTargetPtr
Target * GetTargetPtr() const
Returns a pointer to the target object.
Definition: ExecutionContext.cpp:198
lldb_private::ObjectFile
Definition: ObjectFile.h:60
ExecutionContext.h
DataBufferHeap.h
lldb_private::IRExecutionUnit::m_object_cache_up
std::unique_ptr< llvm::ObjectCache > m_object_cache_up
Definition: IRExecutionUnit.h:368
LoadAddressResolver::GetBestInternalLoadAddress
lldb::addr_t GetBestInternalLoadAddress() const
Definition: IRExecutionUnit.cpp:762
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138
lldb_private::Status::AsCString
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:130
lldb_private::IRExecutionUnit::CommitOneAllocation
bool CommitOneAllocation(lldb::ProcessSP &process_sp, Status &error, AllocationRecord &record)
Definition: IRExecutionUnit.cpp:1034
lldb::eLanguageTypeC_plus_plus
@ eLanguageTypeC_plus_plus
ISO C++:1998.
Definition: lldb-enumerations.h:441