feat(libc): add a breakpoint table for guest NIDs, off by default #17261

Open
MarcZX10 wants to merge 22 commits from upstream-pr/17261 into main
MarcZX10 commented 2026-11-08 16:31:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-08T16:31:06Z.


What

Adds a breakpoint table for guest NIDs in the libc debug support, off by default:

  • NID parsing and formatting, with a round trip test.
  • The table: add, remove, duplicate NIDs ignored and counted, capacity limit, empty check and a lock-free armed check.
  • A comma-separated parser for ANYPS5_DEBUG_NIDS, read once on first use. Malformed entries are reported by their text, and the armed NIDs can be listed.
  • With ANYPS5_DEBUG_NIDS unset the table stays empty (tested).
  • ANYPS5_DEBUG_NIDS is documented in docs/dev/ENVIRONMENT.md; the parts not built yet are recorded in docs/dev/debt/libc.md.

No pausing yet: arming a NID does not stop the guest. No call path consults the table yet, and the startup call that reads the variable is not wired yet.

Tested

Linux, host archive build (cmake configure OK), focused tests only, on the head 7857fdaf1a, which is this branch with current main merged in (no rebase). Command:

flock <build lock> env VERIFY_DIR=<worktree> VERIFY_TAG=splitmerge ANYPS5_REQUIRE_DISPLAY=1 bash <main checkout>/.git/info/tools/run_tests.sh '^(guest_debug_nid_breakpoints|guest_debug_nid_stops)$' guest_debug_nid_breakpoints_tests
  • BUILD-EXIT 0
  • 1/1 Test #812: guest_debug_nid_breakpoints ... Passed 0.02 sec
  • 100% tests passed, 0 tests failed out of 1

The earlier head (fe365ab100) also passed guest_radix64; that run is not repeated on the merged head. The per-file SYNTAX stage reports a missing generated header (RelinkerRevision.hpp) for one file; BUILD-EXIT is 0.

Also python3 tools/check_conventions.py passes and git diff --check is clean against the base.

Checklist

  • Based on current main; no other 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: the stop and command PRs of the NID breakpoint debugger series (follow-ups, not opened yet)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5213035668 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17261). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-08T16:31:06Z. --- ### What Adds a breakpoint table for guest NIDs in the libc debug support, off by default: - NID parsing and formatting, with a round trip test. - The table: add, remove, duplicate NIDs ignored and counted, capacity limit, empty check and a lock-free armed check. - A comma-separated parser for `ANYPS5_DEBUG_NIDS`, read once on first use. Malformed entries are reported by their text, and the armed NIDs can be listed. - With `ANYPS5_DEBUG_NIDS` unset the table stays empty (tested). - `ANYPS5_DEBUG_NIDS` is documented in `docs/dev/ENVIRONMENT.md`; the parts not built yet are recorded in `docs/dev/debt/libc.md`. No pausing yet: arming a NID does not stop the guest. No call path consults the table yet, and the startup call that reads the variable is not wired yet. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux, host archive build (cmake configure OK), focused tests only, on the head `7857fdaf1a`, which is this branch with current `main` merged in (no rebase). Command: ``` flock <build lock> env VERIFY_DIR=<worktree> VERIFY_TAG=splitmerge ANYPS5_REQUIRE_DISPLAY=1 bash <main checkout>/.git/info/tools/run_tests.sh '^(guest_debug_nid_breakpoints|guest_debug_nid_stops)$' guest_debug_nid_breakpoints_tests ``` - `BUILD-EXIT 0` - `1/1 Test #812: guest_debug_nid_breakpoints ... Passed 0.02 sec` - `100% tests passed, 0 tests failed out of 1` The earlier head (`fe365ab100`) also passed `guest_radix64`; that run is not repeated on the merged head. The per-file SYNTAX stage reports a missing generated header (`RelinkerRevision.hpp`) for one file; BUILD-EXIT is 0. Also `python3 tools/check_conventions.py` passes and `git diff --check` is clean against the base. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: the stop and command PRs of the NID breakpoint debugger series (follow-ups, not opened yet) <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
