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, /*show_control_flow_kind=*/true,
204  &exe_ctx);
205 
206  return ret;
207 }
208 
209 namespace {
210 struct IRExecDiagnosticHandler : public llvm::DiagnosticHandler {
211  Status *err;
212  IRExecDiagnosticHandler(Status *err) : err(err) {}
213  bool handleDiagnostics(const llvm::DiagnosticInfo &DI) override {
214  if (DI.getKind() == llvm::DK_SrcMgr) {
215  const auto &DISM = llvm::cast<llvm::DiagnosticInfoSrcMgr>(DI);
216  if (err && err->Success()) {
217  err->SetErrorToGenericError();
219  "Inline assembly error: %s",
220  DISM.getSMDiag().getMessage().str().c_str());
221  }
222  return true;
223  }
224 
225  return false;
226  }
227 };
228 } // namespace
229 
231  m_failed_lookups.push_back(name);
232 }
233 
235  lldb::addr_t &func_end) {
236  lldb::ProcessSP process_sp(GetProcessWP().lock());
237 
238  static std::recursive_mutex s_runnable_info_mutex;
239 
240  func_addr = LLDB_INVALID_ADDRESS;
241  func_end = LLDB_INVALID_ADDRESS;
242 
243  if (!process_sp) {
244  error.SetErrorToGenericError();
245  error.SetErrorString("Couldn't write the JIT compiled code into the "
246  "process because the process is invalid");
247  return;
248  }
249 
250  if (m_did_jit) {
251  func_addr = m_function_load_addr;
252  func_end = m_function_end_load_addr;
253 
254  return;
255  };
256 
257  std::lock_guard<std::recursive_mutex> guard(s_runnable_info_mutex);
258 
259  m_did_jit = true;
260 
262 
263  std::string error_string;
264 
265  if (log) {
266  std::string s;
267  llvm::raw_string_ostream oss(s);
268 
269  m_module->print(oss, nullptr);
270 
271  oss.flush();
272 
273  LLDB_LOGF(log, "Module being sent to JIT: \n%s", s.c_str());
274  }
275 
276  m_module_up->getContext().setDiagnosticHandler(
277  std::make_unique<IRExecDiagnosticHandler>(&error));
278 
279  llvm::EngineBuilder builder(std::move(m_module_up));
280  llvm::Triple triple(m_module->getTargetTriple());
281 
282  builder.setEngineKind(llvm::EngineKind::JIT)
283  .setErrorStr(&error_string)
284  .setRelocationModel(triple.isOSBinFormatMachO() ? llvm::Reloc::PIC_
285  : llvm::Reloc::Static)
286  .setMCJITMemoryManager(std::make_unique<MemoryManager>(*this))
287  .setOptLevel(llvm::CodeGenOpt::Less);
288 
289  llvm::StringRef mArch;
290  llvm::StringRef mCPU;
291  llvm::SmallVector<std::string, 0> mAttrs;
292 
293  for (std::string &feature : m_cpu_features)
294  mAttrs.push_back(feature);
295 
296  llvm::TargetMachine *target_machine =
297  builder.selectTarget(triple, mArch, mCPU, mAttrs);
298 
299  m_execution_engine_up.reset(builder.create(target_machine));
300 
301  if (!m_execution_engine_up) {
302  error.SetErrorToGenericError();
303  error.SetErrorStringWithFormat("Couldn't JIT the function: %s",
304  error_string.c_str());
305  return;
306  }
307 
309  (m_execution_engine_up->getDataLayout().getGlobalPrefix() == '_');
310 
311  class ObjectDumper : public llvm::ObjectCache {
312  public:
313  ObjectDumper(FileSpec output_dir) : m_out_dir(output_dir) {}
314  void notifyObjectCompiled(const llvm::Module *module,
315  llvm::MemoryBufferRef object) override {
316  int fd = 0;
317  llvm::SmallVector<char, 256> result_path;
318  std::string object_name_model =
319  "jit-object-" + module->getModuleIdentifier() + "-%%%.o";
320  FileSpec model_spec
321  = m_out_dir.CopyByAppendingPathComponent(object_name_model);
322  std::string model_path = model_spec.GetPath();
323 
324  std::error_code result
325  = llvm::sys::fs::createUniqueFile(model_path, fd, result_path);
326  if (!result) {
327  llvm::raw_fd_ostream fds(fd, true);
328  fds.write(object.getBufferStart(), object.getBufferSize());
329  }
330  }
331  std::unique_ptr<llvm::MemoryBuffer>
332  getObject(const llvm::Module *module) override {
333  // Return nothing - we're just abusing the object-cache mechanism to dump
334  // objects.
335  return nullptr;
336  }
337  private:
338  FileSpec m_out_dir;
339  };
340 
341  FileSpec save_objects_dir = process_sp->GetTarget().GetSaveJITObjectsDir();
342  if (save_objects_dir) {
343  m_object_cache_up = std::make_unique<ObjectDumper>(save_objects_dir);
344  m_execution_engine_up->setObjectCache(m_object_cache_up.get());
345  }
346 
347  // Make sure we see all sections, including ones that don't have
348  // relocations...
349  m_execution_engine_up->setProcessAllSections(true);
350 
351  m_execution_engine_up->DisableLazyCompilation();
352 
353  for (llvm::Function &function : *m_module) {
354  if (function.isDeclaration() || function.hasPrivateLinkage())
355  continue;
356 
357  const bool external = !function.hasLocalLinkage();
358 
359  void *fun_ptr = m_execution_engine_up->getPointerToFunction(&function);
360 
361  if (!error.Success()) {
362  // We got an error through our callback!
363  return;
364  }
365 
366  if (!fun_ptr) {
367  error.SetErrorToGenericError();
368  error.SetErrorStringWithFormat(
369  "'%s' was in the JITted module but wasn't lowered",
370  function.getName().str().c_str());
371  return;
372  }
374  function.getName().str().c_str(), external, reinterpret_cast<uintptr_t>(fun_ptr)));
375  }
376 
377  CommitAllocations(process_sp);
379 
380  // We have to do this after calling ReportAllocations because for the MCJIT,
381  // getGlobalValueAddress will cause the JIT to perform all relocations. That
382  // can only be done once, and has to happen after we do the remapping from
383  // local -> remote. That means we don't know the local address of the
384  // Variables, but we don't need that for anything, so that's okay.
385 
386  std::function<void(llvm::GlobalValue &)> RegisterOneValue = [this](
387  llvm::GlobalValue &val) {
388  if (val.hasExternalLinkage() && !val.isDeclaration()) {
389  uint64_t var_ptr_addr =
390  m_execution_engine_up->getGlobalValueAddress(val.getName().str());
391 
392  lldb::addr_t remote_addr = GetRemoteAddressForLocal(var_ptr_addr);
393 
394  // This is a really unfortunae API that sometimes returns local addresses
395  // and sometimes returns remote addresses, based on whether the variable
396  // was relocated during ReportAllocations or not.
397 
398  if (remote_addr == LLDB_INVALID_ADDRESS) {
399  remote_addr = var_ptr_addr;
400  }
401 
402  if (var_ptr_addr != 0)
404  val.getName().str().c_str(), LLDB_INVALID_ADDRESS, remote_addr));
405  }
406  };
407 
408  for (llvm::GlobalVariable &global_var : m_module->getGlobalList()) {
409  RegisterOneValue(global_var);
410  }
411 
412  for (llvm::GlobalAlias &global_alias : m_module->getAliasList()) {
413  RegisterOneValue(global_alias);
414  }
415 
416  WriteData(process_sp);
417 
418  if (m_failed_lookups.size()) {
419  StreamString ss;
420 
421  ss.PutCString("Couldn't lookup symbols:\n");
422 
423  bool emitNewLine = false;
424 
425  for (ConstString failed_lookup : m_failed_lookups) {
426  if (emitNewLine)
427  ss.PutCString("\n");
428  emitNewLine = true;
429  ss.PutCString(" ");
430  ss.PutCString(Mangled(failed_lookup).GetDemangledName().GetStringRef());
431  }
432 
433  m_failed_lookups.clear();
434 
435  error.SetErrorString(ss.GetString());
436 
437  return;
438  }
439 
442 
443  for (JittedFunction &jitted_function : m_jitted_functions) {
444  jitted_function.m_remote_addr =
445  GetRemoteAddressForLocal(jitted_function.m_local_addr);
446 
447  if (!m_name.IsEmpty() && jitted_function.m_name == m_name) {
448  AddrRange func_range =
449  GetRemoteRangeForLocal(jitted_function.m_local_addr);
450  m_function_end_load_addr = func_range.first + func_range.second;
451  m_function_load_addr = jitted_function.m_remote_addr;
452  }
453  }
454 
455  if (log) {
456  LLDB_LOGF(log, "Code can be run in the target.");
457 
458  StreamString disassembly_stream;
459 
460  Status err = DisassembleFunction(disassembly_stream, process_sp);
461 
462  if (!err.Success()) {
463  LLDB_LOGF(log, "Couldn't disassemble function : %s",
464  err.AsCString("unknown error"));
465  } else {
466  LLDB_LOGF(log, "Function disassembly:\n%s", disassembly_stream.GetData());
467  }
468 
469  LLDB_LOGF(log, "Sections: ");
470  for (AllocationRecord &record : m_records) {
471  if (record.m_process_address != LLDB_INVALID_ADDRESS) {
472  record.dump(log);
473 
474  DataBufferHeap my_buffer(record.m_size, 0);
475  Status err;
476  ReadMemory(my_buffer.GetBytes(), record.m_process_address,
477  record.m_size, err);
478 
479  if (err.Success()) {
480  DataExtractor my_extractor(my_buffer.GetBytes(),
481  my_buffer.GetByteSize(),
483  my_extractor.PutToLog(log, 0, my_buffer.GetByteSize(),
484  record.m_process_address, 16,
486  }
487  } else {
488  record.dump(log);
489 
490  DataExtractor my_extractor((const void *)record.m_host_address,
491  record.m_size, lldb::eByteOrderBig, 8);
492  my_extractor.PutToLog(log, 0, record.m_size, record.m_host_address, 16,
494  }
495  }
496  }
497 
498  func_addr = m_function_load_addr;
499  func_end = m_function_end_load_addr;
500 }
501 
503  m_module_up.reset();
504  m_execution_engine_up.reset();
505  m_context_up.reset();
506 }
507 
509  : m_default_mm_up(new llvm::SectionMemoryManager()), m_parent(parent) {}
510 
512 
514  const llvm::StringRef &name, IRExecutionUnit::AllocationKind alloc_kind) {
516  switch (alloc_kind) {
518  sect_type = lldb::eSectionTypeCode;
519  break;
521  sect_type = lldb::eSectionTypeCode;
522  break;
524  sect_type = lldb::eSectionTypeData;
525  break;
527  sect_type = lldb::eSectionTypeData;
528  break;
530  sect_type = lldb::eSectionTypeOther;
531  break;
532  }
533 
534  if (!name.empty()) {
535  if (name.equals("__text") || name.equals(".text"))
536  sect_type = lldb::eSectionTypeCode;
537  else if (name.equals("__data") || name.equals(".data"))
538  sect_type = lldb::eSectionTypeCode;
539  else if (name.startswith("__debug_") || name.startswith(".debug_")) {
540  const uint32_t name_idx = name[0] == '_' ? 8 : 7;
541  llvm::StringRef dwarf_name(name.substr(name_idx));
542  switch (dwarf_name[0]) {
543  case 'a':
544  if (dwarf_name.equals("abbrev"))
546  else if (dwarf_name.equals("aranges"))
548  else if (dwarf_name.equals("addr"))
550  break;
551 
552  case 'f':
553  if (dwarf_name.equals("frame"))
555  break;
556 
557  case 'i':
558  if (dwarf_name.equals("info"))
560  break;
561 
562  case 'l':
563  if (dwarf_name.equals("line"))
565  else if (dwarf_name.equals("loc"))
567  else if (dwarf_name.equals("loclists"))
569  break;
570 
571  case 'm':
572  if (dwarf_name.equals("macinfo"))
574  break;
575 
576  case 'p':
577  if (dwarf_name.equals("pubnames"))
579  else if (dwarf_name.equals("pubtypes"))
581  break;
582 
583  case 's':
584  if (dwarf_name.equals("str"))
586  else if (dwarf_name.equals("str_offsets"))
588  break;
589 
590  case 'r':
591  if (dwarf_name.equals("ranges"))
593  break;
594 
595  default:
596  break;
597  }
598  } else if (name.startswith("__apple_") || name.startswith(".apple_"))
599  sect_type = lldb::eSectionTypeInvalid;
600  else if (name.equals("__objc_imageinfo"))
601  sect_type = lldb::eSectionTypeOther;
602  }
603  return sect_type;
604 }
605 
607  uintptr_t Size, unsigned Alignment, unsigned SectionID,
608  llvm::StringRef SectionName) {
610 
611  uint8_t *return_value = m_default_mm_up->allocateCodeSection(
612  Size, Alignment, SectionID, SectionName);
613 
614  m_parent.m_records.push_back(AllocationRecord(
615  (uintptr_t)return_value,
616  lldb::ePermissionsReadable | lldb::ePermissionsExecutable,
618  Alignment, SectionID, SectionName.str().c_str()));
619 
620  LLDB_LOGF(log,
621  "IRExecutionUnit::allocateCodeSection(Size=0x%" PRIx64
622  ", Alignment=%u, SectionID=%u) = %p",
623  (uint64_t)Size, Alignment, SectionID, (void *)return_value);
624 
625  if (m_parent.m_reported_allocations) {
626  Status err;
627  lldb::ProcessSP process_sp =
628  m_parent.GetBestExecutionContextScope()->CalculateProcess();
629 
630  m_parent.CommitOneAllocation(process_sp, err, m_parent.m_records.back());
631  }
632 
633  return return_value;
634 }
635 
637  uintptr_t Size, unsigned Alignment, unsigned SectionID,
638  llvm::StringRef SectionName, bool IsReadOnly) {
640 
641  uint8_t *return_value = m_default_mm_up->allocateDataSection(
642  Size, Alignment, SectionID, SectionName, IsReadOnly);
643 
644  uint32_t permissions = lldb::ePermissionsReadable;
645  if (!IsReadOnly)
646  permissions |= lldb::ePermissionsWritable;
647  m_parent.m_records.push_back(AllocationRecord(
648  (uintptr_t)return_value, permissions,
650  Alignment, SectionID, SectionName.str().c_str()));
651  LLDB_LOGF(log,
652  "IRExecutionUnit::allocateDataSection(Size=0x%" PRIx64
653  ", Alignment=%u, SectionID=%u) = %p",
654  (uint64_t)Size, Alignment, SectionID, (void *)return_value);
655 
656  if (m_parent.m_reported_allocations) {
657  Status err;
658  lldb::ProcessSP process_sp =
659  m_parent.GetBestExecutionContextScope()->CalculateProcess();
660 
661  m_parent.CommitOneAllocation(process_sp, err, m_parent.m_records.back());
662  }
663 
664  return return_value;
665 }
666 
667 void IRExecutionUnit::CollectCandidateCNames(std::vector<ConstString> &C_names,
668  ConstString name) {
669  if (m_strip_underscore && name.AsCString()[0] == '_')
670  C_names.insert(C_names.begin(), ConstString(&name.AsCString()[1]));
671  C_names.push_back(name);
672 }
673 
675  std::vector<ConstString> &CPP_names,
676  const std::vector<ConstString> &C_names, const SymbolContext &sc) {
678  for (const ConstString &name : C_names) {
679  Mangled mangled(name);
680  if (cpp_lang->SymbolNameFitsToLanguage(mangled)) {
681  if (ConstString best_alternate =
682  cpp_lang->FindBestAlternateFunctionMangledName(mangled, sc)) {
683  CPP_names.push_back(best_alternate);
684  }
685  }
686 
687  std::vector<ConstString> alternates =
688  cpp_lang->GenerateAlternateFunctionManglings(name);
689  CPP_names.insert(CPP_names.end(), alternates.begin(), alternates.end());
690 
691  // As a last-ditch fallback, try the base name for C++ names. It's
692  // terrible, but the DWARF doesn't always encode "extern C" correctly.
693  ConstString basename =
694  cpp_lang->GetDemangledFunctionNameWithoutArguments(mangled);
695  CPP_names.push_back(basename);
696  }
697  }
698 }
699 
701 public:
702  LoadAddressResolver(Target *target, bool &symbol_was_missing_weak)
703  : m_target(target), m_symbol_was_missing_weak(symbol_was_missing_weak) {}
704 
705  llvm::Optional<lldb::addr_t> Resolve(SymbolContextList &sc_list) {
706  if (sc_list.IsEmpty())
707  return llvm::None;
708 
709  lldb::addr_t load_address = LLDB_INVALID_ADDRESS;
710 
711  // Missing_weak_symbol will be true only if we found only weak undefined
712  // references to this symbol.
713  m_symbol_was_missing_weak = true;
714 
715  for (auto candidate_sc : sc_list.SymbolContexts()) {
716  // Only symbols can be weak undefined.
717  if (!candidate_sc.symbol ||
718  candidate_sc.symbol->GetType() != lldb::eSymbolTypeUndefined ||
719  !candidate_sc.symbol->IsWeak())
720  m_symbol_was_missing_weak = false;
721 
722  // First try the symbol.
723  if (candidate_sc.symbol) {
724  load_address = candidate_sc.symbol->ResolveCallableAddress(*m_target);
725  if (load_address == LLDB_INVALID_ADDRESS) {
726  Address addr = candidate_sc.symbol->GetAddress();
727  load_address = m_target->GetProcessSP()
728  ? addr.GetLoadAddress(m_target)
729  : addr.GetFileAddress();
730  }
731  }
732 
733  // If that didn't work, try the function.
734  if (load_address == LLDB_INVALID_ADDRESS && candidate_sc.function) {
735  Address addr =
736  candidate_sc.function->GetAddressRange().GetBaseAddress();
737  load_address = m_target->GetProcessSP() ? addr.GetLoadAddress(m_target)
738  : addr.GetFileAddress();
739  }
740 
741  // We found a load address.
742  if (load_address != LLDB_INVALID_ADDRESS) {
743  // If the load address is external, we're done.
744  const bool is_external =
745  (candidate_sc.function) ||
746  (candidate_sc.symbol && candidate_sc.symbol->IsExternal());
747  if (is_external)
748  return load_address;
749 
750  // Otherwise, remember the best internal load address.
751  if (m_best_internal_load_address == LLDB_INVALID_ADDRESS)
752  m_best_internal_load_address = load_address;
753  }
754  }
755 
756  // You test the address of a weak symbol against NULL to see if it is
757  // present. So we should return 0 for a missing weak symbol.
758  if (m_symbol_was_missing_weak)
759  return 0;
760 
761  return llvm::None;
762  }
763 
765  return m_best_internal_load_address;
766  }
767 
768 private:
771  lldb::addr_t m_best_internal_load_address = LLDB_INVALID_ADDRESS;
772 };
773 
775 IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
776  const lldb_private::SymbolContext &sc,
777  bool &symbol_was_missing_weak) {
778  symbol_was_missing_weak = false;
779 
780  Target *target = sc.target_sp.get();
781  if (!target) {
782  // We shouldn't be doing any symbol lookup at all without a target.
783  return LLDB_INVALID_ADDRESS;
784  }
785 
786  LoadAddressResolver resolver(target, symbol_was_missing_weak);
787 
788  ModuleFunctionSearchOptions function_options;
789  function_options.include_symbols = true;
790  function_options.include_inlines = false;
791 
792  for (const ConstString &name : names) {
793  if (sc.module_sp) {
794  SymbolContextList sc_list;
795  sc.module_sp->FindFunctions(name, CompilerDeclContext(),
796  lldb::eFunctionNameTypeFull, function_options,
797  sc_list);
798  if (auto load_addr = resolver.Resolve(sc_list))
799  return *load_addr;
800  }
801 
802  if (sc.target_sp) {
803  SymbolContextList sc_list;
804  sc.target_sp->GetImages().FindFunctions(name, lldb::eFunctionNameTypeFull,
805  function_options, sc_list);
806  if (auto load_addr = resolver.Resolve(sc_list))
807  return *load_addr;
808  }
809 
810  if (sc.target_sp) {
811  SymbolContextList sc_list;
812  sc.target_sp->GetImages().FindSymbolsWithNameAndType(
813  name, lldb::eSymbolTypeAny, sc_list);
814  if (auto load_addr = resolver.Resolve(sc_list))
815  return *load_addr;
816  }
817 
818  lldb::addr_t best_internal_load_address =
819  resolver.GetBestInternalLoadAddress();
820  if (best_internal_load_address != LLDB_INVALID_ADDRESS)
821  return best_internal_load_address;
822  }
823 
824  return LLDB_INVALID_ADDRESS;
825 }
826 
828 IRExecutionUnit::FindInRuntimes(const std::vector<ConstString> &names,
829  const lldb_private::SymbolContext &sc) {
830  lldb::TargetSP target_sp = sc.target_sp;
831 
832  if (!target_sp) {
833  return LLDB_INVALID_ADDRESS;
834  }
835 
836  lldb::ProcessSP process_sp = sc.target_sp->GetProcessSP();
837 
838  if (!process_sp) {
839  return LLDB_INVALID_ADDRESS;
840  }
841 
842  for (const ConstString &name : names) {
843  for (LanguageRuntime *runtime : process_sp->GetLanguageRuntimes()) {
844  lldb::addr_t symbol_load_addr = runtime->LookupRuntimeSymbol(name);
845 
846  if (symbol_load_addr != LLDB_INVALID_ADDRESS)
847  return symbol_load_addr;
848  }
849  }
850 
851  return LLDB_INVALID_ADDRESS;
852 }
853 
855  const std::vector<ConstString> &names,
856  const lldb_private::SymbolContext &sc) {
857  lldb::TargetSP target_sp = sc.target_sp;
858 
859  for (const ConstString &name : names) {
860  lldb::addr_t symbol_load_addr = target_sp->GetPersistentSymbol(name);
861 
862  if (symbol_load_addr != LLDB_INVALID_ADDRESS)
863  return symbol_load_addr;
864  }
865 
866  return LLDB_INVALID_ADDRESS;
867 }
868 
870  bool &missing_weak) {
871  std::vector<ConstString> candidate_C_names;
872  std::vector<ConstString> candidate_CPlusPlus_names;
873 
874  CollectCandidateCNames(candidate_C_names, name);
875 
876  lldb::addr_t ret = FindInSymbols(candidate_C_names, m_sym_ctx, missing_weak);
877  if (ret != LLDB_INVALID_ADDRESS)
878  return ret;
879 
880  // If we find the symbol in runtimes or user defined symbols it can't be
881  // a missing weak symbol.
882  missing_weak = false;
883  ret = FindInRuntimes(candidate_C_names, m_sym_ctx);
884  if (ret != LLDB_INVALID_ADDRESS)
885  return ret;
886 
887  ret = FindInUserDefinedSymbols(candidate_C_names, m_sym_ctx);
888  if (ret != LLDB_INVALID_ADDRESS)
889  return ret;
890 
891  CollectCandidateCPlusPlusNames(candidate_CPlusPlus_names, candidate_C_names,
892  m_sym_ctx);
893  ret = FindInSymbols(candidate_CPlusPlus_names, m_sym_ctx, missing_weak);
894  return ret;
895 }
896 
898  std::vector<lldb::addr_t> &static_initializers) {
900 
901  llvm::GlobalVariable *global_ctors =
902  m_module->getNamedGlobal("llvm.global_ctors");
903  if (!global_ctors) {
904  LLDB_LOG(log, "Couldn't find llvm.global_ctors.");
905  return;
906  }
907  auto *ctor_array =
908  llvm::dyn_cast<llvm::ConstantArray>(global_ctors->getInitializer());
909  if (!ctor_array) {
910  LLDB_LOG(log, "llvm.global_ctors not a ConstantArray.");
911  return;
912  }
913 
914  for (llvm::Use &ctor_use : ctor_array->operands()) {
915  auto *ctor_struct = llvm::dyn_cast<llvm::ConstantStruct>(ctor_use);
916  if (!ctor_struct)
917  continue;
918  // this is standardized
919  lldbassert(ctor_struct->getNumOperands() == 3);
920  auto *ctor_function =
921  llvm::dyn_cast<llvm::Function>(ctor_struct->getOperand(1));
922  if (!ctor_function) {
923  LLDB_LOG(log, "global_ctor doesn't contain an llvm::Function");
924  continue;
925  }
926 
927  ConstString ctor_function_name(ctor_function->getName().str());
928  LLDB_LOG(log, "Looking for callable jitted function with name {0}.",
929  ctor_function_name);
930 
931  for (JittedFunction &jitted_function : m_jitted_functions) {
932  if (ctor_function_name != jitted_function.m_name)
933  continue;
934  if (jitted_function.m_remote_addr == LLDB_INVALID_ADDRESS) {
935  LLDB_LOG(log, "Found jitted function with invalid address.");
936  continue;
937  }
938  static_initializers.push_back(jitted_function.m_remote_addr);
939  LLDB_LOG(log, "Calling function at address {0:x}.",
940  jitted_function.m_remote_addr);
941  break;
942  }
943  }
944 }
945 
946 llvm::JITSymbol
948  bool missing_weak = false;
949  uint64_t addr = GetSymbolAddressAndPresence(Name, missing_weak);
950  // This is a weak symbol:
951  if (missing_weak)
952  return llvm::JITSymbol(addr,
953  llvm::JITSymbolFlags::Exported | llvm::JITSymbolFlags::Weak);
954  else
955  return llvm::JITSymbol(addr, llvm::JITSymbolFlags::Exported);
956 }
957 
958 uint64_t
960  bool missing_weak = false;
961  return GetSymbolAddressAndPresence(Name, missing_weak);
962 }
963 
964 uint64_t
966  const std::string &Name, bool &missing_weak) {
968 
969  ConstString name_cs(Name.c_str());
970 
971  lldb::addr_t ret = m_parent.FindSymbol(name_cs, missing_weak);
972 
973  if (ret == LLDB_INVALID_ADDRESS) {
974  LLDB_LOGF(log,
975  "IRExecutionUnit::getSymbolAddress(Name=\"%s\") = <not found>",
976  Name.c_str());
977 
978  m_parent.ReportSymbolLookupError(name_cs);
979  return 0;
980  } else {
981  LLDB_LOGF(log, "IRExecutionUnit::getSymbolAddress(Name=\"%s\") = %" PRIx64,
982  Name.c_str(), ret);
983  return ret;
984  }
985 }
986 
988  const std::string &Name, bool AbortOnFailure) {
989  return (void *)getSymbolAddress(Name);
990 }
991 
995 
996  for (AllocationRecord &record : m_records) {
997  if (local_address >= record.m_host_address &&
998  local_address < record.m_host_address + record.m_size) {
999  if (record.m_process_address == LLDB_INVALID_ADDRESS)
1000  return LLDB_INVALID_ADDRESS;
1001 
1002  lldb::addr_t ret =
1003  record.m_process_address + (local_address - record.m_host_address);
1004 
1005  LLDB_LOGF(log,
1006  "IRExecutionUnit::GetRemoteAddressForLocal() found 0x%" PRIx64
1007  " in [0x%" PRIx64 "..0x%" PRIx64 "], and returned 0x%" PRIx64
1008  " from [0x%" PRIx64 "..0x%" PRIx64 "].",
1009  local_address, (uint64_t)record.m_host_address,
1010  (uint64_t)record.m_host_address + (uint64_t)record.m_size, ret,
1011  record.m_process_address,
1012  record.m_process_address + record.m_size);
1013 
1014  return ret;
1015  }
1016  }
1017 
1018  return LLDB_INVALID_ADDRESS;
1019 }
1020 
1023  for (AllocationRecord &record : m_records) {
1024  if (local_address >= record.m_host_address &&
1025  local_address < record.m_host_address + record.m_size) {
1026  if (record.m_process_address == LLDB_INVALID_ADDRESS)
1027  return AddrRange(0, 0);
1028 
1029  return AddrRange(record.m_process_address, record.m_size);
1030  }
1031  }
1032 
1033  return AddrRange(0, 0);
1034 }
1035 
1036 bool IRExecutionUnit::CommitOneAllocation(lldb::ProcessSP &process_sp,
1037  Status &error,
1038  AllocationRecord &record) {
1039  if (record.m_process_address != LLDB_INVALID_ADDRESS) {
1040  return true;
1041  }
1042 
1043  switch (record.m_sect_type) {
1065  error.Clear();
1066  break;
1067  default:
1068  const bool zero_memory = false;
1069  record.m_process_address =
1070  Malloc(record.m_size, record.m_alignment, record.m_permissions,
1071  eAllocationPolicyProcessOnly, zero_memory, error);
1072  break;
1073  }
1074 
1075  return error.Success();
1076 }
1077 
1078 bool IRExecutionUnit::CommitAllocations(lldb::ProcessSP &process_sp) {
1079  bool ret = true;
1080 
1082 
1083  for (AllocationRecord &record : m_records) {
1084  ret = CommitOneAllocation(process_sp, err, record);
1085 
1086  if (!ret) {
1087  break;
1088  }
1089  }
1090 
1091  if (!ret) {
1092  for (AllocationRecord &record : m_records) {
1093  if (record.m_process_address != LLDB_INVALID_ADDRESS) {
1094  Free(record.m_process_address, err);
1095  record.m_process_address = LLDB_INVALID_ADDRESS;
1096  }
1097  }
1098  }
1099 
1100  return ret;
1101 }
1102 
1103 void IRExecutionUnit::ReportAllocations(llvm::ExecutionEngine &engine) {
1104  m_reported_allocations = true;
1105 
1106  for (AllocationRecord &record : m_records) {
1107  if (record.m_process_address == LLDB_INVALID_ADDRESS)
1108  continue;
1109 
1110  if (record.m_section_id == eSectionIDInvalid)
1111  continue;
1112 
1113  engine.mapSectionAddress((void *)record.m_host_address,
1114  record.m_process_address);
1115  }
1116 
1117  // Trigger re-application of relocations.
1118  engine.finalizeObject();
1119 }
1120 
1121 bool IRExecutionUnit::WriteData(lldb::ProcessSP &process_sp) {
1122  bool wrote_something = false;
1123  for (AllocationRecord &record : m_records) {
1124  if (record.m_process_address != LLDB_INVALID_ADDRESS) {
1126  WriteMemory(record.m_process_address, (uint8_t *)record.m_host_address,
1127  record.m_size, err);
1128  if (err.Success())
1129  wrote_something = true;
1130  }
1131  }
1132  return wrote_something;
1133 }
1134 
1136  if (!log)
1137  return;
1138 
1139  LLDB_LOGF(log,
1140  "[0x%llx+0x%llx]->0x%llx (alignment %d, section ID %d, name %s)",
1141  (unsigned long long)m_host_address, (unsigned long long)m_size,
1142  (unsigned long long)m_process_address, (unsigned)m_alignment,
1143  (unsigned)m_section_id, m_name.c_str());
1144 }
1145 
1148  return exe_ctx.GetByteOrder();
1149 }
1150 
1153  return exe_ctx.GetAddressByteSize();
1154 }
1155 
1157  lldb_private::Symtab &symtab) {
1158  // No symbols yet...
1159 }
1160 
1162  lldb_private::ObjectFile *obj_file,
1163  lldb_private::SectionList &section_list) {
1164  for (AllocationRecord &record : m_records) {
1165  if (record.m_size > 0) {
1166  lldb::SectionSP section_sp(new lldb_private::Section(
1167  obj_file->GetModule(), obj_file, record.m_section_id,
1168  ConstString(record.m_name), record.m_sect_type,
1169  record.m_process_address, record.m_size,
1170  record.m_host_address, // file_offset (which is the host address for
1171  // the data)
1172  record.m_size, // file_size
1173  0,
1174  record.m_permissions)); // flags
1175  section_list.AddSection(section_sp);
1176  }
1177  }
1178 }
1179 
1182  if(Target *target = exe_ctx.GetTargetPtr())
1183  return target->GetArchitecture();
1184  return ArchSpec();
1185 }
1186 
1189  Target *target = exe_ctx.GetTargetPtr();
1190  if (!target)
1191  return nullptr;
1192 
1193  auto Delegate = std::static_pointer_cast<lldb_private::ObjectFileJITDelegate>(
1194  shared_from_this());
1195 
1196  lldb::ModuleSP jit_module_sp =
1197  lldb_private::Module::CreateModuleFromObjectFile<ObjectFileJIT>(Delegate);
1198  if (!jit_module_sp)
1199  return nullptr;
1200 
1201  bool changed = false;
1202  jit_module_sp->SetLoadAddress(*target, 0, true, changed);
1203  return jit_module_sp;
1204 }
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:854
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:677
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:234
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:687
lldb_private::IRExecutionUnit::GetAddressByteSize
uint32_t GetAddressByteSize() const override
Definition: IRExecutionUnit.cpp:1151
lldb::eSectionTypeDWARFAppleObjC
@ eSectionTypeDWARFAppleObjC
Definition: lldb-enumerations.h:688
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:32
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:1925
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:1135
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:672
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:502
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:344
lldb::eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugRanges
Definition: lldb-enumerations.h:682
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:674
Module.h
lldb::eSectionTypeDWARFDebugLine
@ eSectionTypeDWARFDebugLine
Definition: lldb-enumerations.h:676
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:671
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:192
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:1121
lldb_private::IRExecutionUnit::FindSymbol
lldb::addr_t FindSymbol(ConstString name, bool &missing_weak)
Definition: IRExecutionUnit.cpp:869
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:775
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:66
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:684
Debugger.h
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::Target
Definition: Target.h:469
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:636
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:68
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:508
lldb_private::SectionList::AddSection
size_t AddSection(const lldb::SectionSP &section_sp)
Definition: Section.cpp:469
lldb_private::FileSpec
Definition: FileSpec.h:55
lldb_private::InstructionList::Dump
void Dump(Stream *s, bool show_address, bool show_bytes, bool show_control_flow_kind, const ExecutionContext *exe_ctx)
Definition: Disassembler.cpp:995
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb::eSymbolTypeAny
@ eSymbolTypeAny
Definition: lldb-enumerations.h:620
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:1161
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:1103
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:993
lldb_private::IRExecutionUnit::CollectCandidateCNames
void CollectCandidateCNames(std::vector< ConstString > &C_names, ConstString name)
Definition: IRExecutionUnit.cpp:667
lldb_private::InstructionList
Definition: Disassembler.h:283
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:670
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:646
lldb_private::ConstString::IsEmpty
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:303
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:683
LoadAddressResolver::Resolve
llvm::Optional< lldb::addr_t > Resolve(SymbolContextList &sc_list)
Definition: IRExecutionUnit.cpp:705
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:947
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:39
lldb_private::StreamString
Definition: StreamString.h:23
lldb::eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugInfo
Definition: lldb-enumerations.h:675
lldb::eLanguageTypeC_plus_plus
@ eLanguageTypeC_plus_plus
ISO C++:1998.
Definition: lldb-enumerations.h:442
LoadAddressResolver
Definition: IRExecutionUnit.cpp:700
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:686
lldb::eSectionTypeDWARFAppleNames
@ eSectionTypeDWARFAppleNames
Definition: lldb-enumerations.h:685
lldb_private::IRExecutionUnit::MemoryManager::getPointerToNamedFunction
void * getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure=true) override
Definition: IRExecutionUnit.cpp:987
lldb::eSectionTypeDWARFGNUDebugAltLink
@ eSectionTypeDWARFGNUDebugAltLink
Definition: lldb-enumerations.h:701
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:416
lldb_private::IRExecutionUnit::AllocationRecord::m_alignment
unsigned m_alignment
Definition: IRExecutionUnit.h:344
lldb::eSectionTypeDWARFDebugCuIndex
@ eSectionTypeDWARFDebugCuIndex
Definition: lldb-enumerations.h:673
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:513
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:694
lldb_private::IRExecutionUnit::m_did_jit
std::atomic< bool > m_did_jit
Definition: IRExecutionUnit.h:385
lldb::eSectionTypeData
@ eSectionTypeData
Definition: lldb-enumerations.h:657
lldb_private::IRExecutionUnit::PopulateSymtab
void PopulateSymtab(lldb_private::ObjectFile *obj_file, lldb_private::Symtab &symtab) override
Definition: IRExecutionUnit.cpp:1156
lldb_private::ModuleFunctionSearchOptions
Options used by Module::FindFunctions.
Definition: Module.h:64
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:230
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:1078
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:606
lldb::eSectionTypeOther
@ eSectionTypeOther
Definition: lldb-enumerations.h:704
lldb::eSectionTypeCode
@ eSectionTypeCode
Definition: lldb-enumerations.h:655
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:897
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:547
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:653
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:681
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:674
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:1022
lldb::eSectionTypeDWARFDebugPubNames
@ eSectionTypeDWARFDebugPubNames
Definition: lldb-enumerations.h:680
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:654
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:702
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:1146
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:337
lldb_private::IRExecutionUnit::GetArchitecture
ArchSpec GetArchitecture() override
Definition: IRExecutionUnit.cpp:1180
DataExtractor.h
LanguageRuntime.h
lldb_private::SymbolContextList::IsEmpty
bool IsEmpty() const
Definition: SymbolContext.cpp:1276
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:828
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:769
lldb_private::IRExecutionUnit::MemoryManager::GetSymbolAddressAndPresence
uint64_t GetSymbolAddressAndPresence(const std::string &Name, bool &missing_weak)
Definition: IRExecutionUnit.cpp:965
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:141
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:770
lldb_private::IRExecutionUnit::m_execution_engine_up
std::unique_ptr< llvm::ExecutionEngine > m_execution_engine_up
Definition: IRExecutionUnit.h:367
lldb_private::IRExecutionUnit::MemoryManager::getSymbolAddress
uint64_t getSymbolAddress(const std::string &Name) override
Definition: IRExecutionUnit.cpp:959
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:3362
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:1187
lldb::eSectionTypeDWARFDebugMacInfo
@ eSectionTypeDWARFDebugMacInfo
Definition: lldb-enumerations.h:678
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:309
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:364
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:707
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:764
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:139
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:1036