Open In App

Debugger – Remix

Last Updated : 24 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The Remix debugger is a tool that allows you to step through your Solidity code and examine the values of variables and the state of the Ethereum blockchain at different points in the execution. It is built into the Remix development environment, which is a web-based development environment for the Solidity programming language. The article focuses on discussing Debugger in Remix IDE. The following topics will be discussed here:

  1. What is Debugger?
  2. Debugger’s Navigation.
  3. Debugger’s Panels
  4. Breakpoint
  5. Debugging Transactions.
  6. Initiate Debugging from the Debugger
  7. Using the Debugger

Let’s start discussing each of these topics in detail.

What is Debugger?

Remix debugger allows you to debug the solidity code and to use the Remix debugger, you can open the Solidity file that you want to debug in the Remix editor and click the “Debug” button in the right pane. This will open the debugger window, which allows one to execute the code line by line and examine the values of variables and the state of the blockchain at each step. You can also set breakpoints, inspect the values of variables, and view the state of the blockchain using the debugger.

  • The Remix debugger is a useful tool for debugging Solidity code and troubleshooting errors in smart contracts. 
  • It is especially useful for testing and debugging smart contracts that are deployed on the Ethereum blockchain, as it allows you to examine the state of the blockchain and see how the contract is interacting with it.

Debugger Navigation

It debugs the smart contracts written in the Solidity programming language. It provides a number of tools and features for debugger navigation, including:

  • Slider: Moving the slider will highlight the relevant code in the Editor. On the most granular level, it scrolls through a transaction’s opcodes (see the opcode section below). At each opcode, the transaction’s state changes, and these changes are reflected in the Debugger’s panels.
  • Step over back: This button goes to the previous opcode. If the previous step involves a function call, the function will not be entered.
  • Step back: This button steps back to the previous opcode.
  • Step into: This button advances to the next opcode. If the next line contains a function call, Step into will go into the function.
  • Step over forward: This button advances to the next opcode. If the next step involves a function call, the function will not be entered.
  • Jump to the previous breakpoint: Breakpoints can be placed in the gutter of the Editor. If the current step in the call has passed a breakpoint, this button will move the slider to the most recently passed breakpoint.
  • Jump out: When you are on a call and click on this button, the slider will be moved to the end of the call.
  • Jump to the next breakpoint: If a breakpoint is ahead in the code, this button will advance to that point.
Tools for debugger navigation

 

Debugger Panels

1. Function Stack: The Function Stack panel displays a list of the functions that have been called and are currently on the call stack. You can use this panel to see the sequence of function calls that led to the current execution point.

Function Stack

 

2. Solidity Locals: The Solidity Locals panel displays the local variables and their values for the current function. You can use this panel to see the current state of the contract’s local variables.

Solidity Locals

 

3. Solidity State: The Solidity State panel displays the contract’s state variables and their values. You can use this panel to see the current state of the contract’s state variables.

Solidity State

 

4. Opcodes: The Opcodes panel displays the EVM opcodes that are being executed as the contract runs. You can use this panel to see the low-level operations that the contract is performing.

Opcodes

 

5. Step details: The Step details panel provides information about the current step being executed, including the source code line, the corresponding bytecode, and any relevant data.

Step details

 

6. Stack: The Stack panel displays the current contents of the EVM stack. You can use this panel to see the data that is being manipulated by the contract.

Stack

 

7. Memory: The Memory panel displays the current contents of the EVM memory. You can use this panel to see the data that is being stored in memory by the contract.

Memory

 

8. Storage: The Storage panel displays the contract’s storage variables and their values. You can use this panel to see the current state of the contract’s storage.

Storage

 

9. Call Stack: The Call Stack panel displays a list of the calls that have been made and are currently on the call stack. You can use this panel to see the sequence of calls that led to the current execution point.

Call Stack

 

10. Call Data: The Call Data panel displays the input data for the current call. You can use this panel to see the arguments that were passed to the current function.

Call Data

 

11. Return Value: The Return Value panel displays the return value for the current call. You can use this panel to see the result of the current function.

Return Value

 

12. Full Storage: The Full Storage Changes panel displays the storage variables and their values before and after each call. You can use this panel to see how the contract’s storage is being modified during execution.

Full Storage

 

Breakpoints

