Repository navigation
Expand file tree
/
Copy pathdeveloper-console.js
More file actions
864 lines (851 loc) · 64.6 KB
/
Copy pathdeveloper-console.js
File metadata and controls
864 lines (851 loc) · 64.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
// Render360 developer tools are opt-in. Production mode keeps only the tiny UI guard.
// V73: adaptive Xenia HIR diagnostics + dual-lane correctness/Wasm coverage.
const SETTINGS_KEY='render360.settings.v44';
const $=id=>document.getElementById(id);
const entries=[];
const MAX_LOGS=60;
let enabled=false;
let listenersInstalled=false;
let opened=false;
let lastBlocker=null;
function readDeveloperMode(){
try{return !!JSON.parse(localStorage.getItem(SETTINGS_KEY)||'{}')?.developerMode;}catch{return false;}
}
function unlockNavigation(){
for(const id of ['settingsButton','importButton','emptyImportButton']){
const el=$(id);if(!el)continue;el.disabled=false;el.removeAttribute('disabled');el.removeAttribute('aria-disabled');el.style.pointerEvents='auto';
}
}
function compactRuntimeStatus(){
const el=$('runtimeSyncText');if(!el)return;
const text=String(el.textContent||'');
const match=text.match(/Runtime V(\d+).*?Core V(\d+).*?\(([^)]+)\)/i);
if(match)el.textContent=`Emulator ready · Core build ${match[2]} · ${match[3]}`;
}
function present(value){return value!==undefined&&value!==null&&value!=='';}
function number(value){return present(value)&&Number.isFinite(Number(value))?Number(value):undefined;}
function address(value){const n=number(value);return n===undefined?undefined:`0x${(n>>>0).toString(16).toUpperCase().padStart(8,'0')}`;}
function compact(value){return Object.fromEntries(Object.entries(value).filter(([,item])=>present(item)));}
function hexDelta(value){
const n=number(value);if(n===undefined)return '—';
const sign=n<0?'-':'+';
return `${sign}0x${Math.abs(n).toString(16).toUpperCase()}`;
}
function readWasmCString(memory,ptr,max=128){
const start=number(ptr);if(!(memory instanceof WebAssembly.Memory)||!start)return undefined;
const bytes=new Uint8Array(memory.buffer);let end=start>>>0;const limit=Math.min(bytes.length,end+Math.max(1,max|0));
while(end<limit&&bytes[end])end++;
if(end===(start>>>0))return '';
try{return new TextDecoder().decode(bytes.subarray(start>>>0,end));}catch{return undefined;}
}
function compactBlocker(detail){
const source=detail?.blocker||detail?.schedulerBlocker||detail||{};
return compact({
kind:source.kind||detail?.stage,
message:source.message||source.reason||detail?.message||detail?.reason,
address:address(source.address??source.sourceAddress??source.entry),
opcode:number(source.opcode??source.executionBlockerOpcode),
status:number(source.status??source.executionStatus),
instructions:number(source.instructions??source.executionInstructions),
module:source.module,
ordinal:present(source.ordinal)?`0x${Number(source.ordinal).toString(16).toUpperCase()}`:undefined,
});
}
function decodePpcInstruction(word,sourceAddress){
if(word===undefined)return undefined;
const primary=word>>>26;
const rt=(word>>>21)&31,ra=(word>>>16)&31;
if(primary===14){
const imm=(word<<16)>>16;
return {kind:'addi',text:`addi r${rt},r${ra},${imm}`,rt,ra,immediate:imm};
}
if(primary===15){
const imm=(word<<16)>>16;
return {kind:'addis',text:`addis r${rt},r${ra},${imm}`,rt,ra,immediate:imm};
}
if(primary===31){
const rb=(word>>>11)&31,xo=(word>>>1)&0x3FF;
if(xo===26)return {kind:'cntlz',text:`cntlzw r${ra},r${rt}`,rs:rt,ra,xo,mnemonic:'cntlzw'};
if(xo===58)return {kind:'cntlz',text:`cntlzd r${ra},r${rt}`,rs:rt,ra,xo,mnemonic:'cntlzd'};
const xMemoryNames={
23:'lwzx',55:'lwzux',87:'lbzx',119:'lbzux',
151:'stwx',183:'stwux',215:'stbx',247:'stbux',
279:'lhzx',311:'lhzux',343:'lhax',375:'lhaux',
407:'sthx',439:'sthux'
};
const mnemonic=xMemoryNames[xo];
if(mnemonic)return {kind:'x-form-memory',text:`${mnemonic} r${rt},r${ra},r${rb}`,rt,ra,rb,mnemonic,indexed:true};
}
if(primary===58||primary===62){
let ds=(word>>>2)&0x3FFF;if(ds&0x2000)ds-=0x4000;
const displacement=(ds<<2)|0;
const xo=word&3;
const mnemonic=primary===58?(xo===1?'ldu':xo===2?'lwa':'ld'):(xo===1?'stdu':'std');
return {kind:'ds-form-memory',text:`${mnemonic} r${rt},${displacement}(r${ra})`,rt,ra,displacement,mnemonic};
}
if(primary>=32&&primary<=55){
const displacement=(word<<16)>>16;
const names={32:'lwz',33:'lwzu',34:'lbz',35:'lbzu',36:'stw',37:'stwu',38:'stb',39:'stbu',40:'lhz',41:'lhzu',42:'lha',43:'lhau',44:'sth',45:'sthu',46:'lmw',47:'stmw',48:'lfs',49:'lfsu',50:'lfd',51:'lfdu',52:'stfs',53:'stfsu',54:'stfd',55:'stfdu'};
const mnemonic=names[primary]||`op${primary}`;
return {kind:'d-form-memory',text:`${mnemonic} r${rt},${displacement}(r${ra})`,rt,ra,displacement,mnemonic};
}
if(primary===18){
let displacement=word&0x03FFFFFC;if(displacement&0x02000000)displacement|=0xFC000000;
displacement|=0;
const absolute=!!(word&2),link=!!(word&1);
const target=(absolute?displacement:((sourceAddress>>>0)+displacement))>>>0;
return {kind:'direct-branch',text:`b${link?'l':''} ${address(target)}`,target:address(target),displacement,absolute,link};
}
if(primary===16){
let displacement=word&0x0000FFFC;displacement=(displacement<<16)>>16;
const absolute=!!(word&2),link=!!(word&1);
const target=(absolute?displacement:((sourceAddress>>>0)+displacement))>>>0;
return {kind:'conditional-branch',text:`bc${link?'l':''} ${address(target)}`,target:address(target),displacement,absolute,link,bo:(word>>>21)&31,bi:(word>>>16)&31};
}
if(primary===19){
const xo=(word>>>1)&0x3FF,link=!!(word&1);
if(xo===16)return {kind:'bclr',text:`bclr${link?'l':''}`,link,bo:(word>>>21)&31,bi:(word>>>16)&31};
if(xo===528)return {kind:'bcctr',text:`bcctr${link?'l':''}`,link,bo:(word>>>21)&31,bi:(word>>>16)&31};
}
return {kind:'other',text:`opcode ${primary}`,primaryOpcode:primary};
}
function readInstructionWord(read8,sourceAddress){
const a=number(sourceAddress);if(!read8||a===undefined)return undefined;
const b0=read8(a>>>0)>>>0,b1=read8((a+1)>>>0)>>>0,b2=read8((a+2)>>>0)>>>0,b3=read8((a+3)>>>0)>>>0;
return ((b0<<24)|(b1<<16)|(b2<<8)|b3)>>>0;
}
function readPpcWindow(read8,center,radius=3){
const c=number(center);if(!read8||c===undefined)return undefined;
const rows=[];
for(let i=-radius;i<=radius;i++){
const at=(c+i*4)>>>0;
const word=readInstructionWord(read8,at);
if(word===undefined)continue;
const decoded=decodePpcInstruction(word,at);
rows.push(compact({
address:address(at),
word:`0x${word.toString(16).toUpperCase().padStart(8,'0')}`,
decoded:decoded?.text,
kind:decoded?.kind,
current:i===0,
}));
}
return rows.length?rows:undefined;
}
function readPpcForward(read8,start,count=12){
const s=number(start);if(!read8||s===undefined)return undefined;
const rows=[];
const n=Math.max(1,Math.min(32,Number(count)||12));
for(let i=0;i<n;i++){
const at=(s+i*4)>>>0;
const word=readInstructionWord(read8,at);
if(word===undefined)continue;
const decoded=decodePpcInstruction(word,at);
rows.push(compact({
address:address(at),
word:`0x${word.toString(16).toUpperCase().padStart(8,'0')}`,
decoded:decoded?.text,
kind:decoded?.kind,
current:i===0,
}));
}
return rows.length?rows:undefined;
}
function memoryDiagnostics(state,result){
const bootstrap=state?.bootstrap,exp=bootstrap?.exports||{};
const fn=name=>{const value=exp[name]??exp[`_${name}`];return typeof value==='function'?value:null;};
const faultAddressFn=fn('r360_sparse_guest_memory_last_fault_address');
const faultCodeFn=fn('r360_sparse_guest_memory_last_fault_code');
const mappedPagesFn=fn('r360_sparse_guest_memory_mapped_pages');
const backingPagesFn=fn('r360_sparse_guest_memory_backing_pages');
const read8=fn('r360_sparse_guest_memory_read_u8');
const gprSnapshotFn=fn('r360_ppc_probe_correctness_gpr');
const runtimeBeginFn=fn('r360_pe_guest_runtime_function_begin');
const runtimeEndFn=fn('r360_pe_guest_runtime_function_end');
const runtimePrologFn=fn('r360_pe_guest_runtime_function_prolog_bytes');
const runtimeOwner=value=>{
const a=number(value);if(a===undefined||!runtimeBeginFn||!runtimeEndFn||!runtimePrologFn)return undefined;
const begin=runtimeBeginFn(a>>>0)>>>0,end=runtimeEndFn(a>>>0)>>>0;
if(!begin||!end||end<=begin)return undefined;
return compact({begin:address(begin),end:address(end),prologBytes:runtimePrologFn(a>>>0)>>>0,offset:(a>>>0)-begin});
};
const runtimeOwnerWindow=owner=>{
if(!owner?.begin)return undefined;
const prolog=number(owner.prologBytes)||0;
return readPpcForward(read8,owner.begin,Math.min(32,Math.max(8,Math.ceil(prolog/4)+4)));
};
const readStackU32=name=>{const f=fn(name);return f?(f()>>>0):undefined;};
const resultStack=result?.stackTrace||{};
const writeHistory=(Array.isArray(resultStack.writeHistory)?resultStack.writeHistory:[]).map(event=>compact({
sequence:number(event.sequence),address:address(event.address),oldR1:address(event.oldR1),newR1:address(event.newR1),depth:number(event.depth),
}));
const callHistory=(Array.isArray(resultStack.callHistory)?resultStack.callHistory:[]).map(event=>compact({
sequence:number(event.sequence),source:address(event.source),target:address(event.target),r1:address(event.r1),depth:number(event.depth),flags:number(event.flags),
sourceOwner:runtimeOwner(event.source),targetOwner:runtimeOwner(event.target),
}));
const tailCallDiagnostics=callHistory
.filter(event=>(((number(event.flags)||0)&2)!==0))
.map(event=>compact({
sequence:event.sequence,source:event.source,target:event.target,r1:event.r1,depth:event.depth,flags:event.flags,
sourceOwner:event.sourceOwner,targetOwner:event.targetOwner,
sourceWindow:readPpcWindow(read8,event.source,10),
targetWindow:readPpcWindow(read8,event.target,5),
sourceOwnerPrologue:runtimeOwnerWindow(event.sourceOwner),
targetOwnerPrologue:runtimeOwnerWindow(event.targetOwner),
}));
const stackTrace=compact({
blockerR1:address(number(resultStack.blockerR1)??readStackU32('r360_ppc_probe_stack_blocker_r1')),
initialR1:address(number(resultStack.initialR1)??readStackU32('r360_ppc_probe_stack_initial_r1')),
lastWriteAddress:address(number(resultStack.lastWriteAddress)??readStackU32('r360_ppc_probe_stack_last_write_address')),
lastOldR1:address(number(resultStack.lastOldR1)??readStackU32('r360_ppc_probe_stack_last_old_r1')),
lastNewR1:address(number(resultStack.lastNewR1)??readStackU32('r360_ppc_probe_stack_last_new_r1')),
lastWriteDepth:number(resultStack.lastWriteDepth)??readStackU32('r360_ppc_probe_stack_last_write_depth'),
lastCallSource:address(number(resultStack.lastCallSource)??readStackU32('r360_ppc_probe_stack_last_call_source')),
lastCallTarget:address(number(resultStack.lastCallTarget)??readStackU32('r360_ppc_probe_stack_last_call_target')),
lastCallR1:address(number(resultStack.lastCallR1)??readStackU32('r360_ppc_probe_stack_last_call_r1')),
lastCallDepth:number(resultStack.lastCallDepth)??readStackU32('r360_ppc_probe_stack_last_call_depth'),
writeHistory:writeHistory.length?writeHistory:undefined,
callHistory:callHistory.length?callHistory:undefined,
});
const capturedFaultAddress=number(result?.memoryFaultAddress);
const capturedFaultCode=number(result?.memoryFaultCode);
const faultAddress=capturedFaultAddress!==undefined?capturedFaultAddress:(faultAddressFn?(faultAddressFn()>>>0):undefined);
const faultCode=capturedFaultCode!==undefined?capturedFaultCode:(faultCodeFn?(faultCodeFn()>>>0):undefined);
const blockerAddress=number(result?.executionBlockerAddress);
const instructionWord=readInstructionWord(read8,blockerAddress);
const decoded=instructionWord===undefined?undefined:decodePpcInstruction(instructionWord,blockerAddress);
let baseRegisterValue,indexRegisterValue,effectiveAddress;
const readSnapshotGpr=index=>{
if(!gprSnapshotFn||index===undefined)return undefined;
try{
const raw=gprSnapshotFn(index>>>0);
return typeof raw==='bigint'?Number(BigInt.asUintN(32,raw))>>>0:Number(raw)>>>0;
}catch{return undefined;}
};
if(decoded&&(decoded.kind==='d-form-memory'||decoded.kind==='ds-form-memory')&&faultAddress!==undefined&&faultCode){
effectiveAddress=faultAddress>>>0;
baseRegisterValue=readSnapshotGpr(decoded.ra);
if(baseRegisterValue===undefined)baseRegisterValue=decoded.ra===0?0:(effectiveAddress-(decoded.displacement|0))>>>0;
}
if(decoded?.kind==='x-form-memory'&&faultAddress!==undefined&&faultCode){
effectiveAddress=faultAddress>>>0;
baseRegisterValue=readSnapshotGpr(decoded.ra);
indexRegisterValue=readSnapshotGpr(decoded.rb);
}
const faultNames={0:'none',1:'unmapped',2:'read-protection',3:'write-protection',4:'invalid-argument',5:'already-mapped'};
const context=result?.mainThreadContext||{};
const runtimeFunctions=compact({
entry:runtimeOwner(result?.entry),
xexEntry:runtimeOwner(result?.xexEntry),
peEntry:runtimeOwner(result?.peEntry),
lastWrite:runtimeOwner(stackTrace.lastWriteAddress),
lastCallSource:runtimeOwner(stackTrace.lastCallSource),
lastCallTarget:runtimeOwner(stackTrace.lastCallTarget),
blocker:runtimeOwner(blockerAddress),
});
return compact({
faultAddress:faultAddress===undefined?undefined:address(faultAddress),
faultCode,
faultName:faultCode===undefined?undefined:(faultNames[faultCode]||`fault-${faultCode}`),
faultCapturedAtExecution:capturedFaultCode!==undefined&&capturedFaultCode!==0,
blockerInstruction:instructionWord===undefined?undefined:`0x${instructionWord.toString(16).toUpperCase().padStart(8,'0')}`,
blockerDecoded:decoded?.text,
instructionKind:decoded?.kind||'unknown',
ppcPrimaryOpcode:instructionWord===undefined?undefined:instructionWord>>>26,
rt:decoded?.rt,rs:decoded?.rs,ra:decoded?.ra,rb:decoded?.rb,displacement:decoded?.displacement,
effectiveAddress:effectiveAddress===undefined?undefined:address(effectiveAddress),
baseRegisterValue:baseRegisterValue===undefined?undefined:address(baseRegisterValue),
indexRegisterValue:indexRegisterValue===undefined?undefined:address(indexRegisterValue),
branchDisplacement:decoded?.displacement,
branchTarget:decoded?.target,
branchAbsolute:decoded?.absolute,
branchLink:decoded?.link,
branchBO:decoded?.bo,
branchBI:decoded?.bi,
faultInstructionAttribution:faultCode&&decoded&&!['d-form-memory','ds-form-memory'].includes(decoded.kind)?'fault-not-derived-from-boundary-instruction':undefined,
mappedPages:mappedPagesFn?(mappedPagesFn()>>>0):undefined,
backingPages:backingPagesFn?(backingPagesFn()>>>0):undefined,
stackTop:address(context.stackTop),stackLimit:address(context.stackLimit),stackBase:address(context.stackBase),stackSlotBase:address(context.stackSlotBase),
stackGuardBytes:number(context.stackGuardBytes),pcrAddress:address(context.pcrAddress),tlsAddress:address(context.tlsAddress),
stackTrace:Object.keys(stackTrace).length?stackTrace:undefined,
runtimeFunctions:Object.keys(runtimeFunctions).length?runtimeFunctions:undefined,
tailCallDiagnostics:tailCallDiagnostics.length?tailCallDiagnostics:undefined,
codeWindows:compact({
entry:readPpcWindow(read8,result?.entry,4),
xexEntry:readPpcWindow(read8,result?.xexEntry,4),
peEntry:readPpcWindow(read8,result?.peEntry,4),
r1Write:readPpcWindow(read8,stackTrace.lastWriteAddress,3),
callSite:readPpcWindow(read8,stackTrace.lastCallSource,2),
blocker:readPpcWindow(read8,blockerAddress,2),
entryOwnerPrologue:runtimeOwnerWindow(runtimeFunctions.entry),
lastWriteOwnerPrologue:runtimeOwnerWindow(runtimeFunctions.lastWrite),
lastCallSourceOwnerPrologue:runtimeOwnerWindow(runtimeFunctions.lastCallSource),
lastCallTargetOwnerPrologue:runtimeOwnerWindow(runtimeFunctions.lastCallTarget),
}),
});
}
function hirDiagnostics(state,result){
const exp=state?.bootstrap?.exports||{};
const fn=name=>{const value=exp[name]??exp[`_${name}`];return typeof value==='function'?value:null;};
const opcode=number(result?.executionBlockerOpcode);
const countFn=fn('r360_hir_opcode_count'),nameFn=fn('r360_hir_opcode_name');
const executorFn=fn('r360_hir_correctness_supports_opcode'),wasmFn=fn('r360_wasm_backend_supports_hir_opcode');
const executorCountFn=fn('r360_hir_correctness_supported_opcode_count'),wasmCountFn=fn('r360_wasm_backend_supported_opcode_count');
const totalOpcodes=countFn?(countFn()>>>0):undefined;
const rawName=opcode!==undefined&&nameFn?readWasmCString(exp.memory,nameFn(opcode>>>0)):undefined;
const opcodeName=rawName&&rawName!=='unknown'?rawName.toUpperCase():rawName;
const executorSupportsCurrent=opcode!==undefined&&executorFn?!!(executorFn(opcode>>>0)>>>0):undefined;
const wasmSupportsCurrent=opcode!==undefined&&wasmFn?!!(wasmFn(opcode>>>0)>>>0):undefined;
const executorSupported=executorCountFn?(executorCountFn()>>>0):undefined;
const wasmSupported=wasmCountFn?(wasmCountFn()>>>0):undefined;
const percent=(part,total)=>part!==undefined&&total?Number((part*100/total).toFixed(1)):undefined;
let recommendedLane;
if(opcode!==undefined){
if(executorSupportsCurrent===false&&wasmSupportsCurrent===false)recommendedLane='correctness-oracle + generated-Wasm';
else if(executorSupportsCurrent===false)recommendedLane='correctness-oracle';
else if(wasmSupportsCurrent===false)recommendedLane='generated-Wasm';
else recommendedLane='runtime integration / callable function path';
}
return compact({
opcode,opcodeName,xeniaReferenceAvailable:!!(rawName&&rawName!=='unknown'),
executorSupportsCurrent,wasmSupportsCurrent,recommendedLane,totalOpcodes,executorSupported,wasmSupported,
executorCoveragePercent:percent(executorSupported,totalOpcodes),wasmCoveragePercent:percent(wasmSupported,totalOpcodes),
});
}
function ppcDiagnosticSummary(memory){
if(!memory?.blockerInstruction)return undefined;
if((memory.instructionKind==='d-form-memory'||memory.instructionKind==='ds-form-memory')&&present(memory.ra))
return `PPC memory: rA=${memory.ra}=${memory.baseRegisterValue||'—'} rT=${memory.rt??'—'} disp=${memory.displacement??'—'} EA=${memory.effectiveAddress||'—'}`;
if(memory.instructionKind==='direct-branch'||memory.instructionKind==='conditional-branch')
return `PPC ${memory.instructionKind}: target=${memory.branchTarget||'—'} disp=${memory.branchDisplacement??'—'} AA=${memory.branchAbsolute?1:0} LK=${memory.branchLink?1:0}${memory.faultInstructionAttribution?' · memory fault belongs to an earlier/different boundary':''}`;
return `PPC ${memory.instructionKind||'other'} · primary opcode ${memory.ppcPrimaryOpcode??'—'}`;
}
function stackDiagnosticSummary(memory){
const trace=memory?.stackTrace;if(!trace?.blockerR1)return undefined;
return `stack r1=${trace.blockerR1} initial=${trace.initialR1||'—'} · last write ${trace.lastWriteAddress||'—'} ${trace.lastOldR1||'—'}→${trace.lastNewR1||'—'} depth=${trace.lastWriteDepth??'—'} · last call ${trace.lastCallSource||'—'}→${trace.lastCallTarget||'—'} r1=${trace.lastCallR1||'—'} depth=${trace.lastCallDepth??'—'}`;
}
function problemFocus(memory,cpu,kernel,gpu,runtimeAsset,hir){
const trace=memory?.stackTrace||{};
const blockerR1=number(trace.blockerR1),initialR1=number(trace.initialR1),stackBase=number(memory?.stackBase),stackTop=number(memory?.stackTop);
const lastOld=number(trace.lastOldR1),lastNew=number(trace.lastNewR1),fault=number(memory?.faultAddress),ea=number(memory?.effectiveAddress);
const stackCrossing=blockerR1!==undefined&&stackBase!==undefined?(blockerR1-stackBase):undefined;
const faultIntoGuard=fault!==undefined&&stackBase!==undefined?(fault-stackBase):undefined;
const r1WriteDelta=lastOld!==undefined&&lastNew!==undefined?(lastNew-lastOld):undefined;
const initialAbiCorrect=initialR1!==undefined&&stackTop!==undefined&&initialR1===stackTop;
const crossedGuard=stackCrossing!==undefined&&stackCrossing>0&&memory?.faultCode===1;
const isR1Fault=memory?.ra===1&&ea!==undefined&&fault!==undefined&&ea===fault;
const writeWindow=memory?.codeWindows?.r1Write||[];
const writeInstruction=writeWindow.find(row=>row.current);
const writes=trace.writeHistory||[],calls=trace.callHistory||[];
const lastCall=calls.length?calls[calls.length-1]:undefined;
const tailCall=lastCall&&(((number(lastCall.flags)||0)&2)!==0)?lastCall:undefined;
const unresolvedTail=cpu?.runtimeBoundary==='unresolved-guest-call'&&number(cpu?.executionBlockerKind)===2&&number(cpu?.executionBlockerOpcode)===0&&!!tailCall;
const unsupportedTail=cpu?.runtimeBoundary==='unsupported-hir'&&number(cpu?.executionBlockerKind)===1&&!!tailCall;
const entryAddress=number(cpu?.entry),blockerAddress=number(cpu?.executionBlockerAddress);
const indexedEntryZero=!!memory?.faultCode&&fault===0&&memory?.instructionKind==='x-form-memory'&&
entryAddress!==undefined&&blockerAddress===((entryAddress+4)>>>0)&&
number(memory?.baseRegisterValue)===0&&number(memory?.indexRegisterValue)===0;
if(indexedEntryZero){
const ra=number(memory?.ra),rb=number(memory?.rb);
const selected=cpu?.entry,xex=cpu?.xexEntry,pe=cpu?.peEntry;
const xexMatches=present(selected)&&present(xex)&&selected===xex;
const peMatches=present(selected)&&present(pe)&&selected===pe;
return compact({
classification:'TITLE_ENTRY_INDEXED_ZERO_DEPENDENCY',
headline:`XEX-selected entry immediately dereferenced r${ra??'A'}+r${rb??'B'}=0`,
primarySuspect:cpu?.executionBlockerAddress,
initialAbiCorrect,
faultDerivedFromBaseRegister:true,
entryProvenance:compact({selected,xex,pe,source:cpu?.entrySource,xexMatchesSelected:xexMatches,peMatchesSelected:peMatches}),
evidence:[
`Failing PPC: ${memory?.blockerDecoded||'indexed memory load'} at ${cpu?.executionBlockerAddress||'—'}, only +0x4 from selected entry ${cpu?.entry||'—'}.`,
`Live blocker snapshot: r${ra??'A'}=${memory?.baseRegisterValue||'—'}, r${rb??'B'}=${memory?.indexRegisterValue||'—'} → effective address ${memory?.effectiveAddress||memory?.faultAddress||'—'}.`,
`Entry provenance: selected=${selected||'—'} XEX=${xex||'—'} PE=${pe||'—'} source=${cpu?.entrySource||'—'}.`,
'V64 strict zero-page behavior exposed this before the later call/epilogue chain; the V63 +0x100 stack failure is downstream evidence, not the first blocker.',
initialAbiCorrect?`Entry r1 remains correct: ${trace.initialR1} == stackTop ${memory.stackTop}.`:undefined,
].filter(Boolean),
ruledOut:[
initialAbiCorrect?'Initial stack reservation / stackTop mismatch':undefined,
'Synthesizing r11/r29 startup values without proof',
'Making 0x00000000-0x0000FFFF writable or zero-filled',
'The later +0x100 teardown as the first failure',
number(kernel?.calls)===0?'XAM/xboxkrnl HLE as the current cause (kernel calls = 0)':undefined,
gpu?.ringInitialized===false||gpu?.reason==='ring-not-initialized'?'GPU/ring path as the current cause (CPU stops first)':undefined,
].filter(Boolean),
next:[
'Reconcile XEX optional-header entry, PE AddressOfEntryPoint, and the prepared executable bytes mapped at the selected entry.',
'If XEX and PE entries differ, inspect why the selected XEX entry starts with an indexed load requiring pre-existing registers; if they match, audit prepared-image section placement/decompression at that address.',
'Keep the strict zero guard and verified r1/LR ABI unchanged while proving image/entry parity.',
],
runtime:runtimeAsset?.verified?compact({sourceCommit:runtimeAsset.sourceCommit,sourceRun:runtimeAsset.sourceRun,sha256:runtimeAsset.sha256}):undefined,
cpuCheckpoint:compact({entry:cpu?.entry,instructions:cpu?.instructions,blockerAddress:cpu?.executionBlockerAddress,blockerOpcode:cpu?.executionBlockerOpcode}),
});
}
const lowApertureFault=!!memory?.faultCode&&fault!==undefined&&fault<0x10000&&
(memory?.instructionKind==='d-form-memory'||memory?.instructionKind==='ds-form-memory')&&number(memory?.baseRegisterValue)===0;
if(lowApertureFault){
const baseReg=number(memory?.ra);
return compact({
classification:'XENIA_ZERO_APERTURE_STATE_MISSING',
headline:`guest memory reached Xenia-protected low memory through r${baseReg??'A'}=0`,
primarySuspect:cpu?.executionBlockerAddress,
initialAbiCorrect,
faultDerivedFromBaseRegister:true,
evidence:[
`Failing PPC: ${memory?.blockerDecoded||'memory instruction'} at ${cpu?.executionBlockerAddress||'—'}.`,
`Effective address ${memory?.effectiveAddress||memory?.faultAddress||'—'} came from r${baseReg??'A'}=${memory?.baseRegisterValue||'0x00000000'} plus displacement ${memory?.displacement??'—'}.`,
`The access is inside 0x00000000-0x0000FFFF. V64 intentionally leaves that aperture inaccessible instead of returning synthetic zero data.`,
initialAbiCorrect?`Entry r1 remains correct: ${trace.initialR1} == stackTop ${memory.stackTop}.`:undefined,
].filter(Boolean),
ruledOut:[
initialAbiCorrect?'Initial stack reservation / stackTop mismatch':undefined,
'The later +0x100 teardown as the first cause; V63 proved it was downstream of this masked state path',
'Making low memory writable as a compatibility fix',
number(kernel?.calls)===0?'XAM/xboxkrnl HLE as the current cause (kernel calls = 0)':undefined,
gpu?.ringInitialized===false||gpu?.reason==='ring-not-initialized'?'GPU/ring path as the current cause (CPU stops first)':undefined,
].filter(Boolean),
next:[
`Trace why live r${baseReg??'A'} is zero at ${cpu?.executionBlockerAddress||'this instruction'} and restore the missing Xenia loader/title startup state.`,
'Keep 0x00000000-0x0000FFFF inaccessible; do not reintroduce a zero-filled low-memory aperture.',
'Do not change the verified r1/stackTop geometry while fixing this register/runtime-state dependency.',
],
runtime:runtimeAsset?.verified?compact({sourceCommit:runtimeAsset.sourceCommit,sourceRun:runtimeAsset.sourceRun,sha256:runtimeAsset.sha256}):undefined,
cpuCheckpoint:compact({entry:cpu?.entry,instructions:cpu?.instructions,blockerAddress:cpu?.executionBlockerAddress,blockerOpcode:cpu?.executionBlockerOpcode}),
});
}
if(unresolvedTail){
const stackHealthy=present(trace.lastNewR1)&&present(memory?.stackTop)&&trace.lastNewR1===memory.stackTop;
const timeline=[...writes.map(event=>({kind:'r1',...event})),...calls.map(event=>({kind:'call',...event}))].sort((a,b)=>(number(a.sequence)||0)-(number(b.sequence)||0)).map(event=>event.kind==='call'
?`#${event.sequence} CALL d${event.depth} ${event.source} → ${event.target} r1=${event.r1} flags=0x${(number(event.flags)||0).toString(16).toUpperCase()}`
:`#${event.sequence} r1 d${event.depth} ${event.address} ${event.oldR1} → ${event.newR1} (${hexDelta((number(event.newR1)||0)-(number(event.oldR1)||0))})`);
return compact({
classification:'CPU_RUNTIME_BLOCKER',
headline:'CPU execution stopped at an unresolved tail target',
tailTarget:tailCall.target,
tailSource:tailCall.source,
reason:'HIR interior entry unavailable',
stackState:stackHealthy?`Healthy · restored to ${memory.stackTop}`:`r1=${trace.lastNewR1||trace.lastCallR1||'—'}`,
primarySuspect:cpu.executionBlockerAddress,
initialAbiCorrect,
callEdge:`${tailCall.source} -> ${tailCall.target}`,
historyReady:writes.length>0&&calls.length>0,
timeline,
evidence:[
`Tail branch reached ${tailCall.target} from ${tailCall.source} with flags=0x${(number(tailCall.flags)||0).toString(16).toUpperCase()}.`,
`Runtime boundary is unresolved-guest-call with blocker opcode 0; the PPC instruction at ${cpu.executionBlockerAddress} has not been proven to execute.`,
`No sparse-memory fault was captured (faultCode ${memory?.faultCode??'—'}).`,
stackHealthy?`Stack is balanced at the boundary: ${trace.lastNewR1} == stackTop ${memory.stackTop}.`:undefined,
].filter(Boolean),
ruledOut:[
initialAbiCorrect?'Initial stack reservation / stackTop mismatch':undefined,
stackHealthy?'The completed inner/outer r1 teardown as the current cause':undefined,
'A guest-memory fault at the displayed target instruction',
number(kernel?.calls)===0?'XAM/xboxkrnl HLE as the current cause (kernel calls = 0)':undefined,
gpu?.ringInitialized===false||gpu?.reason==='ring-not-initialized'?'GPU/ring path as the current cause (CPU stops first)':undefined,
].filter(Boolean),
next:[
`Retry ${tailCall.target} as an exact target-rooted PPC fragment bounded by its owning .pdata end.`,
'Do not resume at the nearest earlier or later SOURCE_OFFSET; preserve exact PPC side effects.',
'Do not modify the balanced stack restore and do not map address 0 writable.',
],
runtime:runtimeAsset?.verified?compact({sourceCommit:runtimeAsset.sourceCommit,sourceRun:runtimeAsset.sourceRun,sha256:runtimeAsset.sha256}):undefined,
cpuCheckpoint:compact({entry:cpu?.entry,instructions:cpu?.instructions,blockerAddress:cpu?.executionBlockerAddress,blockerOpcode:cpu?.executionBlockerOpcode}),
});
}
if(unsupportedTail){
const stackHealthy=present(trace.lastNewR1)&&present(memory?.stackTop)&&trace.lastNewR1===memory.stackTop;
const timeline=[...writes.map(event=>({kind:'r1',...event})),...calls.map(event=>({kind:'call',...event}))].sort((a,b)=>(number(a.sequence)||0)-(number(b.sequence)||0)).map(event=>event.kind==='call'
?`#${event.sequence} CALL d${event.depth} ${event.source} → ${event.target} r1=${event.r1} flags=0x${(number(event.flags)||0).toString(16).toUpperCase()}`
:`#${event.sequence} r1 d${event.depth} ${event.address} ${event.oldR1} → ${event.newR1} (${hexDelta((number(event.newR1)||0)-(number(event.oldR1)||0))})`);
return compact({
classification:'CPU_RUNTIME_BLOCKER',
headline:`CPU execution stopped on unsupported HIR${hir?.opcodeName?`: ${hir.opcodeName}`:''} in a tail fragment`,
tailTarget:tailCall.target,
tailSource:tailCall.source,
reason:`${hir?.opcodeName?`${hir.opcodeName} (opcode ${cpu.executionBlockerOpcode??'—'})`:`HIR opcode ${cpu.executionBlockerOpcode??'—'}`} failed in the compatibility executor`,
stackState:stackHealthy?`Healthy · restored to ${memory.stackTop}`:`r1=${trace.lastNewR1||trace.lastCallR1||'—'}`,
primarySuspect:cpu.executionBlockerAddress,
initialAbiCorrect,
callEdge:`${tailCall.source} -> ${tailCall.target}`,
historyReady:writes.length>0&&calls.length>0,
timeline,
evidence:[
`Tail fragment reached ${tailCall.target} from ${tailCall.source}.`,
`Compatibility HIR stopped on ${hir?.opcodeName?`${hir.opcodeName} (opcode ${cpu.executionBlockerOpcode??'—'})`:`opcode ${cpu.executionBlockerOpcode??'—'}`} at ${cpu.executionBlockerAddress}; this is not a sparse-memory fault.`,
hir?.recommendedLane?`Adaptive HIR lane: ${hir.recommendedLane}. Executor support=${hir.executorSupportsCurrent??'unknown'}; generated-Wasm support=${hir.wasmSupportsCurrent??'unknown'}.`:undefined,
`No sparse-memory fault was captured (faultCode ${memory?.faultCode??'—'}).`,
stackHealthy?`Stack is balanced at the boundary: ${trace.lastNewR1} == stackTop ${memory.stackTop}.`:undefined,
].filter(Boolean),
ruledOut:[
initialAbiCorrect?'Initial stack reservation / stackTop mismatch':undefined,
stackHealthy?'The completed r1 teardown as the current cause':undefined,
'A guest-memory fault at the displayed PPC instruction',
number(kernel?.calls)===0?'XAM/xboxkrnl HLE as the current cause (kernel calls = 0)':undefined,
gpu?.ringInitialized===false||gpu?.reason==='ring-not-initialized'?'GPU/ring path as the current cause (CPU stops first)':undefined,
].filter(Boolean),
next:[
`Resolve ${hir?.opcodeName?`${hir.opcodeName} (HIR ${cpu.executionBlockerOpcode??'—'})`:`HIR opcode ${cpu.executionBlockerOpcode??'—'}`} using Xenia semantics and proven live-context provenance at ${cpu.executionBlockerAddress}.`,
hir?.recommendedLane?`Implement the ${hir.recommendedLane} lane indicated by the runtime support matrix instead of waiting for another one-off blocker.`:undefined,
'Do not alter the balanced stack restore or map address 0 writable.',
],
runtime:runtimeAsset?.verified?compact({sourceCommit:runtimeAsset.sourceCommit,sourceRun:runtimeAsset.sourceRun,sha256:runtimeAsset.sha256}):undefined,
cpuCheckpoint:compact({entry:cpu?.entry,instructions:cpu?.instructions,blockerAddress:cpu?.executionBlockerAddress,blockerOpcode:cpu?.executionBlockerOpcode}),
});
}
// A kernel import boundary is not a sparse-memory fault. Prefer the exact
// guest-visible HLE service over stale stack-history heuristics so the
// problem-first console names the service the title actually reached.
if(cpu?.runtimeBoundary==='kernel-import-unimplemented'&&kernel?.reachedBlocker){
const service=kernel.reachedBlocker;
const moduleName=service.module||'kernel';
const ordinal=service.ordinal||'unknown ordinal';
return compact({
classification:'KERNEL_IMPORT_BLOCKER',
headline:`Xbox kernel service ${moduleName} ${ordinal} is not implemented`,
primarySuspect:cpu?.executionBlockerAddress,
serviceModule:moduleName,
serviceOrdinal:ordinal,
serviceCalls:kernel?.calls,
initialAbiCorrect,
callEdge:trace.lastCallSource&&trace.lastCallTarget?`${trace.lastCallSource} -> ${trace.lastCallTarget}`:undefined,
evidence:[
`Runtime boundary is kernel-import-unimplemented at ${cpu?.executionBlockerAddress||'—'}.`,
`Guest reached ${moduleName} ordinal ${ordinal}; kernel calls=${kernel?.calls??'—'}.`,
memory?.faultCode===0?'No sparse guest-memory fault was captured for this boundary.':undefined,
memory?.faultCapturedAtExecution===false?'The displayed memory fault address is diagnostic history, not an execution-captured fault.':undefined,
initialAbiCorrect?`Entry r1 remains correct: ${trace.initialR1} == stackTop ${memory.stackTop}.`:undefined,
].filter(Boolean),
ruledOut:[
memory?.faultCode===0?'Guest-memory boundary as the active stop reason':undefined,
initialAbiCorrect?'Initial stack reservation / stackTop mismatch':undefined,
gpu?.ringInitialized===false||gpu?.reason==='ring-not-initialized'?'GPU/ring path as the current cause (CPU stops first)':undefined,
].filter(Boolean),
next:[
`Resolve ${moduleName} ${ordinal} from Xenia's kernel export table and implement its guest-visible semantics.`,
'Keep sparse-memory guards and the verified stack ABI unchanged unless a later captured fault proves otherwise.',
],
runtime:runtimeAsset?.verified?compact({sourceCommit:runtimeAsset.sourceCommit,sourceRun:runtimeAsset.sourceRun,sha256:runtimeAsset.sha256}):undefined,
cpuCheckpoint:compact({entry:cpu?.entry,instructions:cpu?.instructions,blockerAddress:cpu?.executionBlockerAddress,blockerOpcode:cpu?.executionBlockerOpcode}),
});
}
const suspectWrite=[...writes].reverse().find(event=>event.address===trace.lastWriteAddress&&event.newR1===trace.lastNewR1)||writes.at(-1);
const suspectSequence=number(suspectWrite?.sequence),suspectDepth=number(suspectWrite?.depth)??number(trace.lastWriteDepth);
const enteringCall=suspectDepth===undefined?undefined:[...calls].reverse().find(event=>number(event.depth)===suspectDepth-1&&(suspectSequence===undefined||number(event.sequence)<suspectSequence));
const sameOwner=(a,b)=>!!(a?.begin&&b?.begin&&a.begin===b.begin&&a.end===b.end);
const frameEntrySameOwner=!!enteringCall&&sameOwner(enteringCall.sourceOwner,enteringCall.targetOwner);
const immediateCall=calls.length?calls[calls.length-1]:undefined;
const immediateTailSameOwner=!!immediateCall&&(((number(immediateCall.flags)||0)&2)!==0)&&sameOwner(immediateCall.sourceOwner,immediateCall.targetOwner);
const frameEntryCrossPdataInterior=!!enteringCall&&(((number(enteringCall.flags)||0)&2)!==0)&&!!enteringCall.sourceOwner?.begin&&!!enteringCall.targetOwner?.begin&&!frameEntrySameOwner&&Number(enteringCall.targetOwner.offset||0)>0;
const immediateCrossPdataInterior=!!immediateCall&&(((number(immediateCall.flags)||0)&2)!==0)&&!!immediateCall.sourceOwner?.begin&&!!immediateCall.targetOwner?.begin&&!immediateTailSameOwner&&Number(immediateCall.targetOwner.offset||0)>0;
const frameWrites=writes.filter(event=>{
const seq=number(event.sequence),depth=number(event.depth);
return depth===suspectDepth&&(!enteringCall||seq>number(enteringCall.sequence))&&(suspectSequence===undefined||seq<=suspectSequence);
});
const frameDeltas=frameWrites.map(event=>({event,delta:(number(event.newR1)-number(event.oldR1))})).filter(item=>Number.isFinite(item.delta));
const matchingAllocation=r1WriteDelta>0?[...frameDeltas].reverse().find(item=>item.delta===-r1WriteDelta&&item.event.address!==trace.lastWriteAddress):undefined;
const historyReady=writes.length>0&&calls.length>0;
const missingAllocation=historyReady&&r1WriteDelta>0&&suspectDepth>1&&!!enteringCall&&!matchingAllocation;
const classification=missingAllocation&&(frameEntrySameOwner||immediateTailSameOwner)
?'SAME_PDATA_TAIL_FRAME_SPLIT'
:missingAllocation&&(frameEntryCrossPdataInterior||immediateCrossPdataInterior)
?'CROSS_PDATA_INTERIOR_TAIL_STACK_MISMATCH'
:crossedGuard&&isR1Fault?(missingAllocation?'FRAME_ENTRY_MISSING_PROLOGUE':historyReady?'STACK_BALANCE_OR_EPILOGUE_MISMATCH':'STACK_FRAME_TEARDOWN_MISMATCH'):memory?.faultCode?'GUEST_MEMORY_BOUNDARY':'CPU_RUNTIME_BLOCKER';
const timeline=[...writes.map(event=>({kind:'r1',...event})),...calls.map(event=>({kind:'call',...event}))].sort((a,b)=>(number(a.sequence)||0)-(number(b.sequence)||0)).map(event=>event.kind==='call'
?`#${event.sequence} CALL d${event.depth} ${event.source} → ${event.target} r1=${event.r1} flags=0x${(number(event.flags)||0).toString(16).toUpperCase()}`
:`#${event.sequence} r1 d${event.depth} ${event.address} ${event.oldR1} → ${event.newR1} (${hexDelta((number(event.newR1)||0)-(number(event.oldR1)||0))})`);
const evidence=[
initialAbiCorrect?`Entry r1 is correct: ${trace.initialR1} == stackTop ${memory.stackTop}.`:undefined,
r1WriteDelta!==undefined?`Last r1 write: ${trace.lastWriteAddress} moved ${trace.lastOldR1} → ${trace.lastNewR1} (${hexDelta(r1WriteDelta)}).`:undefined,
writeInstruction?`Instruction at last r1 write: ${writeInstruction.word} · ${writeInstruction.decoded||writeInstruction.kind}.`:undefined,
crossedGuard?`At the blocker r1 is ${hexDelta(stackCrossing)} above stackBase ${memory.stackBase}.`:undefined,
faultIntoGuard!==undefined&&faultIntoGuard>=0?`Fault address ${memory.faultAddress} is ${hexDelta(faultIntoGuard)} into the protected upper stack guard.`:undefined,
isR1Fault?`Fault equation: ${memory.baseRegisterValue} + (${memory.displacement}) = ${memory.effectiveAddress}.`:undefined,
frameEntrySameOwner?`Frame-entry tail ${enteringCall.source} → ${enteringCall.target} stays inside .pdata owner ${enteringCall.sourceOwner.begin}-${enteringCall.sourceOwner.end}; target offset +0x${Number(enteringCall.targetOwner.offset||0).toString(16).toUpperCase()}.`:undefined,
immediateTailSameOwner?`Immediate tail ${immediateCall.source} → ${immediateCall.target} stays inside .pdata owner ${immediateCall.sourceOwner.begin}-${immediateCall.sourceOwner.end}; the synthetic fragment boundary can therefore change an internal branch into CALL_TAIL.`:undefined,
frameEntryCrossPdataInterior?`Frame-entry tail ${enteringCall.source} → ${enteringCall.target} crosses .pdata ${enteringCall.sourceOwner.begin}-${enteringCall.sourceOwner.end} → ${enteringCall.targetOwner.begin}-${enteringCall.targetOwner.end} and lands +0x${Number(enteringCall.targetOwner.offset||0).toString(16).toUpperCase()} inside the target record; the V59 same-owner split hypothesis is ruled out for this edge.`:undefined,
immediateCrossPdataInterior?`Immediate tail ${immediateCall.source} → ${immediateCall.target} crosses .pdata ${immediateCall.sourceOwner.begin}-${immediateCall.sourceOwner.end} → ${immediateCall.targetOwner.begin}-${immediateCall.targetOwner.end} and lands +0x${Number(immediateCall.targetOwner.offset||0).toString(16).toUpperCase()} inside the target record.`:undefined,
enteringCall?.targetOwner?`Frame-entry target owner ${enteringCall.targetOwner.begin}-${enteringCall.targetOwner.end} prologue=${enteringCall.targetOwner.prologBytes??'—'} bytes offset=+0x${Number(enteringCall.targetOwner.offset||0).toString(16).toUpperCase()}.`:undefined,
trace.lastCallSource&&trace.lastCallTarget?`Immediate call edge: ${trace.lastCallSource} → ${trace.lastCallTarget}, depth ${trace.lastCallDepth??'—'}, r1=${trace.lastCallR1||'—'}.`:undefined,
historyReady&&enteringCall?`Frame-entry call for depth ${suspectDepth}: ${enteringCall.source} → ${enteringCall.target} with r1=${enteringCall.r1}.`:undefined,
historyReady&&matchingAllocation?`Matching frame allocation found at ${matchingAllocation.event.address}: ${matchingAllocation.event.oldR1} → ${matchingAllocation.event.newR1} (${hexDelta(matchingAllocation.delta)}).`:undefined,
missingAllocation?`No ${hexDelta(-r1WriteDelta)} r1 allocation was observed in depth ${suspectDepth} after its entry call and before the ${hexDelta(r1WriteDelta)} teardown.`:undefined,
].filter(Boolean);
const ruledOut=[
initialAbiCorrect?'Initial stack reservation / stackTop mismatch':undefined,
crossedGuard?'Mapping or clamping the upper guard page (guard violation is real evidence)':undefined,
number(kernel?.calls)===0?'XAM/xboxkrnl HLE as the current cause (kernel calls = 0)':undefined,
gpu?.ringInitialized===false||gpu?.reason==='ring-not-initialized'?'GPU/ring path as the current cause (CPU stops first)':undefined,
].filter(Boolean);
const next=[
missingAllocation&&(frameEntryCrossPdataInterior||immediateCrossPdataInterior)?`Inspect memory.tailCallDiagnostics for the cross-.pdata tail chain. Compare each source window with the source-owner prologue and each target window with the target-owner prologue; specifically look for an update-form stack allocation (stdu/stwu r1,-0x100) that the live path bypassed.`:missingAllocation&&enteringCall?`Inspect the translated function entered at ${enteringCall.target}; the runtime reached its +0x100 teardown without recording a -0x100 r1 allocation in that frame.`:trace.lastWriteAddress?`Inspect the frame teardown at ${trace.lastWriteAddress}; determine whether its positive r1 restore has a matching earlier allocation in the same guest frame.`:undefined,
historyReady&&matchingAllocation?`A matching allocation exists, so inspect intervening r1 writes/branches for a duplicate restore or wrong shared epilogue.`:trace.lastCallSource?`Verify function/shared-epilogue classification around ${trace.lastCallSource} and the target ${trace.lastCallTarget||'—'}.`:undefined,
`Do not synthesize a -0x100 frame and do not patch ${memory?.faultAddress||'the fault address'} writable; preserve Xenia's stack guard until the exact skipped/incorrect control-flow edge is proven.`,
].filter(Boolean);
return compact({
classification,
headline:missingAllocation&&(frameEntrySameOwner||immediateTailSameOwner)?`same .pdata owner tail split reached a ${hexDelta(r1WriteDelta)} teardown without its frame allocation`:missingAllocation&&(frameEntryCrossPdataInterior||immediateCrossPdataInterior)?`cross-.pdata interior tail chain reached a ${hexDelta(r1WriteDelta)} teardown without a live matching allocation`:missingAllocation?`depth ${suspectDepth} reached a ${hexDelta(r1WriteDelta)} epilogue without its matching allocation`:crossedGuard?'r1 crossed the Xenia stack base before the restore load':'CPU execution stopped at a guest-memory boundary',
primarySuspect:trace.lastWriteAddress,
primarySuspectInstruction:writeInstruction,
stackCrossingBytes:stackCrossing,
r1WriteDelta,
faultIntoGuardBytes:faultIntoGuard,
initialAbiCorrect,
faultDerivedFromR1:isR1Fault,
callEdge:trace.lastCallSource&&trace.lastCallTarget?`${trace.lastCallSource} -> ${trace.lastCallTarget}`:undefined,
historyReady,missingAllocation,ownerTopology:compact({frameEntrySameOwner,immediateTailSameOwner,frameEntryCrossPdataInterior,immediateCrossPdataInterior,frameEntrySource:enteringCall?.sourceOwner,frameEntryTarget:enteringCall?.targetOwner,immediateSource:immediateCall?.sourceOwner,immediateTarget:immediateCall?.targetOwner}),tailPath:memory?.tailCallDiagnostics,frameEntryCall:enteringCall,matchingAllocation:matchingAllocation?.event,
timeline,evidence,ruledOut,next,
runtime:runtimeAsset?.verified?compact({sourceCommit:runtimeAsset.sourceCommit,sourceRun:runtimeAsset.sourceRun,sha256:runtimeAsset.sha256}):undefined,
cpuCheckpoint:compact({entry:cpu?.entry,instructions:cpu?.instructions,blockerAddress:cpu?.executionBlockerAddress,blockerOpcode:cpu?.executionBlockerOpcode}),
});
}
function addEntry(level,message){
if(!enabled)return;
const next={at:Date.now(),level:String(level||'info'),message:String(message||'')};
const previous=entries.at(-1);
if(previous&&previous.level===next.level&&previous.message===next.message){previous.at=next.at;previous.count=(previous.count||1)+1;}
else entries.push(next);
if(entries.length>MAX_LOGS)entries.splice(0,entries.length-MAX_LOGS);
render();
}
function eventHandler(event){
if(!enabled)return;
const type=event.type.replace('render360:',''),detail=event.detail||{};
if(type==='runtimeBlocker'||type==='fatalError'||detail?.stage==='blocked')lastBlocker=compactBlocker(detail);
const message=detail.message||detail.reason||detail.stage||type;
addEntry(type==='runtimeBlocker'||type==='fatalError'?'error':detail.level||'info',`${type}: ${message}`);
}
function installListeners(){
if(listenersInstalled)return;listenersInstalled=true;
for(const type of ['bootStage','runtimeBlocker','fatalError','titleStarted','ready','log','framePresented'])globalThis.addEventListener(`render360:${type}`,eventHandler);
globalThis.addEventListener('error',e=>{if(enabled)addEntry('error',`${e.message||'Browser error'}${e.filename?` · ${e.filename.split('/').pop()}:${e.lineno||0}`:''}`);});
globalThis.addEventListener('unhandledrejection',e=>{if(enabled)addEntry('error',`Unhandled promise rejection · ${e.reason?.message||String(e.reason)}`);});
}
function consoleCss(){return `
#r360DevConsole{position:fixed;inset:0;z-index:100000;background:rgba(0,0,0,.72);display:flex;align-items:flex-end}
.r360-dev-panel{width:100%;max-width:100dvw;height:min(92dvh,900px);max-height:calc(100dvh - env(safe-area-inset-top));background:#090a0c;color:#f5f5f7;border-radius:24px 24px 0 0;display:flex;flex-direction:column;overflow:hidden;border:1px solid rgba(255,255,255,.12)}
.r360-dev-head{display:flex;align-items:center;gap:8px;padding:13px 12px 11px;border-bottom:1px solid rgba(255,255,255,.1)}
.r360-dev-title{min-width:0;flex:1}.r360-dev-title b{display:block;font-size:17px}.r360-dev-title small{display:block;color:#8e8e93;font-size:10px;margin-top:1px}
.r360-dev-head button{height:38px;border:0;border-radius:11px;background:#242529;color:#fff;padding:0 11px;font-weight:700;white-space:nowrap}
.r360-dev-body{overflow:auto;-webkit-overflow-scrolling:touch;padding:11px 11px calc(18px + env(safe-area-inset-bottom))}
.r360-focus-card,.r360-dev-section{border:1px solid rgba(255,255,255,.1);border-radius:14px;background:#101114;margin-bottom:10px;overflow:hidden}
.r360-focus-card{border-color:rgba(255,69,58,.42);background:linear-gradient(180deg,rgba(255,69,58,.13),rgba(255,69,58,.06))}
.r360-focus-head{padding:11px 12px;border-bottom:1px solid rgba(255,255,255,.08)}
.r360-focus-kicker{font:700 9px/1.2 ui-monospace,SFMono-Regular,Menlo,monospace;color:#ff6961;letter-spacing:.08em}
.r360-focus-head h3{font-size:15px;line-height:1.25;margin:5px 0 0}
.r360-focus-grid{display:grid;grid-template-columns:1fr 1fr;gap:1px;background:rgba(255,255,255,.07)}
.r360-focus-cell{background:#0e0f12;padding:9px 10px;min-width:0}.r360-focus-cell b{display:block;font-size:9px;color:#8e8e93;text-transform:uppercase;letter-spacing:.05em;margin-bottom:3px}.r360-focus-cell span{display:block;font:11px/1.35 ui-monospace,SFMono-Regular,Menlo,monospace;word-break:break-word}
.r360-dev-section h4{margin:0;padding:9px 11px;border-bottom:1px solid rgba(255,255,255,.07);font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:#aeaeb2}
.r360-bullet-list{margin:0;padding:8px 11px 9px 25px;font:10.5px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace}.r360-bullet-list li{margin:3px 0}
.r360-code-window{padding:7px 8px;font:10px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace}
.r360-code-row{display:grid;grid-template-columns:76px 86px minmax(0,1fr);gap:6px;padding:3px 4px;border-radius:6px}.r360-code-row.current{background:rgba(255,214,10,.12);outline:1px solid rgba(255,214,10,.22)}.r360-code-row .addr{color:#64d2ff}.r360-code-row .word{color:#aeaeb2}.r360-code-row .decoded{word-break:break-word}
.r360-dev-note{padding:8px 10px;color:#8e8e93;font-size:10px;line-height:1.35}
.r360-dev-details{border:1px solid rgba(255,255,255,.09);border-radius:13px;overflow:hidden;background:#0d0e10}.r360-dev-details summary{padding:10px 11px;font-size:11px;font-weight:700;cursor:pointer}
.r360-dev-log{font:10px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace;border-top:1px solid rgba(255,255,255,.07)}
.r360-dev-line{display:grid;grid-template-columns:64px 42px minmax(0,1fr);gap:6px;padding:7px 8px;border-bottom:1px solid rgba(255,255,255,.06)}.r360-dev-line:last-child{border-bottom:0}.r360-dev-line time{color:#6e6e73}.r360-dev-line strong{font-size:9px;color:#64d2ff}.r360-dev-line.error strong{color:#ff453a}.r360-dev-line.warn strong{color:#ffd60a}.r360-dev-line span{white-space:pre-wrap;word-break:break-word}
.r360-console-fab{position:absolute;z-index:80;left:50%;top:max(6px,env(safe-area-inset-top));transform:translateX(-50%);width:48px;height:42px;border-radius:14px;border:1px solid rgba(255,255,255,.2);background:rgba(20,20,22,.72);color:#fff;font:700 12px ui-monospace,SFMono-Regular,Menlo,monospace}
.r360-dev-settings-row .console-mark{color:#0a84ff;font:700 12px ui-monospace,SFMono-Regular,Menlo,monospace}
#r360DevConsole.hidden{display:none!important}
@media(max-width:390px){.r360-dev-head{gap:6px}.r360-dev-title small{display:none}.r360-dev-head button{padding:0 9px;font-size:12px}.r360-focus-grid{grid-template-columns:1fr}.r360-code-row{grid-template-columns:70px 82px minmax(0,1fr)}}
`;}
function ensureUi(){
if(!$('r360DevConsoleStyle')){const s=document.createElement('style');s.id='r360DevConsoleStyle';s.textContent=consoleCss();document.head.appendChild(s);}
if(!$('r360DevConsole')){
const root=document.createElement('section');root.id='r360DevConsole';root.className='hidden';
root.innerHTML='<div class="r360-dev-panel"><div class="r360-dev-head"><div class="r360-dev-title"><b>Braid CPU Diagnostic</b><small>Problem-first developer console</small></div><button id="r360DevCopy" type="button">Copy Report</button><button id="r360DevClose" type="button">Done</button></div><div class="r360-dev-body"><div id="r360DevFocus"></div><details id="r360DevFullLog" class="r360-dev-details"><summary id="r360DevLogSummary">Full event log</summary><div id="r360DevLog" class="r360-dev-log"></div></details></div></div>';
document.body.appendChild(root);
root.addEventListener('click',e=>{if(e.target===root)closeConsole();});
$('r360DevClose').onclick=closeConsole;$('r360DevCopy').onclick=copyReport;
}
installEntryPoints();render();
}
function installEntryPoints(){
const stage=document.querySelector('.runtime-stage');
if(stage&&!$('r360RuntimeConsole')){const b=document.createElement('button');b.id='r360RuntimeConsole';b.type='button';b.className='r360-console-fab';b.textContent='>_';b.onclick=openConsole;stage.appendChild(b);}
const anchor=$('appDiagnosticsButton');
if(anchor&&!$('appDeveloperConsoleButton')){const b=document.createElement('button');b.id='appDeveloperConsoleButton';b.type='button';b.className='row row-button r360-dev-settings-row';b.innerHTML='<span>Developer Console</span><span class="console-mark">>_</span>';b.onclick=openConsole;anchor.after(b);}
}
function removeEntryPoints(){$('r360RuntimeConsole')?.remove();$('appDeveloperConsoleButton')?.remove();$('r360DevConsole')?.classList.add('hidden');opened=false;}
function appendTextList(parent,title,items){
if(!items?.length)return;
const section=document.createElement('section');section.className='r360-dev-section';
const heading=document.createElement('h4');heading.textContent=title;section.appendChild(heading);
const ul=document.createElement('ul');ul.className='r360-bullet-list';
for(const item of items){const li=document.createElement('li');li.textContent=item;ul.appendChild(li);}
section.appendChild(ul);parent.appendChild(section);
}
function appendCodeWindow(parent,title,rows){
if(!rows?.length)return;
const section=document.createElement('section');section.className='r360-dev-section';
const heading=document.createElement('h4');heading.textContent=title;section.appendChild(heading);
const body=document.createElement('div');body.className='r360-code-window';
for(const row of rows){
const line=document.createElement('div');line.className=`r360-code-row${row.current?' current':''}`;
for(const [cls,text] of [['addr',row.address],['word',row.word],['decoded',row.decoded||row.kind||'—']]){
const span=document.createElement('span');span.className=cls;span.textContent=text||'—';line.appendChild(span);
}
body.appendChild(line);
}
section.appendChild(body);parent.appendChild(section);
}
function focusCell(label,value){
const cell=document.createElement('div');cell.className='r360-focus-cell';
const b=document.createElement('b');b.textContent=label;const span=document.createElement('span');span.textContent=value||'—';
cell.append(b,span);return cell;
}
function renderFocus(summary){
const root=$('r360DevFocus');if(!root)return;root.innerHTML='';
const focus=summary.problemFocus||{};
if(!summary.blocker&&!summary.cpu?.entry){
const empty=document.createElement('section');empty.className='r360-dev-section';
empty.innerHTML='<div class="r360-dev-note">No CPU blocker captured yet. Start Braid, then reopen this console.</div>';root.appendChild(empty);return;
}
const card=document.createElement('section');card.className='r360-focus-card';
const head=document.createElement('div');head.className='r360-focus-head';
const kicker=document.createElement('div');kicker.className='r360-focus-kicker';kicker.textContent=focus.classification||'CURRENT CPU BLOCKER';
const title=document.createElement('h3');title.textContent=focus.headline||summary.blocker?.message||'Braid execution blocked';
head.append(kicker,title);card.appendChild(head);
const grid=document.createElement('div');grid.className='r360-focus-grid';
if(focus.classification==='KERNEL_IMPORT_BLOCKER'){
grid.append(
focusCell('Kernel service',`${focus.serviceModule||summary.kernel?.reachedBlocker?.module||'—'} · ${focus.serviceOrdinal||summary.kernel?.reachedBlocker?.ordinal||'—'}`),
focusCell('Runtime boundary',summary.cpu?.runtimeBoundary||'—'),
focusCell('Call site',focus.primarySuspect||summary.cpu?.executionBlockerAddress||'—'),
focusCell('Kernel calls',`${focus.serviceCalls??summary.kernel?.calls??'—'}`),
focusCell('Failing PPC',`${summary.memory?.blockerInstruction||'—'} · ${summary.memory?.blockerDecoded||ppcDiagnosticSummary(summary.memory)||'—'}`),
focusCell('Progress',`${summary.cpu?.instructions??'—'} instructions · HIR ${summary.cpu?.hir??'—'}`)
);
}else if(focus.tailTarget){
grid.append(
focusCell('Tail target',focus.tailTarget),
focusCell('Source',focus.tailSource||'—'),
focusCell('Reason',focus.reason||'HIR interior entry unavailable'),
focusCell('Stack',focus.stackState||'—'),
focusCell('HIR opcode',summary.hir?.opcodeName?`${summary.hir.opcodeName} (${summary.hir.opcode??'—'})`:`${summary.hir?.opcode??'—'}`),
focusCell('HIR support',`${summary.hir?.executorSupportsCurrent===true?'executor ✓':summary.hir?.executorSupportsCurrent===false?'executor ✗':'executor —'} · ${summary.hir?.wasmSupportsCurrent===true?'Wasm ✓':summary.hir?.wasmSupportsCurrent===false?'Wasm ✗':'Wasm —'}`),
focusCell('Target PPC',`${summary.memory?.blockerInstruction||'—'} · ${summary.memory?.blockerDecoded||ppcDiagnosticSummary(summary.memory)||'—'}`),
focusCell('Coverage',summary.hir?.totalOpcodes?`oracle ${summary.hir.executorSupported??'—'}/${summary.hir.totalOpcodes} · Wasm ${summary.hir.wasmSupported??'—'}/${summary.hir.totalOpcodes}`:'—'),
focusCell('Progress',`${summary.cpu?.instructions??'—'} instructions · HIR ${summary.cpu?.hir??'—'}`)
);
}else{
grid.append(
focusCell('First suspect',focus.primarySuspect||summary.memory?.stackTrace?.lastWriteAddress),
focusCell('r1 change',focus.r1WriteDelta!==undefined?`${summary.memory?.stackTrace?.lastOldR1||'—'} → ${summary.memory?.stackTrace?.lastNewR1||'—'} (${hexDelta(focus.r1WriteDelta)})`:'—'),
focusCell('Fault',`${summary.memory?.faultName||'—'} @ ${summary.memory?.faultAddress||'—'}`),
focusCell('Failing PPC',`${summary.memory?.blockerInstruction||'—'} · ${summary.memory?.blockerDecoded||ppcDiagnosticSummary(summary.memory)||'—'}`),
focusCell('Call edge',focus.callEdge||'—'),
focusCell('Progress',`${summary.cpu?.instructions??'—'} instructions · HIR ${summary.cpu?.hir??'—'}`)
);
}
card.appendChild(grid);root.appendChild(card);
if(summary.hir?.totalOpcodes){
appendTextList(root,'HIR coverage',[
`Current: ${summary.hir.opcodeName||'unknown'} · opcode ${summary.hir.opcode??'—'} · adaptive lane ${summary.hir.recommendedLane||'—'}.`,
`Compatibility oracle: ${summary.hir.executorSupported??'—'}/${summary.hir.totalOpcodes} opcodes (${summary.hir.executorCoveragePercent??'—'}%).`,
`Generated-Wasm scalar backend: ${summary.hir.wasmSupported??'—'}/${summary.hir.totalOpcodes} opcodes (${summary.hir.wasmCoveragePercent??'—'}%).`,
`Callable title functions: ${summary.cpu?.translatedFunctions??0} translated · first ${summary.cpu?.firstTranslatedFunction||'—'}.`,
]);
}
appendTextList(root,'Evidence',focus.evidence);
appendTextList(root,'Stack / call timeline',focus.timeline);
appendCodeWindow(root,'PPC around title entry',summary.memory?.codeWindows?.entry);
appendCodeWindow(root,'PPC around last r1 write',summary.memory?.codeWindows?.r1Write);
appendCodeWindow(root,'PPC around call site',summary.memory?.codeWindows?.callSite);
appendCodeWindow(root,focus.tailTarget?'PPC around unresolved tail target':'PPC around fault',summary.memory?.codeWindows?.blocker);
appendTextList(root,'Ruled out right now',focus.ruledOut);
appendTextList(root,'Next diagnostic target',focus.next);
const note=document.createElement('div');note.className='r360-dev-note';
const commit=summary.runtimeAsset?.sourceCommit?.slice?.(0,12)||'unknown';
note.textContent=`Runtime ${commit}. Copy Report still includes the complete JSON, full memory diagnostics, kernel/GPU state, code windows and every captured event.`;
root.appendChild(note);
}
function render(){
if(!enabled)return;
const summary=report();renderFocus(summary);
const log=$('r360DevLog');const label=$('r360DevLogSummary');
if(label)label.textContent=`Full event log · ${entries.length} events`;
if(!log)return;log.innerHTML='';
for(const e of entries){
const row=document.createElement('div');row.className=`r360-dev-line ${e.level}`;
row.innerHTML='<time></time><strong></strong><span></span>';
row.children[0].textContent=new Date(e.at).toLocaleTimeString([], {hour:'2-digit',minute:'2-digit',second:'2-digit'});
row.children[1].textContent=e.level.toUpperCase();
row.children[2].textContent=`${e.message}${e.count>1?` ×${e.count}`:''}`;
log.appendChild(row);
}
if(!entries.length)log.innerHTML='<div class="r360-dev-line"><span></span><strong>INFO</strong><span>No runtime events captured yet.</span></div>';
}
function report(){
const state=globalThis.render360ModernTitle||{};
const result=state.result||{};
const compatibility=result.compatibilityExecution||{};
const scheduler=state.threadScheduler?.inspect?.()||state.schedulerReport||result.commercialCpu?.firstPump||null;
const gpuSource=state.gpuTraffic||result.titleGpuTelemetry||result.browserHleTelemetry||{};
const kernelBlocker=result.reachedKernelBlocker||result.firstKernelBlocker||null;
const blocker=lastBlocker||compactBlocker(result.schedulerBlocker||result.blocker||{
kind:result.runtimeBoundary?'native-hir-unsupported-boundary':undefined,
message:result.runtimeBlocker||result.blockerMessage||result.reason,
address:result.entry,
executionBlockerOpcode:result.executionBlockerOpcode,
executionStatus:result.executionStatus,
executionInstructions:result.executionInstructions,
});
const memory=memoryDiagnostics(state,result);
const hir=hirDiagnostics(state,result);
const cpu=compact({
entry:address(result.entry),xexEntry:address(result.xexEntry),peEntry:address(result.peEntry),entrySource:result.entrySource,
hir:number(result.hir),runtimeBoundary:result.runtimeBoundary,
executionStatus:number(result.executionStatus),instructions:number(result.executionInstructions??compatibility.executionInstructions),
executionBlockerKind:result.executionBlockerKind,executionBlockerOpcode:number(result.executionBlockerOpcode),
executionBlockerAddress:address(result.executionBlockerAddress),hirOpcodeName:hir?.opcodeName,
hirExecutorSupport:hir?.executorSupportsCurrent,hirWasmSupport:hir?.wasmSupportsCurrent,
translatedFunctions:number(result.translatedFunctionCount),
firstTranslatedFunction:address(result.firstTranslatedFunction),callableFunctions:number(state.ppcSession?.functionCount??result.commercialCpu?.callableFunctionCount),
schedulerReady:Boolean(state.threadScheduler),schedulerState:scheduler?.state||scheduler?.status,
});
const kernel=compact({
imports:number(result.kernelImportCount??result.importCount),registered:number(result.registeredKernelImports),calls:number(result.kernelCalls),
lastStatus:number(result.lastKernelServiceStatus),reachedBlocker:kernelBlocker?compactBlocker(kernelBlocker):undefined,
});
const gpu=compact({
ringInitialized:gpuSource.ringInitialized,producerObserved:gpuSource.producerObserved,packets:number(gpuSource.packets),draws:number(gpuSource.draws),
swaps:number(gpuSource.swaps),presents:number(gpuSource.presents),realTitleFrameReady:gpuSource.realTitleFrameReady,reason:gpuSource.reason,
});
const runtimeAsset=globalThis.render360PpcRuntimeIdentity||null;
const focus=problemFocus(memory,cpu,kernel,gpu,runtimeAsset,hir);
return {
schema:'render360-blocker-report-v2',
generatedAt:new Date().toISOString(),
page:compact({path:location.pathname,state:document.body.dataset.state||undefined}),
runtimeAsset,
blocker:Object.keys(blocker).length?blocker:null,
problemFocus:Object.keys(focus).length?focus:null,
memory:Object.keys(memory).length?memory:null,
hir:Object.keys(hir).length?hir:null,
cpu,kernel,gpu,
logs:entries.map(e=>({...e,at:new Date(e.at).toISOString()})),
};
}
async function writeClipboard(text){
try{if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(text);return true;}}catch{}
try{const area=document.createElement('textarea');area.value=text;area.setAttribute('readonly','');area.style.position='fixed';area.style.opacity='0';document.body.appendChild(area);area.select();const ok=document.execCommand('copy');area.remove();return ok;}catch{return false;}
}
async function copyReport(){
const button=$('r360DevCopy'),original=button?.textContent||'Copy Report';
const text=JSON.stringify(report(),null,2);
const copied=await writeClipboard(text);
if(button){button.textContent=copied?'Copied':'Copy failed';setTimeout(()=>{button.textContent=original;},1400);}
return copied;
}
function openConsole(){if(!enabled)return;ensureUi();opened=true;$('r360DevConsole').classList.remove('hidden');render();}
function closeConsole(){opened=false;$('r360DevConsole')?.classList.add('hidden');}
function setEnabled(next){
next=!!next;if(next===enabled)return;enabled=next;globalThis.render360DeveloperMode=enabled;
$('appDiagnosticsButton')?.classList.toggle('hidden',!enabled);$('diagnosticsButton')?.classList.toggle('hidden',!enabled);
if(enabled){installListeners();ensureUi();addEntry('info','Developer Mode enabled');}else removeEntryPoints();
}
function tick(){unlockNavigation();compactRuntimeStatus();setEnabled(readDeveloperMode());if(enabled)installEntryPoints();}
function start(){
unlockNavigation();compactRuntimeStatus();setEnabled(readDeveloperMode());setInterval(tick,500);
globalThis.render360DeveloperConsole={open:openConsole,close:closeConsole,report,copy:copyReport,setEnabled,get enabled(){return enabled;}};
}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',start,{once:true});else start();