wasm-idle 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +134 -82
  2. package/dist/container/bash-profile.d.ts +80 -0
  3. package/dist/container/bash-profile.js +328 -0
  4. package/dist/{playground/container → container}/binding.d.ts +21 -8
  5. package/dist/{playground/container → container}/binding.js +109 -25
  6. package/dist/{playground/container → container}/clang-runtime.d.ts +11 -7
  7. package/dist/container/clang-runtime.js +561 -0
  8. package/dist/container/client.d.ts +14 -0
  9. package/dist/{playground/container → container}/client.js +2 -6
  10. package/dist/{playground/container → container}/explorer.d.ts +1 -1
  11. package/dist/container/index.d.ts +11 -0
  12. package/dist/container/index.js +11 -0
  13. package/dist/container/owner-worker.d.ts +19 -0
  14. package/dist/container/owner-worker.js +464 -0
  15. package/dist/{playground/container → container}/protocol.d.ts +12 -1
  16. package/dist/{playground/container → container}/runtime-adapter.d.ts +13 -11
  17. package/dist/{playground/container → container}/runtime-adapter.js +104 -41
  18. package/dist/{playground/container → container}/shell-control.d.ts +2 -2
  19. package/dist/{playground/container → container}/shell-control.js +93 -36
  20. package/dist/{playground/container → container}/workspace.d.ts +5 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/playground/assetBridge.js +5 -2
  23. package/dist/playground/assets.d.ts +8 -0
  24. package/dist/playground/clang.d.ts +5 -1
  25. package/dist/playground/clang.js +61 -5
  26. package/dist/playground/compiledLldb.d.ts +41 -0
  27. package/dist/playground/compiledLldb.js +167 -0
  28. package/dist/playground/d.d.ts +4 -1
  29. package/dist/playground/d.js +78 -9
  30. package/dist/playground/debugDeadline.d.ts +12 -0
  31. package/dist/playground/debugDeadline.js +34 -0
  32. package/dist/playground/debugMailbox.d.ts +12 -0
  33. package/dist/playground/debugMailbox.js +77 -0
  34. package/dist/playground/go.js +9 -4
  35. package/dist/playground/goDebugInstrumentation.js +24 -44
  36. package/dist/playground/java-debug-FMHDKUN6.js +124 -0
  37. package/dist/playground/java-debug-notices.txt +492 -0
  38. package/dist/playground/java.d.ts +17 -1
  39. package/dist/playground/java.js +159 -3
  40. package/dist/playground/javaDebug.d.ts +62 -0
  41. package/dist/playground/javaDebug.js +305 -0
  42. package/dist/playground/javaDebugBridge.d.ts +6 -0
  43. package/dist/playground/javaDebugBridge.js +250 -0
  44. package/dist/playground/javaDebugSource.d.ts +9 -0
  45. package/dist/playground/javaDebugSource.js +4 -0
  46. package/dist/playground/javaRuntimeErrors.js +34 -1
  47. package/dist/playground/lean4Assets.d.ts +1 -25
  48. package/dist/playground/lean4Assets.js +2 -123
  49. package/dist/playground/lfortranAssets.d.ts +2 -2
  50. package/dist/playground/lldbSession.d.ts +23 -2
  51. package/dist/playground/lldbSession.js +278 -58
  52. package/dist/playground/lldbSourcePath.d.ts +2 -0
  53. package/dist/playground/lldbSourcePath.js +9 -0
  54. package/dist/playground/lua.d.ts +20 -1
  55. package/dist/playground/lua.js +190 -8
  56. package/dist/playground/luaDebug.d.ts +1 -0
  57. package/dist/playground/luaDebug.js +1 -0
  58. package/dist/playground/nim.d.ts +1 -0
  59. package/dist/playground/nim.js +8 -0
  60. package/dist/playground/objectivec.d.ts +7 -6
  61. package/dist/playground/objectivec.js +75 -9
  62. package/dist/playground/options.d.ts +10 -4
  63. package/dist/playground/python.d.ts +8 -1
  64. package/dist/playground/python.js +81 -6
  65. package/dist/playground/ruby.d.ts +10 -1
  66. package/dist/playground/ruby.js +66 -1
  67. package/dist/playground/rubyDebug.d.ts +21 -0
  68. package/dist/playground/rubyDebug.js +128 -0
  69. package/dist/playground/rust.d.ts +5 -1
  70. package/dist/playground/rust.js +128 -46
  71. package/dist/playground/sandbox.d.ts +8 -1
  72. package/dist/playground/staticWorkerRuntime.js +8 -2
  73. package/dist/playground/stdinBuffer.d.ts +1 -1
  74. package/dist/playground/stdinBuffer.js +19 -2
  75. package/dist/playground/tinygo.js +7 -0
  76. package/dist/playground/typescript.js +8 -0
  77. package/dist/playground/v.d.ts +3 -2
  78. package/dist/playground/v.js +66 -12
  79. package/dist/playground/wasmC3Version.d.ts +2 -2
  80. package/dist/playground/wasmC3Version.js +2 -2
  81. package/dist/playground/wasmLean4Version.d.ts +1 -110
  82. package/dist/playground/wasmLean4Version.js +2 -111
  83. package/dist/playground/wasmLfortranVersion.d.ts +2 -2
  84. package/dist/playground/wasmLfortranVersion.js +2 -2
  85. package/dist/playground/wasmLuaVersion.d.ts +1 -1
  86. package/dist/playground/wasmLuaVersion.js +1 -1
  87. package/dist/playground/wasmRustVersion.d.ts +26 -38
  88. package/dist/playground/wasmRustVersion.js +25 -40
  89. package/dist/playground/worker/clang.js +1 -1
  90. package/dist/playground/worker/cobol.js +1 -1
  91. package/dist/playground/worker/d.js +51 -2
  92. package/dist/playground/worker/fortran.js +1 -1
  93. package/dist/playground/worker/java.js +188 -35
  94. package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
  95. package/dist/playground/worker/javaDebugEvaluator.js +44 -0
  96. package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
  97. package/dist/playground/worker/javaDebugRuntime.js +315 -0
  98. package/dist/playground/worker/javaOutput.d.ts +11 -0
  99. package/dist/playground/worker/javaOutput.js +54 -0
  100. package/dist/playground/worker/lua.js +13 -0
  101. package/dist/playground/worker/python.js +57 -22
  102. package/dist/playground/worker/ruby.js +13 -0
  103. package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
  104. package/dist/playground/worker/rubyDebugPreview.js +80 -0
  105. package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
  106. package/dist/playground/worker/rubyTracepoint.js +162 -0
  107. package/dist/playground/worker/rust.js +4 -1
  108. package/dist/playground/worker/v.js +30 -5
  109. package/dist/playground/zig.js +4 -0
  110. package/package.json +55 -11
  111. package/dist/playground/container/ContainerExplorer.svelte +0 -307
  112. package/dist/playground/container/ContainerExplorer.svelte.d.ts +0 -14
  113. package/dist/playground/container/clang-runtime.js +0 -343
  114. package/dist/playground/container/client.d.ts +0 -15
  115. package/dist/playground/container/owner.worker.d.ts +0 -1
  116. package/dist/playground/container/owner.worker.js +0 -390
  117. package/dist/playground/container/release.d.ts +0 -31
  118. package/dist/playground/container/release.js +0 -612
  119. /package/dist/{playground/container → container}/explorer.js +0 -0
  120. /package/dist/{playground/container → container}/protocol.js +0 -0
  121. /package/dist/{playground/container → container}/workspace.js +0 -0
