@ton/sandbox 0.21.0-debugger.1 → 0.21.0-debugger.3

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.
@@ -3,10 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TVMDebugSession = exports.Debuggee = void 0;
6
+ exports.Debuggee = void 0;
7
7
  const node_events_1 = __importDefault(require("node:events"));
8
- const debugadapter_1 = require("@vscode/debugadapter");
9
- const node_path_1 = require("node:path");
10
8
  class Debuggee extends node_events_1.default {
11
9
  constructor(executor, finishedCallback) {
12
10
  super();
@@ -18,6 +16,7 @@ class Debuggee extends node_events_1.default {
18
16
  this.breakpoints = new Map();
19
17
  this.breakpointID = 0;
20
18
  this.frames = [];
19
+ this.globals = [];
21
20
  this.executor = executor;
22
21
  this.executor.debugLogFunc = (s) => { this.sendEvent('output', s); };
23
22
  this.finishedCallback = finishedCallback;
@@ -33,6 +32,10 @@ class Debuggee extends node_events_1.default {
33
32
  }
34
33
  }
35
34
  }
35
+ setDebugInfo(debugInfo) {
36
+ this.setSourceMap(debugInfo.sourceMap);
37
+ this.setGlobals(debugInfo.globals);
38
+ }
36
39
  setSourceMap(sourceMap) {
37
40
  this.sourceMap = sourceMap;
38
41
  for (const di in sourceMap) {
@@ -43,6 +46,9 @@ class Debuggee extends node_events_1.default {
43
46
  this.availableLines[sem.path].push(sem.line);
44
47
  }
45
48
  }
49
+ setGlobals(globals) {
50
+ this.globals = globals;
51
+ }
46
52
  getAvailableSourcePaths() {
47
53
  return Object.keys(this.availableLines);
48
54
  }
@@ -57,10 +63,16 @@ class Debuggee extends node_events_1.default {
57
63
  return lines.indexOf(line) >= 0;
58
64
  }
59
65
  continue() {
60
- this.stepUntilLine(true);
66
+ this.stepUntil({ type: 'breakpoint' });
67
+ }
68
+ stepIn() {
69
+ this.stepUntil({ type: 'any-line', stopEvent: 'stopOnStep' });
61
70
  }
62
- step(stopEvent = 'stopOnStep') {
63
- this.stepUntilLine(false, stopEvent);
71
+ stepOver() {
72
+ this.stepUntil({ type: 'next-line' });
73
+ }
74
+ stepOut() {
75
+ this.stepUntil({ type: 'out' });
64
76
  }
65
77
  startGetMethod(args) {
66
78
  this.ptr = this.executor.sbsGetMethodSetup(args);
@@ -74,6 +86,14 @@ class Debuggee extends node_events_1.default {
74
86
  this.ptr = emptr;
75
87
  this.debugType = 'tx';
76
88
  }
89
+ getC7() {
90
+ switch (this.debugType) {
91
+ case 'get':
92
+ return this.executor.sbsGetMethodC7(this.ptr);
93
+ case 'tx':
94
+ return this.executor.sbsTransactionC7(this.ptr);
95
+ }
96
+ }
77
97
  vmStep() {
78
98
  switch (this.debugType) {
79
99
  case 'get':
@@ -98,6 +118,59 @@ class Debuggee extends node_events_1.default {
98
118
  return this.executor.sbsTransactionStack(this.ptr);
99
119
  }
100
120
  }
121
+ getContParam() {
122
+ switch (this.debugType) {
123
+ case 'get':
124
+ return this.executor.sbsGetMethodGetContParam(this.ptr);
125
+ case 'tx':
126
+ return this.executor.sbsTransactionGetContParam(this.ptr);
127
+ }
128
+ }
129
+ setContParam(param) {
130
+ switch (this.debugType) {
131
+ case 'get':
132
+ return this.executor.sbsGetMethodSetContParam(this.ptr, param);
133
+ case 'tx':
134
+ return this.executor.sbsTransactionSetContParam(this.ptr, param);
135
+ }
136
+ }
137
+ getLocalVariables() {
138
+ const sme = this.currentSourceMapEntry();
139
+ if (sme === undefined || sme.type !== 'statement') {
140
+ return undefined;
141
+ }
142
+ const vars = [];
143
+ const stack = this.getStack();
144
+ for (let i = 0; i < sme.variables.length; i++) {
145
+ vars.push({
146
+ name: sme.variables[i],
147
+ value: stack[i],
148
+ });
149
+ }
150
+ return vars;
151
+ }
152
+ getGlobalVariables() {
153
+ const vars = [];
154
+ const c7item = this.getC7();
155
+ if (c7item.type !== 'tuple') {
156
+ return undefined;
157
+ }
158
+ const c7 = c7item.items;
159
+ for (let i = 0; i < this.globals.length; i++) {
160
+ if (i + 1 < c7.length) {
161
+ vars.push({
162
+ name: this.globals[i].name,
163
+ value: c7[i + 1],
164
+ });
165
+ continue;
166
+ }
167
+ vars.push({
168
+ name: this.globals[i].name,
169
+ value: { type: 'null' },
170
+ });
171
+ }
172
+ return vars;
173
+ }
101
174
  currentDebugInfoNumber() {
102
175
  const codepos = this.codePos();
103
176
  const cell = this.codeCells.get(codepos.hash);
@@ -180,7 +253,20 @@ class Debuggee extends node_events_1.default {
180
253
  }
181
254
  this.finishedCallback(r);
182
255
  }
183
- stepUntilLine(breakpointsOnly, stopEvent) {
256
+ stackFrames() {
257
+ return this.frames;
258
+ }
259
+ stepUntil(what) {
260
+ let until;
261
+ switch (what.type) {
262
+ case 'next-line':
263
+ case 'out': {
264
+ until = { type: what.type, depth: this.frames.length };
265
+ break;
266
+ }
267
+ default:
268
+ until = what;
269
+ }
184
270
  while (true) {
185
271
  const finished = this.vmStep();
186
272
  if (finished) {
@@ -188,31 +274,73 @@ class Debuggee extends node_events_1.default {
188
274
  return;
189
275
  }
190
276
  const sme = this.currentSourceMapEntry();
191
- if (sme !== undefined && (!breakpointsOnly || this.hasBreakpoint(sme.path, sme.line))) {
192
- if (breakpointsOnly) {
193
- this.sendEvent('stopOnBreakpoint');
277
+ if (sme !== undefined) {
278
+ switch (sme.type) {
279
+ case 'statement': {
280
+ if (sme.firstStatement) {
281
+ this.frames.push({
282
+ function: sme.function,
283
+ path: sme.path,
284
+ line: sme.line,
285
+ });
286
+ this.setContParam(this.frames.length);
287
+ }
288
+ this.frames[this.frames.length - 1].line = sme.line;
289
+ switch (until.type) {
290
+ case 'breakpoint': {
291
+ if (this.hasBreakpoint(sme.path, sme.line)) {
292
+ this.sendEvent('stopOnBreakpoint');
293
+ return;
294
+ }
295
+ break;
296
+ }
297
+ case 'any-line': {
298
+ this.sendEvent(until.stopEvent);
299
+ return;
300
+ }
301
+ case 'next-line': {
302
+ if (this.frames.length <= until.depth) {
303
+ this.sendEvent('stopOnStep');
304
+ return;
305
+ }
306
+ break;
307
+ }
308
+ case 'out': {
309
+ if (this.frames.length < until.depth) {
310
+ this.sendEvent('stopOnStep');
311
+ return;
312
+ }
313
+ break;
314
+ }
315
+ }
316
+ break;
317
+ }
318
+ case 'return': {
319
+ this.frames.pop();
320
+ break;
321
+ }
322
+ case 'catch': {
323
+ this.frames = this.frames.slice(0, this.getContParam());
324
+ break;
325
+ }
194
326
  }
195
- else if (stopEvent !== undefined) {
196
- this.sendEvent(stopEvent);
197
- }
198
- return;
199
327
  }
200
328
  }
201
329
  }
202
- prepareGetMethod(args, sourceMap) {
330
+ prepareGetMethod(args, debugInfo) {
203
331
  this.startGetMethod(args);
204
332
  this.setCodeCells(args.code);
205
- this.setSourceMap(sourceMap);
333
+ this.setDebugInfo(debugInfo);
206
334
  }
207
- prepareTransaction(args, code, sourceMap) {
335
+ prepareTransaction(args, code, debugInfo) {
208
336
  this.startTransaction(args);
209
337
  this.setCodeCells(code);
210
- this.setSourceMap(sourceMap);
338
+ this.setDebugInfo(debugInfo);
211
339
  }
212
340
  start(debug, stopOnEntry) {
213
341
  if (debug) {
214
342
  if (stopOnEntry) {
215
- this.step('stopOnEntry');
343
+ this.stepUntil({ type: 'any-line', stopEvent: 'stopOnBreakpoint' });
216
344
  }
217
345
  else {
218
346
  this.continue();
@@ -224,244 +352,3 @@ class Debuggee extends node_events_1.default {
224
352
  }
225
353
  }
226
354
  exports.Debuggee = Debuggee;
227
- class TVMDebugSession extends debugadapter_1.LoggingDebugSession {
228
- constructor(debuggee) {
229
- super();
230
- this.debuggee = debuggee;
231
- this.debuggee.on('stopOnEntry', () => {
232
- this.sendEvent(new debugadapter_1.StoppedEvent('entry', TVMDebugSession.threadID));
233
- });
234
- this.debuggee.on('stopOnBreakpoint', () => {
235
- this.sendEvent(new debugadapter_1.StoppedEvent('breakpoint', TVMDebugSession.threadID));
236
- });
237
- this.debuggee.on('stopOnStep', () => {
238
- this.sendEvent(new debugadapter_1.StoppedEvent('step', TVMDebugSession.threadID));
239
- });
240
- this.debuggee.on('end', () => {
241
- this.sendEvent(new debugadapter_1.TerminatedEvent());
242
- });
243
- this.debuggee.on('output', (s) => {
244
- this.sendEvent(new debugadapter_1.OutputEvent(s + '\n', 'stdout'));
245
- });
246
- }
247
- initializeRequest(response, args) {
248
- response.body = response.body || {};
249
- const b = response.body;
250
- b.supportsConfigurationDoneRequest = false;
251
- b.supportsFunctionBreakpoints = false;
252
- b.supportsConditionalBreakpoints = false;
253
- b.supportsHitConditionalBreakpoints = false;
254
- b.supportsEvaluateForHovers = false;
255
- b.supportsStepBack = false;
256
- b.supportsSetVariable = false;
257
- b.supportsRestartFrame = false;
258
- b.supportsGotoTargetsRequest = false;
259
- b.supportsStepInTargetsRequest = false;
260
- b.supportsCompletionsRequest = false;
261
- b.supportsModulesRequest = false;
262
- b.supportsRestartRequest = false;
263
- b.supportsValueFormattingOptions = false;
264
- b.supportsExceptionInfoRequest = false;
265
- b.supportTerminateDebuggee = false;
266
- b.supportSuspendDebuggee = false;
267
- b.supportsDelayedStackTraceLoading = false;
268
- b.supportsLoadedSourcesRequest = true;
269
- b.supportsLogPoints = false;
270
- b.supportsTerminateThreadsRequest = false;
271
- b.supportsSetExpression = false;
272
- b.supportsTerminateRequest = false;
273
- b.supportsDataBreakpoints = false;
274
- b.supportsReadMemoryRequest = false;
275
- b.supportsWriteMemoryRequest = false;
276
- b.supportsDisassembleRequest = false;
277
- b.supportsCancelRequest = false;
278
- b.supportsBreakpointLocationsRequest = true;
279
- b.supportsClipboardContext = false;
280
- b.supportsSteppingGranularity = false;
281
- b.supportsInstructionBreakpoints = false;
282
- b.supportsExceptionFilterOptions = false;
283
- b.supportsSingleThreadExecutionRequests = false;
284
- this.sendResponse(response);
285
- this.sendEvent(new debugadapter_1.InitializedEvent());
286
- }
287
- loadedSourcesRequest(response, args, request) {
288
- response.body = response.body || {};
289
- response.body.sources = this.debuggee.getAvailableSourcePaths().map(v => ({
290
- path: v,
291
- name: (0, node_path_1.basename)(v),
292
- }));
293
- this.sendResponse(response);
294
- }
295
- breakpointLocationsRequest(response, args, request) {
296
- response.body = response.body || {};
297
- const path = args.source.path;
298
- if (path === undefined) {
299
- this.sendErrorResponse(response, {
300
- id: 1001,
301
- format: 'No path',
302
- });
303
- return;
304
- }
305
- response.body.breakpoints = this.debuggee.getAvailableLines(path).filter(l => l >= args.line && l <= (args.endLine ?? args.line)).map(l => ({
306
- line: l,
307
- }));
308
- this.sendResponse(response);
309
- }
310
- launchRequest(response, args, request) {
311
- debugadapter_1.logger.setup(debugadapter_1.Logger.LogLevel.Log);
312
- this.debuggee.start(!args.noDebug, true);
313
- this.sendResponse(response);
314
- }
315
- attachRequest(response, args, request) {
316
- this.launchRequest(response, args, request);
317
- }
318
- setBreakPointsRequest(response, args, request) {
319
- const path = args.source.path;
320
- if (path === undefined) {
321
- this.sendErrorResponse(response, {
322
- id: 1001,
323
- format: 'No path',
324
- });
325
- return;
326
- }
327
- const breakpoints = args.breakpoints;
328
- if (breakpoints === undefined) {
329
- this.sendErrorResponse(response, {
330
- id: 1002,
331
- format: 'No breakpoints',
332
- });
333
- return;
334
- }
335
- this.debuggee.clearBreakpoints(path);
336
- const bps = [];
337
- for (const bp of breakpoints) {
338
- const sbp = this.debuggee.setBreakpoint(path, bp.line);
339
- bps.push({
340
- id: sbp.id,
341
- line: sbp.line,
342
- verified: sbp.verified,
343
- });
344
- }
345
- response.body = {
346
- breakpoints: bps,
347
- };
348
- this.sendResponse(response);
349
- }
350
- threadsRequest(response, request) {
351
- response.body = {
352
- threads: [
353
- new debugadapter_1.Thread(TVMDebugSession.threadID, 'main'),
354
- ],
355
- };
356
- this.sendResponse(response);
357
- }
358
- continueRequest(response, args, request) {
359
- this.debuggee.continue();
360
- this.sendResponse(response);
361
- }
362
- nextRequest(response, args, request) {
363
- this.debuggee.step();
364
- this.sendResponse(response);
365
- }
366
- stepInRequest(response, args, request) {
367
- this.debuggee.step();
368
- this.sendResponse(response);
369
- }
370
- stepOutRequest(response, args, request) {
371
- this.debuggee.step();
372
- this.sendResponse(response);
373
- }
374
- stackTraceRequest(response, args, request) {
375
- response.body = response.body || {};
376
- const sme = this.debuggee.currentSourceMapEntry();
377
- if (sme === undefined) {
378
- response.body.stackFrames = [];
379
- response.body.totalFrames = 0;
380
- this.sendResponse(response);
381
- return;
382
- }
383
- response.body.totalFrames = 1;
384
- if (args.startFrame ?? 0 > 0) {
385
- response.body.stackFrames = [];
386
- this.sendResponse(response);
387
- return;
388
- }
389
- response.body.stackFrames = [{
390
- id: TVMDebugSession.stackFrameID,
391
- name: 'func',
392
- line: sme.line,
393
- column: 0,
394
- source: {
395
- name: (0, node_path_1.basename)(sme.path),
396
- path: sme.path,
397
- },
398
- }];
399
- this.sendResponse(response);
400
- }
401
- scopesRequest(response, args, request) {
402
- response.body = response.body || {};
403
- const sme = this.debuggee.currentSourceMapEntry();
404
- if (sme === undefined) {
405
- response.body.scopes = [];
406
- this.sendResponse(response);
407
- return;
408
- }
409
- response.body.scopes = [{
410
- name: 'Locals',
411
- variablesReference: TVMDebugSession.variablesReference,
412
- expensive: false,
413
- }];
414
- this.sendResponse(response);
415
- }
416
- variablesRequest(response, args, request) {
417
- response.body = response.body || {};
418
- response.body.variables = [];
419
- const sme = this.debuggee.currentSourceMapEntry();
420
- if (sme === undefined) {
421
- this.sendResponse(response);
422
- return;
423
- }
424
- const stack = this.debuggee.getStack();
425
- for (let i = 0; i < sme.variables.length; i++) {
426
- response.body.variables.push({
427
- name: sme.variables[i],
428
- value: tupleItemToString(stack[i]),
429
- type: stack[i].type,
430
- variablesReference: 0,
431
- });
432
- }
433
- response.body.variables.sort((a, b) => (a.name < b.name) ? -1 : (a.name > b.name ? 1 : 0));
434
- this.sendResponse(response);
435
- }
436
- disconnectRequest(response, args, request) {
437
- if (args.restart) {
438
- this.sendErrorResponse(response, {
439
- id: 1003,
440
- format: 'Cannot restart',
441
- });
442
- }
443
- else {
444
- this.sendResponse(response);
445
- }
446
- }
447
- }
448
- exports.TVMDebugSession = TVMDebugSession;
449
- TVMDebugSession.threadID = 1;
450
- TVMDebugSession.stackFrameID = 1;
451
- TVMDebugSession.variablesReference = 1;
452
- function tupleItemToString(ti) {
453
- switch (ti.type) {
454
- case 'int':
455
- return ti.value.toString();
456
- case 'null':
457
- return 'null';
458
- case 'nan':
459
- return 'NaN';
460
- case 'cell':
461
- case 'slice':
462
- case 'builder':
463
- return ti.cell.toBoc().toString('base64');
464
- case 'tuple':
465
- return `[${ti.items.map(v => tupleItemToString(v)).join(', ')}]`;
466
- }
467
- }
@@ -0,0 +1,26 @@
1
+ import { LoggingDebugSession } from "@vscode/debugadapter";
2
+ import { Debuggee } from "./Debuggee";
3
+ import { DebugProtocol } from "@vscode/debugprotocol";
4
+ export declare class TVMDebugSession extends LoggingDebugSession {
5
+ static readonly threadID = 1;
6
+ static readonly stackFrameID = 1;
7
+ static readonly localVariablesReference = 1;
8
+ static readonly globalVariablesReference = 2;
9
+ debuggee: Debuggee;
10
+ constructor(debuggee: Debuggee);
11
+ protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void;
12
+ protected loadedSourcesRequest(response: DebugProtocol.LoadedSourcesResponse, args: DebugProtocol.LoadedSourcesArguments, request?: DebugProtocol.Request | undefined): void;
13
+ protected breakpointLocationsRequest(response: DebugProtocol.BreakpointLocationsResponse, args: DebugProtocol.BreakpointLocationsArguments, request?: DebugProtocol.Request | undefined): void;
14
+ protected launchRequest(response: DebugProtocol.LaunchResponse, args: DebugProtocol.LaunchRequestArguments, request?: DebugProtocol.Request | undefined): void;
15
+ protected attachRequest(response: DebugProtocol.AttachResponse, args: DebugProtocol.AttachRequestArguments, request?: DebugProtocol.Request | undefined): void;
16
+ protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments, request?: DebugProtocol.Request | undefined): void;
17
+ protected threadsRequest(response: DebugProtocol.ThreadsResponse, request?: DebugProtocol.Request | undefined): void;
18
+ protected continueRequest(response: DebugProtocol.ContinueResponse, args: DebugProtocol.ContinueArguments, request?: DebugProtocol.Request | undefined): void;
19
+ protected nextRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments, request?: DebugProtocol.Request | undefined): void;
20
+ protected stepInRequest(response: DebugProtocol.StepInResponse, args: DebugProtocol.StepInArguments, request?: DebugProtocol.Request | undefined): void;
21
+ protected stepOutRequest(response: DebugProtocol.StepOutResponse, args: DebugProtocol.StepOutArguments, request?: DebugProtocol.Request | undefined): void;
22
+ protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments, request?: DebugProtocol.Request | undefined): void;
23
+ protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments, request?: DebugProtocol.Request | undefined): void;
24
+ protected variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments, request?: DebugProtocol.Request | undefined): void;
25
+ protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments, request?: DebugProtocol.Request | undefined): void;
26
+ }