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"
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 
25 
27  : DynamicLoader(process) {}
28 
29 void DynamicLoaderWasmDYLD::Initialize() {
30  PluginManager::RegisterPlugin(GetPluginNameStatic(),
31  GetPluginDescriptionStatic(), CreateInstance);
32 }
33 
34 llvm::StringRef DynamicLoaderWasmDYLD::GetPluginDescriptionStatic() {
35  return "Dynamic loader plug-in that watches for shared library "
36  "loads/unloads in WebAssembly engines.";
37 }
38 
39 DynamicLoader *DynamicLoaderWasmDYLD::CreateInstance(Process *process,
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 
54 void DynamicLoaderWasmDYLD::DidAttach() {
55  Log *log = GetLog(LLDBLog::DynamicLoader);
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 
63 ThreadPlanSP DynamicLoaderWasmDYLD::GetStepThroughTrampolinePlan(Thread &thread,
64  bool stop) {
65  return ThreadPlanSP();
66 }
67 
68 lldb::ModuleSP DynamicLoaderWasmDYLD::LoadModuleAtAddress(
69  const lldb_private::FileSpec &file, lldb::addr_t link_map_addr,
70  lldb::addr_t base_addr, bool base_addr_is_offset) {
71  if (ModuleSP module_sp = DynamicLoader::LoadModuleAtAddress(
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 }
ObjectFileWasm.h
lldb_private::wasm
Definition: DynamicLoaderWasmDYLD.h:15
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:344
lldb_private::Process
Definition: Process.h:338
Module.h
DynamicLoaderWasmDYLD.h
lldb_private::Process::GetTarget
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1219
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:463
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
Section.h
Process.h
Target.h
lldb_private::FileSpec
Definition: FileSpec.h:55
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
Log.h
lldb_private::Thread
Definition: Thread.h:61
lldb_private::DynamicLoader
Definition: DynamicLoader.h:52
lldb_private::Target::GetArchitecture
const ArchSpec & GetArchitecture() const
Definition: Target.h:989
PluginManager.h
lldb_private::wasm::DynamicLoaderWasmDYLD
Definition: DynamicLoaderWasmDYLD.h:17
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
LLDB_PLUGIN_DEFINE
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
lldb_private::Log
Definition: Log.h:115
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
lldb
Definition: SBAddress.h:15
LLDB_LOG_ERROR
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:360
LLDBLog.h