@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.
- package/dist/blockchain/SmartContract.js +5 -5
- package/dist/debugger/DebugInfoCache.d.ts +5 -0
- package/dist/debugger/DebugInfoCache.js +49 -0
- package/dist/debugger/Debuggee.d.ts +51 -31
- package/dist/debugger/Debuggee.js +147 -260
- package/dist/debugger/TVMDebugSession.d.ts +26 -0
- package/dist/debugger/TVMDebugSession.js +267 -0
- package/dist/debugger/debug.d.ts +3 -3
- package/dist/debugger/debug.js +7 -6
- package/dist/executor/Executor.d.ts +6 -0
- package/dist/executor/Executor.js +34 -0
- package/dist/executor/emulator-emscripten.js +1 -1
- package/dist/executor/emulator-emscripten.wasm.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +3 -2
- package/dist/debugger/SourceMapCache.d.ts +0 -5
- package/dist/debugger/SourceMapCache.js +0 -27
|
@@ -0,0 +1,267 @@
|
|
|
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.stepOver();
|
|
143
|
+
this.sendResponse(response);
|
|
144
|
+
}
|
|
145
|
+
stepInRequest(response, args, request) {
|
|
146
|
+
this.debuggee.stepIn();
|
|
147
|
+
this.sendResponse(response);
|
|
148
|
+
}
|
|
149
|
+
stepOutRequest(response, args, request) {
|
|
150
|
+
this.debuggee.stepOut();
|
|
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
|
+
const frames = this.debuggee.stackFrames();
|
|
163
|
+
response.body.totalFrames = frames.length;
|
|
164
|
+
if (args.startFrame ?? 0 >= frames.length) {
|
|
165
|
+
response.body.stackFrames = [];
|
|
166
|
+
this.sendResponse(response);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
response.body.stackFrames = [];
|
|
170
|
+
for (let i = args.startFrame ?? 0; i < frames.length; i++) {
|
|
171
|
+
const frame = frames[i];
|
|
172
|
+
response.body.stackFrames.push({
|
|
173
|
+
id: i === frames.length - 1 ? TVMDebugSession.stackFrameID : 0,
|
|
174
|
+
name: frame.function,
|
|
175
|
+
line: frame.line,
|
|
176
|
+
column: 0,
|
|
177
|
+
source: {
|
|
178
|
+
name: (0, node_path_1.basename)(frame.path),
|
|
179
|
+
path: frame.path,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
response.body.stackFrames.reverse();
|
|
184
|
+
this.sendResponse(response);
|
|
185
|
+
}
|
|
186
|
+
scopesRequest(response, args, request) {
|
|
187
|
+
response.body = response.body || {};
|
|
188
|
+
if (args.frameId !== TVMDebugSession.stackFrameID) {
|
|
189
|
+
response.body.scopes = [];
|
|
190
|
+
this.sendResponse(response);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const sme = this.debuggee.currentSourceMapEntry();
|
|
194
|
+
if (sme === undefined) {
|
|
195
|
+
response.body.scopes = [];
|
|
196
|
+
this.sendResponse(response);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
response.body.scopes = [{
|
|
200
|
+
name: 'Locals',
|
|
201
|
+
variablesReference: TVMDebugSession.localVariablesReference,
|
|
202
|
+
expensive: false,
|
|
203
|
+
}, {
|
|
204
|
+
name: 'Globals',
|
|
205
|
+
variablesReference: TVMDebugSession.globalVariablesReference,
|
|
206
|
+
expensive: false,
|
|
207
|
+
}];
|
|
208
|
+
this.sendResponse(response);
|
|
209
|
+
}
|
|
210
|
+
variablesRequest(response, args, request) {
|
|
211
|
+
response.body = response.body || {};
|
|
212
|
+
response.body.variables = [];
|
|
213
|
+
let vars = undefined;
|
|
214
|
+
if (args.variablesReference === TVMDebugSession.localVariablesReference) {
|
|
215
|
+
vars = this.debuggee.getLocalVariables();
|
|
216
|
+
}
|
|
217
|
+
else if (args.variablesReference === TVMDebugSession.globalVariablesReference) {
|
|
218
|
+
vars = this.debuggee.getGlobalVariables();
|
|
219
|
+
}
|
|
220
|
+
if (vars === undefined) {
|
|
221
|
+
this.sendResponse(response);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
for (const v of vars) {
|
|
225
|
+
response.body.variables.push({
|
|
226
|
+
name: v.name,
|
|
227
|
+
value: tupleItemToString(v.value),
|
|
228
|
+
type: v.value.type,
|
|
229
|
+
variablesReference: 0,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
response.body.variables.sort((a, b) => (a.name < b.name) ? -1 : (a.name > b.name ? 1 : 0));
|
|
233
|
+
this.sendResponse(response);
|
|
234
|
+
}
|
|
235
|
+
disconnectRequest(response, args, request) {
|
|
236
|
+
if (args.restart) {
|
|
237
|
+
this.sendErrorResponse(response, {
|
|
238
|
+
id: 1003,
|
|
239
|
+
format: 'Cannot restart',
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
this.sendResponse(response);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
exports.TVMDebugSession = TVMDebugSession;
|
|
248
|
+
TVMDebugSession.threadID = 1;
|
|
249
|
+
TVMDebugSession.stackFrameID = 1;
|
|
250
|
+
TVMDebugSession.localVariablesReference = 1;
|
|
251
|
+
TVMDebugSession.globalVariablesReference = 2;
|
|
252
|
+
function tupleItemToString(ti) {
|
|
253
|
+
switch (ti.type) {
|
|
254
|
+
case 'int':
|
|
255
|
+
return ti.value.toString();
|
|
256
|
+
case 'null':
|
|
257
|
+
return 'null';
|
|
258
|
+
case 'nan':
|
|
259
|
+
return 'NaN';
|
|
260
|
+
case 'cell':
|
|
261
|
+
case 'slice':
|
|
262
|
+
case 'builder':
|
|
263
|
+
return ti.cell.toBoc().toString('base64');
|
|
264
|
+
case 'tuple':
|
|
265
|
+
return `[${ti.items.map(v => tupleItemToString(v)).join(', ')}]`;
|
|
266
|
+
}
|
|
267
|
+
}
|
package/dist/debugger/debug.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Cell } from '@ton/core';
|
|
2
2
|
import { GetMethodArgs, Executor, GetMethodResult, RunTransactionArgs, EmulationResult } from '../executor/Executor';
|
|
3
|
-
import {
|
|
4
|
-
export declare function debugGetMethod(executor: Executor, args: GetMethodArgs,
|
|
5
|
-
export declare function debugTransaction(executor: Executor, args: RunTransactionArgs, code: Cell,
|
|
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>;
|
package/dist/debugger/debug.js
CHANGED
|
@@ -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,
|
|
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,
|
|
40
|
+
dbg.prepareGetMethod(args, debugInfo);
|
|
40
41
|
const server = Net.createServer((socket) => {
|
|
41
|
-
const session = new
|
|
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,
|
|
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,
|
|
54
|
+
dbg.prepareTransaction(args, code, debugInfo);
|
|
54
55
|
const server = Net.createServer((socket) => {
|
|
55
|
-
const session = new
|
|
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,9 @@ 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;
|
|
102
|
+
sbsGetMethodGetContParam(ptr: number): number;
|
|
103
|
+
sbsGetMethodSetContParam(ptr: number, param: number): number;
|
|
101
104
|
sbsGetMethodCodePos(ptr: number): {
|
|
102
105
|
hash: string;
|
|
103
106
|
offset: number;
|
|
@@ -114,5 +117,8 @@ export declare class Executor implements IExecutor {
|
|
|
114
117
|
offset: number;
|
|
115
118
|
};
|
|
116
119
|
sbsTransactionStack(ptr: number): TupleItem[];
|
|
120
|
+
sbsTransactionC7(ptr: number): TupleItem;
|
|
121
|
+
sbsTransactionGetContParam(ptr: number): number;
|
|
122
|
+
sbsTransactionSetContParam(ptr: number, param: number): number;
|
|
117
123
|
sbsTransactionResult(ptr: number): EmulationResult;
|
|
118
124
|
}
|
|
@@ -247,6 +247,23 @@ 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
|
+
}
|
|
256
|
+
sbsGetMethodGetContParam(ptr) {
|
|
257
|
+
return this.invoke('_sbs_get_cont_param', [
|
|
258
|
+
ptr
|
|
259
|
+
]);
|
|
260
|
+
}
|
|
261
|
+
sbsGetMethodSetContParam(ptr, param) {
|
|
262
|
+
return this.invoke('_sbs_set_cont_param', [
|
|
263
|
+
ptr,
|
|
264
|
+
param
|
|
265
|
+
]);
|
|
266
|
+
}
|
|
250
267
|
sbsGetMethodCodePos(ptr) {
|
|
251
268
|
const resp = this.extractString(this.invoke('_sbs_get_code_pos', [
|
|
252
269
|
ptr
|
|
@@ -305,6 +322,23 @@ class Executor {
|
|
|
305
322
|
]));
|
|
306
323
|
return (0, core_1.parseTuple)(core_1.Cell.fromBase64(resp));
|
|
307
324
|
}
|
|
325
|
+
sbsTransactionC7(ptr) {
|
|
326
|
+
const resp = this.extractString(this.invoke('_em_sbs_c7', [
|
|
327
|
+
ptr
|
|
328
|
+
]));
|
|
329
|
+
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];
|
|
330
|
+
}
|
|
331
|
+
sbsTransactionGetContParam(ptr) {
|
|
332
|
+
return this.invoke('_em_sbs_get_cont_param', [
|
|
333
|
+
ptr
|
|
334
|
+
]);
|
|
335
|
+
}
|
|
336
|
+
sbsTransactionSetContParam(ptr, param) {
|
|
337
|
+
return this.invoke('_em_sbs_set_cont_param', [
|
|
338
|
+
ptr,
|
|
339
|
+
param
|
|
340
|
+
]);
|
|
341
|
+
}
|
|
308
342
|
sbsTransactionResult(ptr) {
|
|
309
343
|
const result = JSON.parse(this.extractString(this.invoke('_em_sbs_result', [
|
|
310
344
|
ptr
|