Merge pull request #2156 from ethereum/fix_solidity_version_while_debugging

Fix solidity version while debugging
pull/2143/head^2
Rob 3 years ago committed by GitHub
commit 5c018329c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      apps/debugger/src/app/debugger-api.ts
  2. 22
      libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts
  3. 4
      libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts
  4. 4
      libs/remix-core-plugin/src/lib/helpers/fetch-sourcify.ts
  5. 1
      libs/remix-debug/src/Ethdebugger.ts
  6. 7
      libs/remix-debug/src/code/breakpointManager.ts
  7. 13
      libs/remix-debug/src/debugger/debugger.ts
  8. 9
      libs/remix-debug/test/debugger.ts
  9. 12
      libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx

@ -127,6 +127,11 @@ export const DebuggerApiMixin = (Base) => class extends Base {
} }
debug (hash, web3?) { debug (hash, web3?) {
try {
this.call('fetchAndCompile', 'clearCache')
} catch (e) {
console.error(e)
}
this.debugHash = hash this.debugHash = hash
if (web3) this._web3 = web3 if (web3) this._web3 = web3
else this._web3 = this.initialWeb3 else this._web3 = this.initialWeb3

@ -1,4 +1,3 @@
import { Plugin } from '@remixproject/engine' import { Plugin } from '@remixproject/engine'
import { compile } from '@remix-project/remix-solidity' import { compile } from '@remix-project/remix-solidity'
import { util } from '@remix-project/remix-lib' import { util } from '@remix-project/remix-lib'
@ -8,7 +7,7 @@ import { fetchContractFromSourcify } from './helpers/fetch-sourcify'
const profile = { const profile = {
name: 'fetchAndCompile', name: 'fetchAndCompile',
methods: ['resolve'], methods: ['resolve', 'clearCache'],
version: '0.0.1' version: '0.0.1'
} }
@ -21,6 +20,14 @@ export class FetchAndCompile extends Plugin {
this.sourceVerifierNetWork = ['Main', 'Rinkeby', 'Ropsten', 'Goerli'] this.sourceVerifierNetWork = ['Main', 'Rinkeby', 'Ropsten', 'Goerli']
} }
/**
* Clear the cache
*
*/
async clearCache () {
this.unresolvedAddresses = []
}
/** /**
* Fetch compiliation metadata from source-Verify from a given @arg contractAddress - https://github.com/ethereum/source-verify * Fetch compiliation metadata from source-Verify from a given @arg contractAddress - https://github.com/ethereum/source-verify
* Put the artifacts in the file explorer * Put the artifacts in the file explorer
@ -68,6 +75,7 @@ export class FetchAndCompile extends Plugin {
} }
} }
targetPath = `${targetPath}/${network.id}/${contractAddress}`
let data let data
try { try {
data = await fetchContractFromSourcify(this, network, contractAddress, targetPath) data = await fetchContractFromSourcify(this, network, contractAddress, targetPath)
@ -100,7 +108,15 @@ export class FetchAndCompile extends Plugin {
const compData = await compile( const compData = await compile(
compilationTargets, compilationTargets,
settings, settings,
async (url, cb) => await this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message))) async (url, cb) => {
// we first try to resolve the content from the compilation target using a more appropiate path
const path = `${targetPath}/${url}`
if (compilationTargets[path] && compilationTargets[path].content) {
return cb(null, compilationTargets[path].content)
} else {
await this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message))
}
})
await this.call('compilerArtefacts', 'addResolvedContract', contractAddress, compData) await this.call('compilerArtefacts', 'addResolvedContract', contractAddress, compData)
return compData return compData
} catch (e) { } catch (e) {

@ -23,7 +23,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres
} }
if (typeof data.result[0].SourceCode === 'string') { if (typeof data.result[0].SourceCode === 'string') {
const fileName = `${targetPath}/${network.id}/${contractAddress}/${data.result[0].ContractName}.sol` const fileName = `${targetPath}/${data.result[0].ContractName}.sol`
await plugin.call('fileManager', 'setFile', fileName , data.result[0].SourceCode) await plugin.call('fileManager', 'setFile', fileName , data.result[0].SourceCode)
compilationTargets[fileName] = { content: data.result[0].SourceCode } compilationTargets[fileName] = { content: data.result[0].SourceCode }
} else if (data.result[0].SourceCode && typeof data.result[0].SourceCode == 'object') { } else if (data.result[0].SourceCode && typeof data.result[0].SourceCode == 'object') {
@ -34,7 +34,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres
if (await plugin.call('contentImport', 'isExternalUrl', file)) { if (await plugin.call('contentImport', 'isExternalUrl', file)) {
// nothing to do, the compiler callback will handle those // nothing to do, the compiler callback will handle those
} else { } else {
const path = `${targetPath}/${network.id}/${contractAddress}/${file}` const path = `${targetPath}/${file}`
const content = (source as any).content const content = (source as any).content
await plugin.call('fileManager', 'setFile', path, content) await plugin.call('fileManager', 'setFile', path, content)
compilationTargets[path] = { content } compilationTargets[path] = { content }

@ -13,7 +13,7 @@ export const fetchContractFromSourcify = async (plugin, network, contractAddress
} }
// set the solidity contract code using metadata // set the solidity contract code using metadata
await plugin.call('fileManager', 'setFile', `${targetPath}/${network.id}/${contractAddress}/metadata.json`, JSON.stringify(data.metadata, null, '\t')) await plugin.call('fileManager', 'setFile', `${targetPath}/metadata.json`, JSON.stringify(data.metadata, null, '\t'))
for (let file in data.metadata.sources) { for (let file in data.metadata.sources) {
const urls = data.metadata.sources[file].urls const urls = data.metadata.sources[file].urls
for (const url of urls) { for (const url of urls) {
@ -24,7 +24,7 @@ export const fetchContractFromSourcify = async (plugin, network, contractAddress
if (await plugin.call('contentImport', 'isExternalUrl', file)) { if (await plugin.call('contentImport', 'isExternalUrl', file)) {
// nothing to do, the compiler callback will handle those // nothing to do, the compiler callback will handle those
} else { } else {
const path = `${targetPath}/${network.id}/${contractAddress}/${file}` const path = `${targetPath}/${file}`
await plugin.call('fileManager', 'setFile', path, source.content) await plugin.call('fileManager', 'setFile', path, source.content)
compilationTargets[path] = { content: source.content } compilationTargets[path] = { content: source.content }
} }

@ -64,7 +64,6 @@ export class Ethdebugger {
this.solidityProxy, this.solidityProxy,
this.codeManager, this.codeManager,
{ ...this.opts, includeLocalVariables }) { ...this.opts, includeLocalVariables })
this.event.trigger('managersChanged')
} }
resolveStep (index) { resolveStep (index) {

@ -87,6 +87,7 @@ export class BreakpointManager {
* *
*/ */
async jump (fromStep, direction, defaultToLimit, trace) { async jump (fromStep, direction, defaultToLimit, trace) {
this.event.trigger('locatingBreakpoint', [])
let sourceLocation let sourceLocation
let previousSourceLocation let previousSourceLocation
let currentStep = fromStep + direction let currentStep = fromStep + direction
@ -113,14 +114,14 @@ export class BreakpointManager {
} }
if (this.hasBreakpointAtLine(sourceLocation.file, lineColumn.start.line)) { if (this.hasBreakpointAtLine(sourceLocation.file, lineColumn.start.line)) {
lineHadBreakpoint = true lineHadBreakpoint = true
if (direction === 1 && this.hitLine(currentStep, sourceLocation, previousSourceLocation, trace)) { if (this.hitLine(currentStep, sourceLocation, previousSourceLocation, trace)) {
return return
} }
} }
} }
currentStep += direction currentStep += direction
} }
this.event.trigger('NoBreakpointHit', []) this.event.trigger('noBreakpointHit', [])
if (!defaultToLimit) { if (!defaultToLimit) {
return return
} }
@ -172,6 +173,7 @@ export class BreakpointManager {
* @param {Object} sourceLocation - position of the breakpoint { file: '<file index>', row: '<line number' } * @param {Object} sourceLocation - position of the breakpoint { file: '<file index>', row: '<line number' }
*/ */
add (sourceLocation) { add (sourceLocation) {
sourceLocation.row -= 1
if (!this.breakpoints[sourceLocation.fileName]) { if (!this.breakpoints[sourceLocation.fileName]) {
this.breakpoints[sourceLocation.fileName] = [] this.breakpoints[sourceLocation.fileName] = []
} }
@ -185,6 +187,7 @@ export class BreakpointManager {
* @param {Object} sourceLocation - position of the breakpoint { file: '<file index>', row: '<line number' } * @param {Object} sourceLocation - position of the breakpoint { file: '<file index>', row: '<line number' }
*/ */
remove (sourceLocation) { remove (sourceLocation) {
sourceLocation.row -= 1
const sources = this.breakpoints[sourceLocation.fileName] const sources = this.breakpoints[sourceLocation.fileName]
if (!sources) { if (!sources) {
return return

@ -41,15 +41,18 @@ export class Debugger {
} }
}) })
this.breakPointManager.event.register('managersChanged', () => {
const { traceManager, callTree, solidityProxy } = this.debugger
this.breakPointManager.setManagers({ traceManager, callTree, solidityProxy })
})
this.breakPointManager.event.register('breakpointStep', (step) => { this.breakPointManager.event.register('breakpointStep', (step) => {
this.step_manager.jumpTo(step) this.step_manager.jumpTo(step)
}) })
this.breakPointManager.event.register('noBreakpointHit', (step) => {
this.event.trigger('noBreakpointHit', [])
})
this.breakPointManager.event.register('locatingBreakpoint', () => {
this.event.trigger('locatingBreakpoint', [])
})
this.debugger.setBreakpointManager(this.breakPointManager) this.debugger.setBreakpointManager(this.breakPointManager)
this.debugger.event.register('newTraceLoaded', this, () => { this.debugger.event.register('newTraceLoaded', this, () => {

@ -277,22 +277,15 @@ function testDebugging (debugManager) {
return sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, sourceMappingDecoder.getLinebreakPositions(ballot)) return sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, sourceMappingDecoder.getLinebreakPositions(ballot))
}}) }})
breakPointManager.event.register('managersChanged', () => { breakPointManager.add({fileName: 'test.sol', row: 39})
const {traceManager, callTree, solidityProxy} = debugManager
breakPointManager.setManagers({traceManager, callTree, solidityProxy})
})
breakPointManager.add({fileName: 'test.sol', row: 38})
breakPointManager.event.register('breakpointHit', function (sourceLocation, step) { breakPointManager.event.register('breakpointHit', function (sourceLocation, step) {
console.log('breakpointHit')
t.equal(JSON.stringify(sourceLocation), JSON.stringify({ start: 1153, length: 6, file: 0, jump: '-' })) t.equal(JSON.stringify(sourceLocation), JSON.stringify({ start: 1153, length: 6, file: 0, jump: '-' }))
t.equal(step, 212) t.equal(step, 212)
}) })
breakPointManager.event.register('noBreakpointHit', function () { breakPointManager.event.register('noBreakpointHit', function () {
t.end('noBreakpointHit') t.end('noBreakpointHit')
console.log('noBreakpointHit')
}) })
breakPointManager.jumpNextBreakpoint(0, true) breakPointManager.jumpNextBreakpoint(0, true)
}) })

@ -87,6 +87,18 @@ export const DebuggerUI = (props: DebuggerUIProps) => {
}) })
}) })
debuggerInstance.event.register('locatingBreakpoint', async (isActive) => {
setState(prevState => {
return { ...prevState, sourceLocationStatus: 'Locating breakpoint, this might take a while...' }
})
})
debuggerInstance.event.register('noBreakpointHit', async (isActive) => {
setState(prevState => {
return { ...prevState, sourceLocationStatus: '' }
})
})
debuggerInstance.event.register('newSourceLocation', async (lineColumnPos, rawLocation, generatedSources, address) => { debuggerInstance.event.register('newSourceLocation', async (lineColumnPos, rawLocation, generatedSources, address) => {
if (!lineColumnPos) { if (!lineColumnPos) {
await debuggerModule.discardHighlight() await debuggerModule.discardHighlight()

Loading…
Cancel
Save