[Lldb-commits] [lldb] [lldb] Support integer registers with more than 64 bits. (PR #166363)

Matej Košík via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 7 08:03:45 PST 2025


================
@@ -206,7 +206,30 @@ Status RegisterValue::SetValueFromData(const RegisterInfo &reg_info,
         int128.x[0] = data2;
         int128.x[1] = data1;
       }
-      SetUInt128(llvm::APInt(128, int128.x));
+      SetUIntN(llvm::APInt(128, int128.x));
+    } else {
+      std::vector<uint8_t> bytes(src_len, 0);
+      for (size_t i = 0; i < src_len; i++)
+        bytes[i] = src.GetU8(&src_offset);
+
+      if (src.GetByteOrder() == eByteOrderBig)
+        // Transform the big-endian input to little-endian
+        // because that is what the "llvm::LoadIntFromMemory" function
+        // we call below expects.
+        std::reverse(bytes.begin(), bytes.end());
+
+      if (llvm::sys::IsBigEndianHost) {
+        // If LLDB runs on a big-endian architecture,
+        // make sure that the input data can be read in
+        // 64-bit chunks because that is what
+        // the "llvm::LoadIntFromMemory" function will do.
----------------
sedymrak wrote:

[Here](https://github.com/sedymrak/llvm-project/blob/f563fcd8c5bb05133bdbe6ec2860355f0ab45e0e/lldb/source/Utility/RegisterValue.cpp#L224), we are calliing the  `llvm::LoadIntFromMemory`. If LLDB is running on little-endian machine, it initializes the arbitrary-precision integer by [calling memset](https://github.com/sedymrak/llvm-project/blob/f563fcd8c5bb05133bdbe6ec2860355f0ab45e0e/llvm/lib/Support/APInt.cpp#L3086). When LLDB is running on a big-endian machine, [situation is trickier](https://github.com/sedymrak/llvm-project/blob/f563fcd8c5bb05133bdbe6ec2860355f0ab45e0e/llvm/lib/Support/APInt.cpp#L3092-L3097). The `llvm::LoadIntFromMemory` tries to read from the memory-region designated by the `Src` pointer in 64-bit (in other words 8-byte) chunks. By "rounding up" we ensure that the `llvm::LoadIntFromMemory` method can read as many 64-bit (i.e. 8-byte) chunks as it will want.

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


More information about the lldb-commits mailing list