Breakpoints are points in the code where the debugger will pause the execution of a program.

  1. In the navigation area, there are two buttons that allow you to jump back to the previous breakpoint or forward to the next breakpoint.
  2. To add or remove a breakpoint, click on the line number in the editor.
  3. During a debug session with breakpoints, the execution will pause at the first encountered breakpoint.
  4. It is important to note that if you add a breakpoint to a line that declares a variable, the breakpoint may be triggered twice – once when the variable is initialized to zero and again when it is assigned its actual value.

Here is an example to illustrate this:

Solidity




// Solidity program to implement
// Breakpoints
pragma solidity ^0.5.0;
  
contract helloGeeks {
  function hid() public {
    uint p = 45;
    uint m;
    m = 89;
    uint l = 34;
  }
}


If you set breakpoints on the lines:

uint p = 45;

m = 89;

uint l = 34;

Then clicking on the “Jump to the next breakpoint” button will pause the execution at the following lines in this order:

uint p = 45; (declaration of p)

uint l = 34; (declaration of l)

uint p = 45; (45 assigned to p)

m = 89; (89 assigned to m)

uint l = 34; (34 assigned to l)

Explanation:

  1. The first breakpoint is on the line where the variable p is declared. The debugger will pause at this point.
  2. The second breakpoint is on the line where the variable l is declared. The debugger will pause at this point.
  3. The third breakpoint is on the line where the value 45 is assigned to the variable p. The debugger will pause at this point.
  4. The fourth breakpoint is on the line where the value 89 is assigned to the variable m. The debugger will pause at this point.
  5. The fifth breakpoint is on the line where the value 34 is assigned to the variable l. The debugger will pause at this point.

Debugging Transactions

Debugging transactions is the process of analyzing and troubleshooting errors or issues that occur when executing a transaction on a blockchain. There are several approaches you can take to debug transactions, depending on the nature of the issue and the tools and resources that are available to you.

Here are some general steps you can follow to debug transactions:

  1. Gather information: To debug a transaction, it is helpful to have as much information as possible about the transaction, including the input data, the output data, and any error messages or logs that are generated. You can gather this information using a blockchain explorer, a debugger, or other tools that are specific to the blockchain platform you are using.
  2. Identify the problem: Once you have gathered the relevant information, try to identify the root cause of the problem. This may involve examining the input data to see if it is valid, analyzing the output data to see if it is what you expected, or looking at error messages or logs to see if they provide any clues.
  3. Determine the solution: Based on the information you have gathered and the problem you have identified, try to determine a solution to the issue. This may involve modifying the input data, adjusting the configuration of your blockchain platform, or implementing a workaround.
  4. Test and verify: Once you have determined a solution to the issue, test it to make sure it works as expected. This may involve running the transaction again and verifying that the output data is correct, or checking the logs to see if the issue has been resolved.

Debugging transactions can be a complex and time-consuming process, but it is an important skill to have when working with blockchain technologies. By following these steps and using the appropriate tools and resources, you can effectively troubleshoot and resolve issues with transactions on a blockchain.

Initiate debugging from the debugger

To perform debugging from the remix debugger, simply follow the below-mentioned steps:

1. Click on the bug icon in the icon panel to access the debugger in the side panel.

Click bug icon

 

2. If you do not see the bug icon, go to the plugin manager and activate the debugger.

Activate debugger

 

3. To begin a debug session, you will need to provide a transaction hash, To find a transaction hash.

  • Go to a transaction in the terminal
  • Click on a line with a transaction to expand the log
  • The transaction hash will be displayed – copy it
Transaction hash

 

4. Then click in the debugger paste the hash and click on the Start debugging button.

Start debugging

 

Using the debugger

To use the debugger, you will typically need to do the following:

  • The Instruction panel with EVM bytecode displays the sequence of instructions that are being executed by the Ethereum Virtual Machine (EVM). This can be helpful in understanding how the program is executed and identifying any issues.
  • The basic information panel displays information about the current state of the program, such as the current instruction being executed, the values of variables, and the call stack. This can be helpful in understanding what is happening in the program and identifying any issues.
  • The slider-to-step transaction execution allows you to step through the execution of a transaction one instruction at a time. This can be helpful in understanding how the program is executed and identifying any issues.
  • The button to step through transaction execution allows you to step through the execution of a transaction one instruction at a time. This can be helpful in understanding how the program is executed and identifying any issues.
Debugger

 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads