crashDumpFixture.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Buffer } from "node:buffer";
  2. /**
  3. * 按 crashpad 的注解布局拼一个最小 dump:MinidumpUTF8String(name) + MinidumpByteArray(value),
  4. * 都是 `u32 长度 + 内容`(name 额外带 NUL 结尾),按 4 字节对齐。
  5. */
  6. export function buildCrashDumpFixture(
  7. annotations: Record<string, string>,
  8. options?: { leadingBytes?: Buffer; trailingBytes?: Buffer },
  9. ): Buffer {
  10. const chunks: Buffer[] = [];
  11. let offset = 0;
  12. const push = (chunk: Buffer): void => {
  13. chunks.push(chunk);
  14. offset += chunk.length;
  15. };
  16. const alignTo4 = (): void => {
  17. const padding = (4 - (offset % 4)) % 4;
  18. if (padding > 0) {
  19. push(Buffer.alloc(padding));
  20. }
  21. };
  22. const pushUInt32 = (value: number): void => {
  23. const chunk = Buffer.alloc(4);
  24. chunk.writeUInt32LE(value);
  25. push(chunk);
  26. };
  27. push(options?.leadingBytes ?? Buffer.from("MDMP ", "latin1"));
  28. for (const [key, value] of Object.entries(annotations)) {
  29. alignTo4();
  30. const keyBytes = Buffer.from(key, "latin1");
  31. pushUInt32(keyBytes.length);
  32. push(keyBytes);
  33. push(Buffer.alloc(1));
  34. alignTo4();
  35. const valueBytes = Buffer.from(value, "utf8");
  36. pushUInt32(valueBytes.length);
  37. push(valueBytes);
  38. }
  39. push(options?.trailingBytes ?? Buffer.alloc(0));
  40. return Buffer.concat(chunks);
  41. }
  42. /** 复刻 2026-09-12 macOS 3.11.2 白屏 dump 里的关键注解(code cage 耗尽型 OOM)。 */
  43. export const CODE_SPACE_OOM_ANNOTATIONS: Record<string, string> = {
  44. process_type: "renderer",
  45. pid: "85886",
  46. "v8-oom-location": "CALL_AND_RETRY_LAST",
  47. "v8-oom-stack": [
  48. "next",
  49. "WI in file:///Applications/ZCode.app/Contents/Resources/app.asar/out/renderer/assets/catalogTree-BYrDsScn.js",
  50. "kq in file:///Applications/ZCode.app/Contents/Resources/app.asar/out/renderer/assets/styles-DyAcaLKy.js",
  51. "Aq in =",
  52. ].join("\n"),
  53. "v8-oom-last-few-messages": [
  54. "[85886:0x10c007c0000] 189710587 ms: Mark-Compact (reduce) 566.5 (598.3) -> 566.5 (597.6) MB, pooled: 0.0 MB, 122.54 / 0.01 ms (average mu = 0.061, current mu = 0.052) last resort; GC in old space requested",
  55. "[85886:0x10c007c0000] 189710714 ms: Mark-Compact (reduce) 566.5 (597.6) -> 566.5 (596.6) MB, pooled: 0.0 MB, 126.75 / 0.00 ms (average mu = 0.031, current mu = 0.001) last resort; GC in old space requested",
  56. ].join("\n"),
  57. "v8-oom-code-cage-last-alloc-status": "ran out of reservation",
  58. "v8-oom-code-cage-free-size": "0B",
  59. "v8-oom-code-cage-size": "256.00MB",
  60. "v8-oom-main-cage-last-alloc-status": "success",
  61. "v8-oom-main-cage-free-size": "3775.00MB",
  62. "v8-oom-trusted-cage-free-size": "905.00MB",
  63. "v8-oom-is-main-isolate": "true",
  64. "v8-oom-isolate-count": "5",
  65. "v8-oom-malloced-peak-memory": "289.04MB",
  66. "v8-oom-memory-allocator-size": "596.59MB",
  67. "v8-oom-code-lo-space-size": "40.34MB",
  68. "v8-oom-code-space-size": "149.89MB",
  69. "v8-oom-old-space-capacity": "291.73MB",
  70. "v8-oom-old-space-size": "284.93MB",
  71. };