/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/DynamicLoader/wasm-DYLD/DynamicLoaderWasmDYLD.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
9 | | #include "DynamicLoaderWasmDYLD.h" |
10 | | |
11 | | #include "Plugins/ObjectFile/wasm/ObjectFileWasm.h" |
12 | | #include "lldb/Core/Module.h" |
13 | | #include "lldb/Core/PluginManager.h" |
14 | | #include "lldb/Core/Section.h" |
15 | | #include "lldb/Target/Process.h" |
16 | | #include "lldb/Target/Target.h" |
17 | | #include "lldb/Utility/LLDBLog.h" |
18 | | #include "lldb/Utility/Log.h" |
19 | | |
20 | | using namespace lldb; |
21 | | using namespace lldb_private; |
22 | | using namespace lldb_private::wasm; |
23 | | |
24 | | LLDB_PLUGIN_DEFINE(DynamicLoaderWasmDYLD) |
25 | | |
26 | | DynamicLoaderWasmDYLD::DynamicLoaderWasmDYLD(Process *process) |
27 | 3 | : DynamicLoader(process) {} |
28 | | |
29 | 3.95k | void DynamicLoaderWasmDYLD::Initialize() { |
30 | 3.95k | PluginManager::RegisterPlugin(GetPluginNameStatic(), |
31 | 3.95k | GetPluginDescriptionStatic(), CreateInstance); |
32 | 3.95k | } |
33 | | |
34 | 3.95k | llvm::StringRef DynamicLoaderWasmDYLD::GetPluginDescriptionStatic() { |
35 | 3.95k | return "Dynamic loader plug-in that watches for shared library " |
36 | 3.95k | "loads/unloads in WebAssembly engines."; |
37 | 3.95k | } |
38 | | |
39 | | DynamicLoader *DynamicLoaderWasmDYLD::CreateInstance(Process *process, |
40 | 3 | bool force) { |
41 | 3 | bool should_create = force; |
42 | 3 | if (!should_create) { |
43 | 3 | should_create = |
44 | 3 | (process->GetTarget().GetArchitecture().GetTriple().getArch() == |
45 | 3 | llvm::Triple::wasm32); |
46 | 3 | } |
47 | | |
48 | 3 | if (should_create) |
49 | 3 | return new DynamicLoaderWasmDYLD(process); |
50 | | |
51 | 0 | return nullptr; |
52 | 3 | } |
53 | | |
54 | 3 | void DynamicLoaderWasmDYLD::DidAttach() { |
55 | 3 | Log *log = GetLog(LLDBLog::DynamicLoader); |
56 | 3 | LLDB_LOGF(log, "DynamicLoaderWasmDYLD::%s()", __FUNCTION__); |
57 | | |
58 | | // Ask the process for the list of loaded WebAssembly modules. |
59 | 3 | auto error = m_process->LoadModules(); |
60 | 3 | LLDB_LOG_ERROR(log, std::move(error), "Couldn't load modules: {0}"); |
61 | 3 | } |
62 | | |
63 | | ThreadPlanSP DynamicLoaderWasmDYLD::GetStepThroughTrampolinePlan(Thread &thread, |
64 | 0 | bool stop) { |
65 | 0 | return ThreadPlanSP(); |
66 | 0 | } |
67 | | |
68 | | lldb::ModuleSP DynamicLoaderWasmDYLD::LoadModuleAtAddress( |
69 | | const lldb_private::FileSpec &file, lldb::addr_t link_map_addr, |
70 | 3 | lldb::addr_t base_addr, bool base_addr_is_offset) { |
71 | 3 | if (ModuleSP module_sp = DynamicLoader::LoadModuleAtAddress( |
72 | 3 | file, link_map_addr, base_addr, base_addr_is_offset)) |
73 | 1 | return module_sp; |
74 | | |
75 | 2 | if (ModuleSP module_sp = m_process->ReadModuleFromMemory(file, base_addr)) { |
76 | 2 | UpdateLoadedSections(module_sp, link_map_addr, base_addr, false); |
77 | 2 | m_process->GetTarget().GetImages().AppendIfNeeded(module_sp); |
78 | 2 | return module_sp; |
79 | 2 | } |
80 | | |
81 | 0 | return nullptr; |
82 | 2 | } |