libc: forward guest diagnostics when normal logging is silent #1569

Open
github-bot wants to merge 3 commits from github-bot/gh-1569 into main AGit
Owner

@⁠Buraddomoon on GitHub · 2026-10-16 20:37 UTC · original
Buraddomoon:fix/1540-guest-stdout → main · +229 −6 · 5 files · 3 commits · open

Mafia: The Old Country, Hellblade: Senua's Sacrifice, and Astro Bot are reported in #1540 to hide their own failure messages when normal logging is silent. This addresses the diagnostic-output request in section 5 of that issue.

Set KYTY_GUEST_STDOUT=1 before launch to additionally forward guest printf/vprintf output to stderr with a GUEST_STDOUT: prefix and an immediate flush. Forwarding is opt-in and read on the first guest print call. snprintf continues to write only to its destination buffer.

Validation

  • Linux Release build of launcher, including kyty_emulator, passed with Clang 19.1.7.
  • Four guest_printf CTest cases passed in the build container and directly on Fedora: variable unset, 0, 1, and a non-enabling value.
  • Tests call the production guest-print functions with synthetic arguments and check formatting, return counts, forwarding with the normal logger silent, immediate flushing, long output without a newline, and buffer-only snprintf behavior.
  • The enabled case fails with the original implementation and passes with this change.
  • The new target and all four cases are included in the Windows, Linux, and macOS CI selections. Windows and macOS builds have not been run locally.
  • clang-format was checked on the added production lines; unrelated existing formatting is preserved.

AI assistance and human review

AI assistance was used for investigation, implementation, regression tests, automated validation, and drafting this description. The contributor reviewed the submitted diff and authorized submission. The automated checks above were run by the assistant. No games, controllers, or GPU were used for these tests, and no in-game improvement is claimed.

**@⁠Buraddomoon** on GitHub · 2026-10-16 20:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1569) `Buraddomoon:fix/1540-guest-stdout` → `main` · +229 −6 · 5 files · 3 commits · open Mafia: The Old Country, Hellblade: Senua's Sacrifice, and Astro Bot are reported in #1540 to hide their own failure messages when normal logging is silent. This addresses the diagnostic-output request in section 5 of that issue. Set `KYTY_GUEST_STDOUT=1` before launch to additionally forward guest `printf`/`vprintf` output to stderr with a `GUEST_STDOUT:` prefix and an immediate flush. Forwarding is opt-in and read on the first guest print call. `snprintf` continues to write only to its destination buffer. ## Validation - Linux Release build of `launcher`, including `kyty_emulator`, passed with Clang 19.1.7. - Four `guest_printf` CTest cases passed in the build container and directly on Fedora: variable unset, `0`, `1`, and a non-enabling value. - Tests call the production guest-print functions with synthetic arguments and check formatting, return counts, forwarding with the normal logger silent, immediate flushing, long output without a newline, and buffer-only `snprintf` behavior. - The enabled case fails with the original implementation and passes with this change. - The new target and all four cases are included in the Windows, Linux, and macOS CI selections. Windows and macOS builds have not been run locally. - clang-format was checked on the added production lines; unrelated existing formatting is preserved. ## AI assistance and human review AI assistance was used for investigation, implementation, regression tests, automated validation, and drafting this description. The contributor reviewed the submitted diff and authorized submission. The automated checks above were run by the assistant. No games, controllers, or GPU were used for these tests, and no in-game improvement is claimed.
Add KYTY_GUEST_STDOUT=1 to forward guest printf/vprintf to stderr with a prefix and immediate flush. Add synthetic regression tests and register them in CI.

Related to #1540, section 5 only. AI-assisted implementation and automated validation; human review is pending.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:59:57 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-16 20:41 UTC · original · edited 2026-10-16 20:56 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4d92c6bf-d2ad-4be4-b491-289155f2f5a1
📥 Commits

Reviewing files that changed from the base of the PR and between 7e76d107e6 and c8537f3326.

📒 Files selected for processing: 2
  • src/libs/guestPrintf.cpp
  • tests/GuestPrintfTests.cpp
