@@ -644,7 +644,7 @@ def do_commands(self, arg):
644644try :
645645bnum = int (arg )
646646except :
647- self .error ( "Usage: commands [bnum] \n ... \n end" )
647+ self ._print_invalid_arg ( arg )
648648return
649649try :
650650self .get_bpbynumber (bnum )
@@ -941,14 +941,22 @@ def do_ignore(self, arg):
941941 condition evaluates to true.
942942 """
943943args = arg .split ()
944- try :
945- count = int (args [1 ].strip ())
946- except :
944+ if not args :
945+ self .error ('Breakpoint number expected' )
946+ return
947+ if len (args )== 1 :
947948count = 0
949+ elif len (args )== 2 :
950+ try :
951+ count = int (args [1 ])
952+ except ValueError :
953+ self ._print_invalid_arg (arg )
954+ return
955+ else :
956+ self ._print_invalid_arg (arg )
957+ return
948958try :
949959bp = self .get_bpbynumber (args [0 ].strip ())
950- except IndexError :
951- self .error ('Breakpoint number expected' )
952960except ValueError as err :
953961self .error (err )
954962else :
@@ -1025,6 +1033,9 @@ def do_where(self, arg):
10251033 An arrow indicates the "current frame", which determines the
10261034 context of most commands. 'bt' is an alias for this command.
10271035 """
1036+ if arg :
1037+ self ._print_invalid_arg (arg )
1038+ return
10281039self .print_stack_trace ()
10291040do_w = do_where
10301041do_bt = do_where
@@ -1112,6 +1123,9 @@ def do_step(self, arg):
11121123 (either in a function that is called or in the current
11131124 function).
11141125 """
1126+ if arg :
1127+ self ._print_invalid_arg (arg )
1128+ return
11151129self .set_step ()
11161130return 1
11171131do_s = do_step
@@ -1122,6 +1136,9 @@ def do_next(self, arg):
11221136 Continue execution until the next line in the current function
11231137 is reached or it returns.
11241138 """
1139+ if arg :
1140+ self ._print_invalid_arg (arg )
1141+ return
11251142self .set_next (self .curframe )
11261143return 1
11271144do_n = do_next
@@ -1153,6 +1170,9 @@ def do_return(self, arg):
11531170
11541171 Continue execution until the current function returns.
11551172 """
1173+ if arg :
1174+ self ._print_invalid_arg (arg )
1175+ return
11561176self .set_return (self .curframe )
11571177return 1
11581178do_r = do_return
@@ -1162,6 +1182,9 @@ def do_continue(self, arg):
11621182
11631183 Continue execution, only stop when a breakpoint is encountered.
11641184 """
1185+ if arg :
1186+ self ._print_invalid_arg (arg )
1187+ return
11651188if not self .nosigint :
11661189try :
11671190Pdb ._previous_sigint_handler = \
@@ -1256,6 +1279,9 @@ def do_args(self, arg):
12561279
12571280 Print the argument list of the current function.
12581281 """
1282+ if arg :
1283+ self ._print_invalid_arg (arg )
1284+ return
12591285co = self .curframe .f_code
12601286dict = self .curframe_locals
12611287n = co .co_argcount + co .co_kwonlyargcount
@@ -1274,6 +1300,9 @@ def do_retval(self, arg):
12741300
12751301 Print the return value for the last return of a function.
12761302 """
1303+ if arg :
1304+ self ._print_invalid_arg (arg )
1305+ return
12771306if '__return__' in self .curframe_locals :
12781307self .message (repr (self .curframe_locals ['__return__' ]))
12791308else :
@@ -1390,6 +1419,9 @@ def do_longlist(self, arg):
13901419
13911420 List the whole source code for the current function or frame.
13921421 """
1422+ if arg :
1423+ self ._print_invalid_arg (arg )
1424+ return
13931425filename = self .curframe .f_code .co_filename
13941426breaklist = self .get_file_breaks (filename )
13951427try :
@@ -1570,7 +1602,9 @@ def do_unalias(self, arg):
15701602 Delete the specified alias.
15711603 """
15721604args = arg .split ()
1573- if len (args )== 0 :return
1605+ if len (args )== 0 :
1606+ self ._print_invalid_arg (arg )
1607+ return
15741608if args [0 ]in self .aliases :
15751609del self .aliases [args [0 ]]
15761610
@@ -1723,7 +1757,7 @@ def _getsourcelines(self, obj):
17231757lineno = max (1 ,lineno )
17241758return lines ,lineno
17251759
1726- def _help_message_from_doc (self ,doc ):
1760+ def _help_message_from_doc (self ,doc , usage_only = False ):
17271761lines = [line .strip ()for line in doc .rstrip ().splitlines ()]
17281762if not lines :
17291763return "No help message found."
@@ -1739,10 +1773,24 @@ def _help_message_from_doc(self, doc):
17391773elif i < usage_end :
17401774prefix = " "
17411775else :
1776+ if usage_only :
1777+ break
17421778prefix = ""
17431779formatted .append (indent + prefix + line )
17441780return "\n " .join (formatted )
17451781
1782+ def _print_invalid_arg (self ,arg ):
1783+ """Return the usage string for a function."""
1784+
1785+ self .error (f"Invalid argument:{ arg } " )
1786+
1787+ # Yes it's a bit hacky. Get the caller name, get the method based on
1788+ # that name, and get the docstring from that method.
1789+ # This should NOT fail if the caller is a method of this class.
1790+ doc = inspect .getdoc (getattr (self ,sys ._getframe (1 ).f_code .co_name ))
1791+ if doc is not None :
1792+ self .message (self ._help_message_from_doc (doc ,usage_only = True ))
1793+
17461794# Collect all command help into docstring, if not run with -OO
17471795
17481796if __doc__ is not None :