From 949c4dd22e2e3ff836d10eb83a7f4f6f954e0f1f Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 29 Nov 2022 16:05:53 +0100 Subject: [PATCH] show state variable --- apps/remix-ide/src/app/tabs/debugger-tab.js | 9 +++++++-- libs/remix-debug/src/Ethdebugger.ts | 15 ++++++++++++++- .../src/solidity-decoder/decodeInfo.ts | 3 ++- .../editor/src/lib/providers/hoverProvider.ts | 11 ++++++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/debugger-tab.js b/apps/remix-ide/src/app/tabs/debugger-tab.js index 74c96915b6..a4f574131a 100644 --- a/apps/remix-ide/src/app/tabs/debugger-tab.js +++ b/apps/remix-ide/src/app/tabs/debugger-tab.js @@ -10,7 +10,7 @@ const css = require('./styles/debugger-tab-styles') const profile = { name: 'debugger', displayName: 'Debugger', - methods: ['debug', 'getTrace', 'decodeVariable'], + methods: ['debug', 'getTrace', 'decodeLocalVariable', 'decodeStateVariable'], events: [], icon: 'assets/img/debuggerLogo.webp', description: 'Debug transactions', @@ -66,8 +66,13 @@ export class DebuggerTab extends DebuggerApiMixin(ViewPlugin) { } } - async decodeVariable (variableId) { + async decodeLocalVariable (variableId) { if (!this.debuggerBackend) return null return await this.debuggerBackend.debugger.decodeLocalVariableByIdAtCurrentStep(this.debuggerBackend.step_manager.currentStepIndex, variableId) } + + async decodeStateVariable (variableId) { + if (!this.debuggerBackend) return null + return await this.debuggerBackend.debugger.decodeStateVariableByIdAtCurrentStep(this.debuggerBackend.step_manager.currentStepIndex, variableId) + } } diff --git a/libs/remix-debug/src/Ethdebugger.ts b/libs/remix-debug/src/Ethdebugger.ts index 08914378c8..30431a568f 100644 --- a/libs/remix-debug/src/Ethdebugger.ts +++ b/libs/remix-debug/src/Ethdebugger.ts @@ -7,6 +7,7 @@ import { CodeManager } from './code/codeManager' import { contractCreationToken } from './trace/traceHelper' import { EventManager } from './eventManager' import { SolidityProxy, stateDecoder, localDecoder, InternalCallTree } from './solidity-decoder' +import { extractStateVariables } from './solidity-decoder/stateDecoder' /** * Ethdebugger is a wrapper around a few classes that helps debugging a transaction @@ -111,6 +112,16 @@ export class Ethdebugger { return await variable.type.decodeFromStack(variable.stackDepth, stack, memory, storageViewer, calldata, null, variable) } + async decodeStateVariableByIdAtCurrentStep (step: number, id: number) { + const stateVars = await this.solidityProxy.extractStateVariablesAt(step) + const variable = stateVars.filter((el) => el.variable.id === id) + if (variable && variable.length) { + const state = await this.decodeStateAt(step, variable) + return state[variable[0].name] + } + return { value: '' } + } + async decodeLocalsAt (step, sourceLocation, callback) { try { const stack = this.traceManager.getStackAt(step) @@ -137,11 +148,13 @@ export class Ethdebugger { return this.solidityProxy.extractStateVariablesAt(step) } - async decodeStateAt (step, stateVars, callback) { + async decodeStateAt (step, stateVars, callback?) { try { + callback = callback || (() => {}) const address = this.traceManager.getCurrentCalledAddressAt(step) const storageViewer = new StorageViewer({ stepIndex: step, tx: this.tx, address: address }, this.storageResolver, this.traceManager) const result = await stateDecoder.decodeState(stateVars, storageViewer) + callback(result) return result } catch (error) { callback(error) diff --git a/libs/remix-debug/src/solidity-decoder/decodeInfo.ts b/libs/remix-debug/src/solidity-decoder/decodeInfo.ts index a66434a2b7..23945164b4 100644 --- a/libs/remix-debug/src/solidity-decoder/decodeInfo.ts +++ b/libs/remix-debug/src/solidity-decoder/decodeInfo.ts @@ -354,7 +354,8 @@ function computeOffsets (types, stateDefinitions, contractName, location) { storagelocation: { offset: !hasStorageSlots ? 0 : storagelocation.offset, slot: !hasStorageSlots ? 0 : storagelocation.slot - } + }, + variable }) if (hasStorageSlots) { if (type.storageSlots === 1 && storagelocation.offset + type.storageBytes <= 32) { diff --git a/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts b/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts index 6275659cd7..b3694ce970 100644 --- a/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/hoverProvider.ts @@ -147,7 +147,16 @@ export class RemixHoverProvider implements languages.HoverProvider { // getScope(nodeAtPosition) try { - const decodedVar = await this.props.plugin.call('debugger', 'decodeVariable', nodeAtPosition.id) + const decodedVar = await this.props.plugin.call('debugger', 'decodeLocalVariable', nodeAtPosition.id) + if (decodedVar !== null) { + contents.push({ + value: JSON.stringify(decodedVar.value, null, '\t') + }) + } + } catch (e) {} + + try { + const decodedVar = await this.props.plugin.call('debugger', 'decodeStateVariable', nodeAtPosition.id) if (decodedVar !== null) { contents.push({ value: JSON.stringify(decodedVar.value, null, '\t')