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.

190 lines
3.9 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 (typeof(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
jumpOutBackAction.enabled(false);
jumpIntoBackAction.enabled(false);
jumpIntoForwardAction.enabled(false);
jumpOutForwardAction.enabled(false);
}
function moveSelection(incr)
{
if (typeof(debugStates) === "undefined")
return;
if (currentSelectedState + incr >= 0)
{
if (currentSelectedState + incr < debugStates.length)
select(currentSelectedState + incr);
10 years ago
statesSlider.value = currentSelectedState;
}
}
function select(stateIndex)
{
if (typeof(debugStates) === "undefined")
return;
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")
jumpIntoForwardAction.enabled(true);
10 years ago
else
jumpIntoForwardAction.enabled(false);
10 years ago
if (state.instruction === "JUMPDEST")
jumpIntoBackAction.enabled(true);
10 years ago
else
jumpIntoBackAction.enabled(false);
10 years ago
}
function codeStr(stateIndex)
{
if (typeof(debugStates) === "undefined")
return;
10 years ago
var state = debugStates[stateIndex];
return bytesCodeMapping.getValue(state.curPC);
}
function highlightSelection(index)
{
statesList.currentIndex = index;
}
function completeCtxInformation(state)
{
if (typeof(debugStates) === "undefined")
return;
currentStep.update(state.step);
10 years ago
mem.update(state.newMemSize.value() + " " + qsTr("words"));
stepCost.update(state.gasCost.value());
gasSpent.update(debugStates[0].gas.subtract(state.gas).value());
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 (typeof(debugStates) === "undefined")
return;
10 years ago
if (jumpStartingPoint != null)
{
select(jumpStartingPoint);
jumpStartingPoint = null;
jumpOutBackAction.enabled(false);
jumpOutForwardAction.enabled(false);
10 years ago
}
}
function stepIntoBack()
{
moveSelection(-1);
}
function stepOverBack()
{
if (typeof(debugStates) === "undefined")
return;
10 years ago
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()
{
if (typeof(debugStates) === "undefined")
return;
10 years ago
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()
{
if (typeof(debugStates) === "undefined")
return;
10 years ago
var state = debugStates[currentSelectedState];
if (state.instruction === "JUMP")
{
jumpStartingPoint = currentSelectedState;
moveSelection(1);
jumpOutBackAction.enabled(true);
jumpOutForwardAction.enabled(true);
10 years ago
}
}
function stepOutForward()
{
if (jumpStartingPoint != null)
{
stepOutBack();
stepOverForward();
jumpOutBackAction.enabled(false);
jumpOutForwardAction.enabled(false);
10 years ago
}
}
function jumpTo(value)
{
currentSelectedState = value;
select(currentSelectedState);
}