Skip to content

Thread dump: the guest callers and registers of a thread waiting in an SVC - #325

Closed
v0lumehi wants to merge 2 commits into
seedds:mainfrom
v0lumehi:thread-dump-callers
Closed

v0lumehi wants to merge 2 commits into
seedds:mainfrom
v0lumehi:thread-dump-callers

Conversation

@v0lumehi

@v0lumehi v0lumehi commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Thread dump: the guest callers and registers of a thread waiting in an SVC

The thread dump (svc_thread_dump: DM_WATCH, DM_WATCH_STALL, DM_HITCH_DUMP, the crash report) gives each guest thread's wait and a frame-pointer backtrace. Engines built without frame pointers, such as Rocksteady's Unreal Engine 3 in Batman: Arkham Knight, stop that backtrace at the SDK's SVC wrapper. A freeze then showed many threads waiting on events, and nothing said which code had called the waits.

A thread waiting in an SVC now gets one more line:

[dm]   0x1023 guest stack: [24]main+0x1a2b3c [88]main+0x44d10 ... | x19=… x20=… … x28=…
  • The callers. The words on the guest stack just above the gate's register frame that point into a module's code, nearest first, at most 16, each with its stack offset.
  • The registers. x19–x28 at the SVC. x23–x28 are registers of the caller that the SDK's wait wrappers leave untouched, and they often hold the task or object the thread waits for.

docs/agents/03-bringup.md's log table mentions the new line.

Diagnostics only: nothing changes unless a dump is printed. These lines helped find Arkham Knight's freezes. They showed the rendering thread waiting on a task's event with no timeout (main+0xbdd9f4, called from main+0x165de24 / main+0x165decc) and every task worker waiting on its own event; lldb then read the task from the wrapper's saved registers. The cause was a task queue whose push and pop lacked barriers. That fix is in the game's own profile, in a PR of its own.

Checked

  • Batman: Arkham Knight 1.0.5 on an M2 Max: the dumps of its frozen runs gave the callers above.
  • ci.sh (host tests, CPU gfx tests, every gfx test built, dmhost for three profiles, the iOS compile check, all tool tests): no failures.
  • dmhost for Breath of the Wild and Arkham Knight, the iOS compile check, test_docs.
  • No unit test: the dump reads a live guest thread's stack and register frame.

Engines built without frame pointers leave the frame-pointer backtrace at the SVC wrapper. A thread in
an SVC now also gets a guest stack line: the words above the gate's register frame that point into a
module's code, nearest first, and x19-x22 (Batman: Arkham Knight's FEvent waits).
…n SVC (x23-x28 are the caller's registers untouched by the SDK's wait wrappers, where a task or object pointer often is)
@seedds

seedds commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Thanks! Both commits are on main as f656796 and c8e4fd1, with one fix on top in 108ab9b.

Checked: on Metroid Dread with DM_WATCH=25, the line does what it says. The gate block pushes the guest's x29 / x30 below the SVC-time sp, so [8] is the return address into the SVC wrapper's caller. The wrappers are leaf functions, so the frame-pointer backtrace never shows that frame.

Fixed in 108ab9b: the stack was read as one 1,280-byte vm_read_overwrite. Guest stacks sit in the stack region, which is PROT_NONE apart from the mapped stacks. So a thread waiting less than 1,280 bytes below its stack top got no line at all. On Metroid, a condvar waiter about 350 bytes from its top was missing, so 7 of the 8 waiting threads had a line. The read now goes page by page up to the first unreadable page and lists the words it got. The line is printed only if the thread is still in the same SVC after the read. Now all 8 waiting threads get the line. The comment now says what regs + 800 holds, and 03-bringup.md says x19–x28 (it said x19–x22).

@seedds seedds closed this Oct 27, 2026
ltrdpper pushed a commit to ltrdpper/BananaNative that referenced this pull request Nov 16, 2026
…as on the console' (seedds#325) from Wick3dPhant0m/BananaNative:ctrl-applet into android
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.

2 participants