🚧 Files skipped from review as they are similar to previous changes: 1
  • tests/GuestPrintfTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

📝 Walkthrough

When KYTY_GUEST_STDOUT is exactly 1, guest printf and vprintf output is also written to stderr with a GUEST_STDOUT: prefix and flushed. The change adds tests for enabled and disabled forwarding, long output, embedded null bytes, and snprintf. CMake and CI build and run the tests on Windows, macOS, and Linux. The README documents the setting and its behavior.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Feature

Merge Risk: ⚪ Minimal · up to c8537

The opt-in diagnostic forwarding matches its documentation, and enabled and disabled tests are configured across Windows, macOS, and Linux. No actionable merge-blocking issue is evident.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description clearly explains the diagnostic forwarding change, configuration behavior, testing, and validation scope.
Title check Passed The title concisely and accurately identifies the main change: forwarding guest diagnostic output when normal logging is silent.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-16 20:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1569#issuecomment-6224297096) · edited 2026-10-16 20:56 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1569?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `4d92c6bf-d2ad-4be4-b491-289155f2f5a1` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 7e76d107e6fdfa8ca7e83281c52972fecad57930 and c8537f3326fbddc6d940a76cf100bb18762109b9. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 2</strong></summary> <dl> <dd> * `src/libs/guestPrintf.cpp` * `tests/GuestPrintfTests.cpp` </dd> </dl> </details> <details> <summary><strong>🚧 Files skipped from review as they are similar to previous changes: 1</strong></summary> <dl> <dd> * tests/GuestPrintfTests.cpp </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> When `KYTY_GUEST_STDOUT` is exactly `1`, guest `printf` and `vprintf` output is also written to stderr with a `GUEST_STDOUT:` prefix and flushed. The change adds tests for enabled and disabled forwarding, long output, embedded null bytes, and `snprintf`. CMake and CI build and run the tests on Windows, macOS, and Linux. The README documents the setting and its behavior. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"c8537f3326fbddc6d940a76cf100bb18762109b9" --> **Change:** Feature <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>c8537</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `c8537` --> <!-- final_review_risk_coverage:{"sourceCommitId":"c8537f3326fbddc6d940a76cf100bb18762109b9","coveredCommitId":"c8537f3326fbddc6d940a76cf100bb18762109b9","kind":"reviewed"} --> The opt-in diagnostic forwarding matches its documentation, and enabled and disabled tests are configured across Windows, macOS, and Linux. No actionable merge-blocking issue is evident. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 warning</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 2 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------- | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description clearly explains the diagnostic forwarding change, configuration behavior, testing, and validation scope. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title concisely and accurately identifies the main change: forwarding guest diagnostic output when normal logging is silent. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1569)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-16 20:41 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0f09baab-3db0-4d17-8740-8ced16efbc05
📥 Commits

Reviewing files that changed from the base of the PR and between 5dec523143 and 7e76d107e6.

📒 Files selected for processing: 5
  • .github/workflows/build.yml
  • CMakeLists.txt
  • README.md
  • src/libs/guestPrintf.cpp
  • tests/GuestPrintfTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-16 20:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1569#pullrequestreview-5553447190) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `0f09baab-3db0-4d17-8740-8ced16efbc05` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 5dec523143930e35a6a5a9839f972774420b7958 and 7e76d107e6fdfa8ca7e83281c52972fecad57930. </details> <details> <summary>📒 Files selected for processing: 5</summary> * `.github/workflows/build.yml` * `CMakeLists.txt` * `README.md` * `src/libs/guestPrintf.cpp` * `tests/GuestPrintfTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=9726f716-05bd-4069-a111-89607b13ba53 attempt=c9d8db65-45da-4d24-9f2d-efebf8d99d2d batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-16 20:41 UTC · original · edited 2026-10-16 20:51 UTC
On src/libs/guestPrintf.cpp line 788 (outdated):

