Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support console stderr redirection #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FenrirWolf
Copy link
Member

@FenrirWolf FenrirWolf commented Feb 26, 2024

Allows you send stderr output to GDB or other debuggers. It's a nice alternative to 3dslink redirection if you're at the point where you have to jump into an interactive debugging session.

Allows you read stderr output from `GDB` or other debuggers
/// Destination for stderr redirection with [`redirect_stderr`].
#[doc(alias = "debugDevice")]
#[repr(u32)]
pub enum Destination {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if we should call this Destination or Redirect or what. I'm open to suggestions about that.

Copy link
Member

Choose a reason for hiding this comment

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

Destination or RedirectTarget maybe?

Also I doubt more would ever be added but maybe #[non_exhaustive] would be good, in case we wanted to make e.g. a Socket target that would use redirect_to_3dslink under the hood or something like that

#[doc(alias = "consoleDebugInit")]
pub fn redirect_stderr(dest: Destination) {
unsafe { consoleDebugInit(dest as _) }
}
Copy link
Member

Choose a reason for hiding this comment

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

This looks fine to me offhand, I wonder how it behaves if you also use redirect_to_3dslink with stderr = true ? I think they use the same mechanism under the hood, so maybe whichever you call first gets overridden by the second one?

Copy link
Member Author

@FenrirWolf FenrirWolf Mar 15, 2024

Choose a reason for hiding this comment

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

I took a look inside libctru and the mechanisms are dfferent. consoleDebugInit changes the underlying devoptab for stderr and 3dslinkConnectToHost replaces stderr's file descriptor via dup2. So unless I'm mistaken, 3dslink redirection will always take priority over console redirection.

Copy link
Member

Choose a reason for hiding this comment

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

That behaviour should be properly documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants