Skip to content

Add debug interpreter flag #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 20, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions cli/debug/debug.go
Original file line number Diff line number Diff line change
@@ -24,18 +24,20 @@ import (
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/debug"
rpc "github.com/arduino/arduino-cli/rpc/commands"
dbg "github.com/arduino/arduino-cli/rpc/debug"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var (
fqbn string
port string
verbose bool
verify bool
importFile string
fqbn string
port string
verbose bool
verify bool
interpreter string
importFile string
)

// NewCommand created a new `upload` command
@@ -50,7 +52,8 @@ func NewCommand() *cobra.Command {
}

debugCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno")
debugCommand.Flags().StringVarP(&port, "port", "p", "", "Upload port, e.g.: COM10 or /dev/ttyACM0")
debugCommand.Flags().StringVarP(&port, "port", "p", "", "Debug port, e.g.: COM10 or /dev/ttyACM0")
debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", "Debug interpreter e.g.: console, mi, mi1, mi2, mi3")
debugCommand.Flags().StringVarP(&importFile, "input", "i", "", "Input file to be uploaded for debug.")

return debugCommand
@@ -74,11 +77,12 @@ func run(command *cobra.Command, args []string) {
signal.Notify(ctrlc, os.Interrupt)

if _, err := debug.Debug(context.Background(), &dbg.DebugConfigReq{
Instance: &dbg.Instance{Id: instance.GetId()},
Fqbn: fqbn,
SketchPath: sketchPath.String(),
Port: port,
ImportFile: importFile,
Instance: &rpc.Instance{Id: instance.GetId()},
Fqbn: fqbn,
SketchPath: sketchPath.String(),
Port: port,
Interpreter: interpreter,
ImportFile: importFile,
}, os.Stdin, os.Stdout, ctrlc); err != nil {
feedback.Errorf("Error during Debug: %v", err)
os.Exit(errorcodes.ErrGeneric)
89 changes: 86 additions & 3 deletions client_example/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client_example/main.go
Original file line number Diff line number Diff line change
@@ -823,7 +823,7 @@ func callDebugger(debugStreamingOpenClient dbg.Debug_DebugClient, instance *rpc.
log.Printf("Send debug request")
err := debugStreamingOpenClient.Send(&dbg.DebugReq{
DebugReq: &dbg.DebugConfigReq{
Instance: &dbg.Instance{Id: instance.GetId()},
Instance: &rpc.Instance{Id: instance.GetId()},
Fqbn: "arduino:samd:mkr1000",
SketchPath: filepath.Join(currDir, "hello"),
Port: "none",
30 changes: 16 additions & 14 deletions commands/debug/debug.go
Original file line number Diff line number Diff line change
@@ -126,12 +126,6 @@ func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager)
return nil, errors.Wrap(err, "opening sketch")
}

// FIXME: make a specification on how a port is specified via command line
port := req.GetPort()
if port == "" {
return nil, fmt.Errorf("no debug port provided")
}

fqbnIn := req.GetFqbn()
if fqbnIn == "" && sketch != nil && sketch.Metadata != nil {
fqbnIn = sketch.Metadata.CPU.Fqbn
@@ -227,19 +221,27 @@ func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager)
}

// Set debug port property
toolProperties.Set("debug.port", port)
if strings.HasPrefix(port, "/dev/") {
toolProperties.Set("debug.port.file", port[5:])
port := req.GetPort()
if port != "" {
toolProperties.Set("debug.port", port)
if strings.HasPrefix(port, "/dev/") {
toolProperties.Set("debug.port.file", port[5:])
} else {
toolProperties.Set("debug.port.file", port)
}
}

// Set debugger interpreter (default value should be "console")
interpreter := req.GetInterpreter()
if interpreter != "" {
toolProperties.Set("interpreter", interpreter)
} else {
toolProperties.Set("debug.port.file", port)
toolProperties.Set("interpreter", "console")
}

// Build recipe for tool
recipe := toolProperties.Get("debug.pattern")
// REMOVEME: hotfix for samd core 1.8.5
if recipe == `"{path}/{cmd}" --interpreter=mi2 -ex "set pagination off" -ex 'target extended-remote | {tools.openocd.path}/{tools.openocd.cmd} -s "{tools.openocd.path}/share/openocd/scripts/" --file "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "gdb_port pipe" -c "telnet_port 0"' {build.path}/{build.project_name}.elf` {
recipe = `"{path}/{cmd}" --interpreter=mi2 -ex "set remotetimeout 5" -ex "set pagination off" -ex 'target extended-remote | "{tools.openocd.path}/{tools.openocd.cmd}" -s "{tools.openocd.path}/share/openocd/scripts/" --file "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "gdb_port pipe" -c "telnet_port 0"' "{build.path}/{build.project_name}.elf"`
}

cmdLine := toolProperties.ExpandPropsInString(recipe)
cmdArgs, err := properties.SplitQuotedString(cmdLine, `"'`, false)
if err != nil {
16 changes: 8 additions & 8 deletions commands/debug/debug_test.go
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ import (
"testing"

"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
rpc "github.com/arduino/arduino-cli/rpc/commands"
dbg "github.com/arduino/arduino-cli/rpc/debug"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/assert"
@@ -45,14 +46,13 @@ func TestGetCommandLine(t *testing.T) {

// Arduino Zero has an integrated debugger port, anc it could be debugged directly using USB
req := &dbg.DebugConfigReq{
Instance: &dbg.Instance{Id: 1},
Instance: &rpc.Instance{Id: 1},
Fqbn: "arduino-test:samd:arduino_zero_edbg",
SketchPath: sketchPath.String(),
Port: "none",
}

goldCommand := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin//arm-none-eabi-gdb%s", dataDir, toolExtension) +
" -ex target extended-remote |" +
" --interpreter=console -ex target extended-remote |" +
fmt.Sprintf(" %s/arduino-test/tools/openocd/0.10.0-arduino7/bin/openocd%s", dataDir, toolExtension) +
fmt.Sprintf(" -s \"%s/arduino-test/tools/openocd/0.10.0-arduino7/share/openocd/scripts/\"", dataDir) +
fmt.Sprintf(" --file \"%s/arduino-test/samd/variants/arduino_zero/openocd_scripts/arduino_zero.cfg\"", customHardware) +
@@ -66,14 +66,14 @@ func TestGetCommandLine(t *testing.T) {
// Other samd boards such as mkr1000 can be debugged using an external tool such as Atmel ICE connected to
// the board debug port
req2 := &dbg.DebugConfigReq{
Instance: &dbg.Instance{Id: 1},
Fqbn: "arduino-test:samd:mkr1000",
SketchPath: sketchPath.String(),
Port: "none",
Instance: &rpc.Instance{Id: 1},
Fqbn: "arduino-test:samd:mkr1000",
SketchPath: sketchPath.String(),
Interpreter: "mi1",
}

goldCommand2 := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin//arm-none-eabi-gdb%s", dataDir, toolExtension) +
" -ex target extended-remote |" +
" --interpreter=mi1 -ex target extended-remote |" +
fmt.Sprintf(" %s/arduino-test/tools/openocd/0.10.0-arduino7/bin/openocd%s", dataDir, toolExtension) +
fmt.Sprintf(" -s \"%s/arduino-test/tools/openocd/0.10.0-arduino7/share/openocd/scripts/\"", dataDir) +
fmt.Sprintf(" --file \"%s/arduino-test/samd/variants/mkr1000/openocd_scripts/arduino_zero.cfg\"", customHardware) +
Original file line number Diff line number Diff line change
@@ -228,4 +228,4 @@ tools.gdb.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
tools.gdb.cmd=arm-none-eabi-gdb
tools.gdb.cmd.windows=arm-none-eabi-gdb.exe

tools.gdb.debug.pattern="{path}/{cmd}" -ex 'target extended-remote | {tools.openocd.path}/{tools.openocd.cmd} -s "{tools.openocd.path}/share/openocd/scripts/" --file "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "gdb_port pipe" -c "telnet_port 0" -c init -c halt' {build.path}/{build.project_name}.elf
tools.gdb.debug.pattern="{path}/{cmd}" --interpreter={interpreter} -ex 'target extended-remote | {tools.openocd.path}/{tools.openocd.cmd} -s "{tools.openocd.path}/share/openocd/scripts/" --file "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "gdb_port pipe" -c "telnet_port 0" -c init -c halt' {build.path}/{build.project_name}.elf
90 changes: 4 additions & 86 deletions rpc/commands/commands.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 48 additions & 89 deletions rpc/debug/debug.pb.go
13 changes: 6 additions & 7 deletions rpc/debug/debug.proto
Original file line number Diff line number Diff line change
@@ -19,10 +19,12 @@ 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 {
rpc Debug(stream DebugReq) returns (stream DebugResp) { }
rpc Debug (stream DebugReq) returns (stream DebugResp) {
}
}

// The top-level message sent by the client for the `Debug` method.
@@ -46,20 +48,17 @@ message DebugReq {
}

message DebugConfigReq {
Instance instance = 1;
cc.arduino.cli.commands.Instance instance = 1;
string fqbn = 2;
string sketch_path = 3;
string port = 4;
bool verbose = 5;
string interpreter = 5;
bool verbose = 6;
string import_file = 7;
}


//
message DebugResp {
bytes data = 1;
string error = 2;
}

// TODO remove this in next proto refactoring because is a duplicate from commands/common.proto
message Instance { int32 id = 1; }
18 changes: 4 additions & 14 deletions rpc/monitor/monitor.pb.go
27 changes: 4 additions & 23 deletions rpc/settings/settings.pb.go