Skip to content

Support console stderr redirection#169

Merged
Meziu merged 3 commits intorust3ds:masterfrom
FenrirWolf:console_debug_init
Aug 9, 2025
Merged

Support console stderr redirection#169
Meziu merged 3 commits intorust3ds:masterfrom
FenrirWolf:console_debug_init

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.

Copy link
Member

@Meziu Meziu left a comment

Choose a reason for hiding this comment

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

Forgot about this one. LGTM

@Meziu Meziu merged commit e8a3107 into rust3ds:master Aug 9, 2025
0 of 4 checks passed
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