I am trying to debug a contract on Remix IDE:
pragma solidity ^0.5.1;
contract DebuggerSampleContract{
int counter = 10;
function LoopCounter(int _input) public view returns (int) {
int returnValue;
for(; _input <counter; _input++)
{
returnValue += _input;
}
returnValue;
}
}
I selected following steps:
1. Solidity Compiler, 2. Compile DebuggerSampleContract.sol, 3. Deployand Run Transactions, 4. Deploy, 5. Clicked arrow to see the function, 6. Debug, 7. Step over (whole contract got selected), 8. step Over, only the value 10 selected, 9. Step Over, It did not enter the function, instead it went to pragma statement.
@goodvibration
Based upon the comments, I changed the contract to:
contract DebuggerSampleContract{
int counter = 10;
constructor(int _input) public{
int returnValue;
for(; _input <counter; _input++)
{
returnValue += _input;
}
//returnValue;
}
}
I started debugging and put the constructor argument to 6. When I pressed debug, it showed me machine language instructions i.e. EVM bytecode. I pressed "Step forward" but I don't know how to keep track of the local variables and state variables through bytecode.
Somebody please guide me.
Zulfi.
Best Answer
As
@Chan-Ho Suh
suggested in the comment you are looking through the debug of the transaction of the contract being deployed. As in your initial question, there is no constructor, there is nothing to step through.The problem is that you are not calling the function
LoopCounter
after deploying the contract in your step 5, you need to enter a value and click the function name for it to run.In the
Deploy and Run Transactions
screen, once you deploy your contract, you will see a gray box representing the contract that you just deployed (1). If you click the arrow in this box, it will show you the functions available in this contract. Add the number you'd like to test and click the blue button with the function name to call the function (2). Now you'll see another log in the console which you can use to debug this function (3). Using this debug, the debugger steps through the function as desired.(the problem is that you need
return returnValue
instead of justreturnValue
)