Author: David Spickett Date: 2023-04-21T11:47:05Z New Revision: c9083bea168699b4078b27ce88fd35562751f46f
URL: https://github.com/llvm/llvm-project/commit/c9083bea168699b4078b27ce88fd35562751f46f DIFF: https://github.com/llvm/llvm-project/commit/c9083bea168699b4078b27ce88fd35562751f46f.diff LOG: [LLDB] Don't print register fields when asked for a specific format Previously if a register had fields we would always print them after the value if the register was asked for by name. ``` (lldb) register read MDCR_EL3 MDCR_EL3 = 0x00000000 = { ETBAD = 0 <...> RLTE = 0 } ``` This can be quite annoying if there are a whole lot of fields but you want to see the register in a specific format. ``` (lldb) register read MDCR_EL3 -f i MDCR_EL3 = 0x00000000 unknown udf #0x0 = { ETBAD = 0 <...lots of fields...> ``` Since it pushes the interesting bit far up the terminal. To solve this, don't print fields if the user passes --format. If they're doing that then I think it's reasonable to assume they know what they want and only want to see that output. This also gives users a way to silence fields, but not change the format. By doing `register read foo -f x`. In case they are not useful or perhaps they are trying to work around a crash. I have customised the help text for --format for register read to explain this: ``` -f <format> ( --format <format> ) Specify a format to be used for display. If this is set, register fields will not be dispayed. ``` Reviewed By: jasonmolenda Differential Revision: https://reviews.llvm.org/D148790 Added: Modified: lldb/source/Commands/CommandObjectRegister.cpp lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py Removed: ################################################################################ diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp index 8784b8b9977a8..a6ea64229eccb 100644 --- a/lldb/source/Commands/CommandObjectRegister.cpp +++ b/lldb/source/Commands/CommandObjectRegister.cpp @@ -44,7 +44,10 @@ class CommandObjectRegisterRead : public CommandObjectParsed { 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 displayed."}}) { CommandArgumentEntry arg; CommandArgumentData register_arg; @@ -215,8 +218,12 @@ class CommandObjectRegisterRead : public CommandObjectParsed { 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.GetFormatValue().OptionWasSet(); 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 index 3ccf3ccae6e9b..e6a80f3c79253 100644 --- a/lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py +++ b/lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py @@ -410,6 +410,15 @@ def test_flags_child_limit(self): 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('<field name="field_0" start="0" end="0"/>') + + 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): _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits