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
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
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
Expand Up @@ -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",
Expand Down
31 changes: 19 additions & 12 deletions commands/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -227,19 +221,32 @@ 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

// REMOVEME: hotfix for samd core 1.8.5/1.8.6
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"`
recipe = `"{path}/{cmd}" --interpreter={interpreter} -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 {
Expand Down
16 changes: 8 additions & 8 deletions commands/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) +
Expand All @@ -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) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ arduino_zero_edbg.name=Arduino Zero (Programming Port)
arduino_zero_edbg.vid.0=0x03eb
arduino_zero_edbg.pid.0=0x2157

arduino_zero_edbg.debug.tool=gdb
arduino_zero_edbg.debug.tool=gdb-openocd
arduino_zero_edbg.upload.tool=openocd
arduino_zero_edbg.upload.protocol=sam-ba
arduino_zero_edbg.upload.maximum_size=262144
Expand Down Expand Up @@ -55,7 +55,7 @@ mkr1000.pid.2=0x824e
mkr1000.vid.3=0x2341
mkr1000.pid.3=0x024e

mkr1000.debug.tool=gdb
mkr1000.debug.tool=gdb-openocd
mkr1000.upload.tool=bossac
mkr1000.upload.protocol=sam-ba
mkr1000.upload.maximum_size=262144
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose
# GDB (Debugger)
#

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-openocd.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
tools.gdb-openocd.cmd=arm-none-eabi-gdb
tools.gdb-openocd.cmd.windows=arm-none-eabi-gdb.exe
tools.gdb-openocd.interpreter=console
tools.gdb-openocd.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.

Loading