diff --git a/lldb/include/lldb/Interpreter/OptionGroupFormat.h b/lldb/include/lldb/Interpreter/OptionGroupFormat.h --- a/lldb/include/lldb/Interpreter/OptionGroupFormat.h +++ b/lldb/include/lldb/Interpreter/OptionGroupFormat.h @@ -53,6 +53,8 @@ const OptionValueFormat &GetFormatValue() const { return m_format; } + bool FormatWasSet() const { return m_format.OptionWasSet(); } + OptionValueUInt64 &GetByteSizeValue() { return m_byte_size; } const OptionValueUInt64 &GetByteSizeValue() const { return m_byte_size; } diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -44,7 +44,10 @@ nullptr, eCommandRequiresFrame | eCommandRequiresRegContext | eCommandProcessMustBeLaunched | eCommandProcessMustBePaused), - m_format_options(eFormatDefault) { + m_format_options(eFormatDefault, UINT64_MAX, UINT64_MAX, + {{CommandArgumentType::eArgTypeFormat, + "Specify a format to be used for display. If this " + "is set, register fields will not be dispayed."}}) { CommandArgumentEntry arg; CommandArgumentData register_arg; @@ -215,8 +218,11 @@ if (const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(arg_str)) { + // If they have asked for a specific format don't obscure that by + // printing flags afterwards. + bool print_flags = !m_format_options.FormatWasSet(); if (!DumpRegister(m_exe_ctx, strm, *reg_ctx, *reg_info, - /*print_flags=*/true)) + print_flags)) strm.Printf("%-12s = error: unavailable\n", reg_info->name); } else { result.AppendErrorWithFormat("Invalid register name '%s'.\n", diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py b/lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py --- a/lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py @@ -410,6 +410,15 @@ self.expect("register read cpsr", substrs=["= (field_2 = 1, field_1 = 1, ...)"]) + @skipIfXmlSupportMissing + @skipIfRemote + def test_format_disables_flags(self): + # If asked for a specific format, don't print flags after it. + self.setup_flags_test('') + + self.expect("register read cpsr --format X", substrs=["cpsr = 0xEEEE7777"]) + self.expect("register read cpsr --format X", substrs=["field_0"], matching=False) + @skipIfXmlSupportMissing @skipIfRemote def test_xml_includes(self):