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