PrivacyOnion commented 2026-11-12 06:08:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T06:08:58Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against f27b676d05:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_debug_nid_breakpoints_tests built cleanly.
  • CTest (guest_debug_nid_breakpoints):
    1/1 Test #853: guest_debug_nid_breakpoints ......   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 1
    
  • Code reading:
    • core/libs/prx/libc/src/DebugNidBreakpoints.cpp: Verified Debug::ParseNid and Debug::FormatNid correctly encode and decode 64-bit NIDs into 11-character base64 strings over the PS5 alphabet [A-Za-z0-9+-], properly checking tail unused bits ((tail & 3u) == 0) and handling edge cases like 0 and boundary values without integer overflow.
    • core/libs/prx/libc/src/DebugNidBreakpoints.cpp: Verified Debug::NidBreakpointTable enforces kCapacity = 256, tracks duplicate additions in duplicates_ without increasing size, and correctly handles removal by replacing the removed slot with the last element.
    • core/libs/prx/libc/src/DebugNidBreakpoints.cpp: Verified thread safety and memory order semantics, confirming mutating operations hold mutex_ and release-store count_, while lock-free readers (Empty, Size, IsArmed) use acquire-loads on count_ and atomic loads on nids_ without data races or out-of-bounds access.
    • core/libs/prx/libc/src/DebugNidBreakpoints.cpp: Verified Debug::AddNidList parses comma-separated entries, trims whitespace, skips empty tokens, reports malformed entries to report callback, and executes once via std::call_once in Debug::LoadNidBreakpointsFromEnvironment.
    • core/libs/tests/GuestDebugNidBreakpoints.cpp and core/libs/prx/libc/CMakeLists.txt: Verified unit tests thoroughly cover known values, malformed entry rejection, round-trip serialization, capacity limits, duplicates, list export, and environment parsing, including Windows DLL PATH configuration.
    • Repository rules (AGENTS.md): Verified code contains zero comments (except allowed macro guards), new environment variable ANYPS5_DEBUG_NIDS is documented in docs/dev/ENVIRONMENT.md, and unimplemented debugger stop/command paths are tracked in docs/dev/debt/libc.md.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5869888772 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17261#pullrequestreview-5869888772). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T06:08:58Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `f27b676d05`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_debug_nid_breakpoints_tests` built cleanly. - **CTest** (`guest_debug_nid_breakpoints`): ``` 1/1 Test #853: guest_debug_nid_breakpoints ...... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 ``` - **Code reading**: - core/libs/prx/libc/src/DebugNidBreakpoints.cpp: Verified Debug::ParseNid and Debug::FormatNid correctly encode and decode 64-bit NIDs into 11-character base64 strings over the PS5 alphabet [A-Za-z0-9+-], properly checking tail unused bits ((tail & 3u) == 0) and handling edge cases like 0 and boundary values without integer overflow. - core/libs/prx/libc/src/DebugNidBreakpoints.cpp: Verified Debug::NidBreakpointTable enforces kCapacity = 256, tracks duplicate additions in duplicates_ without increasing size, and correctly handles removal by replacing the removed slot with the last element. - core/libs/prx/libc/src/DebugNidBreakpoints.cpp: Verified thread safety and memory order semantics, confirming mutating operations hold mutex_ and release-store count_, while lock-free readers (Empty, Size, IsArmed) use acquire-loads on count_ and atomic loads on nids_ without data races or out-of-bounds access. - core/libs/prx/libc/src/DebugNidBreakpoints.cpp: Verified Debug::AddNidList parses comma-separated entries, trims whitespace, skips empty tokens, reports malformed entries to report callback, and executes once via std::call_once in Debug::LoadNidBreakpointsFromEnvironment. - core/libs/tests/GuestDebugNidBreakpoints.cpp and core/libs/prx/libc/CMakeLists.txt: Verified unit tests thoroughly cover known values, malformed entry rejection, round-trip serialization, capacity limits, duplicates, list export, and environment parsing, including Windows DLL PATH configuration. - Repository rules (AGENTS.md): Verified code contains zero comments (except allowed macro guards), new environment variable ANYPS5_DEBUG_NIDS is documented in docs/dev/ENVIRONMENT.md, and unimplemented debugger stop/command paths are tracked in docs/dev/debt/libc.md. - Note: the AI-assisted checkbox can stay. Looks Good To Me
ligmaSec commented 2026-12-03 22:36:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:36:02Z.

Review: COMMENTED


I compiled and ran the exact breakpoint-table fixture on Linux, and the trial merge onto c1601e56d5 was clean. Please define whether IsArmed is allowed to miss an always-armed NID during concurrent table edits. A reader can scan the old contents of an earlier slot, miss the last NID moving into that slot on removal, and read a newly added NID at its old tail slot. The last NID stayed armed across both edits. A stable view or a documented best-effort lookup would make the intended semantics clear before guest stops use this path.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179822820 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17261#pullrequestreview-6179822820). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:36:02Z. **Review:** COMMENTED --- I compiled and ran the exact breakpoint-table fixture on Linux, and the trial merge onto `c1601e56d5` was clean. Please define whether `IsArmed` is allowed to miss an always-armed NID during concurrent table edits. A reader can scan the old contents of an earlier slot, miss the last NID moving into that slot on removal, and read a newly added NID at its old tail slot. The last NID stayed armed across both edits. A stable view or a documented best-effort lookup would make the intended semantics clear before guest stops use this path. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/17261:upstream-pr/17261'
git switch 'upstream-pr/17261'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/17261'
git switch 'upstream-pr/17261'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/17261'
git switch 'upstream-pr/17261'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/17261'
git switch 'main'
git merge --squash 'upstream-pr/17261'
git switch 'main'
git merge --ff-only 'upstream-pr/17261'
git switch 'main'
git merge 'upstream-pr/17261'
git push origin 'main'
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!17261
No description provided.