Detailed description
In this PR we do two things - fix a crash caused by a NULL pointer, and also rework the RTT monitor command to bring it up to spec with the others both in code clarity, and in output clarity
The crash was caused by allowing a NULL target pointer through into the target layer in a state that's nonsensical in the first place. This is fixed by guarding all the status display logic with a check and outputting a different message about not being target-attached otherwise.
The command rework makes the cognitive complexity of command_rtt 19 points lower from 72 to 53 by first hoisting the status display logic into its own function, and then reworking the rest of the sub-command handlers via early returns and logic tidy-up to provide a better flow and a less indented experience, re-using if test logic to supply bool values as much as possible too.
The command rework could and arguably should go further, breaking each non-trivial subcommand into its own function, but this is left to a future exercise as part of the future RTT support work that's needed to improve the implementation and its robustness, and improve maintainability of said implementation.
Your checklist for this pull request
Closing issues
Fixes #2236
<!-- Filling this template is mandatory -->
## Detailed description
In this PR we do two things - fix a crash caused by a `NULL` pointer, and also rework the RTT monitor command to bring it up to spec with the others both in code clarity, and in output clarity
The crash was caused by allowing a `NULL` `target` pointer through into the target layer in a state that's nonsensical in the first place. This is fixed by guarding all the status display logic with a check and outputting a different message about not being target-attached otherwise.
The command rework makes the cognitive complexity of `command_rtt` 19 points lower from 72 to 53 by first hoisting the status display logic into its own function, and then reworking the rest of the sub-command handlers via early returns and logic tidy-up to provide a better flow and a less indented experience, re-using `if` test logic to supply bool values as much as possible too.
The command rework could and arguably should go further, breaking each non-trivial subcommand into its own function, but this is left to a future exercise as part of the future RTT support work that's needed to improve the implementation and its robustness, and improve maintainability of said implementation.
## Your checklist for this pull request
* [x] I've read the [Code of Conduct](https://codeberg.org/blackmagic-debug/blackmagic/src/CODE_OF_CONDUCT.md)
* [x] I've read the [guidelines for contributing](https://codeberg.org/blackmagic-debug/blackmagic/src/CONTRIBUTING.md) to this repository
* [x] It builds for hardware native (see [Building the firmware](https://codeberg.org/blackmagic-debug/blackmagic?tab=readme-ov-file#building-the-firmware))
* [x] It builds as BMDA (see [Building the BMDA](https://codeberg.org/blackmagic-debug/blackmagic?tab=readme-ov-file#building-black-magic-debug-app))
* [x] I've tested it to the best of my ability
* [x] My commit messages provide a useful short description of what the commits do
## Closing issues
Fixes #2236