---
title: "Debug: breakpoints and step mode"
description: "Add and remove breakpoints, switch the step mode and continue a stopped program, for the controller or for one task, with robot.Debug. Brand support table, C# and Python examples."
---

# Debug: breakpoints and step mode

`robot.Debug` debugs the programs of a robot controller from a PC: breakpoints, step mode and continue, for the whole controller or for one task. The support is partial and depends on the brand: some brands have a route for a few of these methods only, and some have none. See the table below.

## Prerequisites

- A connected `RobotController`. See [Connect to your robot](/robotics/documentation/connect).
- The license of the brand of the controller, or the 30 day trial. See [Licensing](/robotics/documentation/license).
- A program that runs or that you start with [Program](/robotics/documentation/program). A program is named with its native name, as the controller names it. Lines are counted from 1.

## Brand support

Each cell gives the protocol that the method uses on this brand, in the default order. The page [Routing](/robotics/documentation/routing) explains how the library chooses it. The table is generated from the route data of the library. (manual) marks a route that you enable yourself. "n of m" is the number of methods of the service that have a route on this brand.

Routes of each method in the default order. The first route is used, the next ones are fallbacks. (manual) marks a route that you enable yourself.

| Method | Fanuc | Yaskawa | Universal Robots | ABB | Stäubli |
| --- | --- | --- | --- | --- | --- |
| Debug.AddBreakpoint | CGTP (CgtpKcl), Telnet | Not available | Primary Interface (Primary) | Robot Web Services | Not available |
| Debug.RemoveBreakpoint | CGTP (CgtpKcl), Telnet | Not available | Primary Interface (Primary) | Not available | Not available |
| Debug.ReadBreakpoints | CGTP (CgtpKcl), Telnet | Not available | Not available | Robot Web Services | Not available |
| Debug.SetStepMode | CGTP (CgtpKcl), Telnet | High Speed Ethernet Server, Ethernet Server | Primary Interface (Primary) | Robot Web Services | Not available |
| Debug.Continue | CGTP (CgtpKcl), Telnet | High Speed Ethernet Server, Ethernet Server | Primary Interface (Primary) | Robot Web Services | Not available |
| Debug.SetTaskStepMode | CGTP (CgtpKcl), Telnet | Not available | Not available | Not available | Not available |
| Debug.ContinueTask | CGTP (CgtpKcl), Telnet | Not available | Not available | Not available | Not available |
| Debug | **7 of 7** | **2 of 7** | **4 of 7** | **4 of 7** | **0 of 7** |

A brand that has no route for a method throws `FeatureNotSupportedException` (see [Errors](/robotics/documentation/errors)). Ask `robot.Debug.IsAvailable(DebugFeature.AddBreakpoint)` before the call.

## Example

### Breakpoints

`AddBreakpoint` adds a breakpoint at a line of a program, `RemoveBreakpoint` removes it and `ReadBreakpoints` returns the lines of the breakpoints of a program.

**C# : DebugBreakpoints**
```csharp
using UnderAutomation.Robotics.Controllers;

public class DebugBreakpoints
{
    static void Main()
    {
        RobotController robot = new RobotController();
        robot.Connect(RobotConnectionParameters.Create("fanuc", "192.168.0.1"));

        /**/
        robot.Debug.AddBreakpoint("MAIN", 12);

        foreach (int line in robot.Debug.ReadBreakpoints("MAIN"))
            Console.WriteLine($"Breakpoint at line {line}");

        robot.Debug.RemoveBreakpoint("MAIN", 12);
        /**/

        robot.Disconnect();
    }
}
```

**Python : DebugBreakpoints**
```python
from underautomation.robotics.controllers.robot_controller import RobotController
from underautomation.robotics.controllers.robot_connection_parameters import RobotConnectionParameters

robot = RobotController()
robot.connect(RobotConnectionParameters.create("fanuc", "192.168.0.1", ""))

##
robot.debug.add_breakpoint("MAIN", 12)

for line in robot.debug.read_breakpoints("MAIN"):
    print(f"Breakpoint at line {line}")

robot.debug.remove_breakpoint("MAIN", 12)
##

robot.disconnect()
```

### Step mode

In step mode, the program stops after each instruction and `Continue` runs the next one. Use these two methods for a debug session. Depending on the brand, `SetStepMode` sets the cycle mode of the controller (as `Program.SetCycleMode` with `CycleMode.Step`) or only changes how `Continue` runs. `SetStepMode(false)` goes back to the continuous execution.

A program paused by `Program.Pause` or `Program.Hold` continues with `Program.Resume`, not with `Continue`.

**C# : DebugStep**
```csharp
using UnderAutomation.Robotics.Controllers;

public class DebugStep
{
    static void Main()
    {
        RobotController robot = new RobotController();
        robot.Connect(RobotConnectionParameters.Create("fanuc", "192.168.0.1"));

        /**/
        robot.Debug.SetStepMode(true);

        // A program stopped on a breakpoint or in step mode goes to the next line
        robot.Debug.Continue();

        robot.Debug.SetStepMode(false);
        /**/

        robot.Disconnect();
    }
}
```

