[PATCH] gdb: explore.py: remove check_args return value

Simon Marchi simon.marchi@polymtl.ca
Sat Oct 2 12:44:04 GMT 2021


The check_args function raises an exception if the args are not
appropriate, so it will never return False.  The return value is in fact
completely unnecessary, as it can only return True.  Remove the return
value and adjust the callers.   Add some tests for these cases.

Change-Id: Idaf684416009002024d4b3d4bf71cd7117600182
---
 gdb/python/lib/gdb/command/explore.py   | 17 +++++------------
 gdb/testsuite/gdb.python/py-explore.exp |  5 +++++
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/gdb/python/lib/gdb/command/explore.py b/gdb/python/lib/gdb/command/explore.py
index 3b930fb0e496..0b655a989620 100644
--- a/gdb/python/lib/gdb/command/explore.py
+++ b/gdb/python/lib/gdb/command/explore.py
@@ -622,20 +622,16 @@ class ExploreUtils(object):
         explore command.
 
         Arguments:
-            name: The name of the explore command.
-            arg_str: The argument string passed to the explore command.
+            arg_str: The command name.
 
         Returns:
-            True if adequate arguments are passed, false otherwise.
+            None
 
         Raises:
             gdb.GdbError if adequate arguments are not passed.
         """
         if len(arg_str) < 1:
             raise gdb.GdbError("ERROR: '%s' requires an argument." % name)
-            return False
-        else:
-            return True
 
     @staticmethod
     def get_type_from_str(type_str):
@@ -693,8 +689,7 @@ class ExploreCommand(gdb.Command):
         )
 
     def invoke(self, arg_str, from_tty):
-        if ExploreUtils.check_args("explore", arg_str) is False:
-            return
+        ExploreUtils.check_args("explore", arg_str)
 
         # Check if it is a value
         value = ExploreUtils.get_value_from_str(arg_str)
@@ -732,8 +727,7 @@ class ExploreValueCommand(gdb.Command):
         )
 
     def invoke(self, arg_str, from_tty):
-        if ExploreUtils.check_args("explore value", arg_str) is False:
-            return
+        ExploreUtils.check_args("explore value", arg_str)
 
         value = ExploreUtils.get_value_from_str(arg_str)
         if value is None:
@@ -763,8 +757,7 @@ class ExploreTypeCommand(gdb.Command):
         )
 
     def invoke(self, arg_str, from_tty):
-        if ExploreUtils.check_args("explore type", arg_str) is False:
-            return
+        ExploreUtils.check_args("explore type", arg_str)
 
         datatype = ExploreUtils.get_type_from_str(arg_str)
         if datatype is not None:
diff --git a/gdb/testsuite/gdb.python/py-explore.exp b/gdb/testsuite/gdb.python/py-explore.exp
index 1772dc0045b7..8d89326f75fd 100644
--- a/gdb/testsuite/gdb.python/py-explore.exp
+++ b/gdb/testsuite/gdb.python/py-explore.exp
@@ -478,3 +478,8 @@ with_test_prefix "using 'cu'" {
 	}
     }
 }
+
+# Test commands with missing argument.
+gdb_test "explore" "ERROR: 'explore' requires an argument."
+gdb_test "explore value" "ERROR: 'explore value' requires an argument."
+gdb_test "explore type" "ERROR: 'explore type' requires an argument."
-- 
2.33.0



More information about the Gdb-patches mailing list