@ton/sandbox 0.21.0-debugger.0 → 0.21.0-debugger.2

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.
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TVMDebugSession = void 0;
4
+ const debugadapter_1 = require("@vscode/debugadapter");
5
+ const node_path_1 = require("node:path");
6
+ class TVMDebugSession extends debugadapter_1.LoggingDebugSession {
7
+ constructor(debuggee) {
8
+ super();
9
+ this.debuggee = debuggee;
10
+ this.debuggee.on('stopOnEntry', () => {
11
+ this.sendEvent(new debugadapter_1.StoppedEvent('entry', TVMDebugSession.threadID));
12
+ });
13
+ this.debuggee.on('stopOnBreakpoint', () => {
14
+ this.sendEvent(new debugadapter_1.StoppedEvent('breakpoint', TVMDebugSession.threadID));
15
+ });
16
+ this.debuggee.on('stopOnStep', () => {
17
+ this.sendEvent(new debugadapter_1.StoppedEvent('step', TVMDebugSession.threadID));
18
+ });
19
+ this.debuggee.on('end', () => {
20
+ this.sendEvent(new debugadapter_1.TerminatedEvent());
21
+ });
22
+ this.debuggee.on('output', (s) => {
23
+ this.sendEvent(new debugadapter_1.OutputEvent(s + '\n', 'stdout'));
24
+ });
25
+ }
26
+ initializeRequest(response, args) {
27
+ response.body = response.body || {};
28
+ const b = response.body;
29
+ b.supportsConfigurationDoneRequest = false;
30
+ b.supportsFunctionBreakpoints = false;
31
+ b.supportsConditionalBreakpoints = false;
32
+ b.supportsHitConditionalBreakpoints = false;
33
+ b.supportsEvaluateForHovers = false;
34
+ b.supportsStepBack = false;
35
+ b.supportsSetVariable = false;
36
+ b.supportsRestartFrame = false;
37
+ b.supportsGotoTargetsRequest = false;
38
+ b.supportsStepInTargetsRequest = false;
39
+ b.supportsCompletionsRequest = false;
40
+ b.supportsModulesRequest = false;
41
+ b.supportsRestartRequest = false;
42
+ b.supportsValueFormattingOptions = false;
43
+ b.supportsExceptionInfoRequest = false;
44
+ b.supportTerminateDebuggee = false;
45
+ b.supportSuspendDebuggee = false;
46
+ b.supportsDelayedStackTraceLoading = false;
47
+ b.supportsLoadedSourcesRequest = true;
48
+ b.supportsLogPoints = false;
49
+ b.supportsTerminateThreadsRequest = false;
50
+ b.supportsSetExpression = false;
51
+ b.supportsTerminateRequest = false;
52
+ b.supportsDataBreakpoints = false;
53
+ b.supportsReadMemoryRequest = false;
54
+ b.supportsWriteMemoryRequest = false;
55
+ b.supportsDisassembleRequest = false;
56
+ b.supportsCancelRequest = false;
57
+ b.supportsBreakpointLocationsRequest = true;
58
+ b.supportsClipboardContext = false;
59
+ b.supportsSteppingGranularity = false;
60
+ b.supportsInstructionBreakpoints = false;
61
+ b.supportsExceptionFilterOptions = false;
62
+ b.supportsSingleThreadExecutionRequests = false;
63
+ this.sendResponse(response);
64
+ this.sendEvent(new debugadapter_1.InitializedEvent());
65
+ }
66
+ loadedSourcesRequest(response, args, request) {
67
+ response.body = response.body || {};
68
+ response.body.sources = this.debuggee.getAvailableSourcePaths().map(v => ({
69
+ path: v,
70
+ name: (0, node_path_1.basename)(v),
71
+ }));
72
+ this.sendResponse(response);
73
+ }
74
+ breakpointLocationsRequest(response, args, request) {
75
+ response.body = response.body || {};
76
+ const path = args.source.path;
77
+ if (path === undefined) {
78
+ this.sendErrorResponse(response, {
79
+ id: 1001,
80
+ format: 'No path',
81
+ });
82
+ return;
83
+ }
84
+ response.body.breakpoints = this.debuggee.getAvailableLines(path).filter(l => l >= args.line && l <= (args.endLine ?? args.line)).map(l => ({
85
+ line: l,
86
+ }));
87
+ this.sendResponse(response);
88
+ }
89
+ launchRequest(response, args, request) {
90
+ debugadapter_1.logger.setup(debugadapter_1.Logger.LogLevel.Log);
91
+ this.debuggee.start(!args.noDebug, true);
92
+ this.sendResponse(response);
93
+ }
94
+ attachRequest(response, args, request) {
95
+ this.launchRequest(response, args, request);
96
+ }
97
+ setBreakPointsRequest(response, args, request) {
98
+ const path = args.source.path;
99
+ if (path === undefined) {
100
+ this.sendErrorResponse(response, {
101
+ id: 1001,
102
+ format: 'No path',
103
+ });
104
+ return;
105
+ }
106
+ const breakpoints = args.breakpoints;
107
+ if (breakpoints === undefined) {
108
+ this.sendErrorResponse(response, {
109
+ id: 1002,
110
+ format: 'No breakpoints',
111
+ });
112
+ return;
113
+ }
114
+ this.debuggee.clearBreakpoints(path);
115
+ const bps = [];
116
+ for (const bp of breakpoints) {
117
+ const sbp = this.debuggee.setBreakpoint(path, bp.line);
118
+ bps.push({
119
+ id: sbp.id,
120
+ line: sbp.line,
121
+ verified: sbp.verified,
122
+ });
123
+ }
124
+ response.body = {
125
+ breakpoints: bps,
126
+ };
127
+ this.sendResponse(response);
128
+ }
129
+ threadsRequest(response, request) {
130
+ response.body = {
131
+ threads: [
132
+ new debugadapter_1.Thread(TVMDebugSession.threadID, 'main'),
133
+ ],
134
+ };
135
+ this.sendResponse(response);
136
+ }
137
+ continueRequest(response, args, request) {
138
+ this.debuggee.continue();
139
+ this.sendResponse(response);
140
+ }
141
+ nextRequest(response, args, request) {
142
+ this.debuggee.step();
143
+ this.sendResponse(response);
144
+ }
145
+ stepInRequest(response, args, request) {
146
+ this.debuggee.step();
147
+ this.sendResponse(response);
148
+ }
149
+ stepOutRequest(response, args, request) {
150
+ this.debuggee.step();
151
+ this.sendResponse(response);
152
+ }
153
+ stackTraceRequest(response, args, request) {
154
+ response.body = response.body || {};
155
+ const sme = this.debuggee.currentSourceMapEntry();
156
+ if (sme === undefined) {
157
+ response.body.stackFrames = [];
158
+ response.body.totalFrames = 0;
159
+ this.sendResponse(response);
160
+ return;
161
+ }
162
+ response.body.totalFrames = 1;
163
+ if (args.startFrame ?? 0 > 0) {
164
+ response.body.stackFrames = [];
165
+ this.sendResponse(response);
166
+ return;
167
+ }
168
+ response.body.stackFrames = [{
169
+ id: TVMDebugSession.stackFrameID,
170
+ name: 'func',
171
+ line: sme.line,
172
+ column: 0,
173
+ source: {
174
+ name: (0, node_path_1.basename)(sme.path),
175
+ path: sme.path,
176
+ },
177
+ }];
178
+ this.sendResponse(response);
179
+ }
180
+ scopesRequest(response, args, request) {
181
+ response.body = response.body || {};
182
+ const sme = this.debuggee.currentSourceMapEntry();
183
+ if (sme === undefined) {
184
+ response.body.scopes = [];
185
+ this.sendResponse(response);
186
+ return;
187
+ }
188
+ response.body.scopes = [{
189
+ name: 'Locals',
190
+ variablesReference: TVMDebugSession.localVariablesReference,
191
+ expensive: false,
192
+ }, {
193
+ name: 'Globals',
194
+ variablesReference: TVMDebugSession.globalVariablesReference,
195
+ expensive: false,
196
+ }];
197
+ this.sendResponse(response);
198
+ }
199
+ variablesRequest(response, args, request) {
200
+ response.body = response.body || {};
201
+ response.body.variables = [];
202
+ let vars = undefined;
203
+ if (args.variablesReference === TVMDebugSession.localVariablesReference) {
204
+ vars = this.debuggee.getLocalVariables();
205
+ }
206
+ else if (args.variablesReference === TVMDebugSession.globalVariablesReference) {
207
+ vars = this.debuggee.getGlobalVariables();
208
+ }
209
+ if (vars === undefined) {
210
+ this.sendResponse(response);
211
+ return;
212
+ }
213
+ for (const v of vars) {
214
+ response.body.variables.push({
215
+ name: v.name,
216
+ value: tupleItemToString(v.value),
217
+ type: v.value.type,
218
+ variablesReference: 0,
219
+ });
220
+ }
221
+ response.body.variables.sort((a, b) => (a.name < b.name) ? -1 : (a.name > b.name ? 1 : 0));
222
+ this.sendResponse(response);
223
+ }
224
+ disconnectRequest(response, args, request) {
225
+ if (args.restart) {
226
+ this.sendErrorResponse(response, {
227
+ id: 1003,
228
+ format: 'Cannot restart',
229
+ });
230
+ }
231
+ else {
232
+ this.sendResponse(response);
233
+ }
234
+ }
235
+ }
236
+ exports.TVMDebugSession = TVMDebugSession;
237
+ TVMDebugSession.threadID = 1;
238
+ TVMDebugSession.stackFrameID = 1;
239
+ TVMDebugSession.localVariablesReference = 1;
240
+ TVMDebugSession.globalVariablesReference = 2;
241
+ function tupleItemToString(ti) {
242
+ switch (ti.type) {
243
+ case 'int':
244
+ return ti.value.toString();
245
+ case 'null':
246
+ return 'null';
247
+ case 'nan':
248
+ return 'NaN';
249
+ case 'cell':
250
+ case 'slice':
251
+ case 'builder':
252
+ return ti.cell.toBoc().toString('base64');
253
+ case 'tuple':
254
+ return `[${ti.items.map(v => tupleItemToString(v)).join(', ')}]`;
255
+ }
256
+ }
@@ -1,5 +1,5 @@
1
1
  import { Cell } from '@ton/core';
