[Lldb-commits] [lldb] [lldb] Improved formatting of 'register read' command. (PR #188049)
via lldb-commits
lldb-commits at lists.llvm.org
Sat Jun 20 10:39:33 PDT 2026
https://github.com/Rifet-c updated https://github.com/llvm/llvm-project/pull/188049
>From f9d15ee5885bf95e833edfa9f38e38acb5bec1a8 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 a87696a8996c35ec98dc26e0360d14ff63568f1c Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 9d1f64a27ccfd7358726f269b599a7a91be5c96b Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 90194ee7aed08d5a4d93bae1d1875a51fb13fc14 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 6f68f76071321dd8aacb6ffeee3dde362d88bc61 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 780578f05a528c8465592769afee3b221495160a Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 bc0920961125e260ecb46d5b7f25971bd651b81a Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 0bb895dd30bc4174989bdb234c85352470901430 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 85f2da8848276cb3f63220e42354ebaf28a5af94 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 39683f10a342089c7a0aa6471b6fd588ec704072 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 0af5f630afdcbc08130ec4810c64f671c89ece9f Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 a1094c51c5e12ac04168a6fc48db529b527b1422 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 dfeabb1fecedc58636250a451d1917a19f2b6a77 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 8b6eea76e78753dab5ce6c1c50e8f6acc566e142 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 af44be61813115ee982a84438aca22e0ab63f20e Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 0c881b8b3da53283ef8a61a9f56be2882a721b83 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 73f06d130a8b29c4e64fd941933764ca882d1174 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 09c05ff9d4fa338fe30c7ab7629e36ee817bf282 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 f0596c4aba5cef6b6f936e003478e2136d4c665a Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 56ec10254ba53d432b7b0c1cfaf5cadb9fab9ed3 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 6b23e98c6f14606fe4c65dbc714bf890b92932ed Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 154944316e3c60c69f34d3ad0cbb1f59d28d85ca Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 16bf49f03e2f86fbeb091a61872b3ff92293a105 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 21c219e5478acefd3859c3bc88be3e46199c6195 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 4154a28c23074807506464fd92ff70b0290b128c Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 7331608872bcb2d8412f43ea531c899d0d5de0ad Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 3e563c6600a86548b0d61caaaa3d8cb904828102 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 c3ecb9141840c3ad3738806d90cffae545d3aee2 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <aleksandr.levin at codasip.com>
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 fcf3093233bb99490d0e1a3cd958d63f17bc769e Mon Sep 17 00:00:00 2001
From: Rifet-c <levinale17 at gmail.com>
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 4f6207733848ec90406d6c1ee6f64b9593a61b57 Mon Sep 17 00:00:00 2001
From: Rifet-c <levinale17 at gmail.com>
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 0c7605e39db6e93094ab73e1363c46d2b62f83c8 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <alexander.levin03 at mail.ru>
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 cd88c2c78623eaae06a5025b6ca967307324a8eb Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <alexander.levin03 at mail.ru>
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 0fc629a21750a77601f3481468c9b182d1b9d04c Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <alexander.levin03 at mail.ru>
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 01a4bbc3dff34df6f1f1a341f43bb1067820e9f8 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <alexander.levin03 at mail.ru>
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 833f32331b8a8f324389f292ca7a5391b4604427 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <alexander.levin03 at mail.ru>
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 d6cb57451c3f0b75bd432d33cb1e35958cc77576 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <alexander.levin03 at mail.ru>
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 3aeb02afe9e3a1640dbffc48bdc96a66dbeec669 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <alexander.levin03 at mail.ru>
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 b303506f9c62f1e9fa1a259cb43b7237729f50ba Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <alexander.levin03 at mail.ru>
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 0a131ff8f94660f4ba6914da234eb6771c588ba9 Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <alexander.levin03 at mail.ru>
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 8f18d1ff58c640f53868ea07e62b8d92af36ce0d Mon Sep 17 00:00:00 2001
From: Aleksandr Levin <alexander.levin03 at mail.ru>
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) {
More information about the lldb-commits
mailing list