Skip to content

Commit

Permalink
feat: global var inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
krigga committed Aug 18, 2024
1 parent 3375fa4 commit a68d98b
Show file tree
Hide file tree
Showing 12 changed files with 450 additions and 335 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ton/sandbox",
"version": "0.21.0-debugger.1",
"version": "0.21.0-debugger.2",
"description": "TON transaction emulator",
"main": "dist/index.js",
"license": "MIT",
Expand All @@ -13,7 +13,7 @@
"url": "git+https://github.com/ton-org/sandbox"
},
"devDependencies": {
"@ton/blueprint": "0.23.0-debugger.0",
"@ton/blueprint": "0.23.0-debugger.1",
"@ton/core": "^0.56.0",
"@ton/crypto": "3.2.0",
"@ton/test-utils": "^0.3.1",
Expand Down
10 changes: 5 additions & 5 deletions src/blockchain/SmartContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import {getSelectorForMethod} from "../utils/selector";
import { EmulationResult, Executor, ExecutorVerbosity, GetMethodArgs, RunCommonArgs, TickOrTock, GetMethodResult as ExecutorGetMethodResult, RunTransactionArgs } from "../executor/Executor";
import { debugGetMethod, debugTransaction } from "../debugger/debug";
import { defaultSourceMapCache } from "../debugger/SourceMapCache";
import { defaultDebugInfoCache } from "../debugger/DebugInfoCache";

export function createShardAccount(args: { address?: Address, code: Cell, data: Cell, balance: bigint, workchain?: number }): ShardAccount {
let wc = args.workchain ?? 0
Expand Down Expand Up @@ -300,7 +300,7 @@ export class SmartContract {
console.log('Debugging uninitialized accounts is unsupported in debugger beta')
return await this.runCommon(() => this.blockchain.executor.runTransaction(args))
}
const sm = defaultSourceMapCache.get(code.hash().toString('base64'))
const sm = defaultDebugInfoCache.get(code.hash().toString('base64'))
if (sm === undefined) {
return await this.runCommon(() => this.blockchain.executor.runTransaction(args))
}
Expand Down Expand Up @@ -379,11 +379,11 @@ export class SmartContract {

let res: ExecutorGetMethodResult
if (this.debug) {
const sm = defaultSourceMapCache.get(args.code.hash().toString('base64'))
if (sm === undefined) {
const di = defaultDebugInfoCache.get(args.code.hash().toString('base64'))
if (di === undefined) {
res = await this.blockchain.executor.runGetMethod(args)
} else {
res = await debugGetMethod(this.blockchain.executor as Executor, args, sm)
res = await debugGetMethod(this.blockchain.executor as Executor, args, di)
}
} else {
res = await this.blockchain.executor.runGetMethod(args)
Expand Down
17 changes: 11 additions & 6 deletions src/debugger/SourceMapCache.ts → src/debugger/DebugInfoCache.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SourceMap } from "./Debuggee";
import { DebugInfo, SourceMap } from "./Debuggee";
import { CompileResult } from '@ton/blueprint';
import { resolve } from 'node:path';

export type SourceMapCache = Map<string, SourceMap>;
export type DebugInfoCache = Map<string, DebugInfo>;

export const defaultSourceMapCache: SourceMapCache = new Map();
export const defaultDebugInfoCache: DebugInfoCache = new Map();

export function registerCompiledContract(c: CompileResult) {
if (c.lang !== 'func') {
Expand All @@ -15,10 +15,12 @@ export function registerCompiledContract(c: CompileResult) {
throw new Error('No debug info');
}

const { locations, globals } = c.debugInfo;

const sm: SourceMap = {};

for (let i = 0; i < c.debugInfo.length; i++) {
const di = c.debugInfo[i];
for (let i = 0; i < locations.length; i++) {
const di = locations[i];
if (di.ret || di.vars === undefined) continue;
sm[i] = {
path: resolve(di.file),
Expand All @@ -27,7 +29,10 @@ export function registerCompiledContract(c: CompileResult) {
};
}

defaultSourceMapCache.set(c.code.hash().toString('base64'), sm);
defaultDebugInfoCache.set(c.code.hash().toString('base64'), {
sourceMap: sm,
globals,
});

return c.code;
}
Loading

0 comments on commit a68d98b

Please sign in to comment.