feat(libc): implement guest backtrace capture #7084

Closed
portalmaster137 wants to merge 1 commit from upstream-pr/7084 into main
portalmaster137 commented 2026-10-17 10:50:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by portalmaster137 on 2026-10-17T10:50:45Z.


What

Implement sceLibcBacktraceGetBufferSize and sceLibcBacktraceSelf by capturing the guest call stack, formatting frame names and addresses, and writing linked frame records to the caller’s buffer. Add a guest backtrace test.

Tested

Linux; not tested. Added guest_backtrace_tests, but it has not been run.

Checklist

  • Based on current main; no known open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4899449233 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7084). Originally posted by [portalmaster137](https://github.com/portalmaster137) on 2026-10-17T10:50:45Z. --- ### What Implement sceLibcBacktraceGetBufferSize and sceLibcBacktraceSelf by capturing the guest call stack, formatting frame names and addresses, and writing linked frame records to the caller’s buffer. Add a guest backtrace test. ### Tested Linux; not tested. Added guest_backtrace_tests, but it has not been run. ### Checklist - [x] Based on current main; no known open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation .md files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-17 10:50:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-17T10:50:50Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5557463776 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7084#pullrequestreview-5557463776). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-17T10:50:50Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
github-actions[bot] commented 2026-10-17 11:21:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T11:21:50Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3965 core/libs/prx/libc/CMakeLists.txt
PR 4627 core/libs/prx/libc/CMakeLists.txt
PR 5021 core/libs/prx/libc/CMakeLists.txt
PR 6044 core/libs/prx/libc/CMakeLists.txt
PR 6079 core/libs/prx/libc/CMakeLists.txt
PR 6084 core/libs/prx/libc/CMakeLists.txt
PR 6085 core/libs/prx/libc/CMakeLists.txt
PR 6086 core/libs/prx/libc/CMakeLists.txt
PR 6713 core/libs/prx/libc/CMakeLists.txt
PR 6819 core/libs/prx/libc/CMakeLists.txt
PR 6985 core/libs/prx/libc/CMakeLists.txt
PR 7081 core/libs/prx/libc/CMakeLists.txt
PR 7201 core/libs/prx/libc/CMakeLists.txt
PR 7332 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/Backtrace.cpp
PR 7411 core/libs/prx/libc/CMakeLists.txt
PR 7417 core/libs/prx/libc/CMakeLists.txt
PR 7447 core/libs/prx/libc/CMakeLists.txt
PR 7470 core/libs/prx/libc/CMakeLists.txt
PR 7525 core/libs/prx/libc/CMakeLists.txt
PR 7715 core/libs/prx/libc/CMakeLists.txt
PR 7839 core/libs/prx/libc/CMakeLists.txt
PR 7841 core/libs/prx/libc/CMakeLists.txt
PR 7851 core/libs/prx/libc/CMakeLists.txt
PR 7897 core/libs/prx/libc/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233295603 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7084#issuecomment-6233295603). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T11:21:50Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 3965](https://www.github.com/boykopovar/AnyPS5/pull/3965) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 4627](https://www.github.com/boykopovar/AnyPS5/pull/4627) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6079](https://www.github.com/boykopovar/AnyPS5/pull/6079) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6084](https://www.github.com/boykopovar/AnyPS5/pull/6084) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6085](https://www.github.com/boykopovar/AnyPS5/pull/6085) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6086](https://www.github.com/boykopovar/AnyPS5/pull/6086) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6713](https://www.github.com/boykopovar/AnyPS5/pull/6713) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6985](https://www.github.com/boykopovar/AnyPS5/pull/6985) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libc/CMakeLists.txt`<br>`core/libs/prx/libc/src/Backtrace.cpp` | | [PR 7411](https://www.github.com/boykopovar/AnyPS5/pull/7411) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7417](https://www.github.com/boykopovar/AnyPS5/pull/7417) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7447](https://www.github.com/boykopovar/AnyPS5/pull/7447) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7470](https://www.github.com/boykopovar/AnyPS5/pull/7470) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7525](https://www.github.com/boykopovar/AnyPS5/pull/7525) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7839](https://www.github.com/boykopovar/AnyPS5/pull/7839) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7841](https://www.github.com/boykopovar/AnyPS5/pull/7841) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7851](https://www.github.com/boykopovar/AnyPS5/pull/7851) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7897](https://www.github.com/boykopovar/AnyPS5/pull/7897) | `core/libs/prx/libc/CMakeLists.txt` |
jotitadev commented 2026-10-17 15:16:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T15:16:32Z.

Review: COMMENTED


First run of the new test (the description says guest_backtrace_tests has not been run).

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build.
Head 5e5844b54 merged onto main 40315fcf8 (clean merge).

  • guest_backtrace passes with the PR. The other exception tests (ctest -R "backtrace|exception", 6 tests) also pass.
  • Test file and its registration only, on main: the test aborts with sceLibcBacktraceGetBufferSize_nid_postfix not implemented, so it covers the change.
  • Non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out"): 683/683, the 682 tests of main plus guest_backtrace.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5558428199 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7084#pullrequestreview-5558428199). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-17T15:16:32Z. **Review:** COMMENTED --- First run of the new test (the description says `guest_backtrace_tests` has not been run). Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`, full build. Head `5e5844b54` merged onto `main` `40315fcf8` (clean merge). - `guest_backtrace` passes with the PR. The other exception tests (`ctest -R "backtrace|exception"`, 6 tests) also pass. - Test file and its registration only, on `main`: the test aborts with `sceLibcBacktraceGetBufferSize_nid_postfix not implemented`, so it covers the change. - Non-GPU suite (`ctest -E "^agc|gpu|vulkan|video_out"`): 683/683, the 682 tests of `main` plus `guest_backtrace`. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
blawesom commented 2026-10-17 18:54:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T18:54:45Z.


Heads-up before rebase effort goes in: main just landed overlapping backtrace work. #7060 ("fix(libc): limit sceLibcBacktraceSelf to Linux and test its record layout", merged today) implements sceLibcBacktraceSelf on Linux with test coverage, and main's Backtrace.cpp already carries sceLibcBacktraceGetBufferSize/CaptureFrames — the same functions this PR adds. Beyond what main has, I can see the Unwind.hpp integration and platform branches (__APPLE__/Windows) in your diff, which may or may not still apply on top of #7060's shape. So the practical options are reducing this PR onto #7060's implementation (keeping whatever it genuinely adds — the macOS/Windows paths, the _Unwind_Backtrace exports) or closing it as superseded — your call with the maintainers. I can carry the reduction as a rebase handoff if that's the wanted direction.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6238999099 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7084#issuecomment-6238999099). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-17T18:54:45Z. --- **Heads-up before rebase effort goes in: `main` just landed overlapping backtrace work.** #7060 ("fix(libc): limit sceLibcBacktraceSelf to Linux and test its record layout", merged today) implements `sceLibcBacktraceSelf` on Linux with test coverage, and `main`'s `Backtrace.cpp` already carries `sceLibcBacktraceGetBufferSize`/`CaptureFrames` — the same functions this PR adds. Beyond what `main` has, I can see the `Unwind.hpp` integration and platform branches (`__APPLE__`/Windows) in your diff, which may or may not still apply on top of #7060's shape. So the practical options are reducing this PR onto #7060's implementation (keeping whatever it genuinely adds — the macOS/Windows paths, the `_Unwind_Backtrace` exports) or closing it as superseded — your call with the maintainers. I can carry the reduction as a rebase handoff if that's the wanted direction.
T3cm0 commented 2026-10-17 23:17:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by T3cm0 on 2026-10-17T23:17:12Z.


Hi @portalmaster137, since this PR was opened, #7060 landed a Linux implementation of sceLibcBacktraceGetBufferSize and sceLibcBacktraceSelf on main, so the two now overlap.

I have a follow-up ready that builds on main's version rather than replacing it: it walks the frames with libc's _Unwind_Backtrace so the functions also run on Windows (main throws there), keeps #7060's record layout and .guest.prx handling, and aligns the edge cases with the console's code in the libc.prx that ASTRO BOT bundles (the walk starts at the caller, and a null argument or a frame outside any module returns 1). It passes guest_backtrace on Windows and Linux.

Are you still working on this one? If not, would you be OK with mine going first? I'm happy to fold in anything from yours that it misses.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6242956553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7084#issuecomment-6242956553). Originally posted by [T3cm0](https://github.com/T3cm0) on 2026-10-17T23:17:12Z. --- Hi @portalmaster137, since this PR was opened, #7060 landed a Linux implementation of `sceLibcBacktraceGetBufferSize` and `sceLibcBacktraceSelf` on `main`, so the two now overlap. I have a follow-up ready that builds on `main`'s version rather than replacing it: it walks the frames with libc's `_Unwind_Backtrace` so the functions also run on Windows (`main` throws there), keeps #7060's record layout and `.guest.prx` handling, and aligns the edge cases with the console's code in the `libc.prx` that ASTRO BOT bundles (the walk starts at the caller, and a null argument or a frame outside any module returns 1). It passes `guest_backtrace` on Windows and Linux. Are you still working on this one? If not, would you be OK with mine going first? I'm happy to fold in anything from yours that it misses.
github-actions[bot] commented 2026-10-19 13:00:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T13:00:57Z.


Progress report (864729d → 5e5844b)

📈 System libraries: 89.68% (+0.05%, +2 implemented functions)

✅ 2 implemented
Library Name
libc sceLibcBacktraceGetBufferSize_nid_postfix
libc sceLibcBacktraceSelf_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6267818327 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7084#issuecomment-6267818327). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T13:00:57Z. --- <!-- progress-report --> ### Progress report (864729d → 5e5844b) 📈 **System libraries**: 89.68% (+0.05%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libc | `sceLibcBacktraceGetBufferSize_nid_postfix` | | libc | `sceLibcBacktraceSelf_nid_postfix` | </details>
adriadam10 commented 2026-10-19 13:01:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T13:01:18Z.


Closing as a duplicate: #7060 already landed sceLibcBacktraceGetBufferSize and sceLibcBacktraceSelf on main (Linux, with a record-layout test), and this PR rewrites the same functions and now conflicts with it.

  • What it would add on top (Windows/macOS frame naming) is untested (the description says the new test was never run) and its record layout isn't checked against the console's libc.prx.
  • A follow-up that builds on main's version for Windows is already in preparation by @T3cm0.

If you want to contribute the Windows part, please open a new PR rebased on current main that extends #7060's implementation instead of replacing it, with a test that fails without the change. You're welcome to reopen with that addressed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6267824831 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7084#issuecomment-6267824831). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T13:01:18Z. --- Closing as a duplicate: #7060 already landed `sceLibcBacktraceGetBufferSize` and `sceLibcBacktraceSelf` on `main` (Linux, with a record-layout test), and this PR rewrites the same functions and now conflicts with it. - What it would add on top (Windows/macOS frame naming) is untested (the description says the new test was never run) and its record layout isn't checked against the console's `libc.prx`. - A follow-up that builds on `main`'s version for Windows is already in preparation by @T3cm0. If you want to contribute the Windows part, please open a new PR rebased on current `main` that extends #7060's implementation instead of replacing it, with a test that fails without the change. You're welcome to reopen with that addressed.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7084
No description provided.