@@ -0,0 +1,41 @@
1
+ import { type PlaygroundRuntimeAssets } from './assets';
2
+ import { LldbSandboxSession, type LldbArtifactPayload } from './lldbSession';
3
+ import type { DebugCommand, DebugDataBreakpoint, DebugDataBreakpointInfoArguments, DebugSessionEvent, SandboxExecutionOptions } from './options';
4
+ import { type DebugEvaluateOptions, type DebugSourceBreakpoint, type DebugSteppingOptions } from '@wasm-idle/core';
5
+ /** The common LLDB controls for compilers that hand a real DWARF module to WAMR. */
6
+ export declare class CompiledLldbSandbox {
7
+ output?: (data: string) => void;
8
+ ondebug?: (event: DebugSessionEvent) => void;
9
+ protected lldbSession?: LldbSandboxSession;
10
+ protected lldbPending: boolean;
11
+ protected lldbEntryFunction: string;
12
+ private lldbRuntime?;
13
+ private lldbSourcePath;
14
+ private readonly lldbBreakpoints;
15
+ private readonly lldbBreakpointSpecifications;
16
+ private lldbPersistentCache?;
17
+ protected configureLldb(runtimeAssets: string | PlaygroundRuntimeAssets, options: SandboxExecutionOptions): void;
18
+ protected prepareLldb(options: SandboxExecutionOptions, defaultPath: string): void;
19
+ protected lldbReloadAssets(): Pick<PlaygroundRuntimeAssets, 'debug' | 'persistentCache'>;
20
+ protected startLldb(artifact: LldbArtifactPayload, options: SandboxExecutionOptions, programArgs: string[], pendingInput: string[], pendingEof: boolean, onOutput?: (text: string) => void | undefined): Promise<true>;
21
+ protected stopLldb(): Promise<void> | undefined;
22
+ private sourcePath;
23
+ debugCommand(command: DebugCommand): Promise<void> | undefined;
24
+ debugPause(): Promise<void> | undefined;
25
+ setBreakpoints(lines: number[], sourcePath?: string): Promise<void> | undefined;
26
+ setSourceBreakpoints(breakpoints: DebugSourceBreakpoint[], sourcePath?: string): Promise<void>;
27
+ debugSetSteppingOptions(options: DebugSteppingOptions): Promise<void>;
28
+ debugEvaluateValue(expression: string, options?: DebugEvaluateOptions): Promise<import("@wasm-idle/core").DebugEvaluateResult>;
29
+ debugEvaluate(expression: string): Promise<string>;
30
+ debugVariables(reference: number, start?: number, count?: number): Promise<import("@wasm-idle/core").DebugVariable[]>;
31
+ debugScopes(frameId: number): Promise<import("@wasm-idle/core").DebugScope[]>;
32
+ debugFrameScopes(frameId: number): Promise<import("@wasm-idle/core").DebugScope[]>;
33
+ debugFrameName(frameId: number): Promise<string | null>;
34
+ debugReadMemory(reference: string, offset: number, count: number): Promise<import("@wasm-idle/core").DebugMemory | null>;
35
+ debugWriteMemory(reference: string, offset: number, data: Uint8Array, allowPartial?: boolean): Promise<{
36
+ offset?: number;
37
+ bytesWritten: number;
38
+ } | null>;
39
+ debugDataBreakpointInfo(arguments_: DebugDataBreakpointInfoArguments): Promise<import("@wasm-idle/core").DebugDataBreakpointInfo | null>;
40
+ debugSetDataBreakpoints(breakpoints: DebugDataBreakpoint[]): Promise<import("@wasm-idle/core").DebugResolvedDataBreakpoint[]>;
41
+ }
@@ -0,0 +1,167 @@
1
+ import { resolveDebugRuntimeUrls } from './assets';
2
+ import { LldbSandboxSession } from './lldbSession';
3
+ import { normalizeLldbWorkspacePath } from './lldbSourcePath';
4
+ import { mergeDebugBreakpointLines, normalizeDebugSourceBreakpoints } from '@wasm-idle/core';
5
+ /** The common LLDB controls for compilers that hand a real DWARF module to WAMR. */
6
+ export class CompiledLldbSandbox {
7
+ output;
8
+ ondebug;
9
+ lldbSession;
10
+ lldbPending = false;
11
+ lldbEntryFunction = 'main';
12
+ lldbRuntime;
13
+ lldbSourcePath = '/workspace/main';
14
+ lldbBreakpoints = new Map();
15
+ lldbBreakpointSpecifications = new Map();
16
+ lldbPersistentCache;
17
+ configureLldb(runtimeAssets, options) {
18
+ this.lldbRuntime = resolveDebugRuntimeUrls(runtimeAssets, typeof window !== 'undefined' ? window.location.href : '');
19
+ this.lldbPersistentCache =
20
+ options.persistentCache ??
21
+ (typeof runtimeAssets === 'object' ? runtimeAssets.persistentCache : undefined);
22
+ }
23
+ prepareLldb(options, defaultPath) {
24
+ this.lldbPending = true;
25
+ this.lldbSourcePath = this.sourcePath(options.debugPath || options.activePath || defaultPath);
26
+ this.lldbBreakpoints.clear();
27
+ this.lldbBreakpointSpecifications.clear();
28
+ for (const entry of options.sourceBreakpoints || []) {
29
+ const path = this.sourcePath(entry.sourcePath);
30
+ if (entry.breakpoints) {
31
+ const values = normalizeDebugSourceBreakpoints(entry.breakpoints);
32
+ this.lldbBreakpointSpecifications.set(path, values);
33
+ this.lldbBreakpoints.set(path, values.filter((value) => value.enabled !== false).map((value) => value.line));
34
+ }
35
+ else
36
+ this.lldbBreakpoints.set(path, [...entry.lines]);
37
+ }
38
+ if (!this.lldbBreakpoints.has(this.lldbSourcePath)) {
39
+ this.lldbBreakpoints.set(this.lldbSourcePath, [...(options.breakpoints || [])]);
40
+ }
41
+ }
42
+ lldbReloadAssets() {
43
+ return {
44
+ debug: this.lldbRuntime
45
+ ? {
46
+ baseUrl: this.lldbRuntime.baseUrl,
47
+ manifestUrl: this.lldbRuntime.manifestUrl,
48
+ manifestSha256: this.lldbRuntime.manifestReceipt?.sha256
49
+ }
50
+ : undefined,
51
+ persistentCache: this.lldbPersistentCache
52
+ };
53
+ }
54
+ startLldb(artifact, options, programArgs, pendingInput, pendingEof, onOutput = (text) => this.output?.(text)) {
55
+ if (!this.lldbRuntime)
56
+ throw new Error('LLDB runtime assets have not been configured.');
57
+ const session = new LldbSandboxSession({
58
+ manifestUrl: this.lldbRuntime.manifestUrl,
59
+ manifestReceipt: this.lldbRuntime.manifestReceipt,
60
+ runtimeBaseUrl: this.lldbRuntime.baseUrl,
61
+ persistentCache: options.persistentCache ?? this.lldbPersistentCache,
62
+ artifact,
63
+ sourcePath: this.lldbSourcePath,
64
+ breakpoints: [...(this.lldbBreakpoints.get(this.lldbSourcePath) || [])],
65
+ sourceBreakpoints: [...this.lldbBreakpoints].map(([sourcePath, lines]) => ({
66
+ sourcePath,
67
+ lines: [...lines],
68
+ ...(this.lldbBreakpointSpecifications.has(sourcePath)
69
+ ? {
70
+ breakpoints: normalizeDebugSourceBreakpoints(this.lldbBreakpointSpecifications.get(sourcePath))
71
+ }
72
+ : {})
73
+ })),
74
+ debugSteppingOptions: options.debugSteppingOptions,
75
+ pauseOnEntry: !!options.pauseOnEntry,
76
+ pauseAtMain: true,
77
+ entryFunctionName: this.lldbEntryFunction,
78
+ programArgs,
79
+ stdin: options.stdin,
80
+ onDebugEvent: (event) => this.ondebug?.(event),
81
+ onOutput
82
+ });
83
+ this.lldbSession = session;
84
+ for (const input of pendingInput.splice(0))
85
+ void session.write(input);
86
+ if (pendingEof)
87
+ void session.eof();
88
+ return session.start().finally(() => {
89
+ if (this.lldbSession === session) {
90
+ this.lldbSession = undefined;
91
+ this.lldbPending = false;
92
+ }
93
+ });
94
+ }
95
+ stopLldb() {
96
+ const session = this.lldbSession;
97
+ this.lldbSession = undefined;
98
+ this.lldbPending = false;
99
+ return session?.disconnect();
100
+ }
101
+ sourcePath(path) {
102
+ const normalized = normalizeLldbWorkspacePath(path);
103
+ if (!normalized)
104
+ throw new Error('LLDB requires a workspace source path.');
105
+ return `/workspace/${normalized}`;
106
+ }
107
+ debugCommand(command) {
108
+ return this.lldbSession?.debugCommand(command);
109
+ }
110
+ debugPause() {
111
+ return this.lldbSession?.pause();
112
+ }
113
+ setBreakpoints(lines, sourcePath) {
114
+ const path = sourcePath ? this.sourcePath(sourcePath) : this.lldbSourcePath;
115
+ if (this.lldbSession)
116
+ return this.lldbSession.setBreakpoints(lines, path);
117
+ if (this.lldbBreakpointSpecifications.has(path))
118
+ return this.setSourceBreakpoints(mergeDebugBreakpointLines(this.lldbBreakpointSpecifications.get(path), lines), path);
119
+ this.lldbBreakpoints.set(path, [...lines]);
120
+ }
121
+ async setSourceBreakpoints(breakpoints, sourcePath) {
122
+ const values = normalizeDebugSourceBreakpoints(breakpoints);
123
+ const path = sourcePath ? this.sourcePath(sourcePath) : this.lldbSourcePath;
124
+ if (this.lldbSession)
125
+ return this.lldbSession.setSourceBreakpoints(values, path);
126
+ this.lldbBreakpointSpecifications.set(path, values);
127
+ this.lldbBreakpoints.set(path, values.filter((value) => value.enabled !== false).map((value) => value.line));
128
+ }
129
+ async debugSetSteppingOptions(options) {
130
+ if (!this.lldbSession)
131
+ throw new Error('Stepping options require an LLDB session.');
132
+ await this.lldbSession.setSteppingOptions(options);
133
+ }
134
+ debugEvaluateValue(expression, options) {
135
+ return (this.lldbSession?.evaluateValue(expression, options) ??
136
+ Promise.reject(new Error('LLDB is not running.')));
137
+ }
138
+ debugEvaluate(expression) {
139
+ return (this.lldbSession?.evaluate(expression) ??
140
+ Promise.reject(new Error('LLDB is not running.')));
141
+ }
142
+ debugVariables(reference, start, count) {
143
+ return this.lldbSession?.variables(reference, start, count) ?? Promise.resolve([]);
144
+ }
145
+ debugScopes(frameId) {
146
+ return this.lldbSession?.scopes(frameId) ?? Promise.resolve([]);
147
+ }
148
+ debugFrameScopes(frameId) {
149
+ return this.lldbSession?.frameScopes(frameId) ?? Promise.resolve([]);
150
+ }
151
+ debugFrameName(frameId) {
152
+ return this.lldbSession?.formattedFrameName(frameId) ?? Promise.resolve(null);
153
+ }
154
+ debugReadMemory(reference, offset, count) {
155
+ return this.lldbSession?.readMemory(reference, offset, count) ?? Promise.resolve(null);
156
+ }
157
+ debugWriteMemory(reference, offset, data, allowPartial = false) {
158
+ return (this.lldbSession?.writeMemory(reference, offset, data, allowPartial) ??
159
+ Promise.resolve(null));
160
+ }
161
+ debugDataBreakpointInfo(arguments_) {
162
+ return this.lldbSession?.dataBreakpointInfo(arguments_) ?? Promise.resolve(null);
163
+ }
164
+ debugSetDataBreakpoints(breakpoints) {
165
+ return this.lldbSession?.setDataBreakpoints(breakpoints) ?? Promise.resolve([]);
166
+ }
167
+ }
@@ -1,8 +1,10 @@
1
1
  import { type PlaygroundRuntimeAssets, type ResolvedDRuntimeAssetConfig } from './assets';
