[Lldb-commits] [lldb] [lldb] Improved formatting of 'register read' command. (PR #188049)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 2 03:01:43 PDT 2026


================
@@ -147,6 +149,62 @@ class CommandObjectRegisterRead : public CommandObjectParsed {
   }
 
 protected:
+  uint32_t GetNameSize(const RegisterInfo * reg_info, bool use_primary_name) {
+      const char *raw = use_primary_name ? reg_info->name : reg_info->alt_name;
+      std::string str = raw ? std::string(raw) : std::string();
+      return static_cast<uint32_t>(str.size());
+  }
+
+  uint32_t ComputeMatchingAlignment(RegisterContext *reg_ctx,
+                                    const RegisterSet *const reg_set,
+                                    bool primitive_only) {
+    bool use_primary_name =
+        !static_cast<bool>(m_command_options.alternate_name);
+    const size_t num_registers = reg_set->num_registers;
+    uint32_t reg_name_align_at = 0;
+
+    // Loop through all the registers to find the longest register name for the
+    // matching alignment
+    for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) {
+      const uint32_t reg = reg_set->registers[reg_idx];
+      if (const RegisterInfo *reg_info = 
+              reg_ctx->GetRegisterInfoAtIndex(reg)) {
+        // Derived registers are skipped if primitive_only is true.
+        if (primitive_only && reg_info->value_regs)
+          continue;
+
+        reg_name_align_at = std::max(reg_name_align_at, GetNameSize(reg_info, use_primary_name));
+      }
+    }
+
+    return reg_name_align_at;
+  }
+
+  // Here, command is basically a list of registers to be printed by DumpRegister() method
+  uint32_t ComputeMatchingAlignment(Args &command, RegisterContext *reg_ctx, bool primitive_only) {
+    bool use_primary_name =
+        !static_cast<bool>(m_command_options.alternate_name);
+    uint32_t reg_name_align_at = 0;
+
+    // Loop through all the arguments to find the longest register name for the
+    // matching alignment
+    for (auto &entry : command) {
+      auto arg_str = entry.ref();
+      arg_str.consume_front("$");
+    
+      if (const RegisterInfo *reg_info =
+              reg_ctx->GetRegisterInfoByName(arg_str)) {
+        // Derived registers are skipped if primitive_only is true.
----------------
DavidSpickett wrote:

I'm confused what primitive_only is doing because if I have a request like:
```
(lldb) register read v0 s0
      v0 = {0x2f 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f 0x2f}
      s0 = 1.59329203E-10
```
`s0` is a value register of `v0`.
```
(lldb) register info v0
       Name: v0
       Size: 16 bytes (128 bits)
Invalidates: s0, d0, z0
  Read from: z0
    In sets: Floating Point Registers (index 1)
(lldb) register info s0
       Name: s0
       Size: 4 bytes (32 bits)
Invalidates: v0, d0, z0
  Read from: z0
    In sets: Floating Point Registers (index 1)
```
So I would still want `s0` to be printed if I've asked for it, and in this case the names are both 2 characters but that's just coincidence.

Then again, I'm not exactly sure what primitive means. Perhaps it is only true when you're asking for whole sets of registers, so in my example it will always be false.

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


More information about the lldb-commits mailing list