7
31
Fork
You've already forked blackmagic
23

Fix: RTT command crash #2255

Merged
northernpaws merged 4 commits from fix/rtt-command-crash into main 2026年05月20日 06:26:59 +02:00

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
dragonmux changed title from (削除) fix/rtt-command-crash (削除ここまで) to Fix: RTT command crash 2026年05月19日 02:46:32 +02:00
esden requested changes 2026年05月19日 02:55:44 +02:00
Dismissed
esden left a comment
Copy link

Just one super tiny nit, otherwise looks good to me. :)

Just one super tiny nit, otherwise looks good to me. :)
src/command.c Outdated
@ -726,0 +777,4 @@
return true;
}
/* If we didn't get picked up in one of the above command blocks, it was an invalid request */
gdb_outf("Unrecognized command format\n");
Owner
Copy link

This should probably be an gdb_out. :)

This should probably be an `gdb_out`. :)
Author
Owner
Copy link

Fixed 🙂

Fixed 🙂
esden marked this conversation as resolved
dragonmux force-pushed fix/rtt-command-crash from 22c76c8d8b
Some checks failed
ci/woodpecker/pr/build-firmware/7 Pipeline was successful
ci/woodpecker/pr/build-firmware/1 Pipeline was successful
ci/woodpecker/pr/build-firmware/5 Pipeline was successful
ci/woodpecker/pr/build-firmware/2 Pipeline was successful
ci/woodpecker/pr/build-firmware/3 Pipeline was successful
ci/woodpecker/pr/build-firmware/6 Pipeline was successful
ci/woodpecker/pr/build-firmware/4 Pipeline was successful
ci/woodpecker/pr/build-firmware/8 Pipeline failed
ci/woodpecker/pr/build-firmware/10 Pipeline was successful
ci/woodpecker/pr/build-firmware/12 Pipeline was successful
ci/woodpecker/pr/build-firmware/14 Pipeline was successful
ci/woodpecker/pr/build-firmware/13 Pipeline failed
ci/woodpecker/pr/build-firmware/11 Pipeline was successful
ci/woodpecker/pr/build-firmware/9 Pipeline was successful
ci/woodpecker/pr/build-linux/1 Pipeline was successful
ci/woodpecker/pr/build-firmware/17 Pipeline was successful
ci/woodpecker/pr/build-firmware/18 Pipeline failed
ci/woodpecker/pr/build-linux/2 Pipeline was successful
ci/woodpecker/pr/build-firmware/16 Pipeline was successful
ci/woodpecker/pr/build-firmware/19 Pipeline was successful
ci/woodpecker/pr/build-firmware/20 Pipeline was successful
ci/woodpecker/pr/build-firmware/15 Pipeline was successful
ci/woodpecker/pr/build-windows Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
to ddc88b5b08
Some checks failed
ci/woodpecker/pr/build-firmware/18 Pipeline failed
ci/woodpecker/pr/build-linux/2 Pipeline was successful
ci/woodpecker/pr/build-linux/1 Pipeline was successful
ci/woodpecker/pr/build-firmware/20 Pipeline was successful
ci/woodpecker/pr/build-firmware/19 Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/build-windows Pipeline was successful
ci/woodpecker/push/build-firmware/8 Pipeline failed
ci/woodpecker/push/build-firmware/6 Pipeline was successful
ci/woodpecker/push/build-firmware/4 Pipeline was successful
ci/woodpecker/push/build-firmware/1 Pipeline was successful
ci/woodpecker/push/build-firmware/2 Pipeline was successful
ci/woodpecker/push/build-firmware/7 Pipeline was successful
ci/woodpecker/push/build-firmware/5 Pipeline was successful
ci/woodpecker/push/build-firmware/3 Pipeline was successful
ci/woodpecker/push/build-firmware/16 Pipeline was successful
ci/woodpecker/push/build-firmware/13 Pipeline failed
ci/woodpecker/push/build-firmware/11 Pipeline was successful
ci/woodpecker/push/build-firmware/14 Pipeline was successful
ci/woodpecker/push/build-firmware/9 Pipeline was successful
ci/woodpecker/push/build-firmware/12 Pipeline was successful
ci/woodpecker/push/build-firmware/15 Pipeline was successful
ci/woodpecker/push/build-firmware/10 Pipeline was successful
ci/woodpecker/push/build-firmware/17 Pipeline was successful
ci/woodpecker/push/build-linux/1 Pipeline was successful
ci/woodpecker/push/build-firmware/18 Pipeline failed
ci/woodpecker/push/build-firmware/19 Pipeline was successful
ci/woodpecker/push/build-firmware/20 Pipeline was successful
ci/woodpecker/push/build-linux/2 Pipeline was successful
ci/woodpecker/push/build-windows Pipeline was successful
2026年05月19日 02:56:23 +02:00
Compare
esden left a comment
Copy link

LGTM! :)

LGTM! :)
northernpaws left a comment
Copy link

Looks good to me!

Looks good to me!
northernpaws deleted branch fix/rtt-command-crash 2026年05月20日 06:27:01 +02:00
Sign in to join this conversation.
No reviewers
Labels
Clear labels
BMD App
Black Magic Debug App (aka. PC hosted) (not firmware)
BMP Firmware
Black Magic Probe Firmware (not PC hosted software)
Bug
Confirmed bug
Build system
Build system
Can't reproduce
Maintainers can't reproduce this problem
CI
Continuous Integration System
Contribution wanted
User contributions welcome
Documentation
Project documentation
Draft
Work in progress draft
Duplicate
This issue or pull request already exists
Enhancement
General project improvement
Feedback wanted
Requires additional submitter feedback
Foreign Host Board
Non Native hardware to runing Black Magic firmware on
GDB
Issue/PR related to GDB
Good first issue
Good for newcommers
HwIssue Mitigation
Solving or mitigating a Hardware issue in Software
Information Needed
Maintainers need more information
NativeHardware
Official Black Magic Debug Hardware
New Host Board
New hardware to run Black Magic firmware on
New Target
New debug target
Off Topic
Something that does not involve the project in any way
Potential Bug
A potential, unconfirmed or very special circumstance bug
Regression
Bug caused by a regression
User Interest Needed
More user interest required before consideration
User Testing Needed
Looking for user testing reports
Won't fix
Outside of the project scope or works as intended
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blackmagic-debug/blackmagic!2255
Reference in a new issue
blackmagic-debug/blackmagic
No description provided.
Delete branch "fix/rtt-command-crash"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?