// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

syntax = "proto3";

package cc.arduino.cli.debug;

option go_package = "github.com/arduino/arduino-cli/rpc/debug";

import "commands/common.proto";

// Service that abstract a debug Session usage
service Debug {
    // Start a debug session and communicate with the debugger tool.
    rpc Debug (stream DebugReq) returns (stream DebugResp) {
    }
}

// The top-level message sent by the client for the `Debug` method.
// Multiple `DebugReq` messages can be sent but the first message
// must contain a `DebugReq` message to initialize the debug session.
// All subsequent messages must contain bytes to be sent to the debug session
// and must not contain a `DebugReq` message.
message DebugReq {
    // Content must be either a debug session config or data to be sent.

    // Provides information to the debug that specifies which is the target.
    // The first `StreamingOpenReq` message must contain a `DebugReq`
    // message.
    DebugConfigReq debugReq = 1;

    // The data to be sent to the target being monitored.
    bytes data = 2;

    // Set this to true to send and Interrupt signal to the debugger process
    bool send_interrupt = 3;
}

message DebugConfigReq {
    // Arduino Core Service instance from the `Init` response.
    cc.arduino.cli.commands.Instance instance = 1;
    // Fully qualified board name of the board in use
    // (e.g., `arduino:samd:mkr1000`). If this is omitted, the FQBN attached to
    // the sketch will be used.
    string fqbn = 2;
    // Path to the sketch that is running on the board. The compiled executable
    // is expected to be located under this path.
    string sketch_path = 3;
    // Port of the debugger. Set to `none` if the debugger doesn't use a port.
    string port = 4;
    // Which GDB command interpreter to use.
    string interpreter = 5;
    // DEPRECATED: use import_dir instead
    string import_file = 7 [deprecated = true];
    // Directory containing the compiled executable. If `import_dir` is not
    // specified, the executable is assumed to be in
    // `{sketch_path}/build/{fqbn}/`.
    string import_dir = 8;
}

//
message DebugResp {
    // Incoming data from the debugger tool.
    bytes data = 1;
    // Incoming error output from the debugger tool.
    string error = 2;
}