**Python : DebugStep**
```python
from underautomation.robotics.controllers.robot_controller import RobotController
from underautomation.robotics.controllers.robot_connection_parameters import RobotConnectionParameters

robot = RobotController()
robot.connect(RobotConnectionParameters.create("fanuc", "192.168.0.1", ""))

##
robot.debug.set_step_mode(True)

# A program stopped on a breakpoint or in step mode goes to the next line
robot.debug.continue_()

robot.debug.set_step_mode(False)
##

robot.disconnect()
```

### One task

`SetTaskStepMode` and `ContinueTask` only have a route on Fanuc today: see the table. On a controller with several tasks, `SetTaskStepMode` switches the step mode of one task and the other tasks keep their mode. `ContinueTask` runs the next instruction of this task, and the other paused tasks stay paused. A brand can refuse `SetTaskStepMode(task, false)` with an `ArgumentException` when its controller turns the step mode off for every task only: use `SetStepMode(false)` then. Check `IsAvailable(DebugFeature.SetTaskStepMode)` first.

## Reference

In Python, the names are in snake_case: `robot.debug.add_breakpoint(...)`, `robot.debug.read_breakpoints(...)`, `robot.debug.set_step_mode(True)`, `robot.debug.set_task_step_mode(...)`, `robot.debug.continue_task(...)`. `continue` is a reserved word of Python: the method is `robot.debug.continue_()`. The enum members keep their names.

### Methods of IDebugService

**Members of Controllers.IDebugService**
```csharp
public interface IDebugService {
    // Adds a breakpoint
    void AddBreakpoint(string program, int line)

    // Continues the program stopped on a breakpoint or in step mode. A program paused by <xref href="UnderAutomation.Robotics.Controllers.IProgramService.Pause" data-throw-if-not-resolved="false"></xref> or <xref href="UnderAutomation.Robotics.Controllers.IProgramService.Hold" data-throw-if-not-resolved="false"></xref>
    // continues with <xref href="UnderAutomation.Robotics.Controllers.IProgramService.Resume" data-throw-if-not-resolved="false"></xref>.
    void Continue()

    // Continues one task stopped on a breakpoint or in step mode. The other paused tasks stay paused.
    void ContinueTask(string task)

    // Returns true when the method can be called on the connected controller.
    // The answer depends on the brand, on the routing settings and on the protocols that answered at the connection, not on the state of the controller.
    bool IsAvailable(DebugFeature feature)

    // Returns the lines of the breakpoints of a program
    int[] ReadBreakpoints(string program)

    // Removes a breakpoint
    void RemoveBreakpoint(string program, int line)

    // Switches the step mode on or off. In step mode, the program stops after each instruction and <xref href="UnderAutomation.Robotics.Controllers.IDebugService.Continue" data-throw-if-not-resolved="false"></xref> runs the next one.
    // Use it for a debug session. Depending on the brand, it sets the cycle mode of the controller (as <xref href="UnderAutomation.Robotics.Controllers.IProgramService.SetCycleMode(UnderAutomation.Robotics.Controllers.CycleMode)" data-throw-if-not-resolved="false"></xref> with <xref href="UnderAutomation.Robotics.Controllers.CycleMode.Step" data-throw-if-not-resolved="false"></xref>)
    // or only changes how <xref href="UnderAutomation.Robotics.Controllers.IDebugService.Continue" data-throw-if-not-resolved="false"></xref> runs. False goes back to the continuous execution.
    void SetStepMode(bool on)

    // Switches the step mode of one task on or off. The other tasks keep their mode. <xref href="UnderAutomation.Robotics.Controllers.IDebugService.ContinueTask(System.String)" data-throw-if-not-resolved="false"></xref> runs the next instruction of the task.
    // A brand can refuse "off" with an <xref href="System.ArgumentException" data-throw-if-not-resolved="false"></xref> when its controller turns the step mode off for every task only: use <xref href="UnderAutomation.Robotics.Controllers.IDebugService.SetStepMode(System.Boolean)" data-throw-if-not-resolved="false"></xref> then.
    void SetTaskStepMode(string task, bool on)
}
```

### Errors

The page [Errors](/robotics/documentation/errors) explains each exception and how to avoid it.

- `FeatureNotSupportedException`: the brand has no route for the method.
- `RouteUnavailableException`: the method has routes, but none of them can be used, for example because the protocol did not answer at the connection.
- `ControllerRefusedException`: the controller received the command and refused it.
- `RobotControllerException`: the route failed. Its inner exception is the exception of the brand SDK.
- `ArgumentException`: an invalid argument, for example a task step mode that the controller refuses.

`IsAvailable` only throws `ArgumentOutOfRangeException`, for a value that is not in the enum.

## What to read next

- [Program](/robotics/documentation/program): start, pause, resume and read the execution state, with the call stack.
- [State](/robotics/documentation/state): operating mode and servo power.
- [Alarm](/robotics/documentation/alarm): read the alarms of the controller.