RFR: 8271356: Modify jdb to treat an empty command as a repeat of the previous command [v5]

Jakob Cornell github.com+5642931+jakobcornell at openjdk.java.net
Thu Sep 23 15:45:57 UTC 2021


On Thu, 23 Sep 2021 15:24:47 GMT, Jakob Cornell <github.com+5642931+jakobcornell at openjdk.org> wrote:

>> This has been under discussion on and off for the past month or so on serviceability-dev, and I think a CSR request is required, so this may be a work in progress.
>> 
>> Notes on the patch:
>> 
>> - The `list` command previously marked a line in each listing with `=>`.  In a bare `list` this is the next line up for execution.  Previously when requesting a specific location (e.g. `list 5`) the requested line would be marked.  With the patch applied, `list` will only ever mark the next line up for execution.  This is consistent with the behavior of GDB and PDB (at least).
>> - `EOF` is printed when the repeat setting is on and a bare `list` command follows a listing containing the last source line.  This feature is from PDB; it's a somewhat softer message than the one for an explicit `list` request that's out of range.
>> - I don't speak Chinese or Japanese, so I've omitted localizations for the new messages in those locales.  However, I updated the help text in both to include the new commands, with the descriptions left empty for now.
>
> Jakob Cornell has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8271356: Invoke auto-advance on empty input after targeted list command

Okay great, that's what I was thinking as well.  Here's a draft for the description section; while writing this up I realized I forgot to implement one aspect of the `list` auto-advance, so I pushed a second commit as well.

## Summary

Add automatic command repetition and `list` auto-advance to JDB 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).  Inconveniences the change addresses include the need to type a full command repeatedly or count lines and issue a compound command when quickly stepping through multiple lines of code, and the need to craft specific `list` commands to show code more than a few lines beyond the current execution.  The change is motivated by personal experience using JDB in the field.

## 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 if `repeat` is enabled.  Previously, a blank line was always a no-op.
- In some situations, `list` command output now starts where the previous `list` output left off.  The situations are (1) an arbitrary `list` command is followed by a `list` command with no target (the commands need not be consecutive; only certain commands [2] reset the listing state), and (2) an arbitrary `list` command is repeated by entering a blank line at the prompt.  This behavior only occurs if `repeat` is enabled, but the listing state survives changes to the `repeat` setting and is updated even when `repeat` 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 of `list` 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 the `repeat` 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].

## 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].

[1] The repeatable commands are listed here: https://github.com/openjdk/jdk/pull/5290/files#diff-7ee3880bc8b83c894ae64ab7e450f8f8d7386bae71e8b51fa95f17f67f53a76dR51.  A repeatable command preceded by a repeat number (e.g. `5 next`) is also repeatable.
[2] The listing reset commands are listed here: https://github.com/openjdk/jdk/pull/5290/files#diff-7ee3880bc8b83c894ae64ab7e450f8f8d7386bae71e8b51fa95f17f67f53a76dR58-R59.  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
[4] https://github.com/openjdk/jdk/pull/5290

-------------

PR: https://git.openjdk.java.net/jdk/pull/5290


More information about the serviceability-dev mailing list