Skip to content

Commit d27c408

Browse files
committed
Added minimum debug_fqbn computation in 'debug check' command
1 parent 4d6b87d commit d27c408

File tree

7 files changed

+189
-83
lines changed

7 files changed

+189
-83
lines changed

Diff for: arduino/cores/fqbn.go

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ type FQBN struct {
3030
Configs *properties.Map
3131
}
3232

33+
// MustParseFQBN extract an FQBN object from the input string
34+
// or panics if the input is not a valid FQBN.
35+
func MustParseFQBN(fqbnIn string) *FQBN {
36+
res, err := ParseFQBN(fqbnIn)
37+
if err != nil {
38+
panic(err)
39+
}
40+
return res
41+
}
42+
3343
// ParseFQBN extract an FQBN object from the input string
3444
func ParseFQBN(fqbnIn string) (*FQBN, error) {
3545
// Split fqbn

Diff for: commands/debug/debug_info.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"encoding/json"
2121
"errors"
22+
"reflect"
2223
"slices"
2324
"strconv"
2425
"strings"
@@ -52,23 +53,40 @@ func IsDebugSupported(ctx context.Context, req *rpc.IsDebugSupportedRequest) (*r
5253
return nil, &arduino.InvalidInstanceError{}
5354
}
5455
defer release()
55-
_, err := getDebugProperties(&rpc.GetDebugConfigRequest{
56+
configRequest := &rpc.GetDebugConfigRequest{
5657
Instance: req.GetInstance(),
5758
Fqbn: req.GetFqbn(),
5859
SketchPath: "",
5960
Port: req.GetPort(),
6061
Interpreter: req.GetInterpreter(),
6162
ImportDir: "",
6263
Programmer: req.GetProgrammer(),
63-
}, pme, true)
64+
}
65+
expectedOutput, err := getDebugProperties(configRequest, pme, true)
6466
var x *arduino.FailedDebugError
6567
if errors.As(err, &x) {
6668
return &rpc.IsDebugSupportedResponse{DebuggingSupported: false}, nil
6769
}
6870
if err != nil {
6971
return nil, err
7072
}
71-
return &rpc.IsDebugSupportedResponse{DebuggingSupported: true}, nil
73+
74+
// Compute the minimum FQBN required to get the same debug configuration.
75+
// (i.e. the FQBN cleaned up of the options that do not affect the debugger configuration)
76+
minimumFQBN := cores.MustParseFQBN(req.GetFqbn())
77+
for _, config := range minimumFQBN.Configs.Keys() {
78+
checkFQBN := minimumFQBN.Clone()
79+
checkFQBN.Configs.Remove(config)
80+
configRequest.Fqbn = checkFQBN.String()
81+
checkOutput, err := getDebugProperties(configRequest, pme, true)
82+
if err == nil && reflect.DeepEqual(expectedOutput, checkOutput) {
83+
minimumFQBN.Configs.Remove(config)
84+
}
85+
}
86+
return &rpc.IsDebugSupportedResponse{
87+
DebuggingSupported: true,
88+
DebugFqbn: minimumFQBN.String(),
89+
}, nil
7290
}
7391

7492
func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Explorer, skipSketchChecks bool) (*rpc.GetDebugConfigResponse, error) {

Diff for: internal/cli/feedback/result/rpc.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1059,11 +1059,13 @@ func NewCompileDiagnosticNote(cdn *rpc.CompileDiagnosticNote) *CompileDiagnostic
10591059
}
10601060

10611061
type IsDebugSupportedResponse struct {
1062-
DebuggingSupported bool `json:"debugging_supported"`
1062+
DebuggingSupported bool `json:"debugging_supported"`
1063+
DebugFQBN string `json:"debug_fqbn,omitempty"`
10631064
}
10641065

10651066
func NewIsDebugSupportedResponse(resp *rpc.IsDebugSupportedResponse) *IsDebugSupportedResponse {
10661067
return &IsDebugSupportedResponse{
10671068
DebuggingSupported: resp.GetDebuggingSupported(),
1069+
DebugFQBN: resp.GetDebugFqbn(),
10681070
}
10691071
}

Diff for: internal/integrationtest/debug/debug_test.go

