You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
3.4 KiB

//humanReadableExecutionCode => contain human readable code.
//debugStates => contain all debug states.
//bytesCodeMapping => mapping between humanReadableExecutionCode and bytesCode.
//statesList => ListView
var currentSelectedState = null;
10 years ago
var jumpStartingPoint = null;
function init()
{
if (debugStates === undefined)
return;
10 years ago
statesSlider.maximumValue = debugStates.length - 1;
statesSlider.value = 0;
10 years ago
statesList.model = humanReadableExecutionCode;
currentSelectedState = 0;
select(currentSelectedState);
10 years ago
10 years ago
jumpoutbackaction.enabled(false);
jumpintobackaction.enabled(false);
jumpintoforwardaction.enabled(false);
jumpoutforwardaction.enabled(false);
}
function moveSelection(incr)
{
if (currentSelectedState + incr >= 0)
{
if (currentSelectedState + incr < debugStates.length)
select(currentSelectedState + incr);
10 years ago
statesSlider.value = currentSelectedState;
}
}
function select(stateIndex)
{
10 years ago
var codeLine = codeStr(stateIndex);
var state = debugStates[stateIndex];
10 years ago
highlightSelection(codeLine);
currentSelectedState = stateIndex;
completeCtxInformation(state);
10 years ago
if (state.instruction === "JUMP")
10 years ago
jumpintoforwardaction.enabled(true);
10 years ago
else
10 years ago
jumpintoforwardaction.enabled(false);
10 years ago
if (state.instruction === "JUMPDEST")
10 years ago
jumpintobackaction.enabled(true);
10 years ago
else
10 years ago
jumpintobackaction.enabled(false);
10 years ago
}
function codeStr(stateIndex)
{
var state = debugStates[stateIndex];
return bytesCodeMapping.getValue(state.curPC);
}
function highlightSelection(index)
{
statesList.currentIndex = index;
}
function completeCtxInformation(state)
{
currentStep.update(state.step);
mem.update(state.newMemSize + " " + qsTr("words"));
stepCost.update(state.gasCost);
gasSpent.update(debugStates[0].gas - state.gas);
10 years ago
10 years ago
stack.listModel = state.debugStack;
storage.listModel = state.debugStorage;
memoryDump.listModel = state.debugMemory;
callDataDump.listModel = state.debugCallData;
}
function displayReturnValue()
{
headerReturnList.model = contractCallReturnParameters;
headerReturnList.update();
}
10 years ago
function stepOutBack()
{
if (jumpStartingPoint != null)
{
select(jumpStartingPoint);
jumpStartingPoint = null;
10 years ago
jumpoutbackaction.enabled(false);
jumpoutforwardaction.enabled(false);
10 years ago
}
}
function stepIntoBack()
{
moveSelection(-1);
}
function stepOverBack()
{
var state = debugStates[currentSelectedState];
if (state.instruction === "JUMPDEST")
{
for (var k = currentSelectedState; k > 0; k--)
{
var line = bytesCodeMapping.getValue(debugStates[k].curPC);
if (line === statesList.currentIndex - 2)
{
select(k);
break;
}
}
}
else
moveSelection(-1);
}
function stepOverForward()
{
var state = debugStates[currentSelectedState];
if (state.instruction === "JUMP")
{
for (var k = currentSelectedState; k < debugStates.length; k++)
{
var line = bytesCodeMapping.getValue(debugStates[k].curPC);
if (line === statesList.currentIndex + 2)
{
select(k);
break;
}
}
}
else
moveSelection(1);
}
function stepIntoForward()
{
var state = debugStates[currentSelectedState];
if (state.instruction === "JUMP")
{
jumpStartingPoint = currentSelectedState;
moveSelection(1);
10 years ago
jumpoutbackaction.enabled(true);
jumpoutforwardaction.enabled(true);
10 years ago
}
}
function stepOutForward()
{
if (jumpStartingPoint != null)
{
stepOutBack();
stepOverForward();
10 years ago
jumpoutbackaction.enabled(false);
jumpoutforwardaction.enabled(false);
10 years ago
}
}
function jumpTo(value)
{
currentSelectedState = value;
select(currentSelectedState);
}