Skip to content

Commit fbcd87f

Browse files
author
Roberto Sora
authored
Add debug interpreter flag (arduino#626)
* Remove hotfix adding --interpreter flag * Update client_example main file * Fix test import * Add interpreter resolution in debug test * Updated testdata debug tool name * Reintroduce hotfix to do not break debug support for samd core 1.8.5 and 1.8.6 * Add interpreter variable in hotfix * Fix interpreter bug
1 parent 97c4f00 commit fbcd87f

File tree

12 files changed

+202
-261
lines changed

12 files changed

+202
-261
lines changed

Diff for: cli/debug/debug.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,20 @@ import (
2424
"github.com/arduino/arduino-cli/cli/feedback"
2525
"github.com/arduino/arduino-cli/cli/instance"
2626
"github.com/arduino/arduino-cli/commands/debug"
27+
rpc "github.com/arduino/arduino-cli/rpc/commands"
2728
dbg "github.com/arduino/arduino-cli/rpc/debug"
2829
"github.com/arduino/go-paths-helper"
2930
"github.com/sirupsen/logrus"
3031
"github.com/spf13/cobra"
3132
)
3233

3334
var (
34-
fqbn string
35-
port string
36-
verbose bool
37-
verify bool
38-
importFile string
35+
fqbn string
36+
port string
37+
verbose bool
38+
verify bool
39+
interpreter string
40+
importFile string
3941
)
4042

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

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

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

7679
if _, err := debug.Debug(context.Background(), &dbg.DebugConfigReq{
77-
Instance: &dbg.Instance{Id: instance.GetId()},
78-
Fqbn: fqbn,
79-
SketchPath: sketchPath.String(),
80-
Port: port,
81-
ImportFile: importFile,
80+
Instance: &rpc.Instance{Id: instance.GetId()},
81+
Fqbn: fqbn,
82+
SketchPath: sketchPath.String(),
83+
Port: port,
84+
Interpreter: interpreter,
85+
ImportFile: importFile,
8286
}, os.Stdin, os.Stdout, ctrlc); err != nil {
8387
feedback.Errorf("Error during Debug: %v", err)
8488
os.Exit(errorcodes.ErrGeneric)

Diff for: client_example/go.sum

+86-3
Large diffs are not rendered by default.

Diff for: client_example/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ func callDebugger(debugStreamingOpenClient dbg.Debug_DebugClient, instance *rpc.
823823
log.Printf("Send debug request")
824824
err := debugStreamingOpenClient.Send(&dbg.DebugReq{
825825
DebugReq: &dbg.DebugConfigReq{
826-
Instance: &dbg.Instance{Id: instance.GetId()},
826+
Instance: &rpc.Instance{Id: instance.GetId()},
827827
Fqbn: "arduino:samd:mkr1000",
828828
SketchPath: filepath.Join(currDir, "hello"),
829829
Port: "none",

Diff for: commands/debug/debug.go

+19-12
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager)
126126
return nil, errors.Wrap(err, "opening sketch")
127127
}
128128

129-
// FIXME: make a specification on how a port is specified via command line
130-
port := req.GetPort()
131-
if port == "" {
132-
return nil, fmt.Errorf("no debug port provided")
133-
}
134-
135129
fqbnIn := req.GetFqbn()
136130
if fqbnIn == "" && sketch != nil && sketch.Metadata != nil {
137131
fqbnIn = sketch.Metadata.CPU.Fqbn
@@ -227,19 +221,32 @@ func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager)
227221
}
228222

229223
// Set debug port property
230-
toolProperties.Set("debug.port", port)
231-
if strings.HasPrefix(port, "/dev/") {
232-
toolProperties.Set("debug.port.file", port[5:])
224+
port := req.GetPort()
225+
if port != "" {
226+
toolProperties.Set("debug.port", port)
227+
if strings.HasPrefix(port, "/dev/") {
228+
toolProperties.Set("debug.port.file", port[5:])
229+
} else {
230+
toolProperties.Set("debug.port.file", port)
231+
}
232+
}
233+
234+
// Set debugger interpreter (default value should be "console")
235+
interpreter := req.GetInterpreter()
236+
if interpreter != "" {
237+
toolProperties.Set("interpreter", interpreter)
233238
} else {
234-
toolProperties.Set("debug.port.file", port)
239+
toolProperties.Set("interpreter", "console")
235240
}
236241

237242
// Build recipe for tool
238243
recipe := toolProperties.Get("debug.pattern")
239-
// REMOVEME: hotfix for samd core 1.8.5
244+
245+
// REMOVEME: hotfix for samd core 1.8.5/1.8.6
240246
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` {
241-
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"`
247+
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"`
242248
}
249+
243250
cmdLine := toolProperties.ExpandPropsInString(recipe)
244251
cmdArgs, err := properties.SplitQuotedString(cmdLine, `"'`, false)
245252
if err != nil {

Diff for: commands/debug/debug_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"testing"
2323

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

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

5454
goldCommand := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin//arm-none-eabi-gdb%s", dataDir, toolExtension) +
55-
" -ex target extended-remote |" +
55+
" --interpreter=console -ex target extended-remote |" +
5656
fmt.Sprintf(" %s/arduino-test/tools/openocd/0.10.0-arduino7/bin/openocd%s", dataDir, toolExtension) +
5757
fmt.Sprintf(" -s \"%s/arduino-test/tools/openocd/0.10.0-arduino7/share/openocd/scripts/\"", dataDir) +
5858
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) {
6666
// Other samd boards such as mkr1000 can be debugged using an external tool such as Atmel ICE connected to
6767
// the board debug port
6868
req2 := &dbg.DebugConfigReq{
69-
Instance: &dbg.Instance{Id: 1},
70-
Fqbn: "arduino-test:samd:mkr1000",
71-
SketchPath: sketchPath.String(),
72-
Port: "none",
69+
Instance: &rpc.Instance{Id: 1},
70+
Fqbn: "arduino-test:samd:mkr1000",
71+
SketchPath: sketchPath.String(),
72+
Interpreter: "mi1",
7373
}
7474

7575
goldCommand2 := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin//arm-none-eabi-gdb%s", dataDir, toolExtension) +
76-
" -ex target extended-remote |" +
76+
" --interpreter=mi1 -ex target extended-remote |" +
7777
fmt.Sprintf(" %s/arduino-test/tools/openocd/0.10.0-arduino7/bin/openocd%s", dataDir, toolExtension) +
7878
fmt.Sprintf(" -s \"%s/arduino-test/tools/openocd/0.10.0-arduino7/share/openocd/scripts/\"", dataDir) +
7979
fmt.Sprintf(" --file \"%s/arduino-test/samd/variants/mkr1000/openocd_scripts/arduino_zero.cfg\"", customHardware) +

Diff for: commands/debug/testdata/custom_hardware/arduino-test/samd/boards.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ arduino_zero_edbg.name=Arduino Zero (Programming Port)
2020
arduino_zero_edbg.vid.0=0x03eb
2121
arduino_zero_edbg.pid.0=0x2157
2222

23-
arduino_zero_edbg.debug.tool=gdb
23+
arduino_zero_edbg.debug.tool=gdb-openocd
2424
arduino_zero_edbg.upload.tool=openocd
2525
arduino_zero_edbg.upload.protocol=sam-ba
2626
arduino_zero_edbg.upload.maximum_size=262144
@@ -55,7 +55,7 @@ mkr1000.pid.2=0x824e
5555
mkr1000.vid.3=0x2341
5656
mkr1000.pid.3=0x024e
5757

58-
mkr1000.debug.tool=gdb
58+
mkr1000.debug.tool=gdb-openocd
5959
mkr1000.upload.tool=bossac
6060
mkr1000.upload.protocol=sam-ba
6161
mkr1000.upload.maximum_size=262144

Diff for: commands/debug/testdata/custom_hardware/arduino-test/samd/platform.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose
224224
# GDB (Debugger)
225225
#
226226

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

Diff for: rpc/commands/commands.pb.go

+4-86
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)