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(context_up.release()),
54 m_module_up(module_up.release()), m_module(m_module_up.get()),
55 m_cpu_features(cpu_features), m_name(name), m_sym_ctx(sym_ctx),
59
60lldb::addr_t IRExecutionUnit::WriteNow(const uint8_t *bytes, size_t size,
61 Status &error) {
62 const bool zero_memory = false;
63 auto address_or_error =
64 Malloc(size, 8, lldb::ePermissionsWritable | lldb::ePermissionsReadable,
65 eAllocationPolicyMirror, zero_memory);
66 if (!address_or_error) {
67 error = Status::FromError(address_or_error.takeError());
69 }
70 lldb::addr_t allocation_process_addr = *address_or_error;
71
72 WriteMemory(allocation_process_addr, bytes, size, error);
73
74 if (!error.Success()) {
75 Status err;
76 Free(allocation_process_addr, err);
77
79 }
80
81 if (Log *log = GetLog(LLDBLog::Expressions)) {
82 DataBufferHeap my_buffer(size, 0);
83 Status err;
84 ReadMemory(my_buffer.GetBytes(), allocation_process_addr, size, err);
85
86 if (err.Success()) {
87 DataExtractor my_extractor(my_buffer.GetBytes(), my_buffer.GetByteSize(),
89 my_extractor.PutToLog(log, 0, my_buffer.GetByteSize(),
90 allocation_process_addr, 16,
92 }
93 }
94
95 return allocation_process_addr;
96}
97
99 if (allocation == LLDB_INVALID_ADDRESS)
100 return;
101
102 Status err;
103
104 Free(allocation, err);
105}
106
108 lldb::ProcessSP &process_wp) {
110
111 ExecutionContext exe_ctx(process_wp);
112
113 Status ret;
114
115 ret.Clear();
116
117 lldb::addr_t func_local_addr = LLDB_INVALID_ADDRESS;
118 lldb::addr_t func_remote_addr = LLDB_INVALID_ADDRESS;
119
120 for (JittedFunction &function : m_jitted_functions) {
121 if (function.m_name == m_name) {
122 func_local_addr = function.m_local_addr;
123 func_remote_addr = function.m_remote_addr;
124 }
125 }
126
127 if (func_local_addr == LLDB_INVALID_ADDRESS) {
129 "Couldn't find function %s for disassembly", m_name.AsCString());
130 return ret;
131 }
132
133 LLDB_LOGF(log,
134 "Found function, has local address 0x%" PRIx64
135 " and remote address 0x%" PRIx64,
136 (uint64_t)func_local_addr, (uint64_t)func_remote_addr);
137
138 std::pair<lldb::addr_t, lldb::addr_t> func_range;
139
140 func_range = GetRemoteRangeForLocal(func_local_addr);
141
142 if (func_range.first == 0 && func_range.second == 0) {
144 "Couldn't find code range for function %s", m_name.AsCString());
145 return ret;
146 }
147
148 LLDB_LOGF(log, "Function's code range is [0x%" PRIx64 "+0x%" PRIx64 "]",
149 func_range.first, func_range.second);
150
151 Target *target = exe_ctx.GetTargetPtr();
152 if (!target) {
153 ret = Status::FromErrorString("Couldn't find the target");
154 return ret;
155 }
156
158 new DataBufferHeap(func_range.second, 0));
159
160 Process *process = exe_ctx.GetProcessPtr();
161 Status err;
162 process->ReadMemory(func_remote_addr, buffer_sp->GetBytes(),
163 buffer_sp->GetByteSize(), err);
164
165 if (!err.Success()) {
166 ret = Status::FromErrorStringWithFormat("Couldn't read from process: %s",
167 err.AsCString("unknown error"));
168 return ret;
169 }
170
171 ArchSpec arch(target->GetArchitecture());
172
173 const char *plugin_name = nullptr;
174 const char *flavor_string = nullptr;
175 const char *cpu_string = nullptr;
176 const char *features_string = nullptr;
178 arch, flavor_string, cpu_string, features_string, plugin_name);
179
180 if (!disassembler_sp) {
182 "Unable to find disassembler plug-in for %s architecture.",
183 arch.GetArchitectureName());
184 return ret;
185 }
186
187 if (!process) {
188 ret = Status::FromErrorString("Couldn't find the process");
189 return ret;
190 }
191
192 DataExtractor extractor(buffer_sp, process->GetByteOrder(),
194
195 if (log) {
196 LLDB_LOGF(log, "Function data has contents:");
197 extractor.PutToLog(log, 0, extractor.GetByteSize(), func_remote_addr, 16,
199 }
200
201 disassembler_sp->DecodeInstructions(Address(func_remote_addr), extractor, 0,
202 UINT32_MAX, false, false);
203
204 InstructionList &instruction_list = disassembler_sp->GetInstructionList();
205 instruction_list.Dump(&stream, true, true, /*show_control_flow_kind=*/false,
206 &exe_ctx);
207
208 return ret;
209}
210
211namespace {
212struct IRExecDiagnosticHandler : public llvm::DiagnosticHandler {
213 Status *err;
214 IRExecDiagnosticHandler(Status *err) : err(err) {}
215 bool handleDiagnostics(const llvm::DiagnosticInfo &DI) override {
216 if (DI.getSeverity() == llvm::DS_Error) {
217 const auto &DISM = llvm::cast<llvm::DiagnosticInfoSrcMgr>(DI);
218 if (err && err->Success()) {
220 "IRExecution error: %s",
221 DISM.getSMDiag().getMessage().str().c_str());
222 }
223 }
224
225 return true;
226 }
227};
228} // namespace
229
233
235 lldb::addr_t &func_end) {
236 lldb::ProcessSP process_sp(GetProcessWP().lock());
237
238 static std::recursive_mutex s_runnable_info_mutex;
239
240 func_addr = LLDB_INVALID_ADDRESS;
241 func_end = LLDB_INVALID_ADDRESS;
242
243 if (!process_sp) {
244 error =
245 Status::FromErrorString("Couldn't write the JIT compiled code into the "
246 "process because the process is invalid");
247 return;
248 }
249
250 if (m_did_jit) {
251 func_addr = m_function_load_addr;
252 func_end = m_function_end_load_addr;
253
254 return;
255 };
256
257 std::lock_guard<std::recursive_mutex> guard(s_runnable_info_mutex);
258
259 m_did_jit = true;
260
262
263 std::string error_string;
264
265 if (log) {
266 std::string s;
267 llvm::raw_string_ostream oss(s);
268
269 m_module->print(oss, nullptr);
270
271 LLDB_LOGF(log, "Module being sent to JIT: \n%s", s.c_str());
272 }
273
274 m_module_up->getContext().setDiagnosticHandler(
275 std::make_unique<IRExecDiagnosticHandler>(&error));
276
277 llvm::EngineBuilder builder(std::move(m_module_up));
278 llvm::Triple triple(m_module->getTargetTriple());
279
280 builder.setEngineKind(llvm::EngineKind::JIT)
281 .setErrorStr(&error_string)
282 .setRelocationModel(triple.isOSBinFormatMachO() ? llvm::Reloc::PIC_
283 : llvm::Reloc::Static)
284 .setMCJITMemoryManager(std::make_unique<MemoryManager>(*this))
285 .setOptLevel(llvm::CodeGenOptLevel::Less);
286
287 // Resulted jitted code can be placed too far from the code in the binary
288 // and thus can contain more than +-2GB jumps, that are not available
289 // in RISC-V without large code model.
290 if (triple.isRISCV64())
291 builder.setCodeModel(llvm::CodeModel::Large);
292
293 llvm::StringRef mArch;
294 llvm::StringRef mCPU;
295 llvm::SmallVector<std::string, 0> mAttrs;
296
297 for (std::string &feature : m_cpu_features)
298 mAttrs.push_back(feature);
299
300 llvm::TargetMachine *target_machine =
301 builder.selectTarget(triple, mArch, mCPU, mAttrs);
302
303 m_execution_engine_up.reset(builder.create(target_machine));
304
306 error = Status::FromErrorStringWithFormat("Couldn't JIT the function: %s",
307 error_string.c_str());
308 return;
309 }
310
312 (m_execution_engine_up->getDataLayout().getGlobalPrefix() == '_');
313
314 class ObjectDumper : public llvm::ObjectCache {
315 public:
316 ObjectDumper(FileSpec output_dir) : m_out_dir(output_dir) {}
317 void notifyObjectCompiled(const llvm::Module *module,
318 llvm::MemoryBufferRef object) override {
319 int fd = 0;
320 llvm::SmallVector<char, 256> result_path;
321 std::string object_name_model =
322 "jit-object-" + module->getModuleIdentifier() + "-%%%.o";
323 FileSpec model_spec
324 = m_out_dir.CopyByAppendingPathComponent(object_name_model);
325 std::string model_path = model_spec.GetPath();
326
327 std::error_code result
328 = llvm::sys::fs::createUniqueFile(model_path, fd, result_path);
329 if (!result) {
330 llvm::raw_fd_ostream fds(fd, true);
331 fds.write(object.getBufferStart(), object.getBufferSize());
332 }
333 }
334 std::unique_ptr<llvm::MemoryBuffer>
335 getObject(const llvm::Module *module) override {
336 // Return nothing - we're just abusing the object-cache mechanism to dump
337 // objects.
338 return nullptr;
339 }
340 private:
341 FileSpec m_out_dir;
342 };
343
344 FileSpec save_objects_dir = process_sp->GetTarget().GetSaveJITObjectsDir();
345 if (save_objects_dir) {
346 m_object_cache_up = std::make_unique<ObjectDumper>(save_objects_dir);
347 m_execution_engine_up->setObjectCache(m_object_cache_up.get());
348 }
349
350 // Make sure we see all sections, including ones that don't have
351 // relocations...
352 m_execution_engine_up->setProcessAllSections(true);
353
354 m_execution_engine_up->DisableLazyCompilation();
355
356 for (llvm::Function &function : *m_module) {
357 if (function.isDeclaration() || function.hasPrivateLinkage())
358 continue;
359
360 const bool external = !function.hasLocalLinkage();
361
362 void *fun_ptr = m_execution_engine_up->getPointerToFunction(&function);
363
364 if (!error.Success()) {
365 // We got an error through our callback!
366 return;
367 }
368
369 if (!fun_ptr) {
371 "'%s' was in the JITted module but wasn't lowered",
372 function.getName().str().c_str());
373 return;
374 }
376 function.getName().str().c_str(), external, reinterpret_cast<uintptr_t>(fun_ptr)));
377 }
378
379 CommitAllocations(process_sp);
381
382 // We have to do this after calling ReportAllocations because for the MCJIT,
383 // getGlobalValueAddress will cause the JIT to perform all relocations. That
384 // can only be done once, and has to happen after we do the remapping from
385 // local -> remote. That means we don't know the local address of the
386 // Variables, but we don't need that for anything, so that's okay.
387
388 std::function<void(llvm::GlobalValue &)> RegisterOneValue = [this](
389 llvm::GlobalValue &val) {
390 if (val.hasExternalLinkage() && !val.isDeclaration()) {
391 uint64_t var_ptr_addr =
392 m_execution_engine_up->getGlobalValueAddress(val.getName().str());
393
394 lldb::addr_t remote_addr = GetRemoteAddressForLocal(var_ptr_addr);
395
396 // This is a really unfortunae API that sometimes returns local addresses
397 // and sometimes returns remote addresses, based on whether the variable
398 // was relocated during ReportAllocations or not.
399
400 if (remote_addr == LLDB_INVALID_ADDRESS) {
401 remote_addr = var_ptr_addr;
402 }
403
404 if (var_ptr_addr != 0)
406 val.getName().str().c_str(), LLDB_INVALID_ADDRESS, remote_addr));
407 }
408 };
409
410 for (llvm::GlobalVariable &global_var : m_module->globals()) {
411 RegisterOneValue(global_var);
412 }
413
414 for (llvm::GlobalAlias &global_alias : m_module->aliases()) {
415 RegisterOneValue(global_alias);
416 }
417
418 WriteData(process_sp);
419
420 if (m_failed_lookups.size()) {
421 StreamString ss;
422
423 ss.PutCString("Couldn't look up symbols:\n");
424
425 bool emitNewLine = false;
426
427 for (ConstString failed_lookup : m_failed_lookups) {
428 if (emitNewLine)
429 ss.PutCString("\n");
430 emitNewLine = true;
431 ss.PutCString(" ");
432 ss.PutCString(Mangled(failed_lookup).GetDemangledName().GetStringRef());
433 }
434
435 m_failed_lookups.clear();
436 ss.PutCString(
437 "\nHint: The expression tried to call a function that is not present "
438 "in the target, perhaps because it was optimized out by the compiler.");
439 error = Status(ss.GetString().str());
440
441 return;
442 }
443
446
447 for (JittedFunction &jitted_function : m_jitted_functions) {
448 jitted_function.m_remote_addr =
449 GetRemoteAddressForLocal(jitted_function.m_local_addr);
450
451 if (!m_name.IsEmpty() && jitted_function.m_name == m_name) {
452 AddrRange func_range =
453 GetRemoteRangeForLocal(jitted_function.m_local_addr);
454 m_function_end_load_addr = func_range.first + func_range.second;
455 m_function_load_addr = jitted_function.m_remote_addr;
456 }
457 }
458
459 if (log) {
460 LLDB_LOGF(log, "Code can be run in the target.");
461
462 StreamString disassembly_stream;
463
464 Status err = DisassembleFunction(disassembly_stream, process_sp);
465
466 if (!err.Success()) {
467 LLDB_LOGF(log, "Couldn't disassemble function : %s",
468 err.AsCString("unknown error"));
469 } else {
470 LLDB_LOGF(log, "Function disassembly:\n%s", disassembly_stream.GetData());
471 }
472
473 LLDB_LOGF(log, "Sections: ");
474 for (AllocationRecord &record : m_records) {
475 if (record.m_process_address != LLDB_INVALID_ADDRESS) {
476 record.dump(log);
477
478 DataBufferHeap my_buffer(record.m_size, 0);
479 Status err;
480 ReadMemory(my_buffer.GetBytes(), record.m_process_address,
481 record.m_size, err);
482
483 if (err.Success()) {
484 DataExtractor my_extractor(my_buffer.GetBytes(),
485 my_buffer.GetByteSize(),
487 my_extractor.PutToLog(log, 0, my_buffer.GetByteSize(),
488 record.m_process_address, 16,
490 }
491 } else {
492 record.dump(log);
493
494 DataExtractor my_extractor((const void *)record.m_host_address,
495 record.m_size, lldb::eByteOrderBig, 8);
496 my_extractor.PutToLog(log, 0, record.m_size, record.m_host_address, 16,
498 }
499 }
500 }
501
502 func_addr = m_function_load_addr;
503 func_end = m_function_end_load_addr;
504}
505
511
513 : m_default_mm_up(new llvm::SectionMemoryManager()), m_parent(parent) {}
514
516
518 const llvm::StringRef &name, IRExecutionUnit::AllocationKind alloc_kind) {
520 switch (alloc_kind) {
522 sect_type = lldb::eSectionTypeCode;
523 break;
525 sect_type = lldb::eSectionTypeCode;
526 break;
528 sect_type = lldb::eSectionTypeData;
529 break;
531 sect_type = lldb::eSectionTypeData;
532 break;
534 sect_type = lldb::eSectionTypeOther;
535 break;
536 }
537
538 if (!name.empty()) {
539 if (name == "__text" || name == ".text")
540 sect_type = lldb::eSectionTypeCode;
541 else if (name == "__data" || name == ".data")
542 sect_type = lldb::eSectionTypeCode;
543 else if (name.starts_with("__debug_") || name.starts_with(".debug_")) {
544 const uint32_t name_idx = name[0] == '_' ? 8 : 7;
545 llvm::StringRef dwarf_name(name.substr(name_idx));
546 sect_type = ObjectFile::GetDWARFSectionTypeFromName(dwarf_name);
547 } else if (name.starts_with("__apple_") || name.starts_with(".apple_"))
548 sect_type = lldb::eSectionTypeInvalid;
549 else if (name == "__objc_imageinfo")
550 sect_type = lldb::eSectionTypeOther;
551 }
552 return sect_type;
553}
554
556 uintptr_t Size, unsigned Alignment, unsigned SectionID,
557 llvm::StringRef SectionName) {
559
560 uint8_t *return_value = m_default_mm_up->allocateCodeSection(
561 Size, Alignment, SectionID, SectionName);
562
563 m_parent.m_records.push_back(AllocationRecord(
564 (uintptr_t)return_value,
565 lldb::ePermissionsReadable | lldb::ePermissionsExecutable,
567 Alignment, SectionID, SectionName.str().c_str()));
568
569 LLDB_LOGF(log,
570 "IRExecutionUnit::allocateCodeSection(Size=0x%" PRIx64
571 ", Alignment=%u, SectionID=%u) = %p",
572 (uint64_t)Size, Alignment, SectionID, (void *)return_value);
573
574 if (m_parent.m_reported_allocations) {
575 Status err;
576 lldb::ProcessSP process_sp =
577 m_parent.GetBestExecutionContextScope()->CalculateProcess();
578
579 m_parent.CommitOneAllocation(process_sp, err, m_parent.m_records.back());
580 }
581
582 return return_value;
583}
584
586 uintptr_t Size, unsigned Alignment, unsigned SectionID,
587 llvm::StringRef SectionName, bool IsReadOnly) {
589
590 uint8_t *return_value = m_default_mm_up->allocateDataSection(
591 Size, Alignment, SectionID, SectionName, IsReadOnly);
592
593 uint32_t permissions = lldb::ePermissionsReadable;
594 if (!IsReadOnly)
595 permissions |= lldb::ePermissionsWritable;
596 m_parent.m_records.push_back(AllocationRecord(
597 (uintptr_t)return_value, permissions,
599 Alignment, SectionID, SectionName.str().c_str()));
600 LLDB_LOGF(log,
601 "IRExecutionUnit::allocateDataSection(Size=0x%" PRIx64
602 ", Alignment=%u, SectionID=%u) = %p",
603 (uint64_t)Size, Alignment, SectionID, (void *)return_value);
604
605 if (m_parent.m_reported_allocations) {
606 Status err;
607 lldb::ProcessSP process_sp =
608 m_parent.GetBestExecutionContextScope()->CalculateProcess();
609
610 m_parent.CommitOneAllocation(process_sp, err, m_parent.m_records.back());
611 }
612
613 return return_value;
614}
615
616void IRExecutionUnit::CollectCandidateCNames(std::vector<ConstString> &C_names,
617 ConstString name) {
618 if (m_strip_underscore && name.AsCString()[0] == '_')
619 C_names.insert(C_names.begin(), ConstString(&name.AsCString()[1]));
620 C_names.push_back(name);
621}
622
624 std::vector<ConstString> &CPP_names,
625 const std::vector<ConstString> &C_names, const SymbolContext &sc) {
627 for (const ConstString &name : C_names) {
628 Mangled mangled(name);
629 if (cpp_lang->SymbolNameFitsToLanguage(mangled)) {
630 if (ConstString best_alternate =
631 cpp_lang->FindBestAlternateFunctionMangledName(mangled, sc)) {
632 CPP_names.push_back(best_alternate);
633 }
634 }
635
636 std::vector<ConstString> alternates =
637 cpp_lang->GenerateAlternateFunctionManglings(name);
638 CPP_names.insert(CPP_names.end(), alternates.begin(), alternates.end());
639
640 // As a last-ditch fallback, try the base name for C++ names. It's
641 // terrible, but the DWARF doesn't always encode "extern C" correctly.
642 ConstString basename =
643 cpp_lang->GetDemangledFunctionNameWithoutArguments(mangled);
644 CPP_names.push_back(basename);
645 }
646 }
647}
648
650public:
651 LoadAddressResolver(Target &target, bool &symbol_was_missing_weak)
652 : m_target(target), m_symbol_was_missing_weak(symbol_was_missing_weak) {}
653
654 std::optional<lldb::addr_t> Resolve(SymbolContextList &sc_list) {
655 if (sc_list.IsEmpty())
656 return std::nullopt;
657
658 lldb::addr_t load_address = LLDB_INVALID_ADDRESS;
659
660 // Missing_weak_symbol will be true only if we found only weak undefined
661 // references to this symbol.
663
664 for (auto candidate_sc : sc_list.SymbolContexts()) {
665 // Only symbols can be weak undefined.
666 if (!candidate_sc.symbol ||
667 candidate_sc.symbol->GetType() != lldb::eSymbolTypeUndefined ||
668 !candidate_sc.symbol->IsWeak())
670
671 // First try the symbol.
672 if (candidate_sc.symbol) {
673 load_address = candidate_sc.symbol->ResolveCallableAddress(m_target);
674 if (load_address == LLDB_INVALID_ADDRESS) {
675 Address addr = candidate_sc.symbol->GetAddress();
676 load_address = m_target.GetProcessSP()
677 ? addr.GetLoadAddress(&m_target)
678 : addr.GetFileAddress();
679 }
680 }
681
682 // If that didn't work, try the function.
683 if (load_address == LLDB_INVALID_ADDRESS && candidate_sc.function) {
684 Address addr = candidate_sc.function->GetAddress();
685 load_address = m_target.GetProcessSP()
687 : addr.GetFileAddress();
688 }
689
690 // We found a load address.
691 if (load_address != LLDB_INVALID_ADDRESS) {
692 // If the load address is external, we're done.
693 const bool is_external =
694 (candidate_sc.function) ||
695 (candidate_sc.symbol && candidate_sc.symbol->IsExternal());
696 if (is_external)
697 return load_address;
698
699 // Otherwise, remember the best internal load address.
701 m_best_internal_load_address = load_address;
702 }
703 }
704
705 // You test the address of a weak symbol against NULL to see if it is
706 // present. So we should return 0 for a missing weak symbol.
708 return 0;
709
710 return std::nullopt;
711 }
712
716
717private:
721};
722
723/// Returns address of the function referred to by the special function call
724/// label \c label.
725static llvm::Expected<lldb::addr_t>
728 bool &symbol_was_missing_weak) {
729 symbol_was_missing_weak = false;
730
731 if (!sc.target_sp)
732 return llvm::createStringError("target not available.");
733
734 auto module_sp = sc.target_sp->GetImages().FindModule(label.module_id);
735 if (!module_sp)
736 return llvm::createStringError(
737 llvm::formatv("failed to find module by UID {0}", label.module_id));
738
739 auto *symbol_file = module_sp->GetSymbolFile();
740 if (!symbol_file)
741 return llvm::createStringError(
742 llvm::formatv("no SymbolFile found on module {0:x}.", module_sp.get()));
743
744 auto sc_or_err = symbol_file->ResolveFunctionCallLabel(label);
745 if (!sc_or_err)
746 return llvm::joinErrors(
747 llvm::createStringError("failed to resolve function by UID:"),
748 sc_or_err.takeError());
749
750 SymbolContextList sc_list;
751 sc_list.Append(*sc_or_err);
752
753 LoadAddressResolver resolver(*sc.target_sp, symbol_was_missing_weak);
754 return resolver.Resolve(sc_list).value_or(LLDB_INVALID_ADDRESS);
755}
756
758IRExecutionUnit::FindInSymbols(const std::vector<ConstString> &names,
760 bool &symbol_was_missing_weak) {
761 symbol_was_missing_weak = false;
762
763 Target *target = sc.target_sp.get();
764 if (!target) {
765 // We shouldn't be doing any symbol lookup at all without a target.
767 }
768
769 ModuleList non_local_images = target->GetImages();
770 // We'll process module_sp and any preferred modules separately, before the
771 // other modules.
772 non_local_images.Remove(sc.module_sp);
773 for (size_t i = 0; i < m_preferred_modules.GetSize(); ++i)
774 non_local_images.Remove(m_preferred_modules.GetModuleAtIndex(i));
775
776 LoadAddressResolver resolver(*target, symbol_was_missing_weak);
777
778 ModuleFunctionSearchOptions function_options;
779 function_options.include_symbols = true;
780 function_options.include_inlines = false;
781
782 for (const ConstString &name : names) {
783 // The lookup order here is as follows:
784 // 1) Functions in `sc.module_sp`
785 // 2) Functions in the preferred modules list
786 // 3) Functions in the other modules
787 // 4) Symbols in `sc.module_sp`
788 // 5) Symbols in the preferred modules list
789 // 6) Symbols in the other modules
790 if (sc.module_sp) {
791 SymbolContextList sc_list;
792 sc.module_sp->FindFunctions(name, CompilerDeclContext(),
793 lldb::eFunctionNameTypeFull, function_options,
794 sc_list);
795 if (auto load_addr = resolver.Resolve(sc_list))
796 return *load_addr;
797 }
798
799 {
800 SymbolContextList sc_list;
801 m_preferred_modules.FindFunctions(name, lldb::eFunctionNameTypeFull,
802 function_options, sc_list);
803 if (auto load_addr = resolver.Resolve(sc_list))
804 return *load_addr;
805 }
806
807 {
808 SymbolContextList sc_list;
809 non_local_images.FindFunctions(name, lldb::eFunctionNameTypeFull,
810 function_options, sc_list);
811 if (auto load_addr = resolver.Resolve(sc_list))
812 return *load_addr;
813 }
814
815 if (sc.module_sp) {
816 SymbolContextList sc_list;
817 sc.module_sp->FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
818 sc_list);
819 if (auto load_addr = resolver.Resolve(sc_list))
820 return *load_addr;
821 }
822
823 {
824 SymbolContextList sc_list;
825 m_preferred_modules.FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny,
826 sc_list);
827 if (auto load_addr = resolver.Resolve(sc_list))
828 return *load_addr;
829 }
830
831 {
832 SymbolContextList sc_list;
834 sc_list);
835 if (auto load_addr = resolver.Resolve(sc_list))
836 return *load_addr;
837 }
838
839 lldb::addr_t best_internal_load_address =
841 if (best_internal_load_address != LLDB_INVALID_ADDRESS)
842 return best_internal_load_address;
843 }
844
846}
847
849IRExecutionUnit::FindInRuntimes(const std::vector<ConstString> &names,
850 const lldb_private::SymbolContext &sc) {
851 lldb::TargetSP target_sp = sc.target_sp;
852
853 if (!target_sp) {
855 }
856
857 lldb::ProcessSP process_sp = sc.target_sp->GetProcessSP();
858
859 if (!process_sp) {
861 }
862
863 for (const ConstString &name : names) {
864 for (LanguageRuntime *runtime : process_sp->GetLanguageRuntimes()) {
865 lldb::addr_t symbol_load_addr = runtime->LookupRuntimeSymbol(name);
866
867 if (symbol_load_addr != LLDB_INVALID_ADDRESS)
868 return symbol_load_addr;
869 }
870 }
871
873}
874
876 const std::vector<ConstString> &names,
877 const lldb_private::SymbolContext &sc) {
878 lldb::TargetSP target_sp = sc.target_sp;
879
880 for (const ConstString &name : names) {
881 lldb::addr_t symbol_load_addr = target_sp->GetPersistentSymbol(name);
882
883 if (symbol_load_addr != LLDB_INVALID_ADDRESS)
884 return symbol_load_addr;
885 }
886
888}
889
891 bool &missing_weak) {
892 if (name.GetStringRef().starts_with(FunctionCallLabelPrefix)) {
893 auto label_or_err = FunctionCallLabel::fromString(name);
894 if (!label_or_err) {
895 LLDB_LOG_ERROR(GetLog(LLDBLog::Expressions), label_or_err.takeError(),
896 "failed to create FunctionCallLabel from '{1}': {0}",
897 name.GetStringRef());
899 }
900
901 if (auto addr_or_err =
902 ResolveFunctionCallLabel(*label_or_err, m_sym_ctx, missing_weak)) {
903 return *addr_or_err;
904 } else {
905 LLDB_LOG_ERROR(GetLog(LLDBLog::Expressions), addr_or_err.takeError(),
906 "Failed to resolve function call label '{1}': {0}",
907 name.GetStringRef());
908
909 // Fall back to lookup by name despite error in resolving the label.
910 // May happen in practice if the definition of a function lives in
911 // a different lldb_private::Module than it's declaration. Meaning
912 // we couldn't pin-point it using the information encoded in the label.
913 name.SetString(label_or_err->lookup_name);
914 }
915 }
916
917 // TODO: now with function call labels, do we still need to
918 // generate alternate manglings?
919
920 std::vector<ConstString> candidate_C_names;
921 std::vector<ConstString> candidate_CPlusPlus_names;
922
923 CollectCandidateCNames(candidate_C_names, name);
924
925 lldb::addr_t ret = FindInSymbols(candidate_C_names, m_sym_ctx, missing_weak);
926 if (ret != LLDB_INVALID_ADDRESS)
927 return ret;
928
929 // If we find the symbol in runtimes or user defined symbols it can't be
930 // a missing weak symbol.
931 missing_weak = false;
932 ret = FindInRuntimes(candidate_C_names, m_sym_ctx);
933 if (ret != LLDB_INVALID_ADDRESS)
934 return ret;
935
936 ret = FindInUserDefinedSymbols(candidate_C_names, m_sym_ctx);
937 if (ret != LLDB_INVALID_ADDRESS)
938 return ret;
939
940 CollectCandidateCPlusPlusNames(candidate_CPlusPlus_names, candidate_C_names,
941 m_sym_ctx);
942 ret = FindInSymbols(candidate_CPlusPlus_names, m_sym_ctx, missing_weak);
943 return ret;
944}
945
947 std::vector<lldb::addr_t> &static_initializers) {
949
950 llvm::GlobalVariable *global_ctors =
951 m_module->getNamedGlobal("llvm.global_ctors");
952 if (!global_ctors) {
953 LLDB_LOG(log, "Couldn't find llvm.global_ctors.");
954 return;
955 }
956 auto *ctor_array =
957 llvm::dyn_cast<llvm::ConstantArray>(global_ctors->getInitializer());
958 if (!ctor_array) {
959 LLDB_LOG(log, "llvm.global_ctors not a ConstantArray.");
960 return;
961 }
962
963 for (llvm::Use &ctor_use : ctor_array->operands()) {
964 auto *ctor_struct = llvm::dyn_cast<llvm::ConstantStruct>(ctor_use);
965 if (!ctor_struct)
966 continue;
967 // this is standardized
968 lldbassert(ctor_struct->getNumOperands() == 3);
969 auto *ctor_function =
970 llvm::dyn_cast<llvm::Function>(ctor_struct->getOperand(1));
971 if (!ctor_function) {
972 LLDB_LOG(log, "global_ctor doesn't contain an llvm::Function");
973 continue;
974 }
975
976 ConstString ctor_function_name(ctor_function->getName().str());
977 LLDB_LOG(log, "Looking for callable jitted function with name {0}.",
978 ctor_function_name);
979
980 for (JittedFunction &jitted_function : m_jitted_functions) {
981 if (ctor_function_name != jitted_function.m_name)
982 continue;
983 if (jitted_function.m_remote_addr == LLDB_INVALID_ADDRESS) {
984 LLDB_LOG(log, "Found jitted function with invalid address.");
985 continue;
986 }
987 static_initializers.push_back(jitted_function.m_remote_addr);
988 LLDB_LOG(log, "Calling function at address {0:x}.",
989 jitted_function.m_remote_addr);
990 break;
991 }
992 }
993}
994
995llvm::JITSymbol
997 bool missing_weak = false;
998 uint64_t addr = GetSymbolAddressAndPresence(Name, missing_weak);
999 // This is a weak symbol:
1000 if (missing_weak)
1001 return llvm::JITSymbol(addr,
1002 llvm::JITSymbolFlags::Exported | llvm::JITSymbolFlags::Weak);
1003 else
1004 return llvm::JITSymbol(addr, llvm::JITSymbolFlags::Exported);
1005}
1006
1007uint64_t
1009 bool missing_weak = false;
1010 return GetSymbolAddressAndPresence(Name, missing_weak);
1011}
1012
1013uint64_t
1015 const std::string &Name, bool &missing_weak) {
1017
1018 ConstString name_cs(Name.c_str());
1019
1020 lldb::addr_t ret = m_parent.FindSymbol(name_cs, missing_weak);
1021
1022 if (ret == LLDB_INVALID_ADDRESS) {
1023 LLDB_LOGF(log,
1024 "IRExecutionUnit::getSymbolAddress(Name=\"%s\") = <not found>",
1025 Name.c_str());
1026
1027 m_parent.ReportSymbolLookupError(name_cs);
1028 return 0;
1029 } else {
1030 LLDB_LOGF(log, "IRExecutionUnit::getSymbolAddress(Name=\"%s\") = %" PRIx64,
1031 Name.c_str(), ret);
1032 return ret;
1033 }
1034}
1035
1037 const std::string &Name, bool AbortOnFailure) {
1038 return (void *)getSymbolAddress(Name);
1039}
1040
1044
1045 for (AllocationRecord &record : m_records) {
1046 if (local_address >= record.m_host_address &&
1047 local_address < record.m_host_address + record.m_size) {
1048 if (record.m_process_address == LLDB_INVALID_ADDRESS)
1049 return LLDB_INVALID_ADDRESS;
1050
1051 lldb::addr_t ret =
1052 record.m_process_address + (local_address - record.m_host_address);
1053
1054 LLDB_LOGF(log,
1055 "IRExecutionUnit::GetRemoteAddressForLocal() found 0x%" PRIx64
1056 " in [0x%" PRIx64 "..0x%" PRIx64 "], and returned 0x%" PRIx64
1057 " from [0x%" PRIx64 "..0x%" PRIx64 "].",
1058 local_address, (uint64_t)record.m_host_address,
1059 (uint64_t)record.m_host_address + (uint64_t)record.m_size, ret,
1060 record.m_process_address,
1061 record.m_process_address + record.m_size);
1062
1063 return ret;
1064 }
1065 }
1066
1067 return LLDB_INVALID_ADDRESS;
1068}
1069
1072 for (AllocationRecord &record : m_records) {
1073 if (local_address >= record.m_host_address &&
1074 local_address < record.m_host_address + record.m_size) {
1075 if (record.m_process_address == LLDB_INVALID_ADDRESS)
1076 return AddrRange(0, 0);
1077
1078 return AddrRange(record.m_process_address, record.m_size);
1079 }
1080 }
1081
1082 return AddrRange(0, 0);
1083}
1084
1086 Status &error,
1087 AllocationRecord &record) {
1089 return true;
1090 }
1091
1092 switch (record.m_sect_type) {
1114 error.Clear();
1115 break;
1116 default:
1117 const bool zero_memory = false;
1118 if (auto address_or_error =
1119 Malloc(record.m_size, record.m_alignment, record.m_permissions,
1120 eAllocationPolicyProcessOnly, zero_memory))
1121 record.m_process_address = *address_or_error;
1122 else
1123 error = Status::FromError(address_or_error.takeError());
1124 break;
1125 }
1126
1127 return error.Success();
1128}
1129
1131 bool ret = true;
1132
1134
1135 for (AllocationRecord &record : m_records) {
1136 ret = CommitOneAllocation(process_sp, err, record);
1137
1138 if (!ret) {
1139 break;
1140 }
1141 }
1142
1143 if (!ret) {
1144 for (AllocationRecord &record : m_records) {
1145 if (record.m_process_address != LLDB_INVALID_ADDRESS) {
1146 Free(record.m_process_address, err);
1147 record.m_process_address = LLDB_INVALID_ADDRESS;
1148 }
1149 }
1150 }
1151
1152 return ret;
1153}
1154
1155void IRExecutionUnit::ReportAllocations(llvm::ExecutionEngine &engine) {
1157
1158 for (AllocationRecord &record : m_records) {
1159 if (record.m_process_address == LLDB_INVALID_ADDRESS)
1160 continue;
1161
1162 if (record.m_section_id == eSectionIDInvalid)
1163 continue;
1164
1165 engine.mapSectionAddress((void *)record.m_host_address,
1166 record.m_process_address);
1167 }
1168
1169 // Trigger re-application of relocations.
1170 engine.finalizeObject();
1171}
1172
1174 bool wrote_something = false;
1175 for (AllocationRecord &record : m_records) {
1176 if (record.m_process_address != LLDB_INVALID_ADDRESS) {
1178 WriteMemory(record.m_process_address, (uint8_t *)record.m_host_address,
1179 record.m_size, err);
1180 if (err.Success())
1181 wrote_something = true;
1182 }
1183 }
1184 return wrote_something;
1185}
1186
1188 if (!log)
1189 return;
1190
1191 LLDB_LOGF(log,
1192 "[0x%llx+0x%llx]->0x%llx (alignment %d, section ID %d, name %s)",
1193 (unsigned long long)m_host_address, (unsigned long long)m_size,
1194 (unsigned long long)m_process_address, (unsigned)m_alignment,
1195 (unsigned)m_section_id, m_name.c_str());
1196}
1197
1202
1205 return exe_ctx.GetAddressByteSize();
1206}
1207
1209 lldb_private::Symtab &symtab) {
1210 // No symbols yet...
1211}
1212
1214 lldb_private::ObjectFile *obj_file,
1215 lldb_private::SectionList &section_list) {
1216 for (AllocationRecord &record : m_records) {
1217 if (record.m_size > 0) {
1219 obj_file->GetModule(), obj_file, record.m_section_id,
1220 ConstString(record.m_name), record.m_sect_type,
1221 record.m_process_address, record.m_size,
1222 record.m_host_address, // file_offset (which is the host address for
1223 // the data)
1224 record.m_size, // file_size
1225 0,
1226 record.m_permissions)); // flags
1227 section_list.AddSection(section_sp);
1228 }
1229 }
1230}
1231
1234 if(Target *target = exe_ctx.GetTargetPtr())
1235 return target->GetArchitecture();
1236 return ArchSpec();
1237}
1238
1241 Target *target = exe_ctx.GetTargetPtr();
1242 if (!target)
1243 return nullptr;
1244
1245 auto Delegate = std::static_pointer_cast<lldb_private::ObjectFileJITDelegate>(
1246 shared_from_this());
1247
1248 lldb::ModuleSP jit_module_sp =
1250 if (!jit_module_sp)
1251 return nullptr;
1252
1253 bool changed = false;
1254 jit_module_sp->SetLoadAddress(*target, 0, true, changed);
1255 return jit_module_sp;
1256}
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:369
#define LLDB_LOGF(log,...)
Definition Log.h:376
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
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:301
lldb::addr_t GetCallableLoadAddress(Target *target, bool is_indirect=false) const
Get the load address as a callable code load address.
Definition Address.cpp:326
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:281
An architecture specification class.
Definition ArchSpec.h:31
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:685
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition ArchSpec.cpp:548
Represents a generic declaration context in a program.
A uniqued constant string class.
Definition ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetString(llvm::StringRef s)
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.
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:57
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:374
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)
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.
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
void FreeNow(lldb::addr_t allocation)
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
@ eAllocationPolicyMirror
The intent is that this allocation exist both in the host and the process and have the same content i...
Definition IRMemoryMap.h:47
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:84
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:104
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.
static lldb::ModuleSP CreateModuleFromObjectFile(Args &&...args)
Definition Module.h:135
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:45
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:357
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:1930
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:3616
size_t AddSection(const lldb::SectionSP &section_sp)
Definition Section.cpp:482
An error handling class.
Definition Status.h:118
void Clear()
Clear the object state.
Definition Status.cpp:215
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:195
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:137
bool Success() const
Test for success condition.
Definition Status.cpp:304
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:65
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.
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1014
const ArchSpec & GetArchitecture() const
Definition Target.h:1056
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:332
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:66
bool include_inlines
Include inlined functions.
Definition Module.h:70
bool include_symbols
Include the symbol table.
Definition Module.h:68