2
2
  import { GetMethodArgs, Executor, GetMethodResult, RunTransactionArgs, EmulationResult } from '../executor/Executor';
3
- import { SourceMap } from "./Debuggee";
4
- export declare function debugGetMethod(executor: Executor, args: GetMethodArgs, sourceMap: SourceMap): Promise<GetMethodResult>;
5
- export declare function debugTransaction(executor: Executor, args: RunTransactionArgs, code: Cell, sourceMap: SourceMap): Promise<EmulationResult>;
3
+ import { DebugInfo } from "./Debuggee";
4
+ export declare function debugGetMethod(executor: Executor, args: GetMethodArgs, debugInfo: DebugInfo): Promise<GetMethodResult>;
5
+ export declare function debugTransaction(executor: Executor, args: RunTransactionArgs, code: Cell, debugInfo: DebugInfo): Promise<EmulationResult>;
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.debugTransaction = exports.debugGetMethod = void 0;
27
27
  const Debuggee_1 = require("./Debuggee");
28
28
  const Net = __importStar(require("net"));
29
+ const TVMDebugSession_1 = require("./TVMDebugSession");
29
30
  function initDebuggee(executor) {
30
31
  let dbg = null;
31
32
  const promise = new Promise((resolve) => {
@@ -33,12 +34,12 @@ function initDebuggee(executor) {
33
34
  });
34
35
  return { dbg, promise };
35
36
  }
36
- async function debugGetMethod(executor, args, sourceMap) {
37
+ async function debugGetMethod(executor, args, debugInfo) {
37
38
  console.log('Launched get method debug session. Please connect using the extension.');
38
39
  const { dbg, promise } = initDebuggee(executor);
39
- dbg.prepareGetMethod(args, sourceMap);
40
+ dbg.prepareGetMethod(args, debugInfo);
40
41
  const server = Net.createServer((socket) => {
41
- const session = new Debuggee_1.TVMDebugSession(dbg);
42
+ const session = new TVMDebugSession_1.TVMDebugSession(dbg);
42
43
  session.setRunAsServer(true);
43
44
  session.start(socket, socket);
44
45
  }).listen(42069);
@@ -47,12 +48,12 @@ async function debugGetMethod(executor, args, sourceMap) {
47
48
  return result;
48
49
  }
49
50
  exports.debugGetMethod = debugGetMethod;
50
- async function debugTransaction(executor, args, code, sourceMap) {
51
+ async function debugTransaction(executor, args, code, debugInfo) {
51
52
  console.log('Launched transaction debug session. Please connect using the extension.');
52
53
  const { dbg, promise } = initDebuggee(executor);
53
- dbg.prepareTransaction(args, code, sourceMap);
54
+ dbg.prepareTransaction(args, code, debugInfo);
54
55
  const server = Net.createServer((socket) => {
55
- const session = new Debuggee_1.TVMDebugSession(dbg);
56
+ const session = new TVMDebugSession_1.TVMDebugSession(dbg);
56
57
  session.setRunAsServer(true);
57
58
  session.start(socket, socket);
58
59
  }).listen(42069);
@@ -98,6 +98,7 @@ export declare class Executor implements IExecutor {
98
98
  destroyTvmEmulator(ptr: number): void;
99
99
  sbsGetMethodStep(ptr: number): boolean;
100
100
  sbsGetMethodStack(ptr: number): TupleItem[];
101
+ sbsGetMethodC7(ptr: number): TupleItem;
101
102
  sbsGetMethodCodePos(ptr: number): {
102
103
  hash: string;
103
104
  offset: number;
@@ -114,5 +115,6 @@ export declare class Executor implements IExecutor {
114
115
  offset: number;
115
116
  };
116
117
  sbsTransactionStack(ptr: number): TupleItem[];
118
+ sbsTransactionC7(ptr: number): TupleItem;
117
119
  sbsTransactionResult(ptr: number): EmulationResult;
118
120
  }
@@ -247,6 +247,12 @@ class Executor {
247
247
  ]));
248
248
  return (0, core_1.parseTuple)(core_1.Cell.fromBase64(resp));
249
249
  }
250
+ sbsGetMethodC7(ptr) {
251
+ const resp = this.extractString(this.invoke('_sbs_get_c7', [
252
+ ptr
253
+ ]));
254
+ return (0, core_1.parseTuple)((0, core_1.beginCell)().storeUint(1, 24).storeRef(core_1.Cell.EMPTY).storeSlice(core_1.Cell.fromBase64(resp).beginParse()).endCell())[0];
255
+ }
250
256
  sbsGetMethodCodePos(ptr) {
251
257
  const resp = this.extractString(this.invoke('_sbs_get_code_pos', [
252
258
  ptr
@@ -305,6 +311,12 @@ class Executor {
305
311
  ]));
306
312
  return (0, core_1.parseTuple)(core_1.Cell.fromBase64(resp));
307
313
  }
314
+ sbsTransactionC7(ptr) {
315
+ const resp = this.extractString(this.invoke('_em_sbs_c7', [
316
+ ptr
317
+ ]));
318
+ return (0, core_1.parseTuple)((0, core_1.beginCell)().storeUint(1, 24).storeRef(core_1.Cell.EMPTY).storeSlice(core_1.Cell.fromBase64(resp).beginParse()).endCell())[0];
319
+ }
308
320
  sbsTransactionResult(ptr) {
309
321
  const result = JSON.parse(this.extractString(this.invoke('_em_sbs_result', [
310
322
  ptr