[Lldb-commits] [lldb] [lldb] Improved formatting of 'register read' command. (PR #188049)
via lldb-commits
lldb-commits at lists.llvm.org
Sun Jul 5 12:17:31 PDT 2026
https://github.com/Rifet-c updated https://github.com/llvm/llvm-project/pull/188049
>From 39db0ebb34bc4319128a8c17177c9933de8f8662 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 0a834bcd89960..b576743e59cd0 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 5d483569bf4a816052a1fa2b897cf7d2ac81d9f8 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 b8fae1406862a7027f10d27aed9740aebb445f38 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 b576743e59cd0..4e4c632c6deaf 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 40dbc124ffe855116e63832f65ef337356af5763 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 4e4c632c6deaf..0a834bcd89960 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 eaaed18c4808d5cc89d198e33ce601e78ee35408 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 f1bb2185e73c4077c6962e32013be38c010c813f 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 c07215a521f7ea81a38445404e9cba543998c1a0 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 d8ad954ab2ef83cf263829eba4d5521a5b624c19 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 6c363702bc03179b749fb588f5853141685f1a5f 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 94f7be97a89381b26c678e6782e91a080e7ec464 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 31afb4501333d4660f4458b274b2b946c3657cca 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 b1b6c708805b39f01e4cdfd8dcf89c1ace90a317 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 ac6bb380e604012052235146c4460a757da5e1db 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 527b6807a5bfab7eb9a18701f16fbe6d48333040 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 3a600b59daa3a243029650573309ee4d0f26d674 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 77c4dee9d82b423883d4f97e4c2c244cd375a47b 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 0af6ce8721907d4e79a4610c222350f1b1a1bc6d 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 c0fea4741f653371e837b7fa83b0e6986d69f816 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 186e9fcd1c255fab593880535f7fd6d96167c4dd 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 180cbbcc5e167d0c9836d9e991eb059895647e04 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 8678fbb8b54ededf3e71e1d7e4785c7c228d3095 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 3098d01d63c00336987bef00efd4666642bde3d3 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 5bded7f08834d26f40e665ff8e8ef4af9811d9b2 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 b14f4458ad513f3dd24480ea5d273e8775dc75c5 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 18e85751181928589a5d9bd3e779c241535d9637 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 d5b8153a323690f4da3eefc3812de0982e59af3a 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 0683d6ae5118437e2ff9a57e71a6e3b1335f5b02 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 e08b6978a6451919e2a98f80bca2922809d653ca 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 d682cd6ec328dede00df463bd0567e6751785af0 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 8f7141dc7a22bb851890b1cc6fd4c0ac191cd753 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 4ec7cd78ac307924fa3f8ab2689255fafb3b92e2 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 27b9b6854df8b25259a4a6b60f60583b92f30f9a 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 b48018a6783773b83f34fbc1660ae19d68176114 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 c5062bb0fb177c30699491bf6411986629973b54 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 b7bac0f5c033b57e32754baa1e13efecff3aa150 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 d3bc1438df98324dbd1509f6965bf66266254c72 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 175bfb00389ae452786d684fae51f6caf8c02244 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 b6d6d25bc4b2849616e2ef1e60952f9ceb4ebc07 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 a61caaccb12c8197a9ea124665d271c876146463 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 bde5ed3479c5e258e4264dce4a09bc0b6c05c60f 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