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/Error.h"
17#include "llvm/Support/SourceMgr.h"
18#include "llvm/Support/raw_ostream.h"
19
20#include "lldb/Core/Debugger.h"
22#include "lldb/Core/Module.h"
23#include "lldb/Core/Section.h"
27#include "lldb/Host/HostInfo.h"
35#include "lldb/Target/Target.h"
40#include "lldb/Utility/Log.h"
41#include "lldb/lldb-defines.h"
42
43#include <optional>
44
45using namespace lldb_private;
46
47IRExecutionUnit::IRExecutionUnit(std::unique_ptr<llvm::LLVMContext> &context_up,
48 std::unique_ptr<llvm::Module> &module_up,
49 ConstString &name,
50 const lldb::TargetSP &target_sp,
51 const SymbolContext &sym_ctx,
52 std::vector<std::string> &cpu_features)
53 : IRMemoryMap(target_sp), m_context_up(std::move(context_up)),
54 m_module_up(std::move(module_up)), m_module(m_module_up.get()),
55 m_cpu_features(cpu_features), m_name(name), m_sym_ctx(sym_ctx),
59 m_module_up ? m_module_up->getDataLayout().getGlobalPrefix() == '_'
60 : false),
62
64 lldb::ProcessSP &process_wp) {
66
67 ExecutionContext exe_ctx(process_wp);
68
69 Status ret;
70
71 ret.Clear();
72
73 lldb::addr_t func_local_addr = LLDB_INVALID_ADDRESS;
74 lldb::addr_t func_remote_addr = LLDB_INVALID_ADDRESS;
75
76 for (JittedFunction &function : m_jitted_functions) {
77 if (function.m_name == m_name) {
78 func_local_addr = function.m_local_addr;
79 func_remote_addr = function.m_remote_addr;
80 }
81 }
82
83 if (func_local_addr == LLDB_INVALID_ADDRESS) {
85 "Couldn't find function {0} for disassembly", m_name);
86 return ret;
87 }
88
89 LLDB_LOGF(log,
90 "Found function, has local address 0x%" PRIx64
91 " and remote address 0x%" PRIx64,
92 (uint64_t)func_local_addr, (uint64_t)func_remote_addr);
93
94 std::pair<lldb::addr_t, lldb::addr_t> func_range;
95
96 func_range = GetRemoteRangeForLocal(func_local_addr);
97
98 if (func_range.first == 0 && func_range.second == 0) {
100 "Couldn't find code range for function {0}", m_name);
101 return ret;
102 }
103
104 LLDB_LOGF(log, "Function's code range is [0x%" PRIx64 "+0x%" PRIx64 "]",
105 func_range.first, func_range.second);
106
107 Target *target = exe_ctx.GetTargetPtr();
108 if (!target) {
109 ret = Status::FromErrorString("Couldn't find the target");
110 return ret;
111 }
112
114 new DataBufferHeap(func_range.second, 0));
115
116 Process *process = exe_ctx.GetProcessPtr();
117 Status err;
118 process->ReadMemory(func_remote_addr, buffer_sp->GetBytes(),
119 buffer_sp->GetByteSize(), err);
120
121 if (!err.Success()) {
122 ret = Status::FromErrorStringWithFormat("Couldn't read from process: %s",
123 err.AsCString("unknown error"));
124 return ret;
125 }
126
127 ArchSpec arch(target->GetArchitecture());
128
129 const char *plugin_name = nullptr;
130 const char *flavor_string = nullptr;
131 const char *cpu_string = nullptr;
132 const char *features_string = nullptr;
134 arch, flavor_string, cpu_string, features_string, plugin_name);
135
136 if (!disassembler_sp) {
138 "Unable to find disassembler plug-in for %s architecture.",
139 arch.GetArchitectureName());
140 return ret;
141 }
142
143 if (!process) {
144 ret = Status::FromErrorString("Couldn't find the process");
145 return ret;
146 }
147
148 DataExtractor extractor(buffer_sp, process->GetByteOrder(),
150
151 if (log) {
152 LLDB_LOGF(log, "Function data has contents:");
153 extractor.PutToLog(log, 0, extractor.GetByteSize(), func_remote_addr, 16,
155 }
156
157 disassembler_sp->DecodeInstructions(Address(func_remote_addr), extractor, 0,
158 UINT32_MAX, false, false);
159
160 InstructionList &instruction_list = disassembler_sp->GetInstructionList();
161 instruction_list.Dump(&stream, true, true, /*show_control_flow_kind=*/false,
162 &exe_ctx);
163
164 return ret;
165}
166
167namespace {
168struct IRExecDiagnosticHandler : public llvm::DiagnosticHandler {
169 Status *err;
170 IRExecDiagnosticHandler(Status *err) : err(err) {}
171 bool handleDiagnostics(const llvm::DiagnosticInfo &DI) override {
172 if (DI.getSeverity() == llvm::DS_Error) {
173 const auto &DISM = llvm::cast<llvm::DiagnosticInfoSrcMgr>(DI);
174 if (err && err->Success()) {
176 "IRExecution error: %s",
177 DISM.getSMDiag().getMessage().str().c_str());
178 }
179 }
180
181 return true;
182 }
183};
184} // namespace
185
189
191 lldb::addr_t &func_end) {
192 lldb::ProcessSP process_sp(GetProcessWP().lock());
193
194 static std::recursive_mutex s_runnable_info_mutex;
195
196 func_addr = LLDB_INVALID_ADDRESS;
197 func_end = LLDB_INVALID_ADDRESS;
198
199 if (!process_sp) {
200 error =
201 Status::FromErrorString("Couldn't write the JIT compiled code into the "
202 "process because the process is invalid");
203 return;
204 }
205
206 if (m_did_jit) {
207 func_addr = m_function_load_addr;
208 func_end = m_function_end_load_addr;
209
210 return;
211 };
212
213 std::lock_guard<std::recursive_mutex> guard(s_runnable_info_mutex);
214
215 m_did_jit = true;
216
218
219 std::string error_string;
220
221 if (log) {
222 std::string s;
223 llvm::raw_string_ostream oss(s);
224
225 m_module->print(oss, nullptr);
226
227 LLDB_LOGF(log, "Module being sent to JIT: \n%s", s.c_str());
228 }
229
230 m_module_up->getContext().setDiagnosticHandler(
231 std::make_unique<IRExecDiagnosticHandler>(&error));
232
233 llvm::EngineBuilder builder(std::move(m_module_up));
234 llvm::Triple triple(m_module->getTargetTriple());
235
236 builder.setEngineKind(llvm::EngineKind::JIT)
237 .setErrorStr(&error_string)
238 .setRelocationModel(triple.isOSBinFormatMachO() ? llvm::Reloc::PIC_
239 : llvm::Reloc::Static)
240 .setMCJITMemoryManager(std::make_unique<MemoryManager>(*this))
241 .setOptLevel(llvm::CodeGenOptLevel::Less);
242
243 // Resulted jitted code can be placed too far from the code in the binary
244 // and thus can contain more than +-2GB jumps, that are not available
245 // in RISC-V without large code model.
246 if (triple.isRISCV64())
247 builder.setCodeModel(llvm::CodeModel::Large);
248
249 llvm::StringRef mArch;
250 llvm::StringRef mCPU;
251 llvm::SmallVector<std::string, 0> mAttrs;
252
253 for (std::string &feature : m_cpu_features)
254 mAttrs.push_back(feature);
255
256 llvm::TargetMachine *target_machine =
257 builder.selectTarget(triple, mArch, mCPU, mAttrs);
258
259 m_execution_engine_up.reset(builder.create(target_machine));
260
262 error = Status::FromErrorStringWithFormat("Couldn't JIT the function: %s",
263 error_string.c_str());
264 return;
265 }
266
267 class ObjectDumper : public llvm::ObjectCache {
268 public:
269 ObjectDumper(FileSpec output_dir) : m_out_dir(output_dir) {}
270 void notifyObjectCompiled(const llvm::Module *module,
271 llvm::MemoryBufferRef object) override {
272 int fd = 0;
273 llvm::SmallVector<char, 256> result_path;
274 std::string object_name_model =
275 "jit-object-" + module->getModuleIdentifier() + "-%%%.o";
276 FileSpec model_spec
277 = m_out_dir.CopyByAppendingPathComponent(object_name_model);
278 std::string model_path = model_spec.GetPath();
279
280 std::error_code result
281 = llvm::sys::fs::createUniqueFile(model_path, fd, result_path);
282 if (!result) {
283 llvm::raw_fd_ostream fds(fd, true);
284 fds.write(object.getBufferStart(), object.getBufferSize());
285 }
286 }
287 std::unique_ptr<llvm::MemoryBuffer>
288 getObject(const llvm::Module *module) override {
289 // Return nothing - we're just abusing the object-cache mechanism to dump
290 // objects.
291 return nullptr;
292 }
293 private:
294 FileSpec m_out_dir;
295 };
296
297 FileSpec save_objects_dir = process_sp->GetTarget().GetSaveJITObjectsDir();
298 if (save_objects_dir) {
299 m_object_cache_up = std::make_unique<ObjectDumper>(save_objects_dir);
300 m_execution_engine_up->setObjectCache(m_object_cache_up.get());
301 }
302
303 // Make sure we see all sections, including ones that don't have
304 // relocations...
305 m_execution_engine_up->setProcessAllSections(true);
306
307 m_execution_engine_up->DisableLazyCompilation();
308
309 for (llvm::Function &function : *m_module) {
310 if (function.isDeclaration() || function.hasPrivateLinkage())
311 continue;
312
313 const bool external = !function.hasLocalLinkage();
314
315 void *fun_ptr = m_execution_engine_up->getPointerToFunction(&function);
316
317 if (!error.Success()) {
318 // We got an error through our callback!
319 return;
320 }
321
322 if (!fun_ptr) {
324 "'%s' was in the JITted module but wasn't lowered",
325 function.getName().str().c_str());
326 return;
327 }
329 function.getName().str().c_str(), external, reinterpret_cast<uintptr_t>(fun_ptr)));
330 }
331
332 CommitAllocations(process_sp);
334
335 // We have to do this after calling ReportAllocations because for the MCJIT,
336 // getGlobalValueAddress will cause the JIT to perform all relocations. That
337 // can only be done once, and has to happen after we do the remapping from
338 // local -> remote. That means we don't know the local address of the
339 // Variables, but we don't need that for anything, so that's okay.
340
341 std::function<void(llvm::GlobalValue &)> RegisterOneValue = [this](
342 llvm::GlobalValue &val) {
343 if (val.hasExternalLinkage() && !val.isDeclaration()) {
344 uint64_t var_ptr_addr =
345 m_execution_engine_up->getGlobalValueAddress(val.getName().str());
346
347 lldb::addr_t remote_addr = GetRemoteAddressForLocal(var_ptr_addr);
348
349 // This is a really unfortunae API that sometimes returns local addresses
350 // and sometimes returns remote addresses, based on whether the variable
351 // was relocated during ReportAllocations or not.
352
353 if (remote_addr == LLDB_INVALID_ADDRESS) {
354 remote_addr = var_ptr_addr;
355 }
356
357 if (var_ptr_addr != 0)
359 val.getName().str().c_str(), LLDB_INVALID_ADDRESS, remote_addr));
360 }
361 };
362
363 for (llvm::GlobalVariable &global_var : m_module->globals()) {
364 RegisterOneValue(global_var);
365 }
366
367 for (llvm::GlobalAlias &global_alias : m_module->aliases()) {
368 RegisterOneValue(global_alias);
369 }
370
371 WriteData(process_sp);
372
373 if (m_failed_lookups.size()) {
374 StreamString ss;
375
376 ss.PutCString("Couldn't look up symbols:\n");
377
378 bool emitNewLine = false;
379
380 for (ConstString failed_lookup : m_failed_lookups) {
381 if (emitNewLine)
382 ss.PutCString("\n");
383 emitNewLine = true;
384 ss.PutCString(" ");
385 ss.PutCString(Mangled(failed_lookup).GetDemangledName().GetStringRef());
386 }
387
388 m_failed_lookups.clear();
389 ss.PutCString(
390 "\nHint: The expression tried to call a function that is not present "
391 "in the target, perhaps because it was optimized out by the compiler.");
392 error = Status(ss.GetString().str());
393
394 return;
395 }
396
399
400 for (JittedFunction &jitted_function : m_jitted_functions) {
401 jitted_function.m_remote_addr =
402 GetRemoteAddressForLocal(jitted_function.m_local_addr);
403
404 if (!m_name.IsEmpty() && jitted_function.m_name == m_name) {
405 AddrRange func_range =
406 GetRemoteRangeForLocal(jitted_function.m_local_addr);
407 m_function_end_load_addr = func_range.first + func_range.second;
408 m_function_load_addr = jitted_function.m_remote_addr;
409 }
410 }
411
412 if (log) {
413 LLDB_LOGF(log, "Code can be run in the target.");
414
415 StreamString disassembly_stream;
416
417 Status err = DisassembleFunction(disassembly_stream, process_sp);
418
419 if (!err.Success()) {
420 LLDB_LOGF(log, "Couldn't disassemble function : %s",
421 err.AsCString("unknown error"));
422 } else {
423 LLDB_LOGF(log, "Function disassembly:\n%s", disassembly_stream.GetData());
424 }
425
426 LLDB_LOGF(log, "Sections: ");
427 for (AllocationRecord &record : m_records) {
428 if (record.m_process_address != LLDB_INVALID_ADDRESS) {
429 record.dump(log);
430
431 DataBufferHeap my_buffer(record.m_size, 0);
432 Status err;
433 ReadMemory(my_buffer.GetBytes(), record.m_process_address,
434 record.m_size, err);
435
436 if (err.Success()) {
437 DataExtractor my_extractor(my_buffer.GetBytes(),
438 my_buffer.GetByteSize(),
440 my_extractor.PutToLog(log, 0, my_buffer.GetByteSize(),
441 record.m_process_address, 16,
443 }
444 } else {
445 record.dump(log);
446
447 DataExtractor my_extractor((const void *)record.m_host_address,
448 record.m_size, lldb::eByteOrderBig, 8);
449 my_extractor.PutToLog(log, 0, record.m_size, record.m_host_address, 16,
451 }
452 }
453 }
454
455 func_addr = m_function_load_addr;
456 func_end = m_function_end_load_addr;
457}
458
464
466 : m_default_mm_up(new llvm::SectionMemoryManager()), m_parent(parent) {}
467
469
471 const llvm::StringRef &name, IRExecutionUnit::AllocationKind alloc_kind) {
473 switch (alloc_kind) {
475 sect_type = lldb::eSectionTypeCode;
476 break;
478 sect_type = lldb::eSectionTypeCode;
479 break;
481 sect_type = lldb::eSectionTypeData;
482 break;
484 sect_type = lldb::eSectionTypeData;
485 break;
487 sect_type = lldb::eSectionTypeOther;
488 break;
489 }
490
491 if (!name.empty()) {
492 if (name == "__text" || name == ".text")
493 sect_type = lldb::eSectionTypeCode;
494 else if (name == "__data" || name == ".data")
495 sect_type = lldb::eSectionTypeCode;
496 else if (name.starts_with("__debug_") || name.starts_with(".debug_")) {
497 const uint32_t name_idx = name[0] == '_' ? 8 : 7;
498 llvm::StringRef dwarf_name(name.substr(name_idx));
499 sect_type = ObjectFile::GetDWARFSectionTypeFromName(dwarf_name);
500 } else if (name.starts_with("__apple_") || name.starts_with(".apple_"))
501 sect_type = lldb::eSectionTypeInvalid;
502 else if (name == "__objc_imageinfo")
503 sect_type = lldb::eSectionTypeOther;
504 }
505 return sect_type;
506}
507
509 uintptr_t Size, unsigned Alignment, unsigned SectionID,
510 llvm::StringRef SectionName) {
512
513 uint8_t *return_value = m_default_mm_up->allocateCodeSection(
514 Size, Alignment, SectionID, SectionName);
515
516 m_parent.m_records.push_back(AllocationRecord(
517 (uintptr_t)return_value,
518 lldb::ePermissionsReadable | lldb::ePermissionsExecutable,
520 Alignment, SectionID, SectionName.str().c_str()));
521
522 LLDB_LOGF(log,
523 "IRExecutionUnit::allocateCodeSection(Size=0x%" PRIx64
524 ", Alignment=%u, SectionID=%u) = %p",
525 (uint64_t)Size, Alignment, SectionID, (void *)return_value);
526
527 if (m_parent.m_reported_allocations) {
528 Status err;
529 lldb::ProcessSP process_sp =
530 m_parent.GetBestExecutionContextScope()->CalculateProcess();
531
532 m_parent.CommitOneAllocation(process_sp, err, m_parent.m_records.back());
533 }
534
535 return return_value;
536}
537
539 uintptr_t Size, unsigned Alignment, unsigned SectionID,
540 llvm::StringRef SectionName, bool IsReadOnly) {
542
543 uint8_t *return_value = m_default_mm_up->allocateDataSection(
544 Size, Alignment, SectionID, SectionName, IsReadOnly);
545
546 uint32_t permissions = lldb::ePermissionsReadable;
547 if (!IsReadOnly)
548 permissions |= lldb::ePermissionsWritable;
549 m_parent.m_records.push_back(AllocationRecord(
550 (uintptr_t)return_value, permissions,
552 Alignment, SectionID, SectionName.str().c_str()));
553 LLDB_LOGF(log,
554 "IRExecutionUnit::allocateDataSection(Size=0x%" PRIx64
555 ", Alignment=%u, SectionID=%u) = %p",
556 (uint64_t)Size, Alignment, SectionID, (void *)return_value);
557
558 if (m_parent.m_reported_allocations) {
559 Status err;
560 lldb::ProcessSP process_sp =
561 m_parent.GetBestExecutionContextScope()->CalculateProcess();
562
563 m_parent.CommitOneAllocation(process_sp, err, m_parent.m_records.back());
564 }
565
566 return return_value;
567}
568
569void IRExecutionUnit::CollectCandidateCNames(std::vector<ConstString> &C_names,
570 ConstString name) {
571 if (m_strip_underscore && name.GetStringRef().starts_with('_'))
572 C_names.insert(C_names.begin(), ConstString(&name.GetCString()[1]));
573 C_names.push_back(name);
574}
575
577 std::vector<ConstString> &CPP_names,
578 const std::vector<ConstString> &C_names, const SymbolContext &sc) {
580 for (const ConstString &name : C_names) {
581 Mangled mangled(name);
582 if (cpp_lang->SymbolNameFitsToLanguage(mangled)) {
583 if (ConstString best_alternate =
584 cpp_lang->FindBestAlternateFunctionMangledName(mangled, sc)) {
585 CPP_names.push_back(best_alternate);
586 }
587 }
588
589 std::vector<ConstString> alternates =
590 cpp_lang->GenerateAlternateFunctionManglings(name);
591 CPP_names.insert(CPP_names.end(), alternates.begin(), alternates.end());
592
593 // As a last-ditch fallback, try the base name for C++ names. It's
594 // terrible, but the DWARF doesn't always encode "extern C" correctly.
595 ConstString basename =
596 cpp_lang->GetDemangledFunctionNameWithoutArguments(mangled);
597 CPP_names.push_back(basename);
598 }
599 }
600}
601
603public:
604 LoadAddressResolver(Target &target, bool &symbol_was_missing_weak)
605 : m_target(target), m_symbol_was_missing_weak(symbol_was_missing_weak) {}
606
607 std::optional<lldb::addr_t> Resolve(SymbolContextList &sc_list) {
608 if (sc_list.IsEmpty())
609 return std::nullopt;
610
611 lldb::addr_t load_address = LLDB_INVALID_ADDRESS;
612
613 // Missing_weak_symbol will be true only if we found only weak undefined
614 // references to this symbol.
616
617 for (auto candidate_sc : sc_list.SymbolContexts()) {
618 // Only symbols can be weak undefined.
619 if (!candidate_sc.symbol ||
620 candidate_sc.symbol->GetType() != lldb::eSymbolTypeUndefined ||
621 !candidate_sc.symbol->IsWeak())
623
624 // First try the symbol.
625 if (candidate_sc.symbol) {
626 load_address = candidate_sc.symbol->ResolveCallableAddress(
627 m_target, candidate_sc.module_sp);
628 if (load_address == LLDB_INVALID_ADDRESS) {
629 Address addr = candidate_sc.symbol->GetAddress();
630 load_address = m_target.GetProcessSP()
631 ? addr.GetLoadAddress(&m_target)
632 : addr.GetFileAddress();
633 }
634 }
635
636 // If that didn't work, try the function.
637 if (load_address == LLDB_INVALID_ADDRESS && candidate_sc.function) {
638 Address addr = candidate_sc.function->GetAddress();
639 load_address = m_target.GetProcessSP()
641 : addr.GetFileAddress();
642 }
643
644 // We found a load address.
645 if (load_address != LLDB_INVALID_ADDRESS) {
646 // If the load address is external, we're done.
647 const bool is_external =
648 (candidate_sc.function) ||
649 (candidate_sc.symbol && candidate_sc.symbol->IsExternal());
650 if (is_external)
651 return load_address;
652
653 // Otherwise, remember the best internal load address.
655 m_best_internal_load_address = load_address;
656 }
657 }
658
659 // You test the address of a weak symbol against NULL to see if it is
660 // present. So we should return 0 for a missing weak symbol.
662 return 0;
663
664 return std::nullopt;
665 }
666
670
671private:
675};
676
677/// Returns address of the function referred to by the special function call
678/// label \c label.
679static llvm::Expected<lldb::addr_t>
682 bool &symbol_was_missing_weak) {
683 symbol_was_missing_weak = false;
684
685 if (!sc.target_sp)
686 return llvm::createStringError("target not available");
687
688 auto module_sp = sc.target_sp->GetImages().FindModule(label.module_id);
689 if (!module_sp)
690 return llvm::createStringError(
691 llvm::formatv("failed to find module by UID {0}", label.module_id));
692
693 auto *symbol_file = module_sp->GetSymbolFile();
694 if (!symbol_file)
695 return llvm::createStringError(
696 llvm::formatv("no SymbolFile found on module {0:x}.", module_sp.get()));
697
698 auto sc_or_err = symbol_file->ResolveFunctionCallLabel(label);
699 if (!sc_or_err)
700 return llvm::joinErrors(
701 llvm::createStringError("failed to resolve function by UID:"),
702 sc_or_err.takeError());
703
704 SymbolContextList sc_list;
705 sc_list.Append(*sc_or_err);
706
707 LoadAddressResolver resolver(*sc.target_sp, symbol_was_missing_weak);
708 lldb::addr_t resolved_addr =
709 resolver.Resolve(sc_list).value_or(LLDB_INVALID_ADDRESS);
710 if (resolved_addr == LLDB_INVALID_ADDRESS)
711 return llvm::createStringError("couldn't resolve address for function");
712
713 return resolved_addr;
714}
715
717IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
719 bool &symbol_was_missing_weak) {
720 symbol_was_missing_weak = false;
721
722 Target *target = sc.target_sp.get();
723 if (!target) {
724 // We shouldn't be doing any symbol lookup at all without a target.
726 }
727
728 ModuleList non_local_images = target->GetImages();
729 // We'll process module_sp and any preferred modules separately, before the
730 // other modules.
731 non_local_images.Remove(sc.module_sp);
732 for (size_t i = 0; i < m_preferred_modules.GetSize(); ++i)
733 non_local_images.Remove(m_preferred_modules.GetModuleAtIndex(i));
734
735 // Drop modules the platform considers off-limits to unconstrained symbol
736 // searches.
737 for (size_t i = non_local_images.GetSize(); i > 0; --i) {
738 lldb::ModuleSP module_sp = non_local_images.GetModuleAtIndex(i - 1);
739 if (target->ModuleIsExcludedForUnconstrainedSearches(module_sp))
740 non_local_images.Remove(module_sp);
741 }
742
743 LoadAddressResolver resolver(*target, symbol_was_missing_weak);
744
745 ModuleFunctionSearchOptions function_options;
746 function_options.include_symbols = true;
747 function_options.include_inlines = false;
748
749 for (const ConstString &name : names) {
750 // The lookup order here is as follows:
751 // 1) Functions in `sc.module_sp`
752 // 2) Functions in the preferred modules list
753 // 3) Functions in the other modules
754 // 4) Symbols in `sc.module_sp`
755 // 5) Symbols in the preferred modules list
756 // 6) Symbols in the other modules
757 if (sc.module_sp) {
758 SymbolContextList sc_list;
759 sc.module_sp->FindFunctions(name, CompilerDeclContext(),
760 lldb::eFunctionNameTypeFull, function_options,
761 sc_list);
762 if (auto load_addr = resolver.Resolve(sc_list))
763 return *load_addr;
764 }
765
766 {
767 SymbolContextList sc_list;
768 m_preferred_modules.FindFunctions(name, lldb::eFunctionNameTypeFull,
769 function_options, sc_list);
770 if (auto load_addr = resolver.Resolve(sc_list))
771 return *load_addr;
772 }
773
774 {
775 SymbolContextList sc_list;
776 non_local_images.FindFunctions(name, lldb::eFunctionNameTypeFull,
777 function_options, sc_list);
778 if (auto load_addr = resolver.Resolve(sc_list))
779 return *load_addr;
780 }
781
782 if (sc.module_sp) {
783 SymbolContextList sc_list;
784 sc.module_sp->FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
785 sc_list);
786 if (auto load_addr = resolver.Resolve(sc_list))
787 return *load_addr;
788 }
789
790 {
791 SymbolContextList sc_list;
792 m_preferred_modules.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
793 sc_list);
794 if (auto load_addr = resolver.Resolve(sc_list))
795 return *load_addr;
796 }
797
798 {
799 SymbolContextList sc_list;
801 sc_list);
802 if (auto load_addr = resolver.Resolve(sc_list))
803 return *load_addr;
804 }
805
806 lldb::addr_t best_internal_load_address =
808 if (best_internal_load_address != LLDB_INVALID_ADDRESS)
809 return best_internal_load_address;
810 }
811
813}
814
816IRExecutionUnit::FindInRuntimes(const std::vector<ConstString> &names,
817 const lldb_private::SymbolContext &sc) {
818 lldb::TargetSP target_sp = sc.target_sp;
819
820 if (!target_sp) {
822 }
823
824 lldb::ProcessSP process_sp = sc.target_sp->GetProcessSP();
825
826 if (!process_sp) {
828 }
829
830 for (const ConstString &name : names) {
831 for (LanguageRuntime *runtime : process_sp->GetLanguageRuntimes()) {
832 lldb::addr_t symbol_load_addr = runtime->LookupRuntimeSymbol(name);
833
834 if (symbol_load_addr != LLDB_INVALID_ADDRESS)
835 return symbol_load_addr;
836 }
837 }
838
840}
841
843 const std::vector<ConstString> &names,
844 const lldb_private::SymbolContext &sc) {
845 lldb::TargetSP target_sp = sc.target_sp;
846
847 for (const ConstString &name : names) {
848 lldb::addr_t symbol_load_addr = target_sp->GetPersistentSymbol(name);
849
850 if (symbol_load_addr != LLDB_INVALID_ADDRESS)
851 return symbol_load_addr;
852 }
853
855}
856
858 bool &missing_weak) {
859 if (name.GetStringRef().starts_with(FunctionCallLabelPrefix)) {
860 auto label_or_err = FunctionCallLabel::fromString(name);
861 if (!label_or_err) {
862 LLDB_LOG_ERROR(GetLog(LLDBLog::Expressions), label_or_err.takeError(),
863 "failed to create FunctionCallLabel from '{1}': {0}",
864 name.GetStringRef());
866 }
867
868 if (auto addr_or_err =
869 ResolveFunctionCallLabel(*label_or_err, m_sym_ctx, missing_weak)) {
870 return *addr_or_err;
871 } else {
872 LLDB_LOG_ERROR(GetLog(LLDBLog::Expressions), addr_or_err.takeError(),
873 "Failed to resolve function call label '{1}': {0}",
874 name.GetStringRef());
875
876 // Fall back to lookup by name despite error in resolving the label.
877 // May happen in practice if the definition of a function lives in
878 // a different lldb_private::Module than it's declaration. Meaning
879 // we couldn't pin-point it using the information encoded in the label.
880 name.SetString(label_or_err->lookup_name);
881 }
882 }
883
884 // TODO: now with function call labels, do we still need to
885 // generate alternate manglings?
886
887 std::vector<ConstString> candidate_C_names;
888 std::vector<ConstString> candidate_CPlusPlus_names;
889
890 CollectCandidateCNames(candidate_C_names, name);
891
892 lldb::addr_t ret = FindInSymbols(candidate_C_names, m_sym_ctx, missing_weak);
893 if (ret != LLDB_INVALID_ADDRESS)
894 return ret;
895
896 // If we find the symbol in runtimes or user defined symbols it can't be
897 // a missing weak symbol.
898 missing_weak = false;
899 ret = FindInRuntimes(candidate_C_names, m_sym_ctx);
900 if (ret != LLDB_INVALID_ADDRESS)
901 return ret;
902
903 ret = FindInUserDefinedSymbols(candidate_C_names, m_sym_ctx);
904 if (ret != LLDB_INVALID_ADDRESS)
905 return ret;
906
907 CollectCandidateCPlusPlusNames(candidate_CPlusPlus_names, candidate_C_names,
908 m_sym_ctx);
909 ret = FindInSymbols(candidate_CPlusPlus_names, m_sym_ctx, missing_weak);
910 return ret;
911}
912
914 std::vector<lldb::addr_t> &static_initializers) {
916
917 llvm::GlobalVariable *global_ctors =
918 m_module->getNamedGlobal("llvm.global_ctors");
919 if (!global_ctors) {
920 LLDB_LOG(log, "Couldn't find llvm.global_ctors.");
921 return;
922 }
923 auto *ctor_array =
924 llvm::dyn_cast<llvm::ConstantArray>(global_ctors->getInitializer());
925 if (!ctor_array) {
926 LLDB_LOG(log, "llvm.global_ctors not a ConstantArray.");
927 return;
928 }
929
930 for (llvm::Use &ctor_use : ctor_array->operands()) {
931 auto *ctor_struct = llvm::dyn_cast<llvm::ConstantStruct>(ctor_use);
932 if (!ctor_struct)
933 continue;
934 // this is standardized
935 lldbassert(ctor_struct->getNumOperands() == 3);
936 auto *ctor_function =
937 llvm::dyn_cast<llvm::Function>(ctor_struct->getOperand(1));
938 if (!ctor_function) {
939 LLDB_LOG(log, "global_ctor doesn't contain an llvm::Function");
940 continue;
941 }
942
943 ConstString ctor_function_name(ctor_function->getName().str());
944 LLDB_LOG(log, "Looking for callable jitted function with name {0}.",
945 ctor_function_name);
946
947 for (JittedFunction &jitted_function : m_jitted_functions) {
948 if (ctor_function_name != jitted_function.m_name)
949 continue;
950 if (jitted_function.m_remote_addr == LLDB_INVALID_ADDRESS) {
951 LLDB_LOG(log, "Found jitted function with invalid address.");
952 continue;
953 }
954 static_initializers.push_back(jitted_function.m_remote_addr);
955 LLDB_LOG(log, "Calling function at address {0:x}.",
956 jitted_function.m_remote_addr);
957 break;
958 }
959 }
960}
961
962llvm::JITSymbol
964 bool missing_weak = false;
965 uint64_t addr = GetSymbolAddressAndPresence(Name, missing_weak);
966 // This is a weak symbol:
967 if (missing_weak)
968 return llvm::JITSymbol(addr,
969 llvm::JITSymbolFlags::Exported | llvm::JITSymbolFlags::Weak);
970 else
971 return llvm::JITSymbol(addr, llvm::JITSymbolFlags::Exported);
972}
973
974uint64_t
976 bool missing_weak = false;
977 return GetSymbolAddressAndPresence(Name, missing_weak);
978}
979
980uint64_t
982 const std::string &Name, bool &missing_weak) {
984
985 ConstString name_cs(Name);
986
987 lldb::addr_t ret = m_parent.FindSymbol(name_cs, missing_weak);
988
989 if (ret == LLDB_INVALID_ADDRESS) {
990 LLDB_LOGF(log,
991 "IRExecutionUnit::getSymbolAddress(Name=\"%s\") = <not found>",
992 Name.c_str());
993
994 m_parent.ReportSymbolLookupError(name_cs);
995 return 0;
996 } else {
997 LLDB_LOGF(log, "IRExecutionUnit::getSymbolAddress(Name=\"%s\") = %" PRIx64,
998 Name.c_str(), ret);
999 return ret;
1000 }
1001}
1002
1004 const std::string &Name, bool AbortOnFailure) {
1005 return (void *)getSymbolAddress(Name);
1006}
1007
1011
1012 for (AllocationRecord &record : m_records) {
1013 if (local_address >= record.m_host_address &&
1014 local_address < record.m_host_address + record.m_size) {
1015 if (record.m_process_address == LLDB_INVALID_ADDRESS)
1016 return LLDB_INVALID_ADDRESS;
1017
1018 lldb::addr_t ret =
1019 record.m_process_address + (local_address - record.m_host_address);
1020
1021 LLDB_LOGF(log,
1022 "IRExecutionUnit::GetRemoteAddressForLocal() found 0x%" PRIx64
1023 " in [0x%" PRIx64 "..0x%" PRIx64 "], and returned 0x%" PRIx64
1024 " from [0x%" PRIx64 "..0x%" PRIx64 "].",
1025 local_address, (uint64_t)record.m_host_address,
1026 (uint64_t)record.m_host_address + (uint64_t)record.m_size, ret,
1027 record.m_process_address,
1028 record.m_process_address + record.m_size);
1029
1030 return ret;
1031 }
1032 }
1033
1034 return LLDB_INVALID_ADDRESS;
1035}
1036
1039 for (AllocationRecord &record : m_records) {
1040 if (local_address >= record.m_host_address &&
1041 local_address < record.m_host_address + record.m_size) {
1042 if (record.m_process_address == LLDB_INVALID_ADDRESS)
1043 return AddrRange(0, 0);
1044
1045 return AddrRange(record.m_process_address, record.m_size);
1046 }
1047 }
1048
1049 return AddrRange(0, 0);
1050}
1051
1053 Status &error,
1054 AllocationRecord &record) {
1056 return true;
1057 }
1058
1059 switch (record.m_sect_type) {
1081 error.Clear();
1082 break;
1083 default:
1084 const bool zero_memory = false;
1085 if (auto address_or_error =
1086 Malloc(record.m_size, record.m_alignment, record.m_permissions,
1087 eAllocationPolicyProcessOnly, zero_memory))
1088 record.m_process_address = *address_or_error;
1089 else
1090 error = Status::FromError(address_or_error.takeError());
1091 break;
1092 }
1093
1094 return error.Success();
1095}
1096
1098 bool ret = true;
1099
1101
1102 for (AllocationRecord &record : m_records) {
1103 ret = CommitOneAllocation(process_sp, err, record);
1104
1105 if (!ret) {
1106 break;
1107 }
1108 }
1109
1110 if (!ret) {
1111 for (AllocationRecord &record : m_records) {
1112 if (record.m_process_address != LLDB_INVALID_ADDRESS) {
1113 Free(record.m_process_address, err);
1114 record.m_process_address = LLDB_INVALID_ADDRESS;
1115 }
1116 }
1117 }
1118
1119 return ret;
1120}
1121
1122void IRExecutionUnit::ReportAllocations(llvm::ExecutionEngine &engine) {
1124
1125 for (AllocationRecord &record : m_records) {
1126 if (record.m_process_address == LLDB_INVALID_ADDRESS)
1127 continue;
1128
1129 if (record.m_section_id == eSectionIDInvalid)
1130 continue;
1131
1132 engine.mapSectionAddress((void *)record.m_host_address,
1133 record.m_process_address);
1134 }
1135
1136 // Trigger re-application of relocations.
1137 engine.finalizeObject();
1138}
1139
1141 bool wrote_something = false;
1142 for (AllocationRecord &record : m_records) {
1143 if (record.m_process_address != LLDB_INVALID_ADDRESS) {
1145 WriteMemory(record.m_process_address, (uint8_t *)record.m_host_address,
1146 record.m_size, err);
1147 if (err.Success())
1148 wrote_something = true;
1149 }
1150 }
1151 return wrote_something;
1152}
1153
1155 if (!log)
1156 return;
1157
1158 LLDB_LOGF(log,
1159 "[0x%llx+0x%llx]->0x%llx (alignment %d, section ID %d, name %s)",
1160 (unsigned long long)m_host_address, (unsigned long long)m_size,
1161 (unsigned long long)m_process_address, (unsigned)m_alignment,
1162 (unsigned)m_section_id, m_name.c_str());
1163}
1164
1169
1172 return exe_ctx.GetAddressByteSize();
1173}
1174
1176 lldb_private::Symtab &symtab) {
1177 // No symbols yet...
1178}
1179
1181 lldb_private::ObjectFile *obj_file,
1182 lldb_private::SectionList &section_list) {
1183 for (AllocationRecord &record : m_records) {
1184 if (record.m_size > 0) {
1185 lldb::SectionSP section_sp = std::make_shared<Section>(
1186 obj_file->GetModule(), obj_file, record.m_section_id, record.m_name,
1187 record.m_sect_type, record.m_process_address, record.m_size,
1188 record.m_host_address, // file_offset (which is the host address for
1189 // the data)
1190 record.m_size, // file_size
1191 0,
1192 record.m_permissions); // flags
1193 section_list.AddSection(section_sp);
1194 }
1195 }
1196}
1197
1200 if(Target *target = exe_ctx.GetTargetPtr())
1201 return target->GetArchitecture();
1202 return ArchSpec();
1203}
1204
1207 Target *target = exe_ctx.GetTargetPtr();
1208 if (!target)
1209 return nullptr;
1210
1211 auto Delegate = std::static_pointer_cast<lldb_private::ObjectFileJITDelegate>(
1212 shared_from_this());
1213
1214 lldb::ModuleSP jit_module_sp =
1216 if (!jit_module_sp)
1217 return nullptr;
1218
1219 bool changed = false;
1220 jit_module_sp->SetLoadAddress(*target, 0, true, changed);
1221 return jit_module_sp;
1222}
static llvm::raw_ostream & error(Stream &strm)
static llvm::Expected< lldb::addr_t > ResolveFunctionCallLabel(FunctionCallLabel &label, const lldb_private::SymbolContext &sc, bool &symbol_was_missing_weak)
Returns address of the function referred to by the special function call label label.
#define lldbassert(x)
Definition LLDBAssert.h:16
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOGF(log,...)
Definition Log.h:389
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:405
LoadAddressResolver(Target &target, bool &symbol_was_missing_weak)
lldb::addr_t m_best_internal_load_address
std::optional< lldb::addr_t > Resolve(SymbolContextList &sc_list)
lldb::addr_t GetBestInternalLoadAddress() const
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:303
lldb::addr_t GetCallableLoadAddress(Target *target, bool is_indirect=false) const
Get the load address as a callable code load address.
Definition Address.cpp:328
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:283
An architecture specification class.
Definition ArchSpec.h:32
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:894
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition ArchSpec.cpp:745
Represents a generic declaration context in a program.
A uniqued constant string class.
Definition ConstString.h:40
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetString(llvm::StringRef s)
const char * GetCString() const
Get the string value as a C string.
A subclass of DataBuffer that stores a data buffer on the heap.
lldb::offset_t GetByteSize() const override
Get the number of bytes in the data buffer.
An data extractor class.
virtual uint64_t GetByteSize() const
Get the number of bytes contained in this object.
@ TypeUInt8
Format output as unsigned 8 bit integers.
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...
static lldb::DisassemblerSP FindPlugin(const ArchSpec &arch, const char *flavor, const char *cpu, const char *features, const char *plugin_name)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
lldb::ByteOrder GetByteOrder() const
Target * GetTargetPtr() const
Returns a pointer to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
A file utility class.
Definition FileSpec.h:56
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
Definition FileSpec.cpp:425
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:380
void * getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure=true) override
std::unique_ptr< SectionMemoryManager > m_default_mm_up
The memory allocator to use in actually creating space.
uint64_t getSymbolAddress(const std::string &Name) override
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.
IRExecutionUnit & m_parent
The execution unit this is a proxy for.
uint64_t GetSymbolAddressAndPresence(const std::string &Name, bool &missing_weak)
llvm::JITSymbol findSymbol(const std::string &Name) override
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.
std::vector< std::string > m_cpu_features
void CollectCandidateCPlusPlusNames(std::vector< ConstString > &CPP_names, const std::vector< ConstString > &C_names, const SymbolContext &sc)
static const unsigned eSectionIDInvalid
void PopulateSymtab(lldb_private::ObjectFile *obj_file, lldb_private::Symtab &symtab) override
lldb::addr_t FindInSymbols(const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc, bool &symbol_was_missing_weak)
void GetRunnableInfo(Status &error, lldb::addr_t &func_addr, lldb::addr_t &func_end)
lldb::ByteOrder GetByteOrder() const override
ObjectFileJITDelegate overrides.
SymbolContext m_sym_ctx
Used for symbol lookups.
std::vector< JittedFunction > m_jitted_functions
A vector of all functions that have been JITted into machine code.
Status DisassembleFunction(Stream &stream, lldb::ProcessSP &process_sp)
std::vector< ConstString > m_failed_lookups
std::unique_ptr< llvm::Module > m_module_up
Holder for the module until it's been handed off.
lldb::addr_t FindSymbol(ConstString name, bool &missing_weak)
lldb::addr_t FindInRuntimes(const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc)
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.
static lldb::SectionType GetSectionTypeFromSectionName(const llvm::StringRef &name, AllocationKind alloc_kind)
uint32_t GetAddressByteSize() const override
bool CommitAllocations(lldb::ProcessSP &process_sp)
Commit all allocations to the process and record where they were stored.
bool CommitOneAllocation(lldb::ProcessSP &process_sp, Status &error, AllocationRecord &record)
void GetStaticInitializers(std::vector< lldb::addr_t > &static_initializers)
void CollectCandidateCNames(std::vector< ConstString > &C_names, ConstString name)
std::unique_ptr< llvm::ExecutionEngine > m_execution_engine_up
llvm::Module * m_module
Owned by the execution engine.
std::unique_ptr< llvm::LLVMContext > m_context_up
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,...
bool m_strip_underscore
True for platforms where global symbols have a _ prefix.
void ReportSymbolLookupError(ConstString name)
lldb::addr_t FindInUserDefinedSymbols(const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc)
void PopulateSectionList(lldb_private::ObjectFile *obj_file, lldb_private::SectionList &section_list) override
std::pair< lldb::addr_t, uintptr_t > AddrRange
std::vector< JittedGlobalVariable > m_jitted_global_variables
A vector of all functions that have been JITted into machine code.
bool WriteData(lldb::ProcessSP &process_sp)
Write the contents of all allocations to the process.
std::unique_ptr< llvm::ObjectCache > m_object_cache_up
~IRExecutionUnit() override
Destructor.
void ReportAllocations(llvm::ExecutionEngine &engine)
Report all committed allocations to the execution engine.
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,...
bool m_reported_allocations
True after allocations have been reported.
void Free(lldb::addr_t process_address, Status &error)
llvm::Expected< lldb::addr_t > Malloc(size_t size, uint8_t alignment, uint32_t permissions, AllocationPolicy policy, bool zero_memory, AllocationPolicy *used_policy=nullptr)
ExecutionContextScope * GetBestExecutionContextScope() const
lldb::ProcessWP & GetProcessWP()
Definition IRMemoryMap.h:92
IRMemoryMap(lldb::TargetSP target_sp)
void WriteMemory(lldb::addr_t process_address, const uint8_t *bytes, size_t size, Status &error)
void ReadMemory(uint8_t *bytes, lldb::addr_t process_address, size_t size, Status &error)
@ eAllocationPolicyProcessOnly
The intent is that this allocation exist only in the process.
Definition IRMemoryMap.h:50
void Dump(Stream *s, bool show_address, bool show_bytes, bool show_control_flow_kind, const ExecutionContext *exe_ctx)
static Language * FindPlugin(lldb::LanguageType language)
Definition Language.cpp:86
A class that handles mangled names.
Definition Mangled.h:34
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A collection class for Module objects.
Definition ModuleList.h:128
void FindFunctions(ConstString name, lldb::FunctionNameType name_type_mask, const ModuleFunctionSearchOptions &options, SymbolContextList &sc_list) const
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
bool Remove(const lldb::ModuleSP &module_sp, bool notify=true)
Remove a module from the module list.
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
size_t GetSize() const
Gets the size of the module list.
static lldb::ModuleSP CreateModuleFromObjectFile(Args &&...args)
Definition Module.h:136
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
static lldb::SectionType GetDWARFSectionTypeFromName(llvm::StringRef name)
Parses the section type from a section name for DWARF sections.
A plug-in interface definition class for debugging a process.
Definition Process.h:369
virtual size_t ReadMemory(const ProcessAddress &process_addr, void *buf, size_t size, Status &error)
Read of memory from a process.
Definition Process.cpp:2114
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:3960
size_t AddSection(const lldb::SectionSP &section_sp)
Definition Section.cpp:483
An error handling class.
Definition Status.h:118
void Clear()
Clear the object state.
Definition Status.cpp:214
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:136
bool Success() const
Test for success condition.
Definition Status.cpp:303
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
Defines a list of symbol context objects.
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
SymbolContextIterable SymbolContexts()
Defines a symbol context baton that can be handed other debug core functions.
lldb::ModuleSP module_sp
The Module for a given query.
lldb::TargetSP target_sp
The Target for a given query.
bool ModuleIsExcludedForUnconstrainedSearches(const FileSpec &module_spec)
Return whether this FileSpec corresponds to a module that should be considered for general searches.
Definition Target.cpp:2061
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1282
const ArchSpec & GetArchitecture() const
Definition Target.h:1324
uint8_t * GetBytes()
Get a pointer to the data.
Definition DataBuffer.h:108
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:338
constexpr llvm::StringRef FunctionCallLabelPrefix
LLDB attaches this prefix to mangled names of functions that get called from JITted expressions.
Definition Expression.h:151
@ eLanguageTypeC_plus_plus
ISO C++:1998.
std::shared_ptr< lldb_private::Process > ProcessSP
@ eSymbolTypeUndefined
std::shared_ptr< lldb_private::Disassembler > DisassemblerSP
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
@ eSectionTypeDWARFDebugStrOffsets
@ eSectionTypeInvalid
@ eSectionTypeDWARFDebugPubNames
@ eSectionTypeDWARFDebugFrame
@ eSectionTypeDWARFDebugLocLists
DWARF v5 .debug_loclists.
@ eSectionTypeDWARFDebugMacInfo
@ eSectionTypeDWARFAppleNamespaces
@ eSectionTypeDWARFAppleTypes
@ eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugLine
@ eSectionTypeDWARFDebugPubTypes
@ eSectionTypeDWARFDebugStr
@ eSectionTypeDWARFDebugLoc
@ eSectionTypeDWARFAppleNames
@ eSectionTypeDWARFAppleObjC
@ eSectionTypeDWARFDebugCuIndex
@ eSectionTypeDWARFDebugAranges
@ eSectionTypeDWARFGNUDebugAltLink
@ eSectionTypeDWARFDebugAbbrev
@ eSectionTypeDWARFDebugAddr
std::shared_ptr< lldb_private::Module > ModuleSP
Holds parsed information about a function call label that LLDB attaches as an AsmLabel to function AS...
Definition Expression.h:110
static llvm::Expected< FunctionCallLabel > fromString(llvm::StringRef label)
Decodes the specified function label into a FunctionCallLabel.
lldb::user_id_t module_id
Unique identifier of the lldb_private::Module which contains the symbol identified by symbol_id.
Definition Expression.h:117
Encapsulates a single allocation request made by the JIT.
"lldb/Expression/IRExecutionUnit.h" Encapsulates a single function that has been generated by the JIT...
Options used by Module::FindFunctions.
Definition Module.h:67
bool include_inlines
Include inlined functions.
Definition Module.h:71
bool include_symbols
Include the symbol table.
Definition Module.h:69