2
+ import { CompiledLldbSandbox } from './compiledLldb';
2
3
  import { RuntimeAssetCache } from '@wasm-idle/core';
3
4
  import { type CompilerDiagnostic, type SandboxExecutionOptions } from './options';
4
5
  import type { Sandbox, SandboxProgress } from './sandbox';
5
- declare class D implements Sandbox {
6
+ declare class D extends CompiledLldbSandbox implements Sandbox {
7
+ protected lldbEntryFunction: string;
6
8
  output: any;
7
9
  worker?: Worker;
8
10
  buffer: import("./sharedBuffer").WasmIdleSharedBuffer;
@@ -19,6 +21,7 @@ declare class D implements Sandbox {
19
21
  waitingForInput: boolean;
20
22
  pendingEof: boolean;
21
23
  private activeOperation;
24
+ private lldbAssets;
22
25
  private disposed;
23
26
  private runtimeAssetCache;
24
27
  private ownsRuntimeAssetCache;
@@ -1,8 +1,9 @@
1
1
  import { resolveDRuntimeAssetConfig } from './assets';
2
+ import { CompiledLldbSandbox } from './compiledLldb';
2
3
  import { BusyError, CancelledError, createRuntimeAssetsKey, createRuntimeWasmModuleService, DEFAULT_WORKSPACE_LIMITS, DiagnosticLimitError, OutputLimitError, RuntimeConfigurationError, RuntimeAssetCache, TimeoutError, resolveExecutionLimits, validateExecutionWorkspace } from '@wasm-idle/core';
3
4
  import { resolveSandboxExecutionArgs } from './options';
4
5
  import { flushBufferedEof, flushQueuedStdin, resetBufferedStdin } from './stdinBuffer';
5
- import { createWasmIdleSharedBuffer } from './sharedBuffer';
6
+ import { createWasmIdleSharedBuffer, requireSharedArrayBuffer } from './sharedBuffer';
6
7
  import { WorkerSession } from './workerSession';
7
8
  import { reportWorkerInputReady, reportWorkerProgress } from './workerProgress';
8
9
  import { WASM_D_COMPILER_PROFILE } from './wasmDVersion';
@@ -11,7 +12,8 @@ const OUTPUT_ENCODER = new TextEncoder();
11
12
  const abortReason = (signal, phase) => signal.reason !== undefined
12
13
  ? signal.reason
13
14
  : new DOMException(phase === 'startup' ? 'D runtime startup aborted' : 'D execution aborted', 'AbortError');
14
- class D {
15
+ class D extends CompiledLldbSandbox {
16
+ lldbEntryFunction = '_Dmain';
15
17
  output = null;
16
18
  worker = null;
17
19
  buffer = createWasmIdleSharedBuffer(1024);
@@ -28,6 +30,7 @@ class D {
28
30
  waitingForInput = false;
29
31
  pendingEof = false;
30
32
  activeOperation = null;
33
+ lldbAssets = {};
31
34
  disposed = false;
32
35
  runtimeAssetCache = new RuntimeAssetCache();
33
36
  ownsRuntimeAssetCache = true;
@@ -187,10 +190,11 @@ class D {
187
190
  if (!this.isOperationActive(operation))
188
191
  return;
189
192
  let timeout;
190
- operation.cleanups.push(() => {
193
+ const cancelTimeout = () => {
191
194
  if (timeout !== undefined)
192
195
  clearTimeout(timeout);
193
- });
196
+ };
197
+ operation.cleanups.push(cancelTimeout);
194
198
  try {
195
199
  timeout = setTimeout(() => {
196
200
  if (!this.isOperationActive(operation))
@@ -208,6 +212,7 @@ class D {
208
212
  catch (error) {
209
213
  this.cancelOperation(operation, error);
210
214
  }
215
+ return cancelTimeout;
211
216
  }
212
217
  resetExplicitStdinState() {
213
218
  this.pendingInput = [];
@@ -238,6 +243,14 @@ class D {
238
243
  let limits;
239
244
  let unbindPreSessionAbort = () => undefined;
240
245
  try {
246
+ // Ordinary D execution only needs its compiler bundle. Keep debugger settings
247
+ // across worker retirement, but resolve their URLs only for an LLDB run.
248
+ const assets = typeof runtimeAssets === 'string' ? { rootUrl: runtimeAssets } : runtimeAssets;
249
+ this.lldbAssets = {
250
+ rootUrl: assets.rootUrl,
251
+ debug: assets.debug ? { ...assets.debug } : undefined,
252
+ persistentCache: options.persistentCache ?? assets.persistentCache
253
+ };
241
254
  signal = options.signal;
242
255
  unbindPreSessionAbort = this.bindPreSessionAbort(activeOperation, signal);
243
256
  if (!this.isOperationActive(activeOperation) || signal?.aborted) {
@@ -361,6 +374,10 @@ class D {
361
374
  });
362
375
  }
363
376
  write(input) {
377
+ if (this.lldbSession) {
378
+ void this.lldbSession.write(input);
379
+ return;
380
+ }
364
381
  if (this.disposed)
365
382
  return;
366
383
  this.pendingInput.push(input);
@@ -368,6 +385,10 @@ class D {
368
385
  this.flushPendingInput();
369
386
  }
370
387
  eof() {
388
+ if (this.lldbSession) {
389
+ void this.lldbSession.eof();
390
+ return;
391
+ }
371
392
  if (this.disposed)
372
393
  return;
373
394
  this.pendingEof = true;
@@ -389,6 +410,7 @@ class D {
389
410
  async run(code, prepare, log = true, progress, args = [], options = {}) {
390
411
  if (!this.worker && this.moduleUrl && this.outerIntegrity && !this.disposed) {
391
412
  await this.load({
413
+ ...this.lldbAssets,
392
414
  d: {
393
415
  moduleUrl: this.moduleUrl,
394
416
  manifestUrl: this.manifestUrl,
@@ -412,17 +434,30 @@ class D {
412
434
  }
413
435
  let signal;
414
436
  let unbindPreSessionAbort = () => undefined;
437
+ let compileArgs;
415
438
  let programArgs;
416
439
  let limits;
417
440
  let workspace;
418
441
  let stdin;
442
+ const debugMode = options.debugMode || (options.debug ? 'trace' : 'none');
419
443
  try {
444
+ if (debugMode !== 'none' && debugMode !== 'lldb') {
445
+ throw new Error('D debugging requires debugMode: lldb.');
446
+ }
447
+ if (debugMode === 'lldb') {
448
+ requireSharedArrayBuffer('D debugging');
449
+ if (options.workspaceFiles?.some((file) => file.path !== options.activePath)) {
450
+ throw new Error('The packaged D compiler supports one source file per LLDB session.');
451
+ }
452
+ this.configureLldb(this.lldbAssets, options);
453
+ this.prepareLldb(options, 'main.d');
454
+ }
420
455
  signal = options.signal;
421
456
  unbindPreSessionAbort = this.bindPreSessionAbort(activeOperation, signal);
422
457
  if (!this.isOperationActive(activeOperation)) {
423
458
  return Promise.reject(this.releaseBeforeSession(activeOperation, 'D execution cancelled'));
424
459
  }
425
- programArgs = resolveSandboxExecutionArgs('D', args, options).programArgs;
460
+ ({ compileArgs, programArgs } = resolveSandboxExecutionArgs('D', args, options));
426
461
  limits = resolveExecutionLimits(options.limits);
427
462
  const workspaceFiles = options.workspaceFiles ?? [];
428
463
  const activePath = options.activePath ?? 'main.d';
@@ -456,18 +491,19 @@ class D {
456
491
  let outputBytes = 0;
457
492
  const operation = this.workerSession.beginRun(worker, reject);
458
493
  const timeoutMs = Math.min(2_147_483_647, limits.compileTimeoutMs + limits.runTimeoutMs);
459
- this.bindOperationTimeout(activeOperation, timeoutMs);
494
+ const cancelCompileTimeout = this.bindOperationTimeout(activeOperation, timeoutMs);
460
495
  this.bindAbortSignal(activeOperation, signal);
461
496
  if (!this.isOperationActive(activeOperation))
462
497
  return;
463
498
  let handler;
499
+ let handedOff = false;
464
500
  const ownsRun = () => this.isOperationActive(activeOperation) &&
465
- this.worker === worker &&
466
- worker.onmessage === handler &&
501
+ (handedOff || (this.worker === worker && worker.onmessage === handler)) &&
467
502
  _uid === this.uid;
468
503
  const claimRun = () => {
469
504
  if (!ownsRun())
470
505
  return false;
506
+ this.lldbPending = false;
471
507
  this.finishExplicitStdin(activeOperation);
472
508
  this.elapse = Date.now() - this.begin;
473
509
  this.exit = true;
@@ -506,7 +542,34 @@ class D {
506
542
  if (!ownsRun())
507
543
  return;
508
544
  try {
509
- const { output, results, error, buffer, diagnostic, progress } = event.data;
545
+ const { output, results, error, buffer, diagnostic, progress, lldbArtifact } = event.data;
546
+ if (lldbArtifact) {
547
+ cancelCompileTimeout?.();
548
+ handedOff = true;
549
+ const completion = this.startLldb(lldbArtifact, options, programArgs, this.pendingInput, this.pendingEof, (output) => {
550
+ if (!ownsRun())
551
+ return;
552
+ outputBytes += OUTPUT_ENCODER.encode(output).byteLength;
553
+ if (outputBytes > limits.maxOutputBytes) {
554
+ failRun(new OutputLimitError(`D output exceeded ${limits.maxOutputBytes} bytes`, {
555
+ actual: outputBytes,
556
+ limit: limits.maxOutputBytes,
557
+ phase: 'execute',
558
+ runtimeId: 'D'
559
+ }), true);
560
+ return;
561
+ }
562
+ this.output?.(output);
563
+ });
564
+ this.pendingEof = false;
565
+ if (this.workerSession.release(worker))
566
+ delete this.worker;
567
+ void completion.then((result) => {
568
+ if (claimRun())
569
+ resolve(result);
570
+ }, (error) => failRun(error));
571
+ return;
572
+ }
510
573
  if (buffer && !hasExplicitStdin) {
511
574
  this.waitingForInput = true;
512
575
  if (!prepare) {
@@ -612,10 +675,12 @@ class D {
612
675
  code,
613
676
  prepare,
614
677
  buffer: this.buffer,
678
+ compileArgs,
615
679
  args: programArgs,
616
680
  stdin,
617
681
  fileName: workspace.activePath,
618
682
  log: _log,
683
+ debugMode,
619
684
  ...(modulePorts.ldc2 ? { compilerModulePorts: modulePorts } : {})
620
685
  };
621
686
  const transfers = Object.values(modulePorts);
@@ -639,6 +704,7 @@ class D {
639
704
  cancelOperation(operation, reason) {
640
705
  if (!this.isOperationActive(operation))
641
706
  return;
707
+ void this.stopLldb();
642
708
  operation.cancelled = true;
643
709
  operation.cancellationReason = reason;
644
710
  this.activeOperation = null;
@@ -665,6 +731,7 @@ class D {
665
731
  this.terminate();
666
732
  }
667
733
  terminate(reason = 'Process terminated') {
734
+ void this.stopLldb();
668
735
  if (this.disposed)
669
736
  return;
670
737
  const activeOperation = this.activeOperation;
@@ -695,6 +762,7 @@ class D {
695
762
  dispose() {
696
763
  if (this.disposePromise)
697
764
  return this.disposePromise;
765
+ void this.stopLldb();
698
766
  this.disposed = true;
699
767
  if (this.ownsRuntimeAssetCache)
700
768
  this.runtimeAssetCache.dispose();
@@ -705,6 +773,7 @@ class D {
705
773
  this.manifestUrl = '';
706
774
  this.outerIntegrity = undefined;
707
775
  this.activeDAssetsKey = '';
776
+ this.lldbAssets = {};
708
777
  this.output = null;
709
778
  this.oncompilerdiagnostic = undefined;
710
779
  this.resetExplicitStdinState();
@@ -0,0 +1,12 @@
1
+ /** Charges execution time while allowing a person to inspect a paused VM. */
2
+ export declare class DebugDeadline {
3
+ private readonly expire;
4
+ private remaining;
5
+ private started;
6
+ private timer?;
7
+ private closed;
8
+ constructor(timeoutMs: number, expire: () => void);
9
+ pause(): void;
10
+ resume(): void;
11
+ dispose(): void;
12
+ }
@@ -0,0 +1,34 @@
1
+ /** Charges execution time while allowing a person to inspect a paused VM. */
2
+ export class DebugDeadline {
3
+ expire;
4
+ remaining;
5
+ started = 0;
6
+ timer;
7
+ closed = false;
8
+ constructor(timeoutMs, expire) {
9
+ this.expire = expire;
10
+ this.remaining = timeoutMs;
11
+ this.resume();
12
+ }
13
+ pause() {
14
+ if (this.timer === undefined)
15
+ return;
16
+ clearTimeout(this.timer);
17
+ this.timer = undefined;
18
+ this.remaining = Math.max(0, this.remaining - (Date.now() - this.started));
19
+ }
20
+ resume() {
21
+ if (this.closed || this.timer !== undefined)
22
+ return;
23
+ this.started = Date.now();
24
+ this.timer = setTimeout(() => {
25
+ this.timer = undefined;
26
+ this.closed = true;
27
+ this.expire();
28
+ }, this.remaining);
29
+ }
30
+ dispose() {
31
+ this.pause();
32
+ this.closed = true;
33
+ }
34
+ }
@@ -0,0 +1,12 @@
1
+ /** One published command plus a bounded UI queue; consumption wakes the next producer write. */
2
+ export declare class DebugCommandMailbox {
3
+ private readonly label;
4
+ readonly buffer: import("./sharedBuffer").WasmIdleSharedBuffer;
5
+ private queued;
6
+ constructor(label?: string);
7
+ reset(): void;
8
+ send(command: string): void;
9
+ flush(): void;
10
+ close(): void;
11
+ }
12
+ export declare function readDebugCommand(buffer: SharedArrayBuffer, blocking: boolean, onConsumed: () => void, label?: string): string | null;
@@ -0,0 +1,77 @@
1
+ import { createWasmIdleSharedBuffer, isSharedBufferBackedView } from './sharedBuffer';
2
+ const HEADER_BYTES = 16;
3
+ const COMMAND_BYTES = 65_536;
4
+ const MAX_QUEUED_COMMANDS = 64;
5
+ const encoder = new TextEncoder();
6
+ const decoder = new TextDecoder('utf-8', { fatal: true });
7
+ /** One published command plus a bounded UI queue; consumption wakes the next producer write. */
8
+ export class DebugCommandMailbox {
9
+ label;
10
+ buffer = createWasmIdleSharedBuffer(HEADER_BYTES + COMMAND_BYTES);
11
+ queued = [];
12
+ constructor(label = 'Lua') {
13
+ this.label = label;
14
+ }
15
+ reset() {
16
+ this.queued = [];
17
+ new Int32Array(this.buffer, 0, 4).fill(0);
18
+ }
19
+ send(command) {
20
+ const header = new Int32Array(this.buffer, 0, 4);
21
+ if (!isSharedBufferBackedView(header))
22
+ throw new Error(`${this.label} debugging requires SharedArrayBuffer.`);
23
+ if (Atomics.load(header, 2))
24
+ throw new Error(`${this.label} debugger is closed.`);
25
+ const bytes = encoder.encode(command);
26
+ if (!bytes.length || bytes.length > COMMAND_BYTES) {
27
+ throw new RangeError(`${this.label} debugger commands must contain 1–${COMMAND_BYTES} UTF-8 bytes.`);
28
+ }
29
+ if (this.queued.length >= MAX_QUEUED_COMMANDS)
30
+ throw new Error(`${this.label} debugger command queue is full.`);
31
+ this.queued.push(bytes);
32
+ this.flush();
33
+ }
34
+ flush() {
35
+ const header = new Int32Array(this.buffer, 0, 4);
36
+ if (!this.queued.length || Atomics.load(header, 1) !== 0 || Atomics.load(header, 2))
37
+ return;
38
+ const bytes = this.queued.shift();
39
+ new Uint8Array(this.buffer, HEADER_BYTES, bytes.length).set(bytes);
40
+ Atomics.store(header, 1, bytes.length);
41
+ Atomics.add(header, 0, 1);
42
+ Atomics.notify(header, 0);
43
+ }
44
+ close() {
45
+ this.queued = [];
46
+ const header = new Int32Array(this.buffer, 0, 4);
47
+ if (!isSharedBufferBackedView(header))
48
+ return;
49
+ Atomics.store(header, 2, 1);
50
+ Atomics.add(header, 0, 1);
51
+ Atomics.notify(header, 0);
52
+ }
53
+ }
54
+ export function readDebugCommand(buffer, blocking, onConsumed, label = 'Lua') {
55
+ const header = new Int32Array(buffer, 0, 4);
56
+ if (!isSharedBufferBackedView(header) || buffer.byteLength !== HEADER_BYTES + COMMAND_BYTES) {
57
+ throw new Error(`Invalid ${label} debugger command buffer.`);
58
+ }
59
+ for (;;) {
60
+ const sequence = Atomics.load(header, 0);
61
+ if (Atomics.load(header, 2))
62
+ return null;
63
+ const size = Atomics.load(header, 1);
64
+ if (size < 0 || size > COMMAND_BYTES)
65
+ throw new Error(`Invalid ${label} debugger command length.`);
66
+ if (size) {
67
+ // Browser TextDecoder rejects shared views; copy while this slot is owned by the reader.
68
+ const command = decoder.decode(new Uint8Array(buffer, HEADER_BYTES, size).slice());
69
+ Atomics.store(header, 1, 0);
70
+ onConsumed();
71
+ return command;
72
+ }
73
+ if (!blocking)
74
+ return '';
75
+ Atomics.wait(header, 0, sequence);
76
+ }
77
+ }
@@ -224,7 +224,12 @@ class Go {
224
224
  resetBufferedStdin(this.buffer);
225
225
  }
226
226
  run(code, prepare, _log = true, _prog, args = [], options = {}) {
227
- if (options.debug)
227
+ const debugMode = options.debugMode ?? (options.debug ? 'trace' : 'none');
228
+ if (debugMode !== 'none' && debugMode !== 'trace') {
229
+ return Promise.reject(new Error('Go native debugging is unavailable: the current Wasm linker does not emit DWARF. Use trace mode.'));
230
+ }
231
+ const debugEnabled = debugMode === 'trace';
232
+ if (debugEnabled)
228
233
  requireSharedArrayBuffer('Go debugging');
229
234
  if (!this.exit) {
230
235
  const error = new BusyError('Go runtime already has an active execution', {
@@ -253,8 +258,8 @@ class Go {
253
258
  const { programArgs } = resolveSandboxExecutionArgs('GO', args, options);
254
259
  const target = options.goTarget || 'wasip1/wasm';
255
260
  const _uid = ++this.uid;
256
- this.setBreakpoints(options.debug ? [...(options.breakpoints || [])] : []);
257
- const hasExplicitStdin = !options.debug && options.stdin !== undefined;
261
+ this.setBreakpoints(debugEnabled ? [...(options.breakpoints || [])] : []);
262
+ const hasExplicitStdin = !debugEnabled && options.stdin !== undefined;
258
263
  this.activeExplicitStdinCleanup?.();
259
264
  let explicitStdinCleaned = false;
260
265
  const cleanupExplicitStdin = () => {
@@ -415,7 +420,7 @@ class Go {
415
420
  args: programArgs,
416
421
  target,
417
422
  log: _log,
418
- debug: !!options.debug,
423
+ debug: debugEnabled,
419
424
  breakpoints: [...(options.breakpoints || [])],
420
425
  pauseOnEntry: !!options.pauseOnEntry,
421
426
  runtimeLimits: limits