wasm-idle 1.1.2 → 1.3.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 (136) hide show
  1. package/README.md +211 -91
  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 +2 -1
  22. package/dist/index.js +1 -0
  23. package/dist/playground/assetBridge.js +5 -2
  24. package/dist/playground/assets.d.ts +8 -0
  25. package/dist/playground/clang.d.ts +5 -1
  26. package/dist/playground/clang.js +61 -5
  27. package/dist/playground/compiledLldb.d.ts +41 -0
  28. package/dist/playground/compiledLldb.js +167 -0
  29. package/dist/playground/d.d.ts +4 -1
  30. package/dist/playground/d.js +78 -9
  31. package/dist/playground/debugDeadline.d.ts +12 -0
  32. package/dist/playground/debugDeadline.js +34 -0
  33. package/dist/playground/debugMailbox.d.ts +12 -0
  34. package/dist/playground/debugMailbox.js +77 -0
  35. package/dist/playground/go.js +9 -4
  36. package/dist/playground/goDebugInstrumentation.js +24 -44
  37. package/dist/playground/java-debug-HUZVAK4F.js +124 -0
  38. package/dist/playground/java-debug-notices.txt +492 -0
  39. package/dist/playground/java.d.ts +17 -1
  40. package/dist/playground/java.js +159 -3
  41. package/dist/playground/javaDebug.d.ts +62 -0
  42. package/dist/playground/javaDebug.js +305 -0
  43. package/dist/playground/javaDebugBridge.d.ts +6 -0
  44. package/dist/playground/javaDebugBridge.js +250 -0
  45. package/dist/playground/javaDebugSource.d.ts +9 -0
  46. package/dist/playground/javaDebugSource.js +4 -0
  47. package/dist/playground/javaRuntimeErrors.js +34 -1
  48. package/dist/playground/lean4Assets.d.ts +1 -25
  49. package/dist/playground/lean4Assets.js +2 -123
  50. package/dist/playground/lfortranAssets.d.ts +2 -2
  51. package/dist/playground/lldbSession.d.ts +24 -2
  52. package/dist/playground/lldbSession.js +322 -59
  53. package/dist/playground/lldbSourcePath.d.ts +2 -0
  54. package/dist/playground/lldbSourcePath.js +9 -0
  55. package/dist/playground/lua.d.ts +20 -1
  56. package/dist/playground/lua.js +190 -8
  57. package/dist/playground/luaDebug.d.ts +1 -0
  58. package/dist/playground/luaDebug.js +1 -0
  59. package/dist/playground/nim.d.ts +1 -0
  60. package/dist/playground/nim.js +8 -0
  61. package/dist/playground/objectivec.d.ts +7 -6
  62. package/dist/playground/objectivec.js +75 -9
  63. package/dist/playground/options.d.ts +10 -4
  64. package/dist/playground/python.d.ts +11 -1
  65. package/dist/playground/python.js +203 -8
  66. package/dist/playground/pythonCompileOptions.d.ts +49 -0
  67. package/dist/playground/pythonCompileOptions.js +40 -0
  68. package/dist/playground/ruby.d.ts +10 -1
  69. package/dist/playground/ruby.js +66 -1
  70. package/dist/playground/rubyDebug.d.ts +21 -0
  71. package/dist/playground/rubyDebug.js +128 -0
  72. package/dist/playground/rust.d.ts +5 -1
  73. package/dist/playground/rust.js +128 -46
  74. package/dist/playground/sandbox.d.ts +8 -1
  75. package/dist/playground/staticRuntimeModuleVersion.d.ts +1 -1
  76. package/dist/playground/staticRuntimeModuleVersion.js +1 -1
  77. package/dist/playground/staticWorkerRuntime.js +8 -2
  78. package/dist/playground/stdinBuffer.d.ts +1 -1
  79. package/dist/playground/stdinBuffer.js +19 -2
  80. package/dist/playground/tinygo.js +7 -0
  81. package/dist/playground/typescript.js +8 -0
  82. package/dist/playground/v.d.ts +3 -2
  83. package/dist/playground/v.js +66 -12
  84. package/dist/playground/wasmC3Version.d.ts +2 -2
  85. package/dist/playground/wasmC3Version.js +2 -2
  86. package/dist/playground/wasmDebugVersion.d.ts +1 -1
  87. package/dist/playground/wasmDebugVersion.js +1 -1
  88. package/dist/playground/wasmLean4Version.d.ts +1 -110
  89. package/dist/playground/wasmLean4Version.js +2 -111
  90. package/dist/playground/wasmLfortranVersion.d.ts +2 -2
  91. package/dist/playground/wasmLfortranVersion.js +2 -2
  92. package/dist/playground/wasmLuaVersion.d.ts +1 -1
  93. package/dist/playground/wasmLuaVersion.js +1 -1
  94. package/dist/playground/wasmPrologVersion.d.ts +17 -17
  95. package/dist/playground/wasmPrologVersion.js +16 -16
  96. package/dist/playground/wasmRustVersion.d.ts +26 -38
  97. package/dist/playground/wasmRustVersion.js +25 -40
  98. package/dist/playground/wasmTypeScriptVersion.d.ts +3 -3
  99. package/dist/playground/wasmTypeScriptVersion.js +3 -3
  100. package/dist/playground/worker/clang.js +1 -1
  101. package/dist/playground/worker/cobol.js +1 -1
  102. package/dist/playground/worker/d.js +51 -2
  103. package/dist/playground/worker/fortran.js +1 -1
  104. package/dist/playground/worker/java.js +188 -35
  105. package/dist/playground/worker/javaDebugEvaluator.d.ts +16 -0
  106. package/dist/playground/worker/javaDebugEvaluator.js +44 -0
  107. package/dist/playground/worker/javaDebugRuntime.d.ts +24 -0
  108. package/dist/playground/worker/javaDebugRuntime.js +315 -0
  109. package/dist/playground/worker/javaOutput.d.ts +11 -0
  110. package/dist/playground/worker/javaOutput.js +54 -0
  111. package/dist/playground/worker/lua.js +13 -0
  112. package/dist/playground/worker/python.js +81 -23
  113. package/dist/playground/worker/pythonCompile.d.ts +4 -0
  114. package/dist/playground/worker/pythonCompile.js +122 -0
  115. package/dist/playground/worker/ruby.js +13 -0
  116. package/dist/playground/worker/rubyDebugPreview.d.ts +2 -0
  117. package/dist/playground/worker/rubyDebugPreview.js +80 -0
  118. package/dist/playground/worker/rubyTracepoint.d.ts +16 -0
  119. package/dist/playground/worker/rubyTracepoint.js +162 -0
  120. package/dist/playground/worker/rust.js +4 -1
  121. package/dist/playground/worker/v.js +30 -5
  122. package/dist/playground/zig.js +4 -0
  123. package/dist/pythonCompiler.d.ts +8 -0
  124. package/dist/pythonCompiler.js +52 -0
  125. package/package.json +76 -28
  126. package/dist/playground/container/ContainerExplorer.svelte +0 -307
  127. package/dist/playground/container/ContainerExplorer.svelte.d.ts +0 -14
  128. package/dist/playground/container/clang-runtime.js +0 -343
  129. package/dist/playground/container/client.d.ts +0 -15
  130. package/dist/playground/container/owner.worker.d.ts +0 -1
  131. package/dist/playground/container/owner.worker.js +0 -390
  132. package/dist/playground/container/release.d.ts +0 -31
  133. package/dist/playground/container/release.js +0 -612
  134. /package/dist/{playground/container → container}/explorer.js +0 -0
  135. /package/dist/{playground/container → container}/protocol.js +0 -0
  136. /package/dist/{playground/container → container}/workspace.js +0 -0
