[Lldb-commits] [lldb] [lldb] Number the Wasm virtual registers (PR #237243)
Felipe de Azevedo Piovezan via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 30 07:49:47 PDT 2026
https://github.com/felipepiovezan created https://github.com/llvm/llvm-project/pull/237243
WasmVirtualRegisterInfo left every register number at 0, the value that
RegisterInfo() gives them. So each local, global and operand stack value
claimed to be LLDB register 0, DWARF register 0 and the generic PC
(LLDB_REGNUM_GENERIC_PC is 0). RegisterContextTask, for example, checks
for the generic PC first, so it would read any local as the PC.
Give each virtual register its own number, GetWasmRegister(kind, index),
as its LLDB number. GetRegisterInfoAtIndex takes that number, and
RegisterContextWasm::ConvertRegisterKindToRegisterNumber returns it.
Leave the other kinds invalid: DWARF names these values with
DW_OP_WASM_location, not with register numbers, and they have no EH
frame or generic number.
>From 18826995320e3d14ada35a74230f4ca08c481f83 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
Date: Fri, 30 Oct 2026 13:34:50 +0000
Subject: [PATCH] [lldb] Number the Wasm virtual registers
WasmVirtualRegisterInfo left every register number at 0, the value that
RegisterInfo() gives them. So each local, global and operand stack value
claimed to be LLDB register 0, DWARF register 0 and the generic PC
(LLDB_REGNUM_GENERIC_PC is 0). RegisterContextTask, for example, checks
for the generic PC first, so it would read any local as the PC.
Give each virtual register its own number, GetWasmRegister(kind, index),
as its LLDB number. GetRegisterInfoAtIndex takes that number, and
RegisterContextWasm::ConvertRegisterKindToRegisterNumber returns it.
Leave the other kinds invalid: DWARF names these values with
DW_OP_WASM_location, not with register numbers, and they have no EH
frame or generic number.
---
.../Process/wasm/RegisterContextWasm.h | 7 +++++-
lldb/unittests/Process/CMakeLists.txt | 1 +
lldb/unittests/Process/wasm/CMakeLists.txt | 6 +++++
.../Process/wasm/RegisterContextWasmTest.cpp | 22 +++++++++++++++++++
4 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 lldb/unittests/Process/wasm/CMakeLists.txt
create mode 100644 lldb/unittests/Process/wasm/RegisterContextWasmTest.cpp
diff --git a/lldb/source/Plugins/Process/wasm/RegisterContextWasm.h b/lldb/source/Plugins/Process/wasm/RegisterContextWasm.h
index dcb6e021435d0d..a9fc177b3bb5d0 100644
--- a/lldb/source/Plugins/Process/wasm/RegisterContextWasm.h
+++ b/lldb/source/Plugins/Process/wasm/RegisterContextWasm.h
@@ -14,6 +14,7 @@
#include "ThreadWasm.h"
#include "Utility/WasmVirtualRegisters.h"
#include "lldb/lldb-private-types.h"
+#include <algorithm>
#include <unordered_map>
namespace lldb_private {
@@ -28,7 +29,11 @@ struct WasmVirtualRegisterInfo : public RegisterInfo {
uint32_t index;
WasmVirtualRegisterInfo(WasmVirtualRegisterKinds kind, uint32_t index)
- : RegisterInfo(), kind(kind), index(index) {}
+ : RegisterInfo(), kind(kind), index(index) {
+ // RegisterInfo() zeroes the numbers, and 0 is the generic PC.
+ std::fill(std::begin(kinds), std::end(kinds), LLDB_INVALID_REGNUM);
+ kinds[lldb::eRegisterKindLLDB] = GetWasmRegister(kind, index);
+ }
};
class RegisterContextWasm
diff --git a/lldb/unittests/Process/CMakeLists.txt b/lldb/unittests/Process/CMakeLists.txt
index da997e1073e909..a8dc6e7f112085 100644
--- a/lldb/unittests/Process/CMakeLists.txt
+++ b/lldb/unittests/Process/CMakeLists.txt
@@ -9,6 +9,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
endif()
add_subdirectory(Utility)
add_subdirectory(minidump)
+add_subdirectory(wasm)
add_lldb_unittest(ProcessTests
ProcessEventDataTest.cpp
diff --git a/lldb/unittests/Process/wasm/CMakeLists.txt b/lldb/unittests/Process/wasm/CMakeLists.txt
new file mode 100644
index 00000000000000..7f5f85df1b366d
--- /dev/null
+++ b/lldb/unittests/Process/wasm/CMakeLists.txt
@@ -0,0 +1,6 @@
+add_lldb_unittest(ProcessWasmTests
+ RegisterContextWasmTest.cpp
+
+ LINK_LIBS
+ lldbPluginProcessWasm
+ )
diff --git a/lldb/unittests/Process/wasm/RegisterContextWasmTest.cpp b/lldb/unittests/Process/wasm/RegisterContextWasmTest.cpp
new file mode 100644
index 00000000000000..f2b7ea03a1fbc3
--- /dev/null
+++ b/lldb/unittests/Process/wasm/RegisterContextWasmTest.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 "Plugins/Process/wasm/RegisterContextWasm.h"
+#include "gtest/gtest.h"
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::wasm;
+
+TEST(WasmVirtualRegisterInfoTest, RegisterNumbers) {
+ const WasmVirtualRegisterInfo info(eWasmTagLocal, 3);
+ EXPECT_EQ(info.kinds[eRegisterKindLLDB], GetWasmRegister(eWasmTagLocal, 3));
+ for (RegisterKind kind : {eRegisterKindEHFrame, eRegisterKindDWARF,
+ eRegisterKindGeneric, eRegisterKindProcessPlugin})
+ EXPECT_EQ(info.kinds[kind], LLDB_INVALID_REGNUM) << "kind " << kind;
+}
More information about the lldb-commits
mailing list