Skip to content

Allow custom implementations of DebugWriter #4382

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ZhekaS
Copy link

@ZhekaS ZhekaS commented Mar 25, 2025

Pull Request Overview

Fixes #4302

Add a trait for debug writer, so the downstream code can implement it's own, not depending on UART backend.

Testing Strategy

Tested on QEMU and local simulated RiscV platform with both UART based and non-UART implentations.
Tested debug buffer overflow on buffered implementation

TODO or Help Wanted

Would be nice to test with some implementation using console_ordered as it has some "intrusive" calls to the debug api

Documentation Updated

Inline documentation added in debug.rs

Formatting

  • Ran make prepush.

Copy link
Contributor

@bradjc bradjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to do something like this, but I get the sense that what is in debug.rs right now is more based on what worked rather than something meant to be extensible.

I think we should create the trait, but having extract() as a member function doesn't make much sense. Probably flush() should be there instead.

The existing struct should be called DebugWriterRingBuffer or something.

@@ -303,22 +303,36 @@ pub struct DebugWriter {
count: Cell<usize>,
}

pub trait DebugWriterTrait: Write + IoWrite {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub trait DebugWriterTrait: Write + IoWrite {
pub trait DebugWriter: Write + IoWrite {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the draft implementation is a somewhat dirty WA intended to keep all the existing implementation as is while also allowing custom one. Ideally the empty trait functions should not be there as they are only required by specific implementations. If we are in agreement we want this, I can look into cleaner implementation when I have some free cycles...

@ZhekaS ZhekaS marked this pull request as ready for review April 24, 2025 21:15
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a DebugWriter with a non-UART backend
3 participants