+27-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ func TestDebug(t *testing.T) {
3838
_, _, err = cli.Run("core", "install", "arduino:samd")
3939
require.NoError(t, err)
4040

41+
// Install custom core
42+
customHw, err := paths.New("testdata", "hardware").Abs()
43+
require.NoError(t, err)
44+
err = customHw.CopyDirTo(cli.SketchbookDir().Join("hardware"))
45+
require.NoError(t, err)
46+
4147
integrationtest.CLISubtests{
4248
{"Start", testDebuggerStarts},
4349
{"WithPdeSketchStarts", testDebuggerWithPdeSketchStarts},
@@ -102,12 +108,6 @@ func testAllDebugInformation(t *testing.T, env *integrationtest.Environment, cli
102108
_, _, err := cli.Run("sketch", "new", sketchPath.String())
103109
require.NoError(t, err)
104110

105-
// Install custom core
106-
customHw, err := paths.New("testdata", "hardware").Abs()
107-
require.NoError(t, err)
108-
err = customHw.CopyDirTo(cli.SketchbookDir().Join("hardware"))
109-
require.NoError(t, err)
110-
111111
// Build sketch
112112
_, _, err = cli.Run("compile", "-b", "my:samd:my", sketchPath.String(), "--format", "json")
113113
require.NoError(t, err)
@@ -354,4 +354,25 @@ func testDebugCheck(t *testing.T, env *integrationtest.Environment, cli *integra
354354
out, _, err = cli.Run("debug", "check", "-b", "arduino:avr:uno", "-P", "atmel_ice", "--format", "json")
355355
require.NoError(t, err)
356356
requirejson.Query(t, out, `.debugging_supported`, `false`)
357+
358+
// Test minimum FQBN compute
359+
out, _, err = cli.Run("debug", "check", "-b", "my:samd:my5", "-P", "atmel_ice", "--format", "json")
360+
require.NoError(t, err)
361+
requirejson.Contains(t, out, `{ "debugging_supported" : false }`)
362+
363+
out, _, err = cli.Run("debug", "check", "-b", "my:samd:my5:dbg=on", "-P", "atmel_ice", "--format", "json")
364+
require.NoError(t, err)
365+
requirejson.Contains(t, out, `{ "debugging_supported" : true, "debug_fqbn" : "my:samd:my5:dbg=on" }`)
366+
367+
out, _, err = cli.Run("debug", "check", "-b", "my:samd:my5:dbg=on,cpu=150m", "-P", "atmel_ice", "--format", "json")
368+
require.NoError(t, err)
369+
requirejson.Contains(t, out, `{ "debugging_supported" : true, "debug_fqbn" : "my:samd:my5:dbg=on" }`)
370+
371+
out, _, err = cli.Run("debug", "check", "-b", "my:samd:my6", "-P", "atmel_ice", "--format", "json")
372+
require.NoError(t, err)
373+
requirejson.Contains(t, out, `{ "debugging_supported" : true, "debug_fqbn" : "my:samd:my6" }`)
374+
375+
out, _, err = cli.Run("debug", "check", "-b", "my:samd:my6:dbg=on", "-P", "atmel_ice", "--format", "json")
376+
require.NoError(t, err)
377+
requirejson.Contains(t, out, `{ "debugging_supported" : true, "debug_fqbn" : "my:samd:my6" }`)
357378
}

Diff for: internal/integrationtest/debug/testdata/hardware/my/samd/boards.txt

+36
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,39 @@ my4.build.mcu=test2
112112
# this one will be overwritten by additional_config
113113
my4.debug.svd_file=svd-file
114114
my4.debug.additional_config=build.debug.config.{build.mcu}
115+
116+
# menu options for the following boards
117+
menu.dbg=Debugger
118+
menu.cpu=CPU Speed
119+
120+
# This does not support debug by default but only after selecting a menu option
121+
my5.name=5th Board
122+
my5.build.core=arduino:arduino
123+
my5.build.variant=arduino:mkr1000
124+
my5.debug.toolchain.path=gcc-path
125+
my5.debug.toolchain.prefix=gcc-prefix
126+
my5.debug.server.openocd.path=openocd-path
127+
my5.debug.server.openocd.scripts_dir=openocd-scripts-dir
128+
my5.debug.server.openocd.script=single-script
129+
my5.debug.executable=
130+
my5.menu.dbg.off=Debug Disabled
131+
my5.menu.dbg.on=Debug Enabled
132+
my5.menu.dbg.on.debug.executable=YES
133+
my5.menu.cpu.100m=100Mhz
134+
my5.menu.cpu.150m=150Mhz
135+
136+
# this one has debugger enabled by default
137+
my6.name=5th Board
138+
my6.build.core=arduino:arduino
139+
my6.build.variant=arduino:mkr1000
140+
my6.debug.toolchain.path=gcc-path
141+
my6.debug.toolchain.prefix=gcc-prefix
142+
my6.debug.server.openocd.path=openocd-path
143+
my6.debug.server.openocd.scripts_dir=openocd-scripts-dir
144+
my6.debug.server.openocd.script=single-script
145+
my6.debug.executable=
146+
my6.menu.dbg.on=Debug Enabled
147+
my6.menu.dbg.on.debug.executable=YES
148+
my6.menu.dbg.off=Debug Disabled
149+
my6.menu.cpu.100m=100Mhz
150+
my6.menu.cpu.150m=150Mhz

0 commit comments

Comments
 (0)