https://github.com/Rifet-c updated https://github.com/llvm/llvm-project/pull/188049
>From 599000a5f214cd8956c343e63882f3646519c458 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Mon, 23 Mar 2026 16:10:26 +0100 Subject: [PATCH 01/40] [lldb] Improved formatting of 'register read' command of lldb. Now it is dynamic in register name lengths and left-aligned. --- .../source/Commands/CommandObjectRegister.cpp | 37 +++++++++++++++++-- lldb/source/Core/DumpRegisterValue.cpp | 6 +-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index c86fd11d4d9e3..defb6ba4919e7 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -75,7 +75,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool DumpRegister(const ExecutionContext &exe_ctx, Stream &strm, RegisterContext ®_ctx, const RegisterInfo ®_info, - bool print_flags) { + bool print_flags, uint32_t reg_name_align_at = 0) { RegisterValue reg_value; if (!reg_ctx.ReadRegister(®_info, reg_value)) return false; @@ -85,7 +85,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool prefix_with_altname = (bool)m_command_options.alternate_name; bool prefix_with_name = !prefix_with_altname; DumpRegisterValue(reg_value, strm, reg_info, prefix_with_name, - prefix_with_altname, m_format_options.GetFormat(), 8, + prefix_with_altname, m_format_options.GetFormat(), reg_name_align_at, exe_ctx.GetBestExecutionContextScope(), print_flags, exe_ctx.GetTargetSP()); if ((reg_info.encoding == eEncodingUint) || @@ -123,6 +123,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { strm.Printf("%s:\n", (reg_set->name ? reg_set->name : "unknown")); strm.IndentMore(); const size_t num_registers = reg_set->num_registers; + uint32_t reg_name_align_at = ComputeMatchingAlignment(reg_ctx, reg_set, primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg); @@ -131,7 +132,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { continue; if (reg_info && DumpRegister(exe_ctx, strm, *reg_ctx, *reg_info, - /*print_flags=*/false)) + /*print_flags=*/false, reg_name_align_at)) ++available_count; else ++unavailable_count; @@ -147,6 +148,36 @@ class CommandObjectRegisterRead : public CommandObjectParsed { } protected: + 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; + + auto getNameSize = [&](auto reg_info){ + auto raw = use_primary_name ? reg_info->name : reg_info->alt_name; + auto str = raw ? std::string(raw) : std::string(); + return static_cast<uint32_t>(str.size()); + }; + + // 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]; + const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg); + + // Derived registers are skipped if primitive_only is true. + if (primitive_only && reg_info && reg_info->value_regs) + continue; + + if (!reg_info) + continue; + + reg_name_align_at = std::max(reg_name_align_at, getNameSize(reg_info)); + } + + return reg_name_align_at; + } + void DoExecute(Args &command, CommandReturnObject &result) override { Stream &strm = result.GetOutputStream(); RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext(); diff --git a/lldb/source/Core/DumpRegisterValue.cpp b/lldb/source/Core/DumpRegisterValue.cpp index aff4d2c621d7e..29b95ba41b085 100644 --- a/lldb/source/Core/DumpRegisterValue.cpp +++ b/lldb/source/Core/DumpRegisterValue.cpp @@ -62,7 +62,7 @@ void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream &s, const RegisterInfo ®_info, bool prefix_with_name, bool prefix_with_alt_name, Format format, - uint32_t reg_name_right_align_at, + uint32_t reg_name_left_align_at, ExecutionContextScope *exe_scope, bool print_flags, TargetSP target_sp) { DataExtractor data; @@ -76,8 +76,8 @@ void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream &s, // prefix_with_name^prefix_with_alt_name is true // StreamString format_string; - if (reg_name_right_align_at && (prefix_with_name ^ prefix_with_alt_name)) - format_string.Printf("%%%us", reg_name_right_align_at); + if (reg_name_left_align_at && (prefix_with_name ^ prefix_with_alt_name)) + format_string.Printf("%%-%us", reg_name_left_align_at); else format_string.Printf("%%s"); std::string fmt = std::string(format_string.GetString()); >From c301dea0c8514acc5947de9cda8055c743979cc2 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Mon, 23 Mar 2026 16:33:09 +0100 Subject: [PATCH 02/40] Fixed formatting --- .../source/Commands/CommandObjectRegister.cpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index defb6ba4919e7..99aecd27f4d18 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -85,9 +85,9 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool prefix_with_altname = (bool)m_command_options.alternate_name; bool prefix_with_name = !prefix_with_altname; DumpRegisterValue(reg_value, strm, reg_info, prefix_with_name, - prefix_with_altname, m_format_options.GetFormat(), reg_name_align_at, - exe_ctx.GetBestExecutionContextScope(), print_flags, - exe_ctx.GetTargetSP()); + prefix_with_altname, m_format_options.GetFormat(), + reg_name_align_at, exe_ctx.GetBestExecutionContextScope(), + print_flags, exe_ctx.GetTargetSP()); if ((reg_info.encoding == eEncodingUint) || (reg_info.encoding == eEncodingSint)) { Process *process = exe_ctx.GetProcessPtr(); @@ -123,7 +123,8 @@ class CommandObjectRegisterRead : public CommandObjectParsed { strm.Printf("%s:\n", (reg_set->name ? reg_set->name : "unknown")); strm.IndentMore(); const size_t num_registers = reg_set->num_registers; - uint32_t reg_name_align_at = ComputeMatchingAlignment(reg_ctx, reg_set, primitive_only); + uint32_t reg_name_align_at = + ComputeMatchingAlignment(reg_ctx, reg_set, primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg); @@ -148,18 +149,21 @@ class CommandObjectRegisterRead : public CommandObjectParsed { } protected: - 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); + 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; - auto getNameSize = [&](auto reg_info){ + auto getNameSize = [&](auto reg_info) { auto raw = use_primary_name ? reg_info->name : reg_info->alt_name; auto str = raw ? std::string(raw) : std::string(); return static_cast<uint32_t>(str.size()); }; - // Loop through all the registers to find the longest register name for the + // 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]; >From 5d5ca6346604f6d3512e35159718c7e173331654 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Tue, 24 Mar 2026 10:40:44 +0100 Subject: [PATCH 03/40] Returned right alignment --- lldb/source/Core/DumpRegisterValue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Core/DumpRegisterValue.cpp b/lldb/source/Core/DumpRegisterValue.cpp index 29b95ba41b085..f5650f44d3fb3 100644 --- a/lldb/source/Core/DumpRegisterValue.cpp +++ b/lldb/source/Core/DumpRegisterValue.cpp @@ -77,7 +77,7 @@ void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream &s, // StreamString format_string; if (reg_name_left_align_at && (prefix_with_name ^ prefix_with_alt_name)) - format_string.Printf("%%-%us", reg_name_left_align_at); + format_string.Printf("%%%us", reg_name_left_align_at); else format_string.Printf("%%s"); std::string fmt = std::string(format_string.GetString()); >From 30a4fa0bd217796793483e78111a0ed413fb2c78 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Tue, 24 Mar 2026 13:58:01 +0100 Subject: [PATCH 04/40] Reversed renaming --- lldb/source/Core/DumpRegisterValue.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lldb/source/Core/DumpRegisterValue.cpp b/lldb/source/Core/DumpRegisterValue.cpp index f5650f44d3fb3..aff4d2c621d7e 100644 --- a/lldb/source/Core/DumpRegisterValue.cpp +++ b/lldb/source/Core/DumpRegisterValue.cpp @@ -62,7 +62,7 @@ void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream &s, const RegisterInfo ®_info, bool prefix_with_name, bool prefix_with_alt_name, Format format, - uint32_t reg_name_left_align_at, + uint32_t reg_name_right_align_at, ExecutionContextScope *exe_scope, bool print_flags, TargetSP target_sp) { DataExtractor data; @@ -76,8 +76,8 @@ void lldb_private::DumpRegisterValue(const RegisterValue ®_val, Stream &s, // prefix_with_name^prefix_with_alt_name is true // StreamString format_string; - if (reg_name_left_align_at && (prefix_with_name ^ prefix_with_alt_name)) - format_string.Printf("%%%us", reg_name_left_align_at); + if (reg_name_right_align_at && (prefix_with_name ^ prefix_with_alt_name)) + format_string.Printf("%%%us", reg_name_right_align_at); else format_string.Printf("%%s"); std::string fmt = std::string(format_string.GetString()); >From ebce8dfcb5406e2c5cc7d49e4b6e2621b7bbe93d Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Tue, 31 Mar 2026 14:48:35 +0200 Subject: [PATCH 05/40] Separate registers printing is now well-aligned as well --- .../source/Commands/CommandObjectRegister.cpp | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 99aecd27f4d18..0f9fc27346579 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -149,6 +149,12 @@ 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) { @@ -157,26 +163,43 @@ class CommandObjectRegisterRead : public CommandObjectParsed { const size_t num_registers = reg_set->num_registers; uint32_t reg_name_align_at = 0; - auto getNameSize = [&](auto reg_info) { - auto raw = use_primary_name ? reg_info->name : reg_info->alt_name; - auto str = raw ? std::string(raw) : std::string(); - return static_cast<uint32_t>(str.size()); - }; - // 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]; - const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg); + 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)); + } + } - // Derived registers are skipped if primitive_only is true. - if (primitive_only && reg_info && reg_info->value_regs) - continue; + return reg_name_align_at; + } - if (!reg_info) - continue; + // 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; - reg_name_align_at = std::max(reg_name_align_at, getNameSize(reg_info)); + // 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. + 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; @@ -230,6 +253,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { result.AppendError("the --set <set> option can't be used when " "registers names are supplied as arguments\n"); } else { + int alignment = ComputeMatchingAlignment(command, reg_ctx, !m_command_options.dump_all_sets.GetCurrentValue()); for (auto &entry : command) { // in most LLDB commands we accept $rbx as the name for register RBX // - and here we would reject it and non-existant. we should be more @@ -246,7 +270,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool print_flags = !m_format_options.GetFormatValue().OptionWasSet(); if (!DumpRegister(m_exe_ctx, strm, *reg_ctx, *reg_info, - print_flags)) + print_flags, alignment)) strm.Printf("%-12s = error: unavailable\n", reg_info->name); } else { result.AppendErrorWithFormat("Invalid register name '%s'", >From 7f24c171f274bfef1c010dc31eb8df00995ee4da Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Wed, 1 Apr 2026 17:09:21 +0200 Subject: [PATCH 06/40] Added two tests: one for register set dumping, other for custom register bundles dumping --- .../source/Commands/CommandObjectRegister.cpp | 1 + ...d-register-read-alignment-custom-regs.test | 13 +++++++ ...mmand-register-read-alignment-reg-set.test | 36 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test create mode 100644 lldb/test/Shell/Commands/command-register-read-alignment-reg-set.test diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 0f9fc27346579..0c49455194b6a 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -254,6 +254,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { "registers names are supplied as arguments\n"); } else { int alignment = ComputeMatchingAlignment(command, reg_ctx, !m_command_options.dump_all_sets.GetCurrentValue()); + alignment += 2; // Extra ident to be consistent with register sets dumping for (auto &entry : command) { // in most LLDB commands we accept $rbx as the name for register RBX // - and here we would reject it and non-existant. we should be more diff --git a/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test b/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test new file mode 100644 index 0000000000000..67be61e094aa7 --- /dev/null +++ b/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test @@ -0,0 +1,13 @@ +# REQUIRES: x86 + +# RUN: %clang_host -g -O0 %S/Inputs/main.c -o %t.out +# RUN: %lldb -b -o "breakpoint set --name main" \ +# RUN: -o run \ +# RUN: -o "register read pc ymm7 ymm12 fs_base" \ +# RUN: %t.out | FileCheck --strict-whitespace %s + +# CHECK: (lldb) register read pc ymm7 ymm12 fs_base +# CHECK: {{^ rip = }} +# CHECK: {{^ ymm7 = }} +# CHECK: {{^ ymm12 = }} +# CHECK: {{^ fs_base = }} \ No newline at end of file diff --git a/lldb/test/Shell/Commands/command-register-read-alignment-reg-set.test b/lldb/test/Shell/Commands/command-register-read-alignment-reg-set.test new file mode 100644 index 0000000000000..d40ea0c35c499 --- /dev/null +++ b/lldb/test/Shell/Commands/command-register-read-alignment-reg-set.test @@ -0,0 +1,36 @@ +# REQUIRES: x86 + +# RUN: %clang_host -g -O0 %S/Inputs/main.c -o %t.out +# RUN: %lldb -b -o "breakpoint set --name main" \ +# RUN: -o run \ +# RUN: -o "register read" \ +# RUN: %t.out | FileCheck --strict-whitespace %s + +# CHECK: (lldb) register read +# CHECK: General Purpose Registers: +# CHECK: {{ rax = }} +# CHECK: {{ rbx = }} +# CHECK: {{ rcx = }} +# CHECK: {{ rdx = }} +# CHECK: {{ rdi = }} +# CHECK: {{ rsi = }} +# CHECK: {{ rbp = }} +# CHECK: {{ rsp = }} +# CHECK: {{ r8 = }} +# CHECK: {{ r9 = }} +# CHECK: {{ r10 = }} +# CHECK: {{ r11 = }} +# CHECK: {{ r12 = }} +# CHECK: {{ r13 = }} +# CHECK: {{ r14 = }} +# CHECK: {{ r15 = }} +# CHECK: {{ rip = }} +# CHECK: {{ rflags = }} +# CHECK: {{ cs = }} +# CHECK: {{ fs = }} +# CHECK: {{ gs = }} +# CHECK: {{ ss = }} +# CHECK: {{ fs_base = }} +# CHECK: {{ gs_base = }} +# CHECK: {{ ds = }} +# CHECK: {{ es = }} \ No newline at end of file >From c1d374800afaf308117b8f932916c8578319e6cc Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 13:44:59 +0200 Subject: [PATCH 07/40] Removed registers that are not guaranteed by x86 architecture --- .../command-register-read-alignment-custom-regs.test | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test b/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test index 67be61e094aa7..9871734d3835b 100644 --- a/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test +++ b/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test @@ -6,8 +6,7 @@ # RUN: -o "register read pc ymm7 ymm12 fs_base" \ # RUN: %t.out | FileCheck --strict-whitespace %s -# CHECK: (lldb) register read pc ymm7 ymm12 fs_base -# CHECK: {{^ rip = }} -# CHECK: {{^ ymm7 = }} -# CHECK: {{^ ymm12 = }} -# CHECK: {{^ fs_base = }} \ No newline at end of file +# CHECK: (lldb) register read pc rax r10d +# CHECK: {{^ pc = }} +# CHECK: {{^ rax = }} +# CHECK: {{^ r10d = }} \ No newline at end of file >From e598f158abe77457bbd87bd15f2efdeadb09eff2 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 14:37:01 +0200 Subject: [PATCH 08/40] Renaming --- .../source/Commands/CommandObjectRegister.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 0c49455194b6a..cee3fd2bd2d8d 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -75,7 +75,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool DumpRegister(const ExecutionContext &exe_ctx, Stream &strm, RegisterContext ®_ctx, const RegisterInfo ®_info, - bool print_flags, uint32_t reg_name_align_at = 0) { + bool print_flags, uint32_t name_right_align_at = 0) { RegisterValue reg_value; if (!reg_ctx.ReadRegister(®_info, reg_value)) return false; @@ -86,7 +86,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool prefix_with_name = !prefix_with_altname; DumpRegisterValue(reg_value, strm, reg_info, prefix_with_name, prefix_with_altname, m_format_options.GetFormat(), - reg_name_align_at, exe_ctx.GetBestExecutionContextScope(), + name_right_align_at, exe_ctx.GetBestExecutionContextScope(), print_flags, exe_ctx.GetTargetSP()); if ((reg_info.encoding == eEncodingUint) || (reg_info.encoding == eEncodingSint)) { @@ -123,7 +123,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { strm.Printf("%s:\n", (reg_set->name ? reg_set->name : "unknown")); strm.IndentMore(); const size_t num_registers = reg_set->num_registers; - uint32_t reg_name_align_at = + uint32_t name_right_align_at = ComputeMatchingAlignment(reg_ctx, reg_set, primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; @@ -133,7 +133,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { continue; if (reg_info && DumpRegister(exe_ctx, strm, *reg_ctx, *reg_info, - /*print_flags=*/false, reg_name_align_at)) + /*print_flags=*/false, name_right_align_at)) ++available_count; else ++unavailable_count; @@ -161,7 +161,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { 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; + uint32_t name_right_align_at = 0; // Loop through all the registers to find the longest register name for the // matching alignment @@ -173,18 +173,18 @@ class CommandObjectRegisterRead : public CommandObjectParsed { if (primitive_only && reg_info->value_regs) continue; - reg_name_align_at = std::max(reg_name_align_at, GetNameSize(reg_info, use_primary_name)); + name_right_align_at = std::max(name_right_align_at, GetNameSize(reg_info, use_primary_name)); } } - return reg_name_align_at; + return name_right_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; + uint32_t name_right_align_at = 0; // Loop through all the arguments to find the longest register name for the // matching alignment @@ -198,11 +198,11 @@ class CommandObjectRegisterRead : public CommandObjectParsed { if (primitive_only && reg_info->value_regs) continue; - reg_name_align_at = std::max(reg_name_align_at, GetNameSize(reg_info, use_primary_name)); + name_right_align_at = std::max(name_right_align_at, GetNameSize(reg_info, use_primary_name)); } } - return reg_name_align_at; + return name_right_align_at; } void DoExecute(Args &command, CommandReturnObject &result) override { >From d450ffef307d3427823aae28e0b8c8cd5a39f473 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 15:42:21 +0200 Subject: [PATCH 09/40] A bit of bug fixing (if a register is specified, it must be printed, so it must be counted into alignment) --- lldb/source/Commands/CommandObjectRegister.cpp | 10 ++++------ .../command-register-read-alignment-custom-regs.test | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index cee3fd2bd2d8d..d3aad94f615f0 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -181,7 +181,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { } // 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) { + uint32_t ComputeMatchingAlignment(Args &command, RegisterContext *reg_ctx) { bool use_primary_name = !static_cast<bool>(m_command_options.alternate_name); uint32_t name_right_align_at = 0; @@ -194,9 +194,6 @@ class CommandObjectRegisterRead : public CommandObjectParsed { if (const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(arg_str)) { - // 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)); } @@ -253,8 +250,8 @@ class CommandObjectRegisterRead : public CommandObjectParsed { result.AppendError("the --set <set> option can't be used when " "registers names are supplied as arguments\n"); } else { - int alignment = ComputeMatchingAlignment(command, reg_ctx, !m_command_options.dump_all_sets.GetCurrentValue()); - alignment += 2; // Extra ident to be consistent with register sets dumping + int alignment = ComputeMatchingAlignment(command, reg_ctx); + strm.IndentMore(); // Extra ident to be consistent with register sets dumping for (auto &entry : command) { // in most LLDB commands we accept $rbx as the name for register RBX // - and here we would reject it and non-existant. we should be more @@ -278,6 +275,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { arg_str.str().c_str()); } } + strm.IndentLess(); } } if (result.GetStatus() != eReturnStatusFailed) diff --git a/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test b/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test index 9871734d3835b..10def3699635d 100644 --- a/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test +++ b/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test @@ -3,10 +3,10 @@ # RUN: %clang_host -g -O0 %S/Inputs/main.c -o %t.out # RUN: %lldb -b -o "breakpoint set --name main" \ # RUN: -o run \ -# RUN: -o "register read pc ymm7 ymm12 fs_base" \ +# RUN: -o "register read rip rax r10d" \ # RUN: %t.out | FileCheck --strict-whitespace %s -# CHECK: (lldb) register read pc rax r10d -# CHECK: {{^ pc = }} +# CHECK: (lldb) register read rip rax r10d +# CHECK: {{^ rip = }} # CHECK: {{^ rax = }} # CHECK: {{^ r10d = }} \ No newline at end of file >From fa47f90dd947dff19bb972e21f5078406fc42066 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 15:46:20 +0200 Subject: [PATCH 10/40] Function renaming [ ComputeMatchingAlignment -> ComputeLongestRegisterName ] --- lldb/source/Commands/CommandObjectRegister.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index d3aad94f615f0..013aa8d4f7a53 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -124,7 +124,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { strm.IndentMore(); const size_t num_registers = reg_set->num_registers; uint32_t name_right_align_at = - ComputeMatchingAlignment(reg_ctx, reg_set, primitive_only); + ComputeLongestRegisterName(reg_ctx, reg_set, primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg); @@ -155,7 +155,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { return static_cast<uint32_t>(str.size()); } - uint32_t ComputeMatchingAlignment(RegisterContext *reg_ctx, + uint32_t ComputeLongestRegisterName(RegisterContext *reg_ctx, const RegisterSet *const reg_set, bool primitive_only) { bool use_primary_name = @@ -181,7 +181,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { } // Here, command is basically a list of registers to be printed by DumpRegister() method - uint32_t ComputeMatchingAlignment(Args &command, RegisterContext *reg_ctx) { + uint32_t ComputeLongestRegisterName(Args &command, RegisterContext *reg_ctx) { bool use_primary_name = !static_cast<bool>(m_command_options.alternate_name); uint32_t name_right_align_at = 0; @@ -250,7 +250,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { result.AppendError("the --set <set> option can't be used when " "registers names are supplied as arguments\n"); } else { - int alignment = ComputeMatchingAlignment(command, reg_ctx); + int alignment = ComputeLongestRegisterName(command, reg_ctx); strm.IndentMore(); // Extra ident to be consistent with register sets dumping for (auto &entry : command) { // in most LLDB commands we accept $rbx as the name for register RBX >From c139aba21b3e7a5f7ec9e10fa96dfa6f49432fe4 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 16:08:45 +0200 Subject: [PATCH 11/40] Made some methods to be static functions (2x ComputeLongestRegisterName and 1x GetNameSize) --- .../source/Commands/CommandObjectRegister.cpp | 103 ++++++++---------- 1 file changed, 48 insertions(+), 55 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 013aa8d4f7a53..4a0d61f5c4b4d 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -36,6 +36,52 @@ using namespace lldb_private; #define LLDB_OPTIONS_register_read #include "CommandOptions.inc" +static 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()); +} + +static uint32_t ComputeLongestRegisterName(RegisterContext *reg_ctx, + const RegisterSet *const reg_set, + bool use_primary_name, bool primitive_only) { + const size_t num_registers = reg_set->num_registers; + uint32_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 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; + + name_right_align_at = std::max(name_right_align_at, GetNameSize(reg_info, use_primary_name)); + } + } + + return name_right_align_at; +} + +// Here, [command] is basically a list of registers to be printed by DumpRegister() method +static uint32_t ComputeLongestRegisterName(Args &command, RegisterContext *reg_ctx, bool use_primary_name) { + uint32_t name_right_align_at = 0; + + // Loop through all the arguments to find the longest register name + for (auto &entry : command) { + auto arg_str = entry.ref(); + arg_str.consume_front("$"); + + if (const RegisterInfo *reg_info = + reg_ctx->GetRegisterInfoByName(arg_str)) { + name_right_align_at = std::max(name_right_align_at, GetNameSize(reg_info, use_primary_name)); + } + } + + return name_right_align_at; +} + class CommandObjectRegisterRead : public CommandObjectParsed { public: CommandObjectRegisterRead(CommandInterpreter &interpreter) @@ -124,7 +170,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { strm.IndentMore(); const size_t num_registers = reg_set->num_registers; uint32_t name_right_align_at = - ComputeLongestRegisterName(reg_ctx, reg_set, primitive_only); + ComputeLongestRegisterName(reg_ctx, reg_set, !static_cast<bool>(m_command_options.alternate_name), primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg); @@ -149,59 +195,6 @@ 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 ComputeLongestRegisterName(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 name_right_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; - - name_right_align_at = std::max(name_right_align_at, GetNameSize(reg_info, use_primary_name)); - } - } - - return name_right_align_at; - } - - // Here, command is basically a list of registers to be printed by DumpRegister() method - uint32_t ComputeLongestRegisterName(Args &command, RegisterContext *reg_ctx) { - bool use_primary_name = - !static_cast<bool>(m_command_options.alternate_name); - uint32_t name_right_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)) { - - name_right_align_at = std::max(name_right_align_at, GetNameSize(reg_info, use_primary_name)); - } - } - - return name_right_align_at; - } - void DoExecute(Args &command, CommandReturnObject &result) override { Stream &strm = result.GetOutputStream(); RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext(); @@ -250,7 +243,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { result.AppendError("the --set <set> option can't be used when " "registers names are supplied as arguments\n"); } else { - int alignment = ComputeLongestRegisterName(command, reg_ctx); + int alignment = ComputeLongestRegisterName(command, reg_ctx, !static_cast<bool>(m_command_options.alternate_name)); strm.IndentMore(); // Extra ident to be consistent with register sets dumping for (auto &entry : command) { // in most LLDB commands we accept $rbx as the name for register RBX >From e1a6decac9df5fa59b6aceec484dee015cbc7474 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 16:15:02 +0200 Subject: [PATCH 12/40] [reg_set] is now passed as constant reference (not as a pointer) --- lldb/source/Commands/CommandObjectRegister.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 4a0d61f5c4b4d..42e7431411e3b 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -43,14 +43,14 @@ static uint32_t GetNameSize(const RegisterInfo * reg_info, bool use_primary_name } static uint32_t ComputeLongestRegisterName(RegisterContext *reg_ctx, - const RegisterSet *const reg_set, + const RegisterSet& reg_set, bool use_primary_name, bool primitive_only) { - const size_t num_registers = reg_set->num_registers; + const size_t num_registers = reg_set.num_registers; uint32_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 uint32_t reg = reg_set->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. @@ -170,7 +170,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { strm.IndentMore(); const size_t num_registers = reg_set->num_registers; uint32_t name_right_align_at = - ComputeLongestRegisterName(reg_ctx, reg_set, !static_cast<bool>(m_command_options.alternate_name), primitive_only); + ComputeLongestRegisterName(reg_ctx, *reg_set, !static_cast<bool>(m_command_options.alternate_name), primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg); >From eb9de0b2ab65d0e9352e03b182551a57940d014f Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 16:21:46 +0200 Subject: [PATCH 13/40] Changed [uint32_t] into [size_t] in new code pieces --- lldb/source/Commands/CommandObjectRegister.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 42e7431411e3b..602fdc93c4fd1 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -36,21 +36,21 @@ using namespace lldb_private; #define LLDB_OPTIONS_register_read #include "CommandOptions.inc" -static uint32_t GetNameSize(const RegisterInfo * reg_info, bool use_primary_name) { +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<uint32_t>(str.size()); + return static_cast<size_t>(str.size()); } -static uint32_t ComputeLongestRegisterName(RegisterContext *reg_ctx, +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; - uint32_t name_right_align_at = 0; + 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 uint32_t reg = reg_set.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. @@ -65,8 +65,8 @@ static uint32_t ComputeLongestRegisterName(RegisterContext *reg_ctx, } // Here, [command] is basically a list of registers to be printed by DumpRegister() method -static uint32_t ComputeLongestRegisterName(Args &command, RegisterContext *reg_ctx, bool use_primary_name) { - uint32_t name_right_align_at = 0; +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) { @@ -121,7 +121,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool DumpRegister(const ExecutionContext &exe_ctx, Stream &strm, RegisterContext ®_ctx, const RegisterInfo ®_info, - bool print_flags, uint32_t name_right_align_at = 0) { + bool print_flags, size_t name_right_align_at = 0) { RegisterValue reg_value; if (!reg_ctx.ReadRegister(®_info, reg_value)) return false; @@ -169,7 +169,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { strm.Printf("%s:\n", (reg_set->name ? reg_set->name : "unknown")); strm.IndentMore(); const size_t num_registers = reg_set->num_registers; - uint32_t name_right_align_at = + size_t name_right_align_at = ComputeLongestRegisterName(reg_ctx, *reg_set, !static_cast<bool>(m_command_options.alternate_name), primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; >From dcf857f6f71cafd4a58fef6cc83800f1d91305c5 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 16:51:02 +0200 Subject: [PATCH 14/40] Replaced [auto] by [StringRef] in one place --- lldb/source/Commands/CommandObjectRegister.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 602fdc93c4fd1..cfe2a6a621b97 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -70,7 +70,7 @@ static size_t ComputeLongestRegisterName(Args &command, RegisterContext *reg_ctx // Loop through all the arguments to find the longest register name for (auto &entry : command) { - auto arg_str = entry.ref(); + llvm::StringRef arg_str = entry.ref(); arg_str.consume_front("$"); if (const RegisterInfo *reg_info = >From 5500cf0e20ed07d691f7c4766f31ccd3eb894526 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 16:53:30 +0200 Subject: [PATCH 15/40] Added missing dots --- lldb/source/Commands/CommandObjectRegister.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index cfe2a6a621b97..998451a94424e 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -48,7 +48,7 @@ static size_t ComputeLongestRegisterName(RegisterContext *reg_ctx, 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 + // 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 = @@ -64,11 +64,11 @@ static size_t ComputeLongestRegisterName(RegisterContext *reg_ctx, return name_right_align_at; } -// Here, [command] is basically a list of registers to be printed by DumpRegister() method +// Here, [command] is basically a list of registers to be printed by DumpRegister() method. 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 + // Loop through all the arguments to find the longest register name. for (auto &entry : command) { llvm::StringRef arg_str = entry.ref(); arg_str.consume_front("$"); @@ -244,7 +244,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { "registers names are supplied as arguments\n"); } else { int alignment = ComputeLongestRegisterName(command, reg_ctx, !static_cast<bool>(m_command_options.alternate_name)); - strm.IndentMore(); // Extra ident to be consistent with register sets dumping + strm.IndentMore(); // Extra ident to be consistent with register sets dumping. for (auto &entry : command) { // in most LLDB commands we accept $rbx as the name for register RBX // - and here we would reject it and non-existant. we should be more >From e38b9145d87273ba76a89f2bfb824cbd808cfa4d Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 17:00:32 +0200 Subject: [PATCH 16/40] Added [reg_] where regs were not obvious from the context --- lldb/source/Commands/CommandObjectRegister.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 998451a94424e..093341aab5810 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -121,7 +121,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool DumpRegister(const ExecutionContext &exe_ctx, Stream &strm, RegisterContext ®_ctx, const RegisterInfo ®_info, - bool print_flags, size_t name_right_align_at = 0) { + bool print_flags, size_t reg_name_right_align_at = 0) { RegisterValue reg_value; if (!reg_ctx.ReadRegister(®_info, reg_value)) return false; @@ -132,7 +132,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool prefix_with_name = !prefix_with_altname; DumpRegisterValue(reg_value, strm, reg_info, prefix_with_name, prefix_with_altname, m_format_options.GetFormat(), - name_right_align_at, exe_ctx.GetBestExecutionContextScope(), + reg_name_right_align_at, exe_ctx.GetBestExecutionContextScope(), print_flags, exe_ctx.GetTargetSP()); if ((reg_info.encoding == eEncodingUint) || (reg_info.encoding == eEncodingSint)) { @@ -169,7 +169,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { strm.Printf("%s:\n", (reg_set->name ? reg_set->name : "unknown")); strm.IndentMore(); const size_t num_registers = reg_set->num_registers; - size_t name_right_align_at = + size_t reg_name_right_align_at = ComputeLongestRegisterName(reg_ctx, *reg_set, !static_cast<bool>(m_command_options.alternate_name), primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; @@ -179,7 +179,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { continue; if (reg_info && DumpRegister(exe_ctx, strm, *reg_ctx, *reg_info, - /*print_flags=*/false, name_right_align_at)) + /*print_flags=*/false, reg_name_right_align_at)) ++available_count; else ++unavailable_count; >From 6847b37fd40044dd087bfde5241c2d67bc7b544e Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 17:08:08 +0200 Subject: [PATCH 17/40] Commentary change --- lldb/source/Commands/CommandObjectRegister.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 093341aab5810..278c68680b026 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -64,7 +64,7 @@ static size_t ComputeLongestRegisterName(RegisterContext *reg_ctx, return name_right_align_at; } -// Here, [command] is basically a list of registers to be printed by DumpRegister() method. +// // 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; >From 22b3c558d5e63507ea586f21ca7b2c52de3e44c8 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 17:08:58 +0200 Subject: [PATCH 18/40] Dum error fix --- lldb/source/Commands/CommandObjectRegister.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 278c68680b026..669de1c022c40 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -64,7 +64,7 @@ static size_t ComputeLongestRegisterName(RegisterContext *reg_ctx, return name_right_align_at; } -// // We expect that [command] only contains register names to be printed. +// 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; >From 90c71f31b503c07dfeed3509c87eb29297f48c8d Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 17:12:16 +0200 Subject: [PATCH 19/40] Removed an extra dot --- lldb/source/Commands/CommandObjectRegister.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 669de1c022c40..5683a421de73c 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -244,7 +244,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { "registers names are supplied as arguments\n"); } else { int alignment = ComputeLongestRegisterName(command, reg_ctx, !static_cast<bool>(m_command_options.alternate_name)); - strm.IndentMore(); // Extra ident to be consistent with register sets dumping. + strm.IndentMore(); // Extra ident to be consistent with register sets dumping for (auto &entry : command) { // in most LLDB commands we accept $rbx as the name for register RBX // - and here we would reject it and non-existant. we should be more >From fd4922cda4b6ef12cf70ab08602e22d42467e641 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 17:17:38 +0200 Subject: [PATCH 20/40] Added comment --- lldb/source/Commands/CommandObjectRegister.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 5683a421de73c..bba288f7fb8c0 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -70,6 +70,8 @@ static size_t ComputeLongestRegisterName(Args &command, RegisterContext *reg_ctx // 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. llvm::StringRef arg_str = entry.ref(); arg_str.consume_front("$"); >From 840c5e7c74c31b5fe5ce3e54eebd28b34375cdf0 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 17:39:42 +0200 Subject: [PATCH 21/40] Unified two tests into one --- ...d-register-read-alignment-custom-regs.test | 32 ++++++++++++++++- ...mmand-register-read-alignment-reg-set.test | 36 ------------------- 2 files changed, 31 insertions(+), 37 deletions(-) delete mode 100644 lldb/test/Shell/Commands/command-register-read-alignment-reg-set.test diff --git a/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test b/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test index 10def3699635d..cad1806fcdbe3 100644 --- a/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test +++ b/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test @@ -4,9 +4,39 @@ # RUN: %lldb -b -o "breakpoint set --name main" \ # RUN: -o run \ # RUN: -o "register read rip rax r10d" \ +# RUN: -o "register read" \ # RUN: %t.out | FileCheck --strict-whitespace %s # CHECK: (lldb) register read rip rax r10d # CHECK: {{^ rip = }} # CHECK: {{^ rax = }} -# CHECK: {{^ r10d = }} \ No newline at end of file +# CHECK: {{^ r10d = }} + +# CHECK: (lldb) register read +# CHECK: General Purpose Registers: +# CHECK: {{ rax = }} +# CHECK: {{ rbx = }} +# CHECK: {{ rcx = }} +# CHECK: {{ rdx = }} +# CHECK: {{ rdi = }} +# CHECK: {{ rsi = }} +# CHECK: {{ rbp = }} +# CHECK: {{ rsp = }} +# CHECK: {{ r8 = }} +# CHECK: {{ r9 = }} +# CHECK: {{ r10 = }} +# CHECK: {{ r11 = }} +# CHECK: {{ r12 = }} +# CHECK: {{ r13 = }} +# CHECK: {{ r14 = }} +# CHECK: {{ r15 = }} +# CHECK: {{ rip = }} +# CHECK: {{ rflags = }} +# CHECK: {{ cs = }} +# CHECK: {{ fs = }} +# CHECK: {{ gs = }} +# CHECK: {{ ss = }} +# CHECK: {{ fs_base = }} +# CHECK: {{ gs_base = }} +# CHECK: {{ ds = }} +# CHECK: {{ es = }} \ No newline at end of file diff --git a/lldb/test/Shell/Commands/command-register-read-alignment-reg-set.test b/lldb/test/Shell/Commands/command-register-read-alignment-reg-set.test deleted file mode 100644 index d40ea0c35c499..0000000000000 --- a/lldb/test/Shell/Commands/command-register-read-alignment-reg-set.test +++ /dev/null @@ -1,36 +0,0 @@ -# REQUIRES: x86 - -# RUN: %clang_host -g -O0 %S/Inputs/main.c -o %t.out -# RUN: %lldb -b -o "breakpoint set --name main" \ -# RUN: -o run \ -# RUN: -o "register read" \ -# RUN: %t.out | FileCheck --strict-whitespace %s - -# CHECK: (lldb) register read -# CHECK: General Purpose Registers: -# CHECK: {{ rax = }} -# CHECK: {{ rbx = }} -# CHECK: {{ rcx = }} -# CHECK: {{ rdx = }} -# CHECK: {{ rdi = }} -# CHECK: {{ rsi = }} -# CHECK: {{ rbp = }} -# CHECK: {{ rsp = }} -# CHECK: {{ r8 = }} -# CHECK: {{ r9 = }} -# CHECK: {{ r10 = }} -# CHECK: {{ r11 = }} -# CHECK: {{ r12 = }} -# CHECK: {{ r13 = }} -# CHECK: {{ r14 = }} -# CHECK: {{ r15 = }} -# CHECK: {{ rip = }} -# CHECK: {{ rflags = }} -# CHECK: {{ cs = }} -# CHECK: {{ fs = }} -# CHECK: {{ gs = }} -# CHECK: {{ ss = }} -# CHECK: {{ fs_base = }} -# CHECK: {{ gs_base = }} -# CHECK: {{ ds = }} -# CHECK: {{ es = }} \ No newline at end of file >From afe9a712da9dcbd506ef2c2f294f95cbe8fa0aa3 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 17:40:15 +0200 Subject: [PATCH 22/40] Test renaming --- ...ment-custom-regs.test => command-register-read-alignment.test} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lldb/test/Shell/Commands/{command-register-read-alignment-custom-regs.test => command-register-read-alignment.test} (100%) diff --git a/lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test b/lldb/test/Shell/Commands/command-register-read-alignment.test similarity index 100% rename from lldb/test/Shell/Commands/command-register-read-alignment-custom-regs.test rename to lldb/test/Shell/Commands/command-register-read-alignment.test >From 2a69c241755f5bc584306ee337239eb05d7aeb75 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 17:43:06 +0200 Subject: [PATCH 23/40] Used [CHECK-NEXT] where possible --- .../command-register-read-alignment.test | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/lldb/test/Shell/Commands/command-register-read-alignment.test b/lldb/test/Shell/Commands/command-register-read-alignment.test index cad1806fcdbe3..9fe2d814ab5e7 100644 --- a/lldb/test/Shell/Commands/command-register-read-alignment.test +++ b/lldb/test/Shell/Commands/command-register-read-alignment.test @@ -8,35 +8,17 @@ # RUN: %t.out | FileCheck --strict-whitespace %s # CHECK: (lldb) register read rip rax r10d -# CHECK: {{^ rip = }} -# CHECK: {{^ rax = }} -# CHECK: {{^ r10d = }} +# CHECK-NEXT: {{^ rip = }} +# CHECK-NEXT: {{^ rax = }} +# CHECK-NEXT: {{^ r10d = }} # CHECK: (lldb) register read # CHECK: General Purpose Registers: -# CHECK: {{ rax = }} -# CHECK: {{ rbx = }} -# CHECK: {{ rcx = }} -# CHECK: {{ rdx = }} -# CHECK: {{ rdi = }} # CHECK: {{ rsi = }} -# CHECK: {{ rbp = }} -# CHECK: {{ rsp = }} # CHECK: {{ r8 = }} -# CHECK: {{ r9 = }} -# CHECK: {{ r10 = }} -# CHECK: {{ r11 = }} -# CHECK: {{ r12 = }} -# CHECK: {{ r13 = }} -# CHECK: {{ r14 = }} -# CHECK: {{ r15 = }} # CHECK: {{ rip = }} # CHECK: {{ rflags = }} # CHECK: {{ cs = }} -# CHECK: {{ fs = }} -# CHECK: {{ gs = }} -# CHECK: {{ ss = }} # CHECK: {{ fs_base = }} # CHECK: {{ gs_base = }} -# CHECK: {{ ds = }} -# CHECK: {{ es = }} \ No newline at end of file +# CHECK: {{ ds = }} \ No newline at end of file >From a9ede952c6dac6fd690823fa8fc46bdd170eb5ab Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Thu, 2 Apr 2026 17:45:50 +0200 Subject: [PATCH 24/40] Changed tested register names --- .../Commands/command-register-read-alignment.test | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lldb/test/Shell/Commands/command-register-read-alignment.test b/lldb/test/Shell/Commands/command-register-read-alignment.test index 9fe2d814ab5e7..9f0c066eb5c3a 100644 --- a/lldb/test/Shell/Commands/command-register-read-alignment.test +++ b/lldb/test/Shell/Commands/command-register-read-alignment.test @@ -3,14 +3,14 @@ # RUN: %clang_host -g -O0 %S/Inputs/main.c -o %t.out # RUN: %lldb -b -o "breakpoint set --name main" \ # RUN: -o run \ -# RUN: -o "register read rip rax r10d" \ +# RUN: -o "register read rip r10d rflags" \ # RUN: -o "register read" \ # RUN: %t.out | FileCheck --strict-whitespace %s -# CHECK: (lldb) register read rip rax r10d -# CHECK-NEXT: {{^ rip = }} -# CHECK-NEXT: {{^ rax = }} -# CHECK-NEXT: {{^ r10d = }} +# CHECK: (lldb) register read rip r10d rflags +# CHECK-NEXT: {{^ rip = }} +# CHECK-NEXT: {{^ r10d = }} +# CHECK-NEXT: {{^ rflags = }} # CHECK: (lldb) register read # CHECK: General Purpose Registers: >From 6169f44181fb06ef478fbd3d07bf4d6b0130ea91 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Tue, 7 Apr 2026 14:54:07 +0200 Subject: [PATCH 25/40] Added dumping alignment test for different register sets --- .../command-register-read-alignment.test | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lldb/test/Shell/Commands/command-register-read-alignment.test b/lldb/test/Shell/Commands/command-register-read-alignment.test index 9f0c066eb5c3a..b103d955c4a79 100644 --- a/lldb/test/Shell/Commands/command-register-read-alignment.test +++ b/lldb/test/Shell/Commands/command-register-read-alignment.test @@ -5,6 +5,7 @@ # RUN: -o run \ # RUN: -o "register read rip r10d rflags" \ # RUN: -o "register read" \ +# RUN: -o "register read --all" \ # RUN: %t.out | FileCheck --strict-whitespace %s # CHECK: (lldb) register read rip r10d rflags @@ -14,11 +15,24 @@ # CHECK: (lldb) register read # CHECK: General Purpose Registers: -# CHECK: {{ rsi = }} -# CHECK: {{ r8 = }} -# CHECK: {{ rip = }} -# CHECK: {{ rflags = }} -# CHECK: {{ cs = }} -# CHECK: {{ fs_base = }} -# CHECK: {{ gs_base = }} -# CHECK: {{ ds = }} \ No newline at end of file +# CHECK: {{^ rsi = }} +# CHECK: {{^ r8 = }} +# CHECK: {{^ rip = }} +# CHECK: {{^ rflags = }} +# CHECK: {{^ cs = }} +# CHECK: {{^ fs_base = }} +# CHECK: {{^ gs_base = }} +# CHECK: {{^ ds = }} + +# CHECK: (lldb) register read --all + +# CHECK: General Purpose Registers: +# CHECK: {{^ rip = }} +# CHECK: {{^ rflags = }} +# CHECK: {{^ fs_base = }} + +# CHECK: Floating Point Registers: +# CHECK: {{^ ftag = }} +# CHECK: {{^ fdp = }} +# CHECK: {{^ mxcsrmask = }} +# CHECK: {{^ xmm10 = }} >From e7aae277bce0d23f6b7a5b565211da300c7456a2 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Tue, 7 Apr 2026 15:11:00 +0200 Subject: [PATCH 26/40] Trying to please GitHub, attempt 1 --- lldb/test/Shell/Commands/command-register-read-alignment.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/test/Shell/Commands/command-register-read-alignment.test b/lldb/test/Shell/Commands/command-register-read-alignment.test index b103d955c4a79..e46b33215b6df 100644 --- a/lldb/test/Shell/Commands/command-register-read-alignment.test +++ b/lldb/test/Shell/Commands/command-register-read-alignment.test @@ -1,4 +1,4 @@ -# REQUIRES: x86 +# REQUIRES: target-x86 # RUN: %clang_host -g -O0 %S/Inputs/main.c -o %t.out # RUN: %lldb -b -o "breakpoint set --name main" \ >From bbbcccd404b6dd4f951a86136bd89e38652f26b7 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Tue, 7 Apr 2026 15:52:12 +0200 Subject: [PATCH 27/40] Formatting --- .../source/Commands/CommandObjectRegister.cpp | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index bba288f7fb8c0..c7ecfd57c3055 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -36,28 +36,30 @@ 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 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 RegisterSet ®_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)) { + 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)); + name_right_align_at = std::max(name_right_align_at, + GetNameSize(reg_info, use_primary_name)); + } } @@ -65,7 +67,9 @@ static size_t ComputeLongestRegisterName(RegisterContext *reg_ctx, } // We expect that [command] only contains register names to be printed. -static size_t ComputeLongestRegisterName(Args &command, RegisterContext *reg_ctx, bool use_primary_name) { +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. @@ -77,7 +81,8 @@ static size_t ComputeLongestRegisterName(Args &command, RegisterContext *reg_ctx if (const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(arg_str)) { - name_right_align_at = std::max(name_right_align_at, GetNameSize(reg_info, use_primary_name)); + name_right_align_at = std::max(name_right_align_at, + GetNameSize(reg_info, use_primary_name)); } } @@ -134,8 +139,9 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool prefix_with_name = !prefix_with_altname; DumpRegisterValue(reg_value, strm, reg_info, prefix_with_name, prefix_with_altname, m_format_options.GetFormat(), - reg_name_right_align_at, exe_ctx.GetBestExecutionContextScope(), - print_flags, exe_ctx.GetTargetSP()); + reg_name_right_align_at, + exe_ctx.GetBestExecutionContextScope(), print_flags, + exe_ctx.GetTargetSP()); if ((reg_info.encoding == eEncodingUint) || (reg_info.encoding == eEncodingSint)) { Process *process = exe_ctx.GetProcessPtr(); @@ -171,8 +177,9 @@ class CommandObjectRegisterRead : public CommandObjectParsed { strm.Printf("%s:\n", (reg_set->name ? reg_set->name : "unknown")); strm.IndentMore(); const size_t num_registers = reg_set->num_registers; - size_t reg_name_right_align_at = - ComputeLongestRegisterName(reg_ctx, *reg_set, !static_cast<bool>(m_command_options.alternate_name), primitive_only); + size_t reg_name_right_align_at = ComputeLongestRegisterName( + reg_ctx, *reg_set, + !static_cast<bool>(m_command_options.alternate_name), primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg); @@ -180,8 +187,9 @@ class CommandObjectRegisterRead : public CommandObjectParsed { if (primitive_only && reg_info && reg_info->value_regs) continue; - if (reg_info && DumpRegister(exe_ctx, strm, *reg_ctx, *reg_info, - /*print_flags=*/false, reg_name_right_align_at)) + if (reg_info && + DumpRegister(exe_ctx, strm, *reg_ctx, *reg_info, + /*print_flags=*/false, reg_name_right_align_at)) ++available_count; else ++unavailable_count; @@ -245,8 +253,11 @@ class CommandObjectRegisterRead : public CommandObjectParsed { result.AppendError("the --set <set> option can't be used when " "registers names are supplied as arguments\n"); } else { - int alignment = ComputeLongestRegisterName(command, reg_ctx, !static_cast<bool>(m_command_options.alternate_name)); - strm.IndentMore(); // Extra ident to be consistent with register sets dumping + int alignment = ComputeLongestRegisterName( + command, reg_ctx, + !static_cast<bool>(m_command_options.alternate_name)); + strm.IndentMore(); // Extra ident to be consistent with register sets + // dumping for (auto &entry : command) { // in most LLDB commands we accept $rbx as the name for register RBX // - and here we would reject it and non-existant. we should be more @@ -262,8 +273,8 @@ class CommandObjectRegisterRead : public CommandObjectParsed { // printing flags afterwards. bool print_flags = !m_format_options.GetFormatValue().OptionWasSet(); - if (!DumpRegister(m_exe_ctx, strm, *reg_ctx, *reg_info, - print_flags, alignment)) + if (!DumpRegister(m_exe_ctx, strm, *reg_ctx, *reg_info, print_flags, + alignment)) strm.Printf("%-12s = error: unavailable\n", reg_info->name); } else { result.AppendErrorWithFormat("Invalid register name '%s'", >From e333b36a2034b4e052b299f93951674be0921300 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Tue, 7 Apr 2026 16:02:18 +0200 Subject: [PATCH 28/40] A bit more formatting --- lldb/source/Commands/CommandObjectRegister.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index c7ecfd57c3055..c75a57ece5667 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -59,7 +59,6 @@ static size_t ComputeLongestRegisterName(RegisterContext *reg_ctx, name_right_align_at = std::max(name_right_align_at, GetNameSize(reg_info, use_primary_name)); - } } >From d3881d21fb7ab76248faa0e0f2723eaedc18db70 Mon Sep 17 00:00:00 2001 From: Rifet-c <[email protected]> Date: Sun, 7 Jun 2026 20:36:11 +0200 Subject: [PATCH 29/40] Removed default value for the reg_align --- lldb/source/Commands/CommandObjectRegister.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index c75a57ece5667..1c3e534da2732 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -127,7 +127,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool DumpRegister(const ExecutionContext &exe_ctx, Stream &strm, RegisterContext ®_ctx, const RegisterInfo ®_info, - bool print_flags, size_t reg_name_right_align_at = 0) { + bool print_flags, size_t reg_name_right_align_at) { RegisterValue reg_value; if (!reg_ctx.ReadRegister(®_info, reg_value)) return false; >From 7ccef899d806a5ac23c216f335402ddb426d9727 Mon Sep 17 00:00:00 2001 From: Rifet-c <[email protected]> Date: Sun, 7 Jun 2026 20:42:50 +0200 Subject: [PATCH 30/40] Removed std::string from reg_name length computation --- lldb/source/Commands/CommandObjectRegister.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 1c3e534da2732..0b2865cca15d7 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -37,9 +37,8 @@ using namespace lldb_private; #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()); + const char *reg_name = use_primary_name ? reg_info->name : reg_info->alt_name; + return reg_name ? strlen(reg_name) : 0; } static size_t ComputeLongestRegisterName(RegisterContext *reg_ctx, >From 3bc88ada662c26396170575b3bb57577d482379b Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Sat, 20 Jun 2026 17:32:49 +0200 Subject: [PATCH 31/40] Removed [->] in a comment --- lldb/source/Commands/CommandObjectRegister.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 0b2865cca15d7..ae3f9a0417945 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -72,8 +72,8 @@ static size_t ComputeLongestRegisterName(Args &command, // 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. + // In most LLDB commands we accept $rbx as the name for register RBX, + // therefore internally it must be restricted to plain [ rbx ] format. llvm::StringRef arg_str = entry.ref(); arg_str.consume_front("$"); >From 98047a8c6b4fed9b5d4f736965ebfe7bfac97be2 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Sat, 20 Jun 2026 17:35:09 +0200 Subject: [PATCH 32/40] Comment change --- lldb/source/Commands/CommandObjectRegister.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index ae3f9a0417945..053fe79fc956e 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -72,8 +72,8 @@ static size_t ComputeLongestRegisterName(Args &command, // 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, - // therefore internally it must be restricted to plain [ rbx ] format. + // In most LLDB commands we accept '$<register>' as well as '<register>' + // for example '$rbx' for 'rbx'. However internally the name does not have '$'. llvm::StringRef arg_str = entry.ref(); arg_str.consume_front("$"); >From add1bbb5b03969a9b930e2e1f08b380ba1ed911a Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Sat, 20 Jun 2026 17:40:37 +0200 Subject: [PATCH 33/40] Comment change x2 --- lldb/source/Commands/CommandObjectRegister.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 053fe79fc956e..ef1f40c03f404 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -254,8 +254,8 @@ class CommandObjectRegisterRead : public CommandObjectParsed { int alignment = ComputeLongestRegisterName( command, reg_ctx, !static_cast<bool>(m_command_options.alternate_name)); - strm.IndentMore(); // Extra ident to be consistent with register sets - // dumping + // Extra ident to be consistent with register sets dumping. + strm.IndentMore(); for (auto &entry : command) { // in most LLDB commands we accept $rbx as the name for register RBX // - and here we would reject it and non-existant. we should be more >From d18a858ead82eab6a89bf5f46d7d61a2facd500d Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Sat, 20 Jun 2026 17:42:33 +0200 Subject: [PATCH 34/40] Var renaming --- lldb/source/Commands/CommandObjectRegister.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index ef1f40c03f404..402c0b910b7f5 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -251,7 +251,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { result.AppendError("the --set <set> option can't be used when " "registers names are supplied as arguments\n"); } else { - int alignment = ComputeLongestRegisterName( + int reg_name_right_align_at = ComputeLongestRegisterName( command, reg_ctx, !static_cast<bool>(m_command_options.alternate_name)); // Extra ident to be consistent with register sets dumping. @@ -272,7 +272,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { bool print_flags = !m_format_options.GetFormatValue().OptionWasSet(); if (!DumpRegister(m_exe_ctx, strm, *reg_ctx, *reg_info, print_flags, - alignment)) + reg_name_right_align_at)) strm.Printf("%-12s = error: unavailable\n", reg_info->name); } else { result.AppendErrorWithFormat("Invalid register name '%s'", >From aa9429258160cfed5c6128de6d5f72e954a276a2 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Sat, 20 Jun 2026 17:45:13 +0200 Subject: [PATCH 35/40] Small [if] statement change (non-functional) --- lldb/source/Commands/CommandObjectRegister.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 402c0b910b7f5..c61bf8fb943b1 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -177,7 +177,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { const size_t num_registers = reg_set->num_registers; size_t reg_name_right_align_at = ComputeLongestRegisterName( reg_ctx, *reg_set, - !static_cast<bool>(m_command_options.alternate_name), primitive_only); + m_command_options.alternate_name != nullptr, primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg); @@ -253,7 +253,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { } else { int reg_name_right_align_at = ComputeLongestRegisterName( command, reg_ctx, - !static_cast<bool>(m_command_options.alternate_name)); + m_command_options.alternate_name != nullptr); // Extra ident to be consistent with register sets dumping. strm.IndentMore(); for (auto &entry : command) { >From 0e331686c86676f5494143f05d9af0058d7289d8 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Sat, 20 Jun 2026 18:29:49 +0200 Subject: [PATCH 36/40] Added a test for alternate register names --- .../Shell/Commands/command-register-read-alignment.test | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lldb/test/Shell/Commands/command-register-read-alignment.test b/lldb/test/Shell/Commands/command-register-read-alignment.test index e46b33215b6df..df1ff023446cf 100644 --- a/lldb/test/Shell/Commands/command-register-read-alignment.test +++ b/lldb/test/Shell/Commands/command-register-read-alignment.test @@ -4,6 +4,7 @@ # RUN: %lldb -b -o "breakpoint set --name main" \ # RUN: -o run \ # RUN: -o "register read rip r10d rflags" \ +# RUN: -o "register read -A rsp rbp rip" \ # RUN: -o "register read" \ # RUN: -o "register read --all" \ # RUN: %t.out | FileCheck --strict-whitespace %s @@ -13,6 +14,11 @@ # CHECK-NEXT: {{^ r10d = }} # CHECK-NEXT: {{^ rflags = }} +# CHECK: (lldb) register read -A rsp rbp rip +# CHECK-NEXT: {{^ rsp/sp = }} +# CHECK-NEXT: {{^ rbp/fp = }} +# CHECK-NEXT: {{^ rip/pc = }} + # CHECK: (lldb) register read # CHECK: General Purpose Registers: # CHECK: {{^ rsi = }} @@ -35,4 +41,4 @@ # CHECK: {{^ ftag = }} # CHECK: {{^ fdp = }} # CHECK: {{^ mxcsrmask = }} -# CHECK: {{^ xmm10 = }} +# CHECK: {{^ xmm10 = }} \ No newline at end of file >From 451884f05cd1f82643719397bef28faf97719968 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Sat, 20 Jun 2026 18:38:26 +0200 Subject: [PATCH 37/40] Made plain register read test a bit more specific + some comments --- .../Shell/Commands/command-register-read-alignment.test | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lldb/test/Shell/Commands/command-register-read-alignment.test b/lldb/test/Shell/Commands/command-register-read-alignment.test index df1ff023446cf..53dcc7b0d44e2 100644 --- a/lldb/test/Shell/Commands/command-register-read-alignment.test +++ b/lldb/test/Shell/Commands/command-register-read-alignment.test @@ -5,7 +5,7 @@ # RUN: -o run \ # RUN: -o "register read rip r10d rflags" \ # RUN: -o "register read -A rsp rbp rip" \ -# RUN: -o "register read" \ +# RUN: -o "register read -s 0" \ # RUN: -o "register read --all" \ # RUN: %t.out | FileCheck --strict-whitespace %s @@ -19,7 +19,8 @@ # CHECK-NEXT: {{^ rbp/fp = }} # CHECK-NEXT: {{^ rip/pc = }} -# CHECK: (lldb) register read +## Registers within a set align to each other. +# CHECK: (lldb) register read -s 0 # CHECK: General Purpose Registers: # CHECK: {{^ rsi = }} # CHECK: {{^ r8 = }} @@ -30,6 +31,7 @@ # CHECK: {{^ gs_base = }} # CHECK: {{^ ds = }} +## Registers within different sets align only within their own set. # CHECK: (lldb) register read --all # CHECK: General Purpose Registers: >From 7c6bcce76ab50ad296e1585c0223531608be8459 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Sat, 20 Jun 2026 18:39:51 +0200 Subject: [PATCH 38/40] Commentary change --- lldb/test/Shell/Commands/command-register-read-alignment.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/test/Shell/Commands/command-register-read-alignment.test b/lldb/test/Shell/Commands/command-register-read-alignment.test index 53dcc7b0d44e2..9cba4adcdd2e2 100644 --- a/lldb/test/Shell/Commands/command-register-read-alignment.test +++ b/lldb/test/Shell/Commands/command-register-read-alignment.test @@ -31,7 +31,7 @@ # CHECK: {{^ gs_base = }} # CHECK: {{^ ds = }} -## Registers within different sets align only within their own set. +## Registers within sets are aligned, but not aligned across different sets. # CHECK: (lldb) register read --all # CHECK: General Purpose Registers: >From 332ccd92c426d3b77e36e0f09aa3ae6291ee6355 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Sat, 20 Jun 2026 19:32:59 +0200 Subject: [PATCH 39/40] Fixing attempt --- lldb/source/Commands/CommandObjectRegister.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index c61bf8fb943b1..4d71120a6ab61 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -177,7 +177,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { const size_t num_registers = reg_set->num_registers; size_t reg_name_right_align_at = ComputeLongestRegisterName( reg_ctx, *reg_set, - m_command_options.alternate_name != nullptr, primitive_only); + !m_command_options.alternate_name, primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg); @@ -253,7 +253,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { } else { int reg_name_right_align_at = ComputeLongestRegisterName( command, reg_ctx, - m_command_options.alternate_name != nullptr); + !m_command_options.alternate_name); // Extra ident to be consistent with register sets dumping. strm.IndentMore(); for (auto &entry : command) { >From f5100b36ad6252b99e95639c93f9df9564d12b36 Mon Sep 17 00:00:00 2001 From: Aleksandr Levin <[email protected]> Date: Sat, 20 Jun 2026 19:38:59 +0200 Subject: [PATCH 40/40] Formatting fixes --- lldb/source/Commands/CommandObjectRegister.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 4d71120a6ab61..83ff915c7b53b 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -73,7 +73,8 @@ static size_t ComputeLongestRegisterName(Args &command, // Loop through all the arguments to find the longest register name. for (auto &entry : command) { // In most LLDB commands we accept '$<register>' as well as '<register>' - // for example '$rbx' for 'rbx'. However internally the name does not have '$'. + // for example '$rbx' for 'rbx'. However internally the name does not have + // '$'. llvm::StringRef arg_str = entry.ref(); arg_str.consume_front("$"); @@ -176,8 +177,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { strm.IndentMore(); const size_t num_registers = reg_set->num_registers; size_t reg_name_right_align_at = ComputeLongestRegisterName( - reg_ctx, *reg_set, - !m_command_options.alternate_name, primitive_only); + reg_ctx, *reg_set, !m_command_options.alternate_name, primitive_only); for (size_t reg_idx = 0; reg_idx < num_registers; ++reg_idx) { const uint32_t reg = reg_set->registers[reg_idx]; const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg); @@ -252,8 +252,7 @@ class CommandObjectRegisterRead : public CommandObjectParsed { "registers names are supplied as arguments\n"); } else { int reg_name_right_align_at = ComputeLongestRegisterName( - command, reg_ctx, - !m_command_options.alternate_name); + command, reg_ctx, !m_command_options.alternate_name); // Extra ident to be consistent with register sets dumping. strm.IndentMore(); for (auto &entry : command) { _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
