LLDB mainline
DynamicLoaderWasmDYLD.cpp
Go to the documentation of this file.
1//===-- DynamicLoaderWasmDYLD.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
10
12#include "lldb/Core/Module.h"
14#include "lldb/Core/Section.h"
15#include "lldb/Target/Process.h"
16#include "lldb/Target/Target.h"
18#include "lldb/Utility/Log.h"
19
20using namespace lldb;
21using namespace lldb_private;
22using namespace lldb_private::wasm;
23
25
28
33
35 return "Dynamic loader plug-in that watches for shared library "
36 "loads/unloads in WebAssembly engines.";
37}
38
40 bool force) {
41 bool should_create = force;
42 if (!should_create) {
43 should_create =
44 (process->GetTarget().GetArchitecture().GetTriple().getArch() ==
45 llvm::Triple::wasm32);
46 }
47
48 if (should_create)
49 return new DynamicLoaderWasmDYLD(process);
50
51 return nullptr;
52}
53
56 LLDB_LOGF(log, "DynamicLoaderWasmDYLD::%s()", __FUNCTION__);
57
58 // Ask the process for the list of loaded WebAssembly modules.
59 auto error = m_process->LoadModules();
60 LLDB_LOG_ERROR(log, std::move(error), "Couldn't load modules: {0}");
61}
62
67
69 const lldb_private::FileSpec &file, lldb::addr_t link_map_addr,
70 lldb::addr_t base_addr, bool base_addr_is_offset) {
72 file, link_map_addr, base_addr, base_addr_is_offset))
73 return module_sp;
74
75 if (ModuleSP module_sp = m_process->ReadModuleFromMemory(file, base_addr)) {
76 UpdateLoadedSections(module_sp, link_map_addr, base_addr, false);
77 m_process->GetTarget().GetImages().AppendIfNeeded(module_sp);
78 return module_sp;
79 }
80
81 return nullptr;
82}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:376
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
#define LLDB_PLUGIN_DEFINE(PluginName)
Process * m_process
The process that this dynamic loader plug-in is tracking.
virtual lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file, lldb::addr_t link_map_addr, lldb::addr_t base_addr, bool base_addr_is_offset)
Locates or creates a module given by file and updates/loads the resulting module at the virtual base ...
virtual void UpdateLoadedSections(lldb::ModuleSP module, lldb::addr_t link_map_addr, lldb::addr_t base_addr, bool base_addr_is_offset)
Updates the load address of every allocatable section in module.
DynamicLoader(Process *process)
Construct with a process.
A file utility class.
Definition FileSpec.h:57
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
A plug-in interface definition class for debugging a process.
Definition Process.h:357
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1270
lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file, lldb::addr_t link_map_addr, lldb::addr_t base_addr, bool base_addr_is_offset) override
Locates or creates a module given by file and updates/loads the resulting module at the virtual base ...
lldb::ThreadPlanSP GetStepThroughTrampolinePlan(Thread &thread, bool stop) override
Provides a plan to step through the dynamic loader trampoline for the current state of thread.
static DynamicLoader * CreateInstance(Process *process, bool force)
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
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP