From adef162317a985a63127245b5c054c36ec6413b8 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 24 Nov 2022 13:58:21 +0100 Subject: [PATCH] take in account generated sources during debugging --- apps/remix-ide-e2e/src/tests/debugger.test.ts | 10 +++++----- libs/remix-debug/src/debugger/debugger.ts | 9 +-------- .../src/solidity-decoder/internalCallTree.ts | 12 +++++++++++- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/debugger.test.ts b/apps/remix-ide-e2e/src/tests/debugger.test.ts index 9fdd7fb6c2..60408cf1d3 100644 --- a/apps/remix-ide-e2e/src/tests/debugger.test.ts +++ b/apps/remix-ide-e2e/src/tests/debugger.test.ts @@ -97,11 +97,6 @@ module.exports = { locateStrategy: 'xpath', selector: '//*[@data-id="treeViewLivm trace step" and contains(.,"545")]', }) - .goToVMTraceStep(10) - .waitForElementVisible({ - locateStrategy: 'xpath', - selector: '//*[@data-id="treeViewLivm trace step" and contains(.,"10")]', - }) .getEditorValue((content) => { browser.assert.ok(content.indexOf(`constructor (string memory name_, string memory symbol_) { _name = name_; @@ -109,6 +104,11 @@ module.exports = { }`) !== -1, 'current displayed content is not from the ERC20 source code') }) + .goToVMTraceStep(10) + .waitForElementVisible({ + locateStrategy: 'xpath', + selector: '//*[@data-id="treeViewLivm trace step" and contains(.,"10")]', + }) }, 'Should display correct source highlighting while debugging a contract which has ABIEncoderV2 #group2': function (browser: NightwatchBrowser) { diff --git a/libs/remix-debug/src/debugger/debugger.ts b/libs/remix-debug/src/debugger/debugger.ts index 09c8d29185..a96171e196 100644 --- a/libs/remix-debug/src/debugger/debugger.ts +++ b/libs/remix-debug/src/debugger/debugger.ts @@ -87,14 +87,7 @@ export class Debugger { const rawLocation = rawLocationAndOpcode.sourceLocation const stepDetail = rawLocationAndOpcode.stepDetail const generatedSources = this.debugger.callTree.sourceLocationTracker.getGeneratedSourcesFromAddress(address) - const astSources = Object.assign({}, compilationResultForAddress.data.sources) - const sources = Object.assign({}, compilationResultForAddress.source.sources) - if (generatedSources) { - for (const genSource of generatedSources) { - astSources[genSource.name] = { id: genSource.id, ast: genSource.ast } - sources[genSource.name] = { content: genSource.contents } - } - } + const lineColumnPos = rawLocationAndOpcode.lineColumnPos let lineGasCostObj = null diff --git a/libs/remix-debug/src/solidity-decoder/internalCallTree.ts b/libs/remix-debug/src/solidity-decoder/internalCallTree.ts index 0227051833..0e9520ae5d 100644 --- a/libs/remix-debug/src/solidity-decoder/internalCallTree.ts +++ b/libs/remix-debug/src/solidity-decoder/internalCallTree.ts @@ -265,7 +265,17 @@ async function buildTree (tree, step, scopeId, isCreation, functionDefinition?, let lineColumnPos if (tree.offsetToLineColumnConverter) { try { - lineColumnPos = await tree.offsetToLineColumnConverter.offsetToLineColumn(validSourceLocation, validSourceLocation.file, tree.solidityProxy.sourcesCode, tree.solidityProxy.sources) + const generatedSources = tree.sourceLocationTracker.getGeneratedSourcesFromAddress(address) + const astSources = Object.assign({}, tree.solidityProxy.sources) + const sources = Object.assign({}, tree.solidityProxy.sourcesCode) + if (generatedSources) { + for (const genSource of generatedSources) { + astSources[genSource.name] = { id: genSource.id, ast: genSource.ast } + sources[genSource.name] = { content: genSource.contents } + } + } + + lineColumnPos = await tree.offsetToLineColumnConverter.offsetToLineColumn(validSourceLocation, validSourceLocation.file, sources, astSources) if (!tree.gasCostPerLine[validSourceLocation.file]) tree.gasCostPerLine[validSourceLocation.file] = {} if (!tree.gasCostPerLine[validSourceLocation.file][lineColumnPos.start.line]) { tree.gasCostPerLine[validSourceLocation.file][lineColumnPos.start.line] = {