[Lldb-commits] [lldb] [lldb] Implement WebAssembly debugging (PR #77949)

Xu Jun via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 22 08:00:07 PST 2024


================
@@ -0,0 +1,108 @@
+//===---- wasmRegisterContext.cpp -----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "wasmRegisterContext.h"
+#include "Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h"
+#include "ProcessWasm.h"
+#include "ThreadWasm.h"
+#include "lldb/Utility/RegisterValue.h"
+#include <memory>
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::process_gdb_remote;
+using namespace lldb_private::wasm;
+
+WasmRegisterContext::WasmRegisterContext(
+    wasm::ThreadWasm &thread, uint32_t concrete_frame_idx,
+    GDBRemoteDynamicRegisterInfoSP reg_info_sp)
+    : GDBRemoteRegisterContext(thread, concrete_frame_idx, reg_info_sp, false,
+                               false) {}
+
+WasmRegisterContext::~WasmRegisterContext() = default;
+
+uint32_t WasmRegisterContext::ConvertRegisterKindToRegisterNumber(
+    lldb::RegisterKind kind, uint32_t num) {
+  return num;
+}
+
+size_t WasmRegisterContext::GetRegisterCount() { return 0; }
+
+const RegisterInfo *WasmRegisterContext::GetRegisterInfoAtIndex(size_t reg) {
+  uint32_t tag = (reg >> 30) & 0x03;
+  if (tag == 0) {
+    return m_reg_info_sp->GetRegisterInfoAtIndex(reg);
+  }
+
+  auto it = m_register_map.find(reg);
+  if (it == m_register_map.end()) {
+    WasmVirtualRegisterKinds kind =
+        static_cast<WasmVirtualRegisterKinds>(tag - 1);
----------------
xujuntwt95329 wrote:

Thanks for the suggestion, that would be better.

@paolosevMSFT Maybe we can modify the `eLocal` to `1` in `wasmRegisterContext.h:WasmVirtualRegisterKinds` so we don't need to do addition and subtracting on the tag
https://github.com/paolosevMSFT/llvm-project/blob/89c4ec1b1dec51df187e84c83ad3cb25eb7e847a/lldb/source/Plugins/Process/wasm/wasmRegisterContext.h#L25

https://github.com/llvm/llvm-project/pull/77949


More information about the lldb-commits mailing list