Skip to content

Commit 324c30f

Browse files
committed
Added custom debug properties to Debug/IsDebugSupported commands (gRPC and CLI)
1 parent 76ff3d6 commit 324c30f

File tree

5 files changed

+162
-114
lines changed

5 files changed

+162
-114
lines changed

commands/service_debug_config.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"encoding/json"
2121
"errors"
22+
"fmt"
2223
"reflect"
2324
"slices"
2425
"strconv"
@@ -55,13 +56,14 @@ func (s *arduinoCoreServerImpl) IsDebugSupported(ctx context.Context, req *rpc.I
5556
}
5657
defer release()
5758
configRequest := &rpc.GetDebugConfigRequest{
58-
Instance: req.GetInstance(),
59-
Fqbn: req.GetFqbn(),
60-
SketchPath: "",
61-
Port: req.GetPort(),
62-
Interpreter: req.GetInterpreter(),
63-
ImportDir: "",
64-
Programmer: req.GetProgrammer(),
59+
Instance: req.GetInstance(),
60+
Fqbn: req.GetFqbn(),
61+
SketchPath: "",
62+
Port: req.GetPort(),
63+
Interpreter: req.GetInterpreter(),
64+
ImportDir: "",
65+
Programmer: req.GetProgrammer(),
66+
DebugProperties: req.GetDebugProperties(),
6567
}
6668
expectedOutput, err := getDebugProperties(configRequest, pme, true)
6769
var x *cmderrors.FailedDebugError
@@ -202,6 +204,13 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl
202204
}
203205
}
204206

207+
// Add user provided custom debug properties
208+
if p, err := properties.LoadFromSlice(req.GetDebugProperties()); err == nil {
209+
debugProperties.Merge(p)
210+
} else {
211+
return nil, fmt.Errorf("invalid build properties: %w", err)
212+
}
213+
205214
if !debugProperties.ContainsKey("executable") || debugProperties.Get("executable") == "" {
206215
return nil, &cmderrors.FailedDebugError{Message: i18n.Tr("Debugging not supported for board %s", req.GetFqbn())}
207216
}

internal/cli/debug/debug.go

+21-16
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ import (
3838
// NewCommand created a new `upload` command
3939
func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
4040
var (
41-
fqbnArg arguments.Fqbn
42-
portArgs arguments.Port
43-
profileArg arguments.Profile
44-
interpreter string
45-
importDir string
46-
printInfo bool
47-
programmer arguments.Programmer
41+
fqbnArg arguments.Fqbn
42+
portArgs arguments.Port
43+
profileArg arguments.Profile
44+
interpreter string
45+
importDir string
46+
printInfo bool
47+
programmer arguments.Programmer
48+
debugProperties []string
4849
)
4950

5051
debugCommand := &cobra.Command{
@@ -54,7 +55,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
5455
Example: " " + os.Args[0] + " debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch",
5556
Args: cobra.MaximumNArgs(1),
5657
Run: func(cmd *cobra.Command, args []string) {
57-
runDebugCommand(cmd.Context(), srv, args, &portArgs, &fqbnArg, interpreter, importDir, &programmer, printInfo, &profileArg)
58+
runDebugCommand(cmd.Context(), srv, args, &portArgs, &fqbnArg, interpreter, importDir, &programmer, printInfo, &profileArg, debugProperties)
5859
},
5960
}
6061

@@ -66,12 +67,15 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
6667
debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", i18n.Tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3"))
6768
debugCommand.Flags().StringVarP(&importDir, "input-dir", "", "", i18n.Tr("Directory containing binaries for debug."))
6869
debugCommand.Flags().BoolVarP(&printInfo, "info", "I", false, i18n.Tr("Show metadata about the debug session instead of starting the debugger."))
70+
debugCommand.Flags().StringArrayVar(&debugProperties, "debug-property", []string{},
71+
i18n.Tr("Override an debug property with a custom value. Can be used multiple times for multiple properties."))
6972

7073
return debugCommand
7174
}
7275

