@0yi0/remix-debug 中文文档教程

发布于 5年前 浏览 24 项目主页 更新于 3年前

remix-debug

remix-debug 包装其他 remix-* 库,可用于调试以太坊交易。

Installation

npm install remix-debug

Development

var Debugger = require('remix-debug').EthDebugger
var BreakpointManager = require('remix-debug').BreakpointManager

var debugger = new Debugger({
  compilationResult: () => {
    return compilationResult // that helps resolving source location
  }
})

debugger.addProvider(web3, 'web3')
debugger.switchProvider('web3')

var breakPointManager = new remixCore.code.BreakpointManager(this.debugger, (sourceLocation) => {
    // return offsetToLineColumn
})
debugger.setBreakpointManager(breakPointManager)
breakPointManager.add({fileName, row})
breakPointManager.add({fileName, row})

debugger.debug(<tx_hash>)

// this.traceManager.getCurrentCalledAddressAt

debugger.event.register('newTraceLoaded', () => {
  // start doing basic stuff like retrieving step details
  debugger.traceManager.getCallStackAt(34, (error, callstack) => {})
})

debugger.callTree.register('callTreeReady', () => {
  // start doing more complex stuff like resolvng local variables
  breakPointManager.jumpNextBreakpoint(true)

  var storageView = debugger.storageViewAt(38, <contract address>, 
  storageView.storageSlot(0, (error, storage) => {})
  storageView.storageRange(error, storage) => {}) // retrieve 0 => 1000 slots

  debugger.extractStateAt(23, (error, state) => {
    debugger.decodeStateAt(23, state, (error, decodedState) => {})
  })

  debugger.sourceLocationFromVMTraceIndex(<contract address>, 23, (error, location) => {
    debugger.decodeLocalsAt(23, location, (error, decodedlocals) => {})
  })

  debugger.extractLocalsAt(23, (null, locals) => {})

})

Library

提供:

{
    code: {
        CodeManager: CodeManager,
        BreakpointManager: BreakpointManager
    },
    storage: {
        StorageViewer: StorageViewer,
        StorageResolver: StorageResolver
    },
    trace: {
        TraceManager: TraceManager
    }
}

TraceManager 是访问 VM Trace 并从中解析某些值的便捷方式。

TraceManager() :

函数 resolveTrace(stepIndex, tx)

函数初始化(stepIndex, tx)

函数 inRange(stepIndex, tx)< /code>

函数 isLoaded(stepIndex, tx)

函数 getLength(stepIndex, tx)

函数 accumulateStorageChanges(stepIndex, tx)

函数 getAddresses (stepIndex, tx)

函数getCallDataAt(stepIndex, tx)

函数getCallStackAt(stepIndex, tx)

函数getStackAt(stepIndex, tx) >

函数 getLastCallChangeSince(stepIndex, tx)

函数 getCurrentCalledAddressAt(stepIndex, tx)

函数 getContractCreationCode(stepIndex, tx)

函数 getMemoryAt(stepIndex , tx)

函数getCurrentPC(stepIndex, tx)

函数getReturnValue(stepIndex, tx)

函数getCurrentStep(stepIndex, tx)

<代码>函数 getMemExpand(stepIndex, tx)

函数 getStepCost(stepIndex, tx )

函数 getRemainingGas(stepIndex, tx)

函数 getStepCost(stepIndex, tx)

函数 isCreationStep(stepIndex, tx)

函数 findStepOverBack(stepIndex,tx)

函数 findStepOverForward(stepIndex,tx)

函数 findStepOverBack(stepIndex,tx)

函数 findNextCall(stepIndex,tx)< /code>

function findStepOut(stepIndex, tx)

function checkRequestedStep(stepIndex, tx)

function waterfall(stepIndex, tx)


代码管理器( _traceManager) :

函数 getCode(stepIndex, tx) : 解析给定的@arg stepIndex 的代码并触发适当的事件

function resolveStep(address, cb) : 检索位于给定 @arg 地址的

