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/Log.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 using namespace lldb_private::wasm;
22 
23 DynamicLoaderWasmDYLD::DynamicLoaderWasmDYLD(Process *process)
24     : DynamicLoader(process) {}
25 
26 void DynamicLoaderWasmDYLD::Initialize() {
27   PluginManager::RegisterPlugin(GetPluginNameStatic(),
28                                 GetPluginDescriptionStatic(), CreateInstance);
29 }
30 
31 ConstString DynamicLoaderWasmDYLD::GetPluginNameStatic() {
32   static ConstString g_plugin_name("wasm-dyld");
33   return g_plugin_name;
34 }
35 
36 const char *DynamicLoaderWasmDYLD::GetPluginDescriptionStatic() {
37   return "Dynamic loader plug-in that watches for shared library "
38          "loads/unloads in WebAssembly engines.";
39 }
40 
41 DynamicLoader *DynamicLoaderWasmDYLD::CreateInstance(Process *process,
42                                                      bool force) {
43   bool should_create = force;
44   if (!should_create) {
45     should_create =
46         (process->GetTarget().GetArchitecture().GetTriple().getArch() ==
47          llvm::Triple::wasm32);
48   }
49 
50   if (should_create)
51     return new DynamicLoaderWasmDYLD(process);
52 
53   return nullptr;
54 }
55 
56 void DynamicLoaderWasmDYLD::DidAttach() {
57   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
58   LLDB_LOGF(log, "DynamicLoaderWasmDYLD::%s()", __FUNCTION__);
59 
60   // Ask the process for the list of loaded WebAssembly modules.
61   auto error = m_process->LoadModules();
62   LLDB_LOG_ERROR(log, std::move(error), "Couldn't load modules: {0}");
63 }
64 
65 ThreadPlanSP DynamicLoaderWasmDYLD::GetStepThroughTrampolinePlan(Thread &thread,
66                                                                  bool stop) {
67   return ThreadPlanSP();
68 }
69