7376
func runDebugCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args []string, portArgs *arguments.Port, fqbnArg *arguments.Fqbn,
74-
interpreter string, importDir string, programmer *arguments.Programmer, printInfo bool, profileArg *arguments.Profile) {
77+
interpreter string, importDir string, programmer *arguments.Programmer, printInfo bool, profileArg *arguments.Profile,
78+
debugProperties []string) {
7579
logrus.Info("Executing `arduino-cli debug`")
7680

7781
path := ""
@@ -111,13 +115,14 @@ func runDebugCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args
111115
}
112116

113117
debugConfigRequested := &rpc.GetDebugConfigRequest{
114-
Instance: inst,
115-
Fqbn: fqbn,
116-
SketchPath: sketchPath.String(),
117-
Port: port,
118-
Interpreter: interpreter,
119-
ImportDir: importDir,
120-
Programmer: prog,
118+
Instance: inst,
119+
Fqbn: fqbn,
120+
SketchPath: sketchPath.String(),
121+
Port: port,
122+
Interpreter: interpreter,
123+
ImportDir: importDir,
124+
Programmer: prog,
125+
DebugProperties: debugProperties,
121126
}
122127

123128
if printInfo {

internal/cli/debug/debug_check.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,32 @@ import (
3131

3232
func newDebugCheckCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
3333
var (
34-
fqbnArg arguments.Fqbn
35-
portArgs arguments.Port
36-
interpreter string
37-
programmer arguments.Programmer
34+
fqbnArg arguments.Fqbn
35+
portArgs arguments.Port
36+
interpreter string
37+
programmer arguments.Programmer
38+
debugProperties []string
3839
)
3940
debugCheckCommand := &cobra.Command{
4041
Use: "check",
4142
Short: i18n.Tr("Check if the given board/programmer combination supports debugging."),
4243
Example: " " + os.Args[0] + " debug check -b arduino:samd:mkr1000 -P atmel_ice",
4344
Run: func(cmd *cobra.Command, args []string) {
44-
runDebugCheckCommand(cmd.Context(), srv, &portArgs, &fqbnArg, interpreter, &programmer)
45+
runDebugCheckCommand(cmd.Context(), srv, &portArgs, &fqbnArg, interpreter, &programmer, debugProperties)
4546
},
4647
}
4748
fqbnArg.AddToCommand(debugCheckCommand, srv)
4849
portArgs.AddToCommand(debugCheckCommand, srv)
4950
programmer.AddToCommand(debugCheckCommand, srv)
5051
debugCheckCommand.Flags().StringVar(&interpreter, "interpreter", "console", i18n.Tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3"))
52+
debugCheckCommand.Flags().StringArrayVar(&debugProperties, "debug-property", []string{},
53+
i18n.Tr("Override an debug property with a custom value. Can be used multiple times for multiple properties."))
5154
return debugCheckCommand
5255
}
5356

54-
func runDebugCheckCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, portArgs *arguments.Port, fqbnArg *arguments.Fqbn, interpreter string, programmerArg *arguments.Programmer) {
57+
func runDebugCheckCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, portArgs *arguments.Port,
58+
fqbnArg *arguments.Fqbn, interpreter string, programmerArg *arguments.Programmer, debugProperties []string,
59+
) {
5560
instance := instance.CreateAndInit(ctx, srv)
5661
logrus.Info("Executing `arduino-cli debug`")
5762

@@ -61,11 +66,12 @@ func runDebugCheckCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer,
6166
}
6267
fqbn := fqbnArg.String()
6368
resp, err := srv.IsDebugSupported(ctx, &rpc.IsDebugSupportedRequest{
64-
Instance: instance,
65-
Fqbn: fqbn,
66-
Port: port,
67-
Interpreter: interpreter,
68-
Programmer: programmerArg.String(ctx, instance, srv, fqbn),
69+
Instance: instance,
70+
Fqbn: fqbn,
71+
Port: port,
72+
Interpreter: interpreter,
73+
Programmer: programmerArg.String(ctx, instance, srv, fqbn),
74+
DebugProperties: debugProperties,
6975
})
7076
if err != nil {
7177
feedback.FatalError(err, feedback.ErrGeneric)

0 commit comments

Comments
 (0)