代码 function getFunctionFromStep(stepIndex, sourceMap, ast) : 检索当前 vm 步骤的调用函数

function getInstructionIndex(address, step, callback) : 检索给定 @arg 步骤的指令索引

function getFunctionFromPC(address, pc, sourceMap, ast) : 为给定的@arg pc 和@arg 地址检索被调用的函数


BreakpointManager(_ethdebugger, _locationToRowConverter)</

code> : 开始寻找下一个断点

function jumpPreviousBreakpoint(defaultToLimit) : 开始寻找上一个断点

function jump(direction, defaultToLimit) : 开始寻找上一个或下一个断点

function hasBreakpointAtLine((fileIndex, line) : 根据注册的断点检查给定的文件索引/行

function hasBreakpoint() : 如果当前管理器有断点,则返回 true

function add(sourceLocation) : 添加一个新断点

向管理器function remove(sourceLocation) : 从管理器中删除断点


StorageViewer(_context, _storageResolver, _traceManager)

function storageRange(defaultToLimit) : 返回当前上下文的存储(地址和 vm 跟踪索引)

function storageSlot(defaultToLimit): 返回当前上下文的槽值(地址和 vm 跟踪索引)

function isComplete(direction, defaultToLimit): 如果@arg 地址处的存储已完成,则返回 True

function initialMappingsLocation((fileIndex, line) : 返回当前上下文(缓存)的所有可能映射位置不返回当前事务期间的状态更改

function mappingsLocation() : 返回当前上下文(缓存)和当前映射槽的所有可能映射位置。 返回当前交易期间的状态变化

function extractMappingsLocationChanges(sourceLocation) : 从存储更改中检索映射位置更改。


StorageResolver() :

函数 storageRange(tx, stepIndex, address, callback) : 返回当前上下文的存储(地址和 vm 跟踪索引)

function initialPreimagesMappings(tx, stepIndex, address, callback): 返回当前上下文的槽值(地址和 vm 跟踪索引)

function storageSlot(slot, tx, stepIndex, address, callback): 如果@arg 地址处的存储已完成,则返回 True

function isComplete(address) : 返回当前上下文(缓存)的所有可能映射位置不返回当前事务期间的状态更改

remix-debug

remix-debug wrap other remix-* libraries and can be used to debug Ethereum transactions.

Installation

npm install remix-debug

Development

var Debugger = require('remix-debug').EthDebugger
var BreakpointManager = require('remix-debug').BreakpointManager

var debugger = new Debugger({
  compilationResult: () => {
    return compilationResult // that helps resolving source location
  }
})

debugger.addProvider(web3, 'web3')
debugger.switchProvider('web3')

var breakPointManager = new remixCore.code.BreakpointManager(this.debugger, (sourceLocation) => {
    // return offsetToLineColumn
})
debugger.setBreakpointManager(breakPointManager)
breakPointManager.add({fileName, row})
breakPointManager.add({fileName, row})

debugger.debug(<tx_hash>)

// this.traceManager.getCurrentCalledAddressAt

debugger.event.register('newTraceLoaded', () => {
  // start doing basic stuff like retrieving step details
  debugger.traceManager.getCallStackAt(34, (error, callstack) => {})
})

debugger.callTree.register('callTreeReady', () => {
  // start doing more complex stuff like resolvng local variables
  breakPointManager.jumpNextBreakpoint(true)

  var storageView = debugger.storageViewAt(38, <contract address>, 
  storageView.storageSlot(0, (error, storage) => {})
  storageView.storageRange(error, storage) => {}) // retrieve 0 => 1000 slots

  debugger.extractStateAt(23, (error, state) => {
    debugger.decodeStateAt(23, state, (error, decodedState) => {})
  })

  debugger.sourceLocationFromVMTraceIndex(<contract address>, 23, (error, location) => {
    debugger.decodeLocalsAt(23, location, (error, decodedlocals) => {})
  })

  debugger.extractLocalsAt(23, (null, locals) => {})

})

Library

Provides:

{
    code: {
        CodeManager: CodeManager,
        BreakpointManager: BreakpointManager
    },
    storage: {
        StorageViewer: StorageViewer,
        StorageResolver: StorageResolver
    },
    trace: {
        TraceManager: TraceManager
    }
}

TraceManager is a convenient way to access a VM Trace and resolve some value from it.

TraceManager() :

function resolveTrace(stepIndex, tx)

function init(stepIndex, tx)

function inRange(stepIndex, tx)

function isLoaded(stepIndex, tx)

function getLength(stepIndex, tx)

function accumulateStorageChanges(stepIndex, tx)

function getAddresses(stepIndex, tx)

function getCallDataAt(stepIndex, tx)

function getCallStackAt(stepIndex, tx)

function getStackAt(stepIndex, tx)

function getLastCallChangeSince(stepIndex, tx)

function getCurrentCalledAddressAt(stepIndex, tx)

function getContractCreationCode(stepIndex, tx)

function getMemoryAt(stepIndex, tx)

function getCurrentPC(stepIndex, tx)

function getReturnValue(stepIndex, tx)

function getCurrentStep(stepIndex, tx)

function getMemExpand(stepIndex, tx)

function getStepCost(stepIndex, tx)

function getRemainingGas(stepIndex, tx)

function getStepCost(stepIndex, tx)

function isCreationStep(stepIndex, tx)

function findStepOverBack(stepIndex, tx)

function findStepOverForward(stepIndex, tx)

function findStepOverBack(stepIndex, tx)

function findNextCall(stepIndex, tx)

function findStepOut(stepIndex, tx)

function checkRequestedStep(stepIndex, tx)

function waterfall(stepIndex, tx)


CodeManager(_traceManager) :

function getCode(stepIndex, tx) : Resolve the code of the given @arg stepIndex and trigger appropriate event

function resolveStep(address, cb) : Retrieve the code located at the given @arg address

function getFunctionFromStep(stepIndex, sourceMap, ast) : Retrieve the called function for the current vm step

function getInstructionIndex(address, step, callback) : Retrieve the instruction index of the given @arg step

function getFunctionFromPC(address, pc, sourceMap, ast) : Retrieve the called function for the given @arg pc and @arg address


BreakpointManager(_ethdebugger, _locationToRowConverter) :

function jumpNextBreakpoint(defaultToLimit) : start looking for the next breakpoint

function jumpPreviousBreakpoint(defaultToLimit) : start looking for the previous breakpoint

function jump(direction, defaultToLimit) : start looking for the previous or next breakpoint

function hasBreakpointAtLine((fileIndex, line) : check the given pair fileIndex/line against registered breakpoints

function hasBreakpoint() : return true if current manager has breakpoint

function add(sourceLocation) : add a new breakpoint to the manager

function remove(sourceLocation) : remove a breakpoint from the manager


StorageViewer(_context, _storageResolver, _traceManager) :

function storageRange(defaultToLimit) : return the storage for the current context (address and vm trace index)

function storageSlot(defaultToLimit) : return a slot value for the current context (address and vm trace index)

function isComplete(direction, defaultToLimit) : return True if the storage at @arg address is complete

function initialMappingsLocation((fileIndex, line) : return all the possible mappings locations for the current context (cached) do not return state changes during the current transaction

function mappingsLocation() : return all the possible mappings locations for the current context (cached) and current mapping slot. returns state changes during the current transaction

function extractMappingsLocationChanges(sourceLocation) : retrieve mapping location changes from the storage changes.


StorageResolver() :

function storageRange(tx, stepIndex, address, callback) : return the storage for the current context (address and vm trace index)

function initialPreimagesMappings(tx, stepIndex, address, callback) : return a slot value for the current context (address and vm trace index)

function storageSlot(slot, tx, stepIndex, address, callback) : return True if the storage at @arg address is complete

function isComplete(address) : return all the possible mappings locations for the current context (cached) do not return state changes during the current transaction

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文