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
@@ -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,
@@ -289,6 +339,19 @@ export class LldbSandboxSession {
289
339
  this.supportsDataBreakpoints =
290
340
  manifestSupportsDataBreakpoints && capabilities.supportsDataBreakpoints === true;
291
341
  this.supportsValueFormatting = capabilities.supportsValueFormattingOptions === true;
342
+ this.supportsConditionalBreakpoints =
343
+ manifest.debugger?.capabilities?.conditionalBreakpoints === true &&
344
+ capabilities.supportsConditionalBreakpoints === true;
345
+ this.supportsHitConditionalBreakpoints =
346
+ manifest.debugger?.capabilities?.hitConditionalBreakpoints === true &&
347
+ capabilities.supportsHitConditionalBreakpoints === true;
348
+ this.supportsLogPoints =
349
+ manifest.debugger?.capabilities?.logPoints === true &&
350
+ capabilities.supportsLogPoints === true;
351
+ this.supportsSkipLibraryCode =
352
+ manifest.debugger?.capabilities?.skipLibraryCode === true;
353
+ this.supportsEvaluateForHovers =
354
+ this.supportsEvaluateExpressions && capabilities.supportsEvaluateForHovers === true;
292
355
  this.initialized = true;
293
356
  if (configuredBreakpointVersion === this.breakpointVersion) {
294
357
  for (const { sourcePath, lines } of sourceBreakpoints) {
@@ -297,7 +360,11 @@ export class LldbSandboxSession {
297
360
  }
298
361
  else {
299
362
  for (const [sourcePath, lines] of this.breakpointsBySource) {
300
- await this.setBreakpoints(lines, sourcePath);
363
+ const values = this.breakpointSpecificationsBySource.get(sourcePath);
364
+ if (values)
365
+ await this.setSourceBreakpoints(values, sourcePath);
366
+ else
367
+ await this.setBreakpoints(lines, sourcePath);
301
368
  }
302
369
  }
303
370
  // Startup breakpoint edits must reach LLDB before automatic source entry. Do not
@@ -391,7 +458,34 @@ export class LldbSandboxSession {
391
458
  }
392
459
  }
393
460
  async setBreakpoints(lines, sourcePath = this.options.sourcePath) {
394
- const requestedLines = snapshotBreakpointLines(lines);
461
+ if (this.breakpointSpecificationsBySource.has(sourcePath))
462
+ return this.setSourceBreakpoints(mergeDebugBreakpointLines(this.breakpointSpecificationsBySource.get(sourcePath), snapshotBreakpointLines(lines)), sourcePath);
463
+ return this.updateSourceBreakpoints(snapshotBreakpointLines(lines).map((line) => ({ line })), sourcePath, false);
464
+ }
465
+ async setSourceBreakpoints(breakpoints, sourcePath = this.options.sourcePath) {
466
+ const values = normalizeDebugSourceBreakpoints(breakpoints);
467
+ if (this.initialized)
468
+ assertDebugBreakpointSupport(values, {
469
+ conditionalBreakpoints: this.supportsConditionalBreakpoints,
470
+ hitConditionalBreakpoints: this.supportsHitConditionalBreakpoints,
471
+ logPoints: this.supportsLogPoints
472
+ });
473
+ return this.updateSourceBreakpoints(values, sourcePath, true);
474
+ }
475
+ async setSteppingOptions(options) {
476
+ const value = normalizeDebugSteppingOptions(options);
477
+ if (!this.supportsSkipLibraryCode || !this.targetStopped)
478
+ throw new Error('Pause a qualified LLDB session before changing stepping options.');
479
+ await this.requireSession().setSteppingOptions(value);
480
+ }
481
+ async updateSourceBreakpoints(values, sourcePath, structured) {
482
+ const requestedLines = values
483
+ .filter((value) => value.enabled !== false)
484
+ .map((value) => value.line);
485
+ if (structured)
486
+ this.breakpointSpecificationsBySource.set(sourcePath, values);
487
+ else
488
+ this.breakpointSpecificationsBySource.delete(sourcePath);
395
489
  this.breakpointsBySource.set(sourcePath, requestedLines);
396
490
  this.breakpointVersion += 1;
397
491
  const requestVersion = (this.breakpointRequestVersions.get(sourcePath) ?? 0) + 1;
@@ -401,7 +495,9 @@ export class LldbSandboxSession {
401
495
  const session = this.requireSession();
402
496
  let breakpoints;
403
497
  try {
404
- breakpoints = await session.setBreakpoints({ path: sourcePath }, requestedLines);
498
+ breakpoints = structured
499
+ ? await session.setSourceBreakpoints({ path: sourcePath }, values)
500
+ : await session.setBreakpoints({ path: sourcePath }, requestedLines);
405
501
  }
406
502
  catch (error) {
407
503
  if (this.session !== session ||
@@ -420,30 +516,66 @@ export class LldbSandboxSession {
420
516
  async evaluate(expression) {
421
517
  if (!this.supportsEvaluateExpressions || !this.activeFrameId)
422
518
  return '?';
519
+ return (await this.evaluateValue(expression)).result;
520
+ }
521
+ async evaluateValue(expression, options = {}) {
522
+ assertBoundedNonEmptyStringArgument(expression, 'expression');
523
+ if (!options ||
524
+ typeof options !== 'object' ||
525
+ Array.isArray(options) ||
526
+ Object.keys(options).some((key) => key !== 'frameId' && key !== 'context'))
527
+ throw new TypeError('Invalid evaluate options.');
528
+ if (options.frameId !== undefined)
529
+ assertPositiveSafeIntegerArgument(options.frameId, 'frameId');
530
+ if (options.context !== undefined &&
531
+ options.context !== 'watch' &&
532
+ options.context !== 'hover')
533
+ throw new TypeError('evaluate context must be watch or hover.');
534
+ const unavailable = { result: '?', variablesReference: 0 };
535
+ if (!this.supportsEvaluateExpressions ||
536
+ !this.activeFrameId ||
537
+ (options.context === 'hover' && !this.supportsEvaluateForHovers))
538
+ return unavailable;
423
539
  const session = this.requireSession();
424
540
  const stateVersion = this.stateVersion;
425
541
  const scopeRequestVersion = this.scopeRequestVersion;
426
- const frameId = this.activeFrameId;
542
+ const frameId = options.frameId ?? this.activeFrameId;
427
543
  try {
428
544
  const response = await session.request('evaluate', {
429
545
  expression,
430
546
  frameId,
431
- context: 'watch'
547
+ context: options.context ?? 'watch'
432
548
  });
433
- if (!this.isCurrentValueRequest(session, stateVersion, scopeRequestVersion)) {
434
- return '?';
435
- }
549
+ if (!this.isCurrentValueRequest(session, stateVersion, scopeRequestVersion))
550
+ return unavailable;
436
551
  assertDapRecord(response, 'evaluate', 'body');
437
552
  assertDapString(response.result, 'evaluate', 'result');
438
553
  assertDapNonNegativeSafeInteger(response.variablesReference, 'evaluate', 'variablesReference');
439
- return response.result;
554
+ for (const key of ['type', 'memoryReference'])
555
+ if (response[key] !== undefined)
556
+ assertDapString(response[key], 'evaluate', key);
557
+ const namedVariables = dapOptionalNonNegativeSafeInteger(response, 'namedVariables', 'evaluate', 'body');
558
+ const indexedVariables = dapOptionalNonNegativeSafeInteger(response, 'indexedVariables', 'evaluate', 'body');
559
+ const presentationHint = response.presentationHint === undefined
560
+ ? undefined
561
+ : normalizePresentationHint(response.presentationHint, 'evaluate', 'presentationHint');
562
+ return {
563
+ result: response.result,
564
+ variablesReference: response.variablesReference,
565
+ ...(response.type === undefined ? {} : { type: response.type }),
566
+ ...(response.memoryReference === undefined
567
+ ? {}
568
+ : { memoryReference: response.memoryReference }),
569
+ ...(namedVariables === undefined ? {} : { namedVariables }),
570
+ ...(indexedVariables === undefined ? {} : { indexedVariables }),
571
+ ...(presentationHint === undefined ? {} : { presentationHint })
572
+ };
440
573
  }
441
574
  catch (error) {
442
- if (!this.isCurrentValueRequest(session, stateVersion, scopeRequestVersion)) {
443
- return '?';
444
- }
575
+ if (!this.isCurrentValueRequest(session, stateVersion, scopeRequestVersion))
576
+ return unavailable;
445
577
  this.rethrowProtocolError(error);
446
- return '?';
578
+ return unavailable;
447
579
  }
448
580
  }
449
581
  async variables(variablesReference, start, count) {
@@ -470,6 +602,9 @@ export class LldbSandboxSession {
470
602
  assertDapString(variable.name, 'variables', `${path}.name`);
471
603
  assertDapString(variable.value, 'variables', `${path}.value`);
472
604
  assertDapNonNegativeSafeInteger(variable.variablesReference, 'variables', `${path}.variablesReference`);
605
+ const presentationHint = variable.presentationHint === undefined
606
+ ? undefined
607
+ : normalizePresentationHint(variable.presentationHint, 'variables', `${path}.presentationHint`);
473
608
  const type = variable.type;
474
609
  if (type !== undefined)
475
610
  assertDapString(type, 'variables', `${path}.type`);
@@ -485,6 +620,7 @@ export class LldbSandboxSession {
485
620
  const indexedVariables = dapOptionalNonNegativeSafeInteger(variable, 'indexedVariables', 'variables', path);
486
621
  return {
487
622
  name: variable.name,
623
+ ...(presentationHint === undefined ? {} : { presentationHint }),
488
624
  value: variable.value,
489
625
  type,
490
626
  ...(evaluateName === undefined ? {} : { evaluateName }),
@@ -948,7 +1084,11 @@ export class LldbSandboxSession {
948
1084
  typeof body.allThreadsStopped !== 'boolean') {
949
1085
  invalidDapPayload('stopped event', 'allThreadsStopped', 'expected a boolean');
950
1086
  }
951
- const reason = this.pauseRequested && body.reason === 'exception' ? 'pause' : body.reason;
1087
+ const reason = this.pauseRequested &&
1088
+ (body.reason === 'exception' ||
1089
+ (this.entryPhase === 'initial' && body.reason === 'entry'))
1090
+ ? 'pause'
1091
+ : body.reason;
952
1092
  this.pauseRequested = false;
953
1093
  const session = this.requireSession();
954
1094
  const version = ++this.stateVersion;
@@ -1009,26 +1149,11 @@ export class LldbSandboxSession {
1009
1149
  if (event.event === 'terminated')
1010
1150
  return;
1011
1151
  }
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.');
1152
+ async requestStackPage(session, threadId, startFrame, levels) {
1028
1153
  const response = await session.request('stackTrace', {
1029
1154
  threadId,
1030
- startFrame: 0,
1031
- levels: 100
1155
+ startFrame,
1156
+ levels
1032
1157
  });
1033
1158
  const frames = dapResponseCollection(response, 'stackTrace', 'stackFrames').map((frame, index) => {
1034
1159
  const path = `stackFrames[${index}]`;
@@ -1054,6 +1179,42 @@ export class LldbSandboxSession {
1054
1179
  column: frame.column
1055
1180
  };
1056
1181
  });
1182
+ if (frames.length > levels)
1183
+ invalidDapResponse('stackTrace', 'stackFrames', 'page exceeds requested levels');
1184
+ const totalFrames = dapOptionalNonNegativeSafeInteger(response, 'totalFrames', 'stackTrace', 'body');
1185
+ return { frames, totalFrames };
1186
+ }
1187
+ debugFrames(frames) {
1188
+ return frames.map((frame) => {
1189
+ const sourcePath = frame.source?.path;
1190
+ const sourceContentSha256 = this.sourceContentSha256ByPath.get(sourcePath || '');
1191
+ return {
1192
+ id: frame.id,
1193
+ functionName: frame.name,
1194
+ line: frame.line,
1195
+ column: frame.column,
1196
+ sourcePath,
1197
+ ...(sourceContentSha256 ? { sourceContentSha256 } : {})
1198
+ };
1199
+ });
1200
+ }
1201
+ async resolveStoppedState(requestedThreadId, reason, version) {
1202
+ const session = this.requireSession();
1203
+ let threadId = requestedThreadId;
1204
+ if (threadId === undefined) {
1205
+ const response = await session.request('threads');
1206
+ const threads = dapResponseCollection(response, 'threads', 'threads').map((thread, index) => {
1207
+ const path = `threads[${index}]`;
1208
+ assertDapRecord(thread, 'threads', path);
1209
+ assertDapPositiveSafeInteger(thread.id, 'threads response', `${path}.id`);
1210
+ assertDapString(thread.name, 'threads', `${path}.name`);
1211
+ return { id: thread.id, name: thread.name };
1212
+ });
1213
+ threadId = threads[0]?.id;
1214
+ }
1215
+ if (!threadId)
1216
+ throw new Error('LLDB stopped without a WebAssembly thread.');
1217
+ const { frames, totalFrames } = await this.requestStackPage(session, threadId, 0, 1);
1057
1218
  const selectedFrame = frames[0];
1058
1219
  if (!selectedFrame)
1059
1220
  throw new Error('LLDB stopped without a stack frame.');
@@ -1065,7 +1226,9 @@ export class LldbSandboxSession {
1065
1226
  if (!this.isCurrentValueRequest(session, version))
1066
1227
  return;
1067
1228
  this.entryPhase = 'done';
1068
- if (reason === 'entry' && selectedFrame.name === '_start' && !isWorkspaceFrame) {
1229
+ if (reason === 'entry' && !isWorkspaceFrame) {
1230
+ // WAMR's initial stop can resolve to a WASI import wrapper in Rust modules.
1231
+ // Only the entry reason authorizes running past a non-workspace frame.
1069
1232
  // configurationDone has already installed all user source breakpoints. Function
1070
1233
  // breakpoints occupy a separate DAP registry owned by this product session.
1071
1234
  this.entryPhase = 'seeking-main';
@@ -1086,7 +1249,7 @@ export class LldbSandboxSession {
1086
1249
  reason = 'pause';
1087
1250
  }
1088
1251
  else {
1089
- this.options.onOutput('LLDB could not resolve main; paused at runtime entry.\n');
1252
+ this.options.onOutput(`LLDB could not resolve ${this.options.entryFunctionName ?? 'main'}; paused at runtime entry.\n`);
1090
1253
  }
1091
1254
  }
1092
1255
  }
@@ -1097,36 +1260,37 @@ export class LldbSandboxSession {
1097
1260
  await this.setMainEntryBreakpoint(session, false);
1098
1261
  if (!this.isCurrentValueRequest(session, version))
1099
1262
  return;
1100
- if (reason === 'breakpoint' && selectedFrame.name === 'main' && isWorkspaceFrame) {
1263
+ if (reason === 'breakpoint' &&
1264
+ selectedFrame.name === (this.options.entryFunctionName ?? 'main') &&
1265
+ isWorkspaceFrame) {
1101
1266
  reason = 'entry';
1102
1267
  }
1103
1268
  }
1104
- const scopes = isWorkspaceFrame ? await this.requestScopes(session, selectedFrame.id) : [];
1105
1269
  if (version !== this.stateVersion || this.session !== session)
1106
1270
  return;
1107
1271
  this.activeThreadId = threadId;
1108
1272
  this.activeFrameId = selectedFrame.id;
1109
1273
  this.stoppedFrames = frames;
1110
1274
  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
1275
  const sourceContentSha256 = this.sourceContentSha256ByPath.get(selectedFrame.source?.path || '');
1276
+ const stopId = ++this.stopId;
1277
+ const sessionId = `${this.sessionIdentity}-${this.lifecycleVersion}`;
1124
1278
  this.options.onDebugEvent({
1125
1279
  type: 'pause',
1280
+ sessionId,
1281
+ stopId,
1126
1282
  capabilities: {
1127
1283
  readMemory: this.supportsReadMemory,
1128
1284
  writeMemory: this.supportsWriteMemory,
1129
- dataBreakpoints: this.supportsDataBreakpoints
1285
+ dataBreakpoints: this.supportsDataBreakpoints,
1286
+ ...(this.supportsEvaluateExpressions ? { evaluateValues: true } : {}),
1287
+ ...(this.supportsEvaluateForHovers ? { evaluateForHovers: true } : {}),
1288
+ ...(this.supportsConditionalBreakpoints ? { conditionalBreakpoints: true } : {}),
1289
+ ...(this.supportsHitConditionalBreakpoints
1290
+ ? { hitConditionalBreakpoints: true }
1291
+ : {}),
1292
+ ...(this.supportsLogPoints ? { logPoints: true } : {}),
1293
+ ...(this.supportsSkipLibraryCode ? { skipLibraryCode: true } : {})
1130
1294
  },
1131
1295
  line: selectedFrame.line,
1132
1296
  sourcePath: selectedFrame.source?.path,
@@ -1136,14 +1300,70 @@ export class LldbSandboxSession {
1136
1300
  threadId,
1137
1301
  frameId: selectedFrame.id,
1138
1302
  locals: [],
1139
- callStack,
1140
- scopes
1303
+ callStack: this.debugFrames(frames),
1304
+ callStackComplete: totalFrames !== undefined && frames.length >= totalFrames,
1305
+ scopes: []
1141
1306
  });
1142
1307
  this.command = null;
1308
+ // Publish the navigable top frame before requesting any scope metadata or
1309
+ // unwinding deeper frames. Each subsequent result belongs to this exact stop.
1310
+ await Promise.all([
1311
+ (async () => {
1312
+ if (!isWorkspaceFrame || !this.isCurrentValueRequest(session, version))
1313
+ return;
1314
+ const scopes = await this.requestScopes(session, selectedFrame.id);
1315
+ if (!this.isCurrentValueRequest(session, version))
1316
+ return;
1317
+ this.options.onDebugEvent({
1318
+ type: 'pauseDetails',
1319
+ sessionId,
1320
+ stopId,
1321
+ frameId: selectedFrame.id,
1322
+ scopes
1323
+ });
1324
+ })(),
1325
+ (async () => {
1326
+ let knownTotalFrames = totalFrames;
1327
+ let end = totalFrames === undefined ? 100 : Math.min(totalFrames, 100);
1328
+ while (frames.length < end && this.isCurrentValueRequest(session, version)) {
1329
+ const { frames: page, totalFrames: total } = await this.requestStackPage(session, threadId, frames.length, Math.min(20, end - frames.length));
1330
+ if (!this.isCurrentValueRequest(session, version))
1331
+ return;
1332
+ if (total !== undefined) {
1333
+ knownTotalFrames = total;
1334
+ end = Math.min(total, 100);
1335
+ }
1336
+ if (!page.length) {
1337
+ this.options.onDebugEvent({
1338
+ type: 'pauseDetails',
1339
+ sessionId,
1340
+ stopId,
1341
+ callStack: this.debugFrames(frames),
1342
+ callStackComplete: knownTotalFrames === undefined || frames.length >= knownTotalFrames
1343
+ });
1344
+ break;
1345
+ }
1346
+ const ids = new Set(frames.map((frame) => frame.id));
1347
+ for (const frame of page) {
1348
+ if (ids.has(frame.id))
1349
+ invalidDapResponse('stackTrace', 'stackFrames', 'duplicate frame id across pages');
1350
+ ids.add(frame.id);
1351
+ }
1352
+ frames.push(...page);
1353
+ this.options.onDebugEvent({
1354
+ type: 'pauseDetails',
1355
+ sessionId,
1356
+ stopId,
1357
+ callStack: this.debugFrames(frames),
1358
+ callStackComplete: knownTotalFrames !== undefined && frames.length >= knownTotalFrames
1359
+ });
1360
+ }
1361
+ })()
1362
+ ]);
1143
1363
  }
1144
1364
  async setMainEntryBreakpoint(session, enabled) {
1145
1365
  const response = await session.request('setFunctionBreakpoints', {
1146
- breakpoints: enabled ? [{ name: 'main' }] : []
1366
+ breakpoints: enabled ? [{ name: this.options.entryFunctionName ?? 'main' }] : []
1147
1367
  });
1148
1368
  const breakpoints = dapResponseCollection(response, 'setFunctionBreakpoints', 'breakpoints');
1149
1369
  if (breakpoints.length !== (enabled ? 1 : 0)) {
@@ -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>;