================
@@ -36,6 +36,58 @@ using namespace lldb_private;
 #define LLDB_OPTIONS_register_read
 #include "CommandOptions.inc"
 
+static size_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<size_t>(str.size());
+}
+
+static size_t ComputeLongestRegisterName(RegisterContext *reg_ctx,
+                                         const RegisterSet &reg_set,
+                                         bool use_primary_name,
+                                         bool primitive_only) {
+  const size_t num_registers = reg_set.num_registers;
+  size_t name_right_align_at = 0;
+
+  // Loop through all the registers to find the longest register name.
+  for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) {
+    const size_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;
+
+      name_right_align_at = std::max(name_right_align_at,
+                                     GetNameSize(reg_info, use_primary_name));
+    }
+  }
+
+  return name_right_align_at;
+}
+
+// We expect that [command] only contains register names to be printed.
+static size_t ComputeLongestRegisterName(Args &command,
+                                         RegisterContext *reg_ctx,
+                                         bool use_primary_name) {
+  size_t name_right_align_at = 0;
+
+  // Loop through all the arguments to find the longest register name.
+  for (auto &entry : command) {
+    // In most LLDB commands we accept $rbx as the name for register RBX
+    //  -> Internally it must be restricted to plain [ rbx ] format.
----------------
Rifet-c wrote:

Changed

https://github.com/llvm/llvm-project/pull/188049
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to