use validSourceLocation

pull/3068/head
yann300 2 years ago
parent ef4e096554
commit e3d516ee2f
  1. 32
      libs/remix-debug/src/solidity-decoder/internalCallTree.ts

@ -161,22 +161,17 @@ export class InternalCallTree {
return functions return functions
} }
async extractSourceLocation (step) { async extractSourceLocation (step: number, address: string) {
try { try {
const address = this.traceManager.getCurrentCalledAddressAt(step) return await this.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, step, this.solidityProxy.contracts)
const location = await this.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, step, this.solidityProxy.contracts)
return location
} catch (error) { } catch (error) {
throw new Error('InternalCallTree - Cannot retrieve sourcelocation for step ' + step + ' ' + error) throw new Error('InternalCallTree - Cannot retrieve sourcelocation for step ' + step + ' ' + error)
} }
} }
async extractValidSourceLocation (step) { async extractValidSourceLocation (step: number, address: string) {
try { try {
const address = this.traceManager.getCurrentCalledAddressAt(step) return await this.sourceLocationTracker.getValidSourceLocationFromVMTraceIndex(address, step, this.solidityProxy.contracts)
const location = await this.sourceLocationTracker.getValidSourceLocationFromVMTraceIndex(address, step, this.solidityProxy.contracts)
return location
} catch (error) { } catch (error) {
throw new Error('InternalCallTree - Cannot retrieve valid sourcelocation for step ' + step + ' ' + error) throw new Error('InternalCallTree - Cannot retrieve valid sourcelocation for step ' + step + ' ' + error)
} }
@ -219,9 +214,12 @@ async function buildTree (tree, step, scopeId, isExternalCall, isCreation) {
let previousSourceLocation = currentSourceLocation let previousSourceLocation = currentSourceLocation
while (step < tree.traceManager.trace.length) { while (step < tree.traceManager.trace.length) {
let sourceLocation let sourceLocation
let validSourceLocation
let newLocation = false let newLocation = false
try { try {
sourceLocation = await tree.extractSourceLocation(step) const address = this.traceManager.getCurrentCalledAddressAt(step)
sourceLocation = await tree.extractSourceLocation(step, address)
validSourceLocation = await tree.extractValidSourceLocation(step, address)
if (!includedSource(sourceLocation, currentSourceLocation)) { if (!includedSource(sourceLocation, currentSourceLocation)) {
tree.reducedTrace.push(step) tree.reducedTrace.push(step)
@ -245,11 +243,15 @@ async function buildTree (tree, step, scopeId, isExternalCall, isCreation) {
// gas per line // gas per line
if (tree.offsetToLineColumnConverter) { if (tree.offsetToLineColumnConverter) {
try { try {
const lineColumnPos = await tree.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, tree.solidityProxy.sourcesCode, tree.solidityProxy.sources) const lineColumnPos = await tree.offsetToLineColumnConverter.offsetToLineColumn(validSourceLocation, validSourceLocation.file, tree.solidityProxy.sourcesCode, tree.solidityProxy.sources)
if (!tree.gasCostPerLine[sourceLocation.file]) tree.gasCostPerLine[sourceLocation.file] = {} if (!tree.gasCostPerLine[validSourceLocation.file]) tree.gasCostPerLine[validSourceLocation.file] = {}
if (!tree.gasCostPerLine[sourceLocation.file][lineColumnPos.start.line]) tree.gasCostPerLine[sourceLocation.file][lineColumnPos.start.line] = 0 if (!tree.gasCostPerLine[validSourceLocation.file][lineColumnPos.start.line]) {
tree.gasCostPerLine[sourceLocation.file][lineColumnPos.start.line] += stepDetail.gasCost tree.gasCostPerLine[validSourceLocation.file][lineColumnPos.start.line] = 0
} catch (e) {} }
tree.gasCostPerLine[validSourceLocation.file][lineColumnPos.start.line] += stepDetail.gasCost
} catch (e) {
console.log(e)
}
} }
const isCallInstrn = isCallInstruction(stepDetail) const isCallInstrn = isCallInstruction(stepDetail)

Loading…
Cancel
Save