@@ -1,4 +1,4 @@
1
- import { ProtocolError } from '@wasm-idle/core';
1
+ import { ProtocolError, normalizeDebugSourceBreakpoints, mergeDebugBreakpointLines, assertDebugBreakpointSupport, normalizeDebugSteppingOptions } from '@wasm-idle/core';
2
2
  import { createBrowserLldbSession, DapProtocolError } from '@wasm-idle/llvm-core/debug';
3
3
  import { loadVerifiedDebugRuntimeManifest } from './lldbManifest';
4
4
  const MAX_DEBUG_MEMORY_BYTES = 256;
@@ -62,6 +62,29 @@ function dapOptionalNonNegativeSafeInteger(record, property, command, path) {
62
62
  assertDapNonNegativeSafeInteger(value, command, `${path}.${property}`);
63
63
  return value;
64
64
  }
65
+ function normalizePresentationHint(value, command, path) {
66
+ assertDapRecord(value, command, path);
67
+ const result = {};
68
+ for (const key of ['kind', 'visibility']) {
69
+ if (value[key] !== undefined) {
70
+ assertDapString(value[key], command, `${path}.${key}`);
71
+ result[key] = value[key];
72
+ }
73
+ }
74
+ if (value.lazy !== undefined) {
75
+ assertDapBoolean(value.lazy, command, `${path}.lazy`);
76
+ result.lazy = value.lazy;
77
+ }
78
+ if (value.attributes !== undefined) {
79
+ if (!Array.isArray(value.attributes) || value.attributes.length > 64)
80
+ invalidDapResponse(command, `${path}.attributes`, 'expected an array of at most 64 strings');
81
+ result.attributes = value.attributes.map((attribute, index) => {
82
+ assertDapString(attribute, command, `${path}.attributes[${index}]`);
83
+ return attribute;
84
+ });
85
+ }
86
+ return result;
87
+ }
65
88
  function snapshotBreakpointLines(lines) {
66
89
  if (lines.some((line) => !Number.isSafeInteger(line) || line < 1)) {
67
90
  throw new RangeError('LLDB breakpoint lines must be positive safe integers.');
@@ -91,8 +114,17 @@ function assertOptionalBooleanArgument(value, name) {
91
114
  throw new TypeError(`${name} must be a boolean.`);
92
115
  }
93
116
  }
117
+ let nextSandboxSessionId = 1;
94
118
  export class LldbSandboxSession {
95
119
  options;
120
+ sessionIdentity = `lldb-sandbox-${nextSandboxSessionId++}`;
121
+ stopId = 0;
122
+ supportsConditionalBreakpoints = false;
123
+ supportsHitConditionalBreakpoints = false;
124
+ supportsLogPoints = false;
125
+ supportsSkipLibraryCode = false;
126
+ supportsEvaluateForHovers = false;
127
+ breakpointSpecificationsBySource = new Map();
96
128
  session;
97
129
  startupAbortController;
98
130
  activeThreadId = 1;
@@ -130,8 +162,13 @@ export class LldbSandboxSession {
130
162
  const sourceBreakpoints = options.sourceBreakpoints?.length
131
163
  ? options.sourceBreakpoints
132
164
  : [{ sourcePath: options.sourcePath, lines: options.breakpoints }];
133
- for (const { sourcePath, lines } of sourceBreakpoints) {
134
- this.breakpointsBySource.set(sourcePath, snapshotBreakpointLines(lines));
165
+ for (const { sourcePath, lines, breakpoints } of sourceBreakpoints) {
166
+ const values = breakpoints ? normalizeDebugSourceBreakpoints(breakpoints) : undefined;
167
+ if (values)
168
+ this.breakpointSpecificationsBySource.set(sourcePath, values);
169
+ this.breakpointsBySource.set(sourcePath, values
170
+ ? values.filter((value) => value.enabled !== false).map((value) => value.line)
171
+ : snapshotBreakpointLines(lines));
135
172
  }
136
173
  for (const source of options.artifact.sources) {
137
174
  if (source.contentSha256) {
@@ -219,20 +256,33 @@ export class LldbSandboxSession {
219
256
  let session;
220
257
  const sourceBreakpoints = Array.from(this.breakpointsBySource, ([sourcePath, lines]) => ({
221
258
  sourcePath,
222
- lines: [...lines]
259
+ lines: [...lines],
260
+ ...(this.breakpointSpecificationsBySource.has(sourcePath)
261
+ ? {
262
+ breakpoints: normalizeDebugSourceBreakpoints(this.breakpointSpecificationsBySource.get(sourcePath))
263
+ }
264
+ : {})
223
265
  }));
224
266
  const configuredBreakpointVersion = this.breakpointVersion;
225
267
  session = createBrowserLldbSession({
226
268
  persistentCache: this.options.persistentCache,
269
+ compiledModuleCache: this.options.compiledModuleCache,
270
+ workerFactory: this.options.workerFactory,
227
271
  manifest,
228
272
  runtimeBaseUrl: this.options.runtimeBaseUrl,
229
273
  module: this.options.artifact.bytes,
230
274
  moduleSha256: this.options.artifact.descriptor?.moduleSha256,
231
275
  sources: this.options.artifact.sources,
232
- breakpoints: sourceBreakpoints.map(({ sourcePath, lines }) => ({
276
+ breakpoints: sourceBreakpoints.map(({ sourcePath, lines, breakpoints }) => ({
233
277
  source: { path: sourcePath },
234
- lines
278
+ lines,
279
+ ...(breakpoints ? { breakpoints } : {})
235
280
  })),
281
+ ...(this.options.debugSteppingOptions
282
+ ? {
283
+ steppingOptions: normalizeDebugSteppingOptions(this.options.debugSteppingOptions)
284
+ }
285
+ : {}),
236
286
  launch: {
237
287
  program: '/workspace/program.wasm',
238
288
  stopOnEntry: this.options.pauseOnEntry,
@@ -240,6 +290,15 @@ export class LldbSandboxSession {
240
290
  },
241
291
  fetchImpl: this.options.fetchImpl,
242
292
  onOutput: (_channel, output) => this.options.onOutput(output),
293
+ onDebuggerOutput: (channel, output) => {
294
+ if (lifecycleVersion !== this.lifecycleVersion || this.session !== session)
295
+ return;
296
+ this.publishDebuggerOutput({
297
+ type: 'output',
298
+ category: channel === 'stderr' ? 'important' : 'console',
299
+ output
300
+ });
301
+ },
243
302
  onLifecycle: (event) => {
244
303
  if (lifecycleVersion !== this.lifecycleVersion || this.session !== session) {
245
304
  return;
@@ -289,6 +348,19 @@ export class LldbSandboxSession {
289
348
  this.supportsDataBreakpoints =
290
349
  manifestSupportsDataBreakpoints && capabilities.supportsDataBreakpoints === true;
291
350
  this.supportsValueFormatting = capabilities.supportsValueFormattingOptions === true;
351
+ this.supportsConditionalBreakpoints =
352
+ manifest.debugger?.capabilities?.conditionalBreakpoints === true &&
353
+ capabilities.supportsConditionalBreakpoints === true;
354
+ this.supportsHitConditionalBreakpoints =
355
+ manifest.debugger?.capabilities?.hitConditionalBreakpoints === true &&
356
+ capabilities.supportsHitConditionalBreakpoints === true;
357
+ this.supportsLogPoints =
358
+ manifest.debugger?.capabilities?.logPoints === true &&
359
+ capabilities.supportsLogPoints === true;
360
+ this.supportsSkipLibraryCode =
361
+ manifest.debugger?.capabilities?.skipLibraryCode === true;
362
+ this.supportsEvaluateForHovers =
363
+ this.supportsEvaluateExpressions && capabilities.supportsEvaluateForHovers === true;
292
364
  this.initialized = true;
293
365
  if (configuredBreakpointVersion === this.breakpointVersion) {
294
366
  for (const { sourcePath, lines } of sourceBreakpoints) {
@@ -297,7 +369,11 @@ export class LldbSandboxSession {
297
369
  }
298
370
  else {
299
371
  for (const [sourcePath, lines] of this.breakpointsBySource) {
300
- await this.setBreakpoints(lines, sourcePath);
372
+ const values = this.breakpointSpecificationsBySource.get(sourcePath);
373
+ if (values)
374
+ await this.setSourceBreakpoints(values, sourcePath);
375
+ else
376
+ await this.setBreakpoints(lines, sourcePath);
301
377
  }
302
378
  }
303
379
  // Startup breakpoint edits must reach LLDB before automatic source entry. Do not
@@ -391,7 +467,34 @@ export class LldbSandboxSession {
391
467
  }
392
468
  }
393
469
  async setBreakpoints(lines, sourcePath = this.options.sourcePath) {
394
- const requestedLines = snapshotBreakpointLines(lines);
470
+ if (this.breakpointSpecificationsBySource.has(sourcePath))
471
+ return this.setSourceBreakpoints(mergeDebugBreakpointLines(this.breakpointSpecificationsBySource.get(sourcePath), snapshotBreakpointLines(lines)), sourcePath);
472
+ return this.updateSourceBreakpoints(snapshotBreakpointLines(lines).map((line) => ({ line })), sourcePath, false);
473
+ }
474
+ async setSourceBreakpoints(breakpoints, sourcePath = this.options.sourcePath) {
475
+ const values = normalizeDebugSourceBreakpoints(breakpoints);
476
+ if (this.initialized)
477
+ assertDebugBreakpointSupport(values, {
478
+ conditionalBreakpoints: this.supportsConditionalBreakpoints,
479
+ hitConditionalBreakpoints: this.supportsHitConditionalBreakpoints,
480
+ logPoints: this.supportsLogPoints
481
+ });
482
+ return this.updateSourceBreakpoints(values, sourcePath, true);
483
+ }
484
+ async setSteppingOptions(options) {
485
+ const value = normalizeDebugSteppingOptions(options);
486
+ if (!this.supportsSkipLibraryCode || !this.targetStopped)
487
+ throw new Error('Pause a qualified LLDB session before changing stepping options.');
488
+ await this.requireSession().setSteppingOptions(value);
489
+ }
490
+ async updateSourceBreakpoints(values, sourcePath, structured) {
491
+ const requestedLines = values
492
+ .filter((value) => value.enabled !== false)
493
+ .map((value) => value.line);
494
+ if (structured)
495
+ this.breakpointSpecificationsBySource.set(sourcePath, values);
496
+ else
497
+ this.breakpointSpecificationsBySource.delete(sourcePath);
395
498
  this.breakpointsBySource.set(sourcePath, requestedLines);
396
499
  this.breakpointVersion += 1;
397
500
  const requestVersion = (this.breakpointRequestVersions.get(sourcePath) ?? 0) + 1;
@@ -401,7 +504,9 @@ export class LldbSandboxSession {
401
504
  const session = this.requireSession();
402
505
  let breakpoints;
403
506
  try {
404
- breakpoints = await session.setBreakpoints({ path: sourcePath }, requestedLines);
507
+ breakpoints = structured
508
+ ? await session.setSourceBreakpoints({ path: sourcePath }, values)
509
+ : await session.setBreakpoints({ path: sourcePath }, requestedLines);
405
510
  }
406
511
  catch (error) {
407
512
  if (this.session !== session ||
@@ -420,30 +525,66 @@ export class LldbSandboxSession {
420
525
  async evaluate(expression) {
421
526
  if (!this.supportsEvaluateExpressions || !this.activeFrameId)
422
527
  return '?';
528
+ return (await this.evaluateValue(expression)).result;
529
+ }
530
+ async evaluateValue(expression, options = {}) {
531
+ assertBoundedNonEmptyStringArgument(expression, 'expression');
532
+ if (!options ||
533
+ typeof options !== 'object' ||
534
+ Array.isArray(options) ||
535
+ Object.keys(options).some((key) => key !== 'frameId' && key !== 'context'))
536
+ throw new TypeError('Invalid evaluate options.');
537
+ if (options.frameId !== undefined)
538
+ assertPositiveSafeIntegerArgument(options.frameId, 'frameId');
539
+ if (options.context !== undefined &&
540
+ options.context !== 'watch' &&
541
+ options.context !== 'hover')
542
+ throw new TypeError('evaluate context must be watch or hover.');
543
+ const unavailable = { result: '?', variablesReference: 0 };
544
+ if (!this.supportsEvaluateExpressions ||
545
+ !this.activeFrameId ||
546
+ (options.context === 'hover' && !this.supportsEvaluateForHovers))
547
+ return unavailable;
423
548
  const session = this.requireSession();
424
549
  const stateVersion = this.stateVersion;
425
550
  const scopeRequestVersion = this.scopeRequestVersion;
426
- const frameId = this.activeFrameId;
551
+ const frameId = options.frameId ?? this.activeFrameId;
427
552
  try {
428
553
  const response = await session.request('evaluate', {
429
554
  expression,
430
555
  frameId,
431
- context: 'watch'
556
+ context: options.context ?? 'watch'
432
557
  });
433
- if (!this.isCurrentValueRequest(session, stateVersion, scopeRequestVersion)) {
434
- return '?';
435
- }
558
+ if (!this.isCurrentValueRequest(session, stateVersion, scopeRequestVersion))
559
+ return unavailable;
436
560
  assertDapRecord(response, 'evaluate', 'body');
437
561
  assertDapString(response.result, 'evaluate', 'result');
438
562
  assertDapNonNegativeSafeInteger(response.variablesReference, 'evaluate', 'variablesReference');
439
- return response.result;
563
+ for (const key of ['type', 'memoryReference'])
564
+ if (response[key] !== undefined)
565
+ assertDapString(response[key], 'evaluate', key);
566
+ const namedVariables = dapOptionalNonNegativeSafeInteger(response, 'namedVariables', 'evaluate', 'body');
567
+ const indexedVariables = dapOptionalNonNegativeSafeInteger(response, 'indexedVariables', 'evaluate', 'body');
568
+ const presentationHint = response.presentationHint === undefined
569
+ ? undefined
570
+ : normalizePresentationHint(response.presentationHint, 'evaluate', 'presentationHint');
571
+ return {
572
+ result: response.result,
573
+ variablesReference: response.variablesReference,
574
+ ...(response.type === undefined ? {} : { type: response.type }),
575
+ ...(response.memoryReference === undefined
576
+ ? {}
577
+ : { memoryReference: response.memoryReference }),
578
+ ...(namedVariables === undefined ? {} : { namedVariables }),
579
+ ...(indexedVariables === undefined ? {} : { indexedVariables }),
580
+ ...(presentationHint === undefined ? {} : { presentationHint })
581
+ };
440
582
  }
441
583
  catch (error) {
442
- if (!this.isCurrentValueRequest(session, stateVersion, scopeRequestVersion)) {
443
- return '?';
444
- }
584
+ if (!this.isCurrentValueRequest(session, stateVersion, scopeRequestVersion))
585
+ return unavailable;
445
586
  this.rethrowProtocolError(error);
446
- return '?';
587
+ return unavailable;
447
588
  }
448
589
  }
449
590
  async variables(variablesReference, start, count) {
@@ -470,6 +611,9 @@ export class LldbSandboxSession {
470
611
  assertDapString(variable.name, 'variables', `${path}.name`);
471
612
  assertDapString(variable.value, 'variables', `${path}.value`);
472
613
  assertDapNonNegativeSafeInteger(variable.variablesReference, 'variables', `${path}.variablesReference`);
614
+ const presentationHint = variable.presentationHint === undefined
615
+ ? undefined
616
+ : normalizePresentationHint(variable.presentationHint, 'variables', `${path}.presentationHint`);
473
617
  const type = variable.type;
474
618
  if (type !== undefined)
475
619
  assertDapString(type, 'variables', `${path}.type`);
@@ -485,6 +629,7 @@ export class LldbSandboxSession {
485
629
  const indexedVariables = dapOptionalNonNegativeSafeInteger(variable, 'indexedVariables', 'variables', path);
486
630
  return {
487
631
  name: variable.name,
632
+ ...(presentationHint === undefined ? {} : { presentationHint }),
488
633
  value: variable.value,
489
634
  type,
490
635
  ...(evaluateName === undefined ? {} : { evaluateName }),
@@ -925,8 +1070,28 @@ export class LldbSandboxSession {
925
1070
  handleDapEvent(event) {
926
1071
  if (event.event === 'output') {
927
1072
  const body = event.body;
928
- if (typeof body?.output === 'string')
1073
+ if (typeof body?.output !== 'string')
1074
+ return;
1075
+ if (body.category === 'stdout' || body.category === 'stderr') {
929
1076
  this.options.onOutput(body.output);
1077
+ }
1078
+ else if (body.category !== 'telemetry') {
1079
+ // DAP defaults missing or unknown categories to debugger console output.
1080
+ // Keep console logpoints and their source location available to host UIs.
1081
+ this.publishDebuggerOutput({
1082
+ type: 'output',
1083
+ category: body.category === 'important' ? 'important' : 'console',
1084
+ output: body.output,
1085
+ ...(typeof body.source?.path === 'string'
1086
+ ? { sourcePath: body.source.path }
1087
+ : {}),
1088
+ ...(typeof body.line === 'number' &&
1089
+ Number.isSafeInteger(body.line) &&
1090
+ body.line > 0
1091
+ ? { line: body.line }
1092
+ : {})
1093
+ });
1094
+ }
930
1095
  return;
931
1096
  }
932
1097
  if (event.event === 'stopped') {
@@ -948,7 +1113,11 @@ export class LldbSandboxSession {
948
1113
  typeof body.allThreadsStopped !== 'boolean') {
949
1114
  invalidDapPayload('stopped event', 'allThreadsStopped', 'expected a boolean');
950
1115
  }
951
- const reason = this.pauseRequested && body.reason === 'exception' ? 'pause' : body.reason;
1116
+ const reason = this.pauseRequested &&
1117
+ (body.reason === 'exception' ||
1118
+ (this.entryPhase === 'initial' && body.reason === 'entry'))
1119
+ ? 'pause'
1120
+ : body.reason;
952
1121
  this.pauseRequested = false;
953
1122
  const session = this.requireSession();
954
1123
  const version = ++this.stateVersion;
@@ -1009,26 +1178,11 @@ export class LldbSandboxSession {
1009
1178
  if (event.event === 'terminated')
1010
1179
  return;
1011
1180
  }
1012
- async resolveStoppedState(requestedThreadId, reason, version) {
1013
- const session = this.requireSession();
1014
- let threadId = requestedThreadId;
1015
- if (threadId === undefined) {
1016
- const response = await session.request('threads');
1017
- const threads = dapResponseCollection(response, 'threads', 'threads').map((thread, index) => {
1018
- const path = `threads[${index}]`;
1019
- assertDapRecord(thread, 'threads', path);
1020
- assertDapPositiveSafeInteger(thread.id, 'threads response', `${path}.id`);
1021
- assertDapString(thread.name, 'threads', `${path}.name`);
1022
- return { id: thread.id, name: thread.name };
1023
- });
1024
- threadId = threads[0]?.id;
1025
- }
1026
- if (!threadId)
1027
- throw new Error('LLDB stopped without a WebAssembly thread.');
1181
+ async requestStackPage(session, threadId, startFrame, levels) {
1028
1182
  const response = await session.request('stackTrace', {
1029
1183
  threadId,
1030
- startFrame: 0,
1031
- levels: 100
1184
+ startFrame,
1185
+ levels
1032
1186
  });
1033
1187
  const frames = dapResponseCollection(response, 'stackTrace', 'stackFrames').map((frame, index) => {
1034
1188
  const path = `stackFrames[${index}]`;
@@ -1054,6 +1208,42 @@ export class LldbSandboxSession {
1054
1208
  column: frame.column
1055
1209
  };
1056
1210
  });
1211
+ if (frames.length > levels)
1212
+ invalidDapResponse('stackTrace', 'stackFrames', 'page exceeds requested levels');
1213
+ const totalFrames = dapOptionalNonNegativeSafeInteger(response, 'totalFrames', 'stackTrace', 'body');
1214
+ return { frames, totalFrames };
1215
+ }
1216
+ debugFrames(frames) {
1217
+ return frames.map((frame) => {
1218
+ const sourcePath = frame.source?.path;
1219
+ const sourceContentSha256 = this.sourceContentSha256ByPath.get(sourcePath || '');
1220
+ return {
1221
+ id: frame.id,
1222
+ functionName: frame.name,
1223
+ line: frame.line,
1224
+ column: frame.column,
1225
+ sourcePath,
1226
+ ...(sourceContentSha256 ? { sourceContentSha256 } : {})
1227
+ };
1228
+ });
1229
+ }
1230
+ async resolveStoppedState(requestedThreadId, reason, version) {
1231
+ const session = this.requireSession();
1232
+ let threadId = requestedThreadId;
1233
+ if (threadId === undefined) {
1234
+ const response = await session.request('threads');
1235
+ const threads = dapResponseCollection(response, 'threads', 'threads').map((thread, index) => {
1236
+ const path = `threads[${index}]`;
1237
+ assertDapRecord(thread, 'threads', path);
1238
+ assertDapPositiveSafeInteger(thread.id, 'threads response', `${path}.id`);
1239
+ assertDapString(thread.name, 'threads', `${path}.name`);
1240
+ return { id: thread.id, name: thread.name };
1241
+ });
1242
+ threadId = threads[0]?.id;
1243
+ }
1244
+ if (!threadId)
1245
+ throw new Error('LLDB stopped without a WebAssembly thread.');
1246
+ const { frames, totalFrames } = await this.requestStackPage(session, threadId, 0, 1);
1057
1247
  const selectedFrame = frames[0];
1058
1248
  if (!selectedFrame)
1059
1249
  throw new Error('LLDB stopped without a stack frame.');
@@ -1065,7 +1255,9 @@ export class LldbSandboxSession {
1065
1255
  if (!this.isCurrentValueRequest(session, version))
1066
1256
  return;
1067
1257
  this.entryPhase = 'done';
1068
- if (reason === 'entry' && selectedFrame.name === '_start' && !isWorkspaceFrame) {
1258
+ if (reason === 'entry' && !isWorkspaceFrame) {
1259
+ // WAMR's initial stop can resolve to a WASI import wrapper in Rust modules.
1260
+ // Only the entry reason authorizes running past a non-workspace frame.
1069
1261
  // configurationDone has already installed all user source breakpoints. Function
1070
1262
  // breakpoints occupy a separate DAP registry owned by this product session.
1071
1263
  this.entryPhase = 'seeking-main';
@@ -1086,7 +1278,11 @@ export class LldbSandboxSession {
1086
1278
  reason = 'pause';
1087
1279
  }
1088
1280
  else {
1089
- this.options.onOutput('LLDB could not resolve main; paused at runtime entry.\n');
1281
+ this.publishDebuggerOutput({
1282
+ type: 'output',
1283
+ category: 'important',
1284
+ output: `LLDB could not resolve ${this.options.entryFunctionName ?? 'main'}; paused at runtime entry.\n`
1285
+ });
1090
1286
  }
1091
1287
  }
1092
1288
  }
@@ -1097,36 +1293,37 @@ export class LldbSandboxSession {
1097
1293
  await this.setMainEntryBreakpoint(session, false);
1098
1294
  if (!this.isCurrentValueRequest(session, version))
1099
1295
  return;
1100
- if (reason === 'breakpoint' && selectedFrame.name === 'main' && isWorkspaceFrame) {
1296
+ if (reason === 'breakpoint' &&
1297
+ selectedFrame.name === (this.options.entryFunctionName ?? 'main') &&
1298
+ isWorkspaceFrame) {
1101
1299
  reason = 'entry';
1102
1300
  }
1103
1301
  }
1104
- const scopes = isWorkspaceFrame ? await this.requestScopes(session, selectedFrame.id) : [];
1105
1302
  if (version !== this.stateVersion || this.session !== session)
1106
1303
  return;
1107
1304
  this.activeThreadId = threadId;
1108
1305
  this.activeFrameId = selectedFrame.id;
1109
1306
  this.stoppedFrames = frames;
1110
1307
  this.targetStopped = true;
1111
- const callStack = frames.map((frame) => {
1112
- const sourcePath = frame.source?.path;
1113
- const sourceContentSha256 = this.sourceContentSha256ByPath.get(sourcePath || '');
1114
- return {
1115
- id: frame.id,
1116
- functionName: frame.name,
1117
- line: frame.line,
1118
- column: frame.column,
1119
- sourcePath,
1120
- ...(sourceContentSha256 ? { sourceContentSha256 } : {})
1121
- };
1122
- });
1123
1308
  const sourceContentSha256 = this.sourceContentSha256ByPath.get(selectedFrame.source?.path || '');
1309
+ const stopId = ++this.stopId;
1310
+ const sessionId = `${this.sessionIdentity}-${this.lifecycleVersion}`;
1124
1311
  this.options.onDebugEvent({
1125
1312
  type: 'pause',
1313
+ sessionId,
1314
+ stopId,
1126
1315
  capabilities: {
1127
1316
  readMemory: this.supportsReadMemory,
1128
1317
  writeMemory: this.supportsWriteMemory,
1129
- dataBreakpoints: this.supportsDataBreakpoints
1318
+ dataBreakpoints: this.supportsDataBreakpoints,
1319
+ ...(this.supportsEvaluateExpressions ? { evaluateValues: true } : {}),
1320
+ ...(this.supportsEvaluateForHovers ? { evaluateForHovers: true } : {}),
1321
+ ...(this.supportsConditionalBreakpoints ? { conditionalBreakpoints: true } : {}),
1322
+ ...(this.supportsHitConditionalBreakpoints
1323
+ ? { hitConditionalBreakpoints: true }
1324
+ : {}),
1325
+ ...(this.supportsLogPoints ? { logPoints: true } : {}),
1326
+ ...(this.supportsSkipLibraryCode ? { skipLibraryCode: true } : {})
1130
1327
  },
1131
1328
  line: selectedFrame.line,
1132
1329
  sourcePath: selectedFrame.source?.path,
@@ -1136,14 +1333,70 @@ export class LldbSandboxSession {
1136
1333
  threadId,
1137
1334
  frameId: selectedFrame.id,
1138
1335
  locals: [],
1139
- callStack,
1140
- scopes
1336
+ callStack: this.debugFrames(frames),
1337
+ callStackComplete: totalFrames !== undefined && frames.length >= totalFrames,
1338
+ scopes: []
1141
1339
  });
1142
1340
  this.command = null;
1341
+ // Publish the navigable top frame before requesting any scope metadata or
1342
+ // unwinding deeper frames. Each subsequent result belongs to this exact stop.
1343
+ await Promise.all([
1344
+ (async () => {
1345
+ if (!isWorkspaceFrame || !this.isCurrentValueRequest(session, version))
1346
+ return;
1347
+ const scopes = await this.requestScopes(session, selectedFrame.id);
1348
+ if (!this.isCurrentValueRequest(session, version))
1349
+ return;
1350
+ this.options.onDebugEvent({
1351
+ type: 'pauseDetails',
1352
+ sessionId,
1353
+ stopId,
1354
+ frameId: selectedFrame.id,
1355
+ scopes
1356
+ });
1357
+ })(),
1358
+ (async () => {
1359
+ let knownTotalFrames = totalFrames;
1360
+ let end = totalFrames === undefined ? 100 : Math.min(totalFrames, 100);
1361
+ while (frames.length < end && this.isCurrentValueRequest(session, version)) {
1362
+ const { frames: page, totalFrames: total } = await this.requestStackPage(session, threadId, frames.length, Math.min(20, end - frames.length));
1363
+ if (!this.isCurrentValueRequest(session, version))
1364
+ return;
1365
+ if (total !== undefined) {
1366
+ knownTotalFrames = total;
1367
+ end = Math.min(total, 100);
1368
+ }
1369
+ if (!page.length) {
1370
+ this.options.onDebugEvent({
1371
+ type: 'pauseDetails',
1372
+ sessionId,
1373
+ stopId,
1374
+ callStack: this.debugFrames(frames),
1375
+ callStackComplete: knownTotalFrames === undefined || frames.length >= knownTotalFrames
1376
+ });
1377
+ break;
1378
+ }
1379
+ const ids = new Set(frames.map((frame) => frame.id));
1380
+ for (const frame of page) {
1381
+ if (ids.has(frame.id))
1382
+ invalidDapResponse('stackTrace', 'stackFrames', 'duplicate frame id across pages');
1383
+ ids.add(frame.id);
1384
+ }
1385
+ frames.push(...page);
1386
+ this.options.onDebugEvent({
1387
+ type: 'pauseDetails',
1388
+ sessionId,
1389
+ stopId,
1390
+ callStack: this.debugFrames(frames),
1391
+ callStackComplete: knownTotalFrames !== undefined && frames.length >= knownTotalFrames
1392
+ });
1393
+ }
1394
+ })()
1395
+ ]);
1143
1396
  }
1144
1397
  async setMainEntryBreakpoint(session, enabled) {
1145
1398
  const response = await session.request('setFunctionBreakpoints', {
1146
- breakpoints: enabled ? [{ name: 'main' }] : []
1399
+ breakpoints: enabled ? [{ name: this.options.entryFunctionName ?? 'main' }] : []
1147
1400
  });
1148
1401
  const breakpoints = dapResponseCollection(response, 'setFunctionBreakpoints', 'breakpoints');
1149
1402
  if (breakpoints.length !== (enabled ? 1 : 0)) {
@@ -1267,6 +1520,16 @@ export class LldbSandboxSession {
1267
1520
  // Consumer callbacks cannot interrupt target teardown or completion settlement.
1268
1521
  }
1269
1522
  }
1523
+ publishDebuggerOutput(event) {
1524
+ if (!event.output)
1525
+ return;
1526
+ try {
1527
+ this.options.onDebugEvent(event);
1528
+ }
1529
+ catch {
1530
+ // A diagnostics consumer must not interrupt target execution or teardown.
1531
+ }
1532
+ }
1270
1533
  publishActiveDebugEvent(event) {
1271
1534
  try {
1272
1535
  this.options.onDebugEvent(event);
@@ -0,0 +1,2 @@
1
+ /** Match the compiler's DWARF workspace paths without loading the compiler runtime. */
2
+ export declare function normalizeLldbWorkspacePath(path: string): string;
@@ -0,0 +1,9 @@
1
+ /** Match the compiler's DWARF workspace paths without loading the compiler runtime. */
2
+ export function normalizeLldbWorkspacePath(path) {
3
+ const normalized = path
4
+ .replaceAll('\\', '/')
5
+ .split('/')
6
+ .filter((part) => part && part !== '.' && part !== '..')
7
+ .join('/');
8
+ return normalized.startsWith('workspace/') ? normalized.slice('workspace/'.length) : normalized;
9
+ }
@@ -1,5 +1,5 @@
1
1
  import { type PlaygroundRuntimeAssets } from './assets';
2
- import { type CompilerDiagnostic, type SandboxExecutionOptions } from './options';
2
+ import { type CompilerDiagnostic, type DebugCommand, type DebugScope, type DebugSessionEvent, type DebugVariable, type SandboxExecutionOptions } from './options';
3
3
  import type { Sandbox, SandboxProgress } from './sandbox';
4
4
  /**
5
5
  * Describes a language that runs on the wasm-lua (wasmoon) VM. Lua itself uses the
@@ -26,6 +26,7 @@ declare class Lua implements Sandbox {
26
26
  exit: boolean;
27
27
  moduleUrl: string;
28
28
  oncompilerdiagnostic?: (diagnostic: CompilerDiagnostic) => void;
29
+ ondebug?: (event: DebugSessionEvent) => void;
29
30
  waitingForInput: boolean;
30
31
  pendingEof: boolean;
31
32
  private activeOperation;
@@ -37,6 +38,14 @@ declare class Lua implements Sandbox {
37
38
  private workerIdentity;
38
39
  private readonly disposeCancellation;
39
40
  private readonly workerSession;
41
+ private readonly debugMailbox;
42
+ private debugEnabled;
43
+ private debugPaused;
44
+ private debugPath;
45
+ private debugFrames;
46
+ private selectedDebugFrame;
47
+ private evaluationId;
48
+ private pendingEvaluations;
40
49
  constructor(dialect?: LuaSandboxDialect);
41
50
  private requireOperationIdle;
42
51
  private beginOperation;
@@ -47,6 +56,16 @@ declare class Lua implements Sandbox {
47
56
  private bindPreSessionAbort;
48
57
  private bindAbortSignal;
49
58
  private bindOperationTimeout;
59
+ private pauseDebugTimeout;
60
+ private finishDebug;
61
+ private handleDebugEvent;
62
+ debugCommand(command: DebugCommand): void;
63
+ setBreakpoints(lines: number[], sourcePath?: string): void;
64
+ debugEvaluate(expression: string): Promise<string>;
65
+ debugScopes(frameId?: number): Promise<DebugScope[]>;
66
+ debugFrameScopes(frameId: number): Promise<DebugScope[]>;
67
+ debugFrameName(frameId: number): Promise<string | null>;
68
+ debugVariables(reference: number, start?: number, count?: number): Promise<DebugVariable[]>;
50
69
  private resetExplicitStdinState;
51
70
  private finishExplicitStdin;
52
71
  load(runtimeAssets?: string | PlaygroundRuntimeAssets, _code?: string, _log?: boolean, _args?: string[], options?: SandboxExecutionOptions, progress?: SandboxProgress): Promise<void>;