gdb: explore.py: remove check_args return value

Message ID 20211002124404.517199-1-simon.marchi@polymtl.ca
State New
Headers show
Series
  • gdb: explore.py: remove check_args return value
Related show

Commit Message

Philippe Waroquiers via Gdb-patches Oct. 2, 2021, 12:44 p.m.
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(-)

-- 
2.33.0

Comments

Tom Tromey Oct. 5, 2021, 6:16 p.m. | #1
>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:


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

Looks good.  Thanks.

Tom

Patch

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."