Summary
Add JDB support for automatic command repetition and list
auto-advance, and make list
command output more intuitive.
Problem
The overall problem is that JDB is not as ergonomic as other command line debuggers like GDB and PDB (the Python debugger). In particular:
- In order to quickly step through a chunk of code in JDB, the user has to either step one line at a time, typing out the next command each time, or use a more intricate approach such as a temporary breakpoint or an next command after counting lines. In other debuggers this is accomplished by issuing a next command and then simply repeating it by pressing Enter as necessary.
- In order to examine code more than 10 lines at a time, a JDB user has to invoke list repeatedly with a manually computed line number each time, and if the user doesn't bother to determine the precise line number at the center of the next chunk the listing duplicates or skips lines. In other debuggers, a large chunk of the source can be easily listed by repeatedly invoking list (or just pressing Enter) as needed.
Solution
A new command is added to make the new functionality available on an opt-in basis. The user may enter repeat on
to enable or repeat off
to disable the features described below. repeat
may be used to query the current setting (off by default).
After issuing one of a certain set of "repeatable" commands [1], entering a blank line at the prompt will now cause the command to be re-executed, just as
!!
does but without first displaying the command. This only occurs ifrepeat
is enabled. Previously, a blank line was always a no-op.In some situations,
list
command output now starts where the previouslist
output left off. The situations are (1) an arbitrarylist
command is followed by alist
command with no target (the commands need not be consecutive; only certain commands [2] reset the listing state), and (2) an arbitrarylist
command is repeated by entering a blank line at the prompt. This behavior only occurs ifrepeat
is enabled, but the listing state survives changes to therepeat
setting and is updated even whenrepeat
is disabled. After reaching the end of the file, only "EOF" is printed until the state is reset.Previously, the marker
=>
was used in the output oflist
to indicate the listing "target"; the one specified in the command (usually a line number), or otherwise the current line of execution. Only the current line of execution is now so marked, regardless of whether a target is specified. This occurs irrespective of therepeat
setting.
An alternative way to address the usability concerns is to integrate Jline into JDB, for an experience similar to that of Jshell. While this is conceptually simpler, there was concern that the extent of the code changes necessary for this integration would be too large compared to the benefit [3].
[1] The repeatable commands are: up
, down
, step
, stepi
, next
, cont
, list
, pop
, and reenter
. A repeatable command preceded by a repeat number (e.g. 5 next
) is also repeatable.
[2] The listing reset commands are: run
, suspend
, resume
, up
, down
, kill
, interrupt
, threadgroup
, step
, stepi
, next
, cont
, pop
, and reenter
. A listing reset command preceded by a repeat number is also a listing reset command.
[3] https://mail.openjdk.java.net/pipermail/serviceability-dev/2021-August/038889.html
Specification
To my knowledge the behavior of JDB is only specified to the extent of its help and usage messages, which are updated as appropriate in the accompanying pull request [4].
- csr of
-
JDK-8271356 Modify jdb to treat an empty command as a repeat of the previous command
-
- Resolved
-