@@ -777,6 +780,14 @@ static int kyty_printf_internal(bool sn, char* sn_s, size_t sn_n, const char* fo
 		EXIT_NOT_IMPLEMENTED(static_cast<size_t>(s) >= sn_n);
 	} else {
 		LOGF_COLOR(Log::Color::BrightMagenta, "%s", buffer.data());
+		static const bool forward_to_stderr = [] {
+			const char* value = std::getenv("KYTY_GUEST_STDOUT");
+			return value != nullptr && std::strcmp(value, "1") == 0;
+		}();
+		if (forward_to_stderr) {
+			std::fprintf(stderr, "GUEST_STDOUT: %s", buffer.data());

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Write all formatted bytes to stderr.

If a guest prints a%cb with a zero-valued %c, idx includes a, the null byte, and b. The new %s write stops at the null byte, so stderr loses b. Write the prefix separately, then write exactly idx bytes from buffer. Keep the flush. (pubs.opengroup.org)

Proposed fix
--- "a/src/libs/guestPrintf.cpp"
+++ "b/src/libs/guestPrintf.cpp"
@@ -785,7 +785,8 @@
 			return value != nullptr && std::strcmp(value, "1") == 0;
 		}();
 		if (forward_to_stderr) {
-			std::fprintf(stderr, "GUEST_STDOUT: %s", buffer.data());
+			std::fputs("GUEST_STDOUT: ", stderr);
+			std::fwrite(buffer.data(), 1, idx, stderr);
 			std::fflush(stderr);
 		}
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

			std::fputs("GUEST_STDOUT: ", stderr);
			std::fwrite(buffer.data(), 1, idx, stderr);

✅ Addressed in commit c8537f3

**@⁠coderabbitai[bot]** on GitHub · 2026-10-16 20:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1569#discussion_r4299129889) · edited 2026-10-16 20:51 UTC On `src/libs/guestPrintf.cpp` line 788 (outdated): ```diff @@ -777,6 +780,14 @@ static int kyty_printf_internal(bool sn, char* sn_s, size_t sn_n, const char* fo EXIT_NOT_IMPLEMENTED(static_cast<size_t>(s) >= sn_n); } else { LOGF_COLOR(Log::Color::BrightMagenta, "%s", buffer.data()); + static const bool forward_to_stderr = [] { + const char* value = std::getenv("KYTY_GUEST_STDOUT"); + return value != nullptr && std::strcmp(value, "1") == 0; + }(); + if (forward_to_stderr) { + std::fprintf(stderr, "GUEST_STDOUT: %s", buffer.data()); ``` **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** **Write all formatted bytes to stderr.** If a guest prints `a%cb` with a zero-valued `%c`, `idx` includes `a`, the null byte, and `b`. The new `%s` write stops at the null byte, so stderr loses `b`. Write the prefix separately, then write exactly `idx` bytes from `buffer`. Keep the flush. ([pubs.opengroup.org](https://pubs.opengroup.org/onlinepubs/009604499/functions/fprintf.html?utm_source=openai)) <details> <summary>Proposed fix</summary> ```diff --- "a/src/libs/guestPrintf.cpp" +++ "b/src/libs/guestPrintf.cpp" @@ -785,7 +785,8 @@ return value != nullptr && std::strcmp(value, "1") == 0; }(); if (forward_to_stderr) { - std::fprintf(stderr, "GUEST_STDOUT: %s", buffer.data()); + std::fputs("GUEST_STDOUT: ", stderr); + std::fwrite(buffer.data(), 1, idx, stderr); std::fflush(stderr); } } ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion std::fputs("GUEST_STDOUT: ", stderr); std::fwrite(buffer.data(), 1, idx, stderr); ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:340fd51ae0777957e6eff38c --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit c8537f3
This pull request has changes conflicting with the target branch.
  • .github/workflows/build.yml
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1569/head:github-bot/gh-1569'
git switch 'github-bot/gh-1569'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1569'
git switch 'github-bot/gh-1569'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1569'
git switch 'github-bot/gh-1569'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1569'
git switch 'main'
git merge --squash 'github-bot/gh-1569'
git switch 'main'
git merge --ff-only 'github-bot/gh-1569'
git switch 'main'
git merge 'github-bot/gh-1569'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.