@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.
@@ -16,7 +16,7 @@ exports.SmartContract = exports.EmulationError = exports.TimeError = exports.Get
16
16
  const core_1 = require("@ton/core");
17
17
  const selector_1 = require("../utils/selector");
18
18
  const debug_1 = require("../debugger/debug");
19
- const SourceMapCache_1 = require("../debugger/SourceMapCache");
19
+ const DebugInfoCache_1 = require("../debugger/DebugInfoCache");
20
20
  function createShardAccount(args) {
21
21
  let wc = args.workchain ?? 0;
22
22
  let address = args.address ?? (0, core_1.contractAddress)(wc, { code: args.code, data: args.data });
@@ -232,7 +232,7 @@ class SmartContract {
232
232
  console.log('Debugging uninitialized accounts is unsupported in debugger beta');
233
233
  return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
234
234
  }
235
- const sm = SourceMapCache_1.defaultSourceMapCache.get(code.hash().toString('base64'));
235
+ const sm = DebugInfoCache_1.defaultDebugInfoCache.get(code.hash().toString('base64'));
236
236
  if (sm === undefined) {
237
237
  return await this.runCommon(() => this.blockchain.executor.runTransaction(args));
238
238
  }
@@ -294,12 +294,12 @@ class SmartContract {
294
294
  };
295
295
  let res;
296
296
  if (this.debug) {
297
- const sm = SourceMapCache_1.defaultSourceMapCache.get(args.code.hash().toString('base64'));
298
- if (sm === undefined) {
297
+ const di = DebugInfoCache_1.defaultDebugInfoCache.get(args.code.hash().toString('base64'));
298
+ if (di === undefined) {
299
299
  res = await this.blockchain.executor.runGetMethod(args);
300
300
  }
301
301
  else {
302
- res = await (0, debug_1.debugGetMethod)(this.blockchain.executor, args, sm);
302
+ res = await (0, debug_1.debugGetMethod)(this.blockchain.executor, args, di);
303
303
  }
304
304
  }
305
305
  else {
@@ -0,0 +1,5 @@
1
+ import { DebugInfo } from "./Debuggee";
2
+ import { CompileResult } from '@ton/blueprint';
3
+ export type DebugInfoCache = Map<string, DebugInfo>;
4
+ export declare const defaultDebugInfoCache: DebugInfoCache;
5
+ export declare function registerCompiledContract(c: CompileResult): import("@ton/core").Cell;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerCompiledContract = exports.defaultDebugInfoCache = void 0;
4
+ const node_path_1 = require("node:path");
5
+ exports.defaultDebugInfoCache = new Map();
6
+ function registerCompiledContract(c) {
7
+ if (c.lang !== 'func') {
8
+ throw new Error('Can only register func contracts');
9
+ }
10
+ if (c.debugInfo === undefined) {
11
+ throw new Error('No debug info');
12
+ }
13
+ const { locations, globals } = c.debugInfo;
14
+ const sm = {};
15
+ for (let i = 0; i < locations.length; i++) {
16
+ const di = locations[i];
17
+ const common = {
18
+ path: (0, node_path_1.resolve)(di.file),
19
+ line: di.line,
20
+ function: di.func,
21
+ };
22
+ if (di.ret) {
23
+ sm[i] = {
24
+ ...common,
25
+ type: 'return',
26
+ };
27
+ }
28
+ else if (di.is_catch) {
29
+ sm[i] = {
30
+ ...common,
31
+ type: 'catch',
32
+ };
33
+ }
34
+ else {
35
+ sm[i] = {
36
+ ...common,
37
+ type: 'statement',
38
+ variables: di.vars ?? [],
39
+ firstStatement: di.first_stmt,
40
+ };
41
+ }
42
+ }
43
+ exports.defaultDebugInfoCache.set(c.code.hash().toString('base64'), {
44
+ sourceMap: sm,
45
+ globals,
46
+ });
47
+ return c.code;
48
+ }
49
+ exports.registerCompiledContract = registerCompiledContract;
@@ -2,21 +2,43 @@
2
2
  import EventEmitter from 'node:events';
3
3
  import { Executor, GetMethodArgs, RunTransactionArgs } from '../executor/Executor';
4
4
  import { Cell, TupleItem } from '@ton/core';
5
- import { LoggingDebugSession } from '@vscode/debugadapter';
6
- import { DebugProtocol } from '@vscode/debugprotocol';
7
- export type SourceMapEntry = {
5
+ export type SourceMapEntry = ({
8
6
  path: string;
9
7
  line: number;
8
+ function: string;
9
+ }) & ({
10
+ type: 'statement';
10
11
  variables: string[];
11
- };
12
+ firstStatement?: true;
13
+ } | {
14
+ type: 'return';
15
+ } | {
16
+ type: 'catch';
17
+ });
12
18
  export type SourceMap = {
13
19
  [k: number]: SourceMapEntry;
14
20
  };
21
+ export type GlobalEntry = {
22
+ name: string;
23
+ };
24
+ export type DebugInfo = {
25
+ sourceMap: SourceMap;
26
+ globals: GlobalEntry[];
27
+ };
15
28
  type Breakpoint = {
16
29
  id: number;
17
30
  line: number;
18
31
  verified: boolean;
19
32
  };
33
+ export type Variable = {
34
+ name: string;
35
+ value: TupleItem;
36
+ };
37
+ type StackFrame = {
38
+ function: string;
39
+ path: string;
40
+ line: number;
41
+ };
20
42
  export declare class Debuggee extends EventEmitter {
21
43
  executor: Executor;
22
44
  ptr: number;
@@ -28,24 +50,34 @@ export declare class Debuggee extends EventEmitter {
28
50
  codeCells: Map<string, Cell>;
29
51
  breakpoints: Map<string, Breakpoint[]>;
30
52
  breakpointID: number;
31
- frames: string[];
53
+ frames: StackFrame[];
54
+ globals: GlobalEntry[];
32
55
  finishedCallback: (v: any) => void;
33
56
  constructor(executor: Executor, finishedCallback: (v: any) => void);
34
57
  setCodeCells(code: Cell): void;
58
+ setDebugInfo(debugInfo: DebugInfo): void;
35
59
  setSourceMap(sourceMap: SourceMap): void;
60
+ setGlobals(globals: GlobalEntry[]): void;
36
61
  getAvailableSourcePaths(): string[];
37
62
  getAvailableLines(path: string): number[];
38
63
  isLineAvailable(path: string, line: number): boolean;
39
64
  continue(): void;
40
- step(stopEvent?: string): void;
65
+ stepIn(): void;
66
+ stepOver(): void;
67
+ stepOut(): void;
41
68
  startGetMethod(args: GetMethodArgs): void;
42
69
  startTransaction(args: RunTransactionArgs): void;
70
+ getC7(): TupleItem;
43
71
  vmStep(): boolean;
44
72
  codePos(): {
45
73
  hash: string;
46
74
  offset: number;
47
75
  };
48
76
  getStack(): TupleItem[];
77
+ getContParam(): number;
78
+ setContParam(param: number): number;
79
+ getLocalVariables(): Variable[] | undefined;
80
+ getGlobalVariables(): Variable[] | undefined;
49
81
  currentDebugInfoNumber(): number | undefined;
50
82
  currentSourceMapEntry(): SourceMapEntry | undefined;
51
83
  breakpointKey(path: string, line: number): string;
@@ -58,31 +90,19 @@ export declare class Debuggee extends EventEmitter {
58
90
  setBreakpoint(path: string, line: number): Breakpoint;
59
91
  sendEvent(event: string, ...args: any[]): void;
60
92
  onFinished(): void;
61
- stepUntilLine(breakpointsOnly: boolean, stopEvent?: string): void;
62
- prepareGetMethod(args: GetMethodArgs, sourceMap: SourceMap): void;
63
- prepareTransaction(args: RunTransactionArgs, code: Cell, sourceMap: SourceMap): void;
93
+ stackFrames(): StackFrame[];
94
+ stepUntil(what: {
95
+ type: 'breakpoint';
96
+ } | {
97
+ type: 'any-line';
98
+ stopEvent: 'stopOnBreakpoint' | 'stopOnStep';
99
+ } | {
100
+ type: 'next-line';
101
+ } | {
102
+ type: 'out';
103
+ }): void;
104
+ prepareGetMethod(args: GetMethodArgs, debugInfo: DebugInfo): void;
105
+ prepareTransaction(args: RunTransactionArgs, code: Cell, debugInfo: DebugInfo): void;
64
106
  start(debug: boolean, stopOnEntry: boolean): void;
65
107
  }
66
- export declare class TVMDebugSession extends LoggingDebugSession {
67
- static readonly threadID = 1;
68
- static readonly stackFrameID = 1;
69
- static readonly variablesReference = 1;
70
- debuggee: Debuggee;
71
- constructor(debuggee: Debuggee);
72
- protected initializeRequest(response: DebugProtocol.InitializeResponse, args: DebugProtocol.InitializeRequestArguments): void;
73
- protected loadedSourcesRequest(response: DebugProtocol.LoadedSourcesResponse, args: DebugProtocol.LoadedSourcesArguments, request?: DebugProtocol.Request | undefined): void;
74
- protected breakpointLocationsRequest(response: DebugProtocol.BreakpointLocationsResponse, args: DebugProtocol.BreakpointLocationsArguments, request?: DebugProtocol.Request | undefined): void;
75
- protected launchRequest(response: DebugProtocol.LaunchResponse, args: DebugProtocol.LaunchRequestArguments, request?: DebugProtocol.Request | undefined): void;
76
- protected attachRequest(response: DebugProtocol.AttachResponse, args: DebugProtocol.AttachRequestArguments, request?: DebugProtocol.Request | undefined): void;
77
- protected setBreakPointsRequest(response: DebugProtocol.SetBreakpointsResponse, args: DebugProtocol.SetBreakpointsArguments, request?: DebugProtocol.Request | undefined): void;
78
- protected threadsRequest(response: DebugProtocol.ThreadsResponse, request?: DebugProtocol.Request | undefined): void;
79
- protected continueRequest(response: DebugProtocol.ContinueResponse, args: DebugProtocol.ContinueArguments, request?: DebugProtocol.Request | undefined): void;
80
- protected nextRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments, request?: DebugProtocol.Request | undefined): void;
81
- protected stepInRequest(response: DebugProtocol.StepInResponse, args: DebugProtocol.StepInArguments, request?: DebugProtocol.Request | undefined): void;
82
- protected stepOutRequest(response: DebugProtocol.StepOutResponse, args: DebugProtocol.StepOutArguments, request?: DebugProtocol.Request | undefined): void;
83
- protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments, request?: DebugProtocol.Request | undefined): void;
84
- protected scopesRequest(response: DebugProtocol.ScopesResponse, args: DebugProtocol.ScopesArguments, request?: DebugProtocol.Request | undefined): void;
85
- protected variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments, request?: DebugProtocol.Request | undefined): void;
86
- protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments, request?: DebugProtocol.Request | undefined): void;
87
- }
88
108
  export {};