public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: explore.py: remove check_args return value
@ 2021-10-02 12:44 Simon Marchi
  2021-10-05 18:16 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Marchi @ 2021-10-02 12:44 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gdb: explore.py: remove check_args return value
  2021-10-02 12:44 [PATCH] gdb: explore.py: remove check_args return value Simon Marchi
@ 2021-10-05 18:16 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2021-10-05 18:16 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-05 18:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-02 12:44 [PATCH] gdb: explore.py: remove check_args return value Simon Marchi
2021-10-05 18:16 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).