[Lldb-commits] [PATCH] D148790: [LLDB] Don't print register fields when asked for a specific format

David Spickett via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 20 03:38:32 PDT 2023


DavidSpickett updated this revision to Diff 515271.
DavidSpickett added a comment.
Herald added a subscriber: JDevlieghere.

Use the getter for the format value instead of adding a WasSet to the group class.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148790/new/

https://reviews.llvm.org/D148790

Files:
  lldb/source/Commands/CommandObjectRegister.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py


Index: lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py
===================================================================
--- lldb/test/API/functionalities/gdb_remote_client/TestXMLRegisterFlags.py
+++ 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('<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):
Index: lldb/source/Commands/CommandObjectRegister.cpp
===================================================================
--- lldb/source/Commands/CommandObjectRegister.cpp
+++ 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,12 @@
 
           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",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148790.515271.patch
Type: text/x-patch
Size: 2426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230420/1ee73241/attachment.bin>


More information about the lldb-commits mailing list