Skip to content

Commit 4c6e007

Browse files
committed
Improved specification of debug configuration
1 parent f561da0 commit 4c6e007

File tree

6 files changed

+375
-121
lines changed

6 files changed

+375
-121
lines changed

commands/debug/debug.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,18 @@ func getCommandLine(req *rpc.GetDebugConfigRequest, pme *packagemanager.Explorer
158158
// Extract path to GDB Server
159159
switch debugInfo.GetServer() {
160160
case "openocd":
161+
var openocdConf rpc.DebugOpenOCDServerConfiguration
162+
if err := debugInfo.ServerConfiguration.UnmarshalTo(&openocdConf); err != nil {
163+
return nil, err
164+
}
165+
161166
serverCmd := fmt.Sprintf(`target extended-remote | "%s"`, debugInfo.ServerPath)
162167

163-
if cfg := debugInfo.ServerConfiguration["scripts_dir"]; cfg != "" {
168+
if cfg := openocdConf.GetScriptsDir(); cfg != "" {
164169
serverCmd += fmt.Sprintf(` -s "%s"`, cfg)
165170
}
166171

167-
if script := debugInfo.ServerConfiguration["script"]; script != "" {
172+
for _, script := range openocdConf.GetScripts() {
168173
serverCmd += fmt.Sprintf(` --file "%s"`, script)
169174
}
170175

commands/debug/debug_info.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/arduino/go-paths-helper"
2929
"github.com/arduino/go-properties-orderedmap"
3030
"github.com/sirupsen/logrus"
31+
"google.golang.org/protobuf/types/known/anypb"
3132
)
3233

3334
// GetDebugConfig returns metadata to start debugging with the specified board
@@ -150,14 +151,43 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl
150151

151152
server := debugProperties.Get("server")
152153
toolchain := debugProperties.Get("toolchain")
154+
155+
var serverConfiguration anypb.Any
156+
switch server {
157+
case "openocd":
158+
openocdProperties := debugProperties.SubTree("server." + server)
159+
scripts := openocdProperties.ExtractSubIndexLists("scripts")
160+
if s := openocdProperties.Get("script"); s != "" {
161+
// backward compatibility
162+
scripts = append(scripts, s)
163+
}
164+
openocdConf := &rpc.DebugOpenOCDServerConfiguration{
165+
Path: openocdProperties.Get("path"),
166+
ScriptsDir: openocdProperties.Get("scripts_dir"),
167+
Scripts: scripts,
168+
}
169+
if err := serverConfiguration.MarshalFrom(openocdConf); err != nil {
170+
return nil, err
171+
}
172+
}
173+
174+
var toolchainConfiguration anypb.Any
175+
switch toolchain {
176+
case "gcc":
177+
gccConf := &rpc.DebugGCCToolchainConfiguration{}
178+
if err := toolchainConfiguration.MarshalFrom(gccConf); err != nil {
179+
return nil, err
180+
}
181+
}
182+
153183
return &rpc.GetDebugConfigResponse{
154184
Executable: debugProperties.Get("executable"),
155185
Server: server,
156186
ServerPath: debugProperties.Get("server." + server + ".path"),
157-
ServerConfiguration: debugProperties.SubTree("server." + server).AsMap(),
187+
ServerConfiguration: &serverConfiguration,
158188
Toolchain: toolchain,
159189
ToolchainPath: debugProperties.Get("toolchain.path"),
160190
ToolchainPrefix: debugProperties.Get("toolchain.prefix"),
161-
ToolchainConfiguration: debugProperties.SubTree("toolchain." + toolchain).AsMap(),
191+
ToolchainConfiguration: &toolchainConfiguration,
162192
}, nil
163193
}

docs/UPGRADING.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,43 @@ Here you can find a list of migration guides to handle breaking changes between
44

55
## 0.35.0
66

7+
### CLI `debug --info` changed JSON output.
8+
9+
The string field `server_configuration.script` is now an array and has been renamed `scripts`, here an example:
10+
11+
```json
12+
{
13+
"executable": "/tmp/arduino/sketches/002050EAA7EFB9A4FC451CDFBC0FA2D3/Blink.ino.elf",
14+
"toolchain": "gcc",
15+
"toolchain_path": "/home/user/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/",
16+
"toolchain_prefix": "arm-none-eabi-",
17+
"server": "openocd",
18+
"server_path": "/home/user/.arduino15/packages/arduino/tools/openocd/0.10.0-arduino7/bin/openocd",
19+
"server_configuration": {
20+
"path": "/home/user/.arduino15/packages/arduino/tools/openocd/0.10.0-arduino7/bin/openocd",
21+
"scripts_dir": "/home/user/.arduino15/packages/arduino/tools/openocd/0.10.0-arduino7/share/openocd/scripts/",
22+
"scripts": [
23+
"/home/user/Workspace/arduino-cli/internal/integrationtest/debug/testdata/hardware/my/samd/variants/arduino:mkr1000/openocd_scripts/arduino_zero.cfg"
24+
]
25+
}
26+
}
27+
```
28+
29+
### gRPC `cc.arduino.cli.commands.v1.GetDebugConfigResponse` message has been changed.
30+
31+
The fields `toolchain_configuration` and `server_configuration` are no more generic `map<string, string>` but they have
32+
changed type to `goog.protobuf.Any`, the concrete type is assigned at runtime based on the value of `toolchain` and
33+
`server` fields respectively.
34+
35+
For the moment:
36+
37+
- only `gcc` is supported for `toolchain`, and the concrete type for `toolchain_configuration` is
38+
`DebugGCCToolchainConfiguration`.
39+
- only `openocd` is supported for `server`, and the concrete type for `server_configuration` is
40+
`DebugOpenOCDServerConfiguration`
41+
42+
More concrete type may be added in the future as more servers/toolchains support is implemented.
43+
744
### gRPC service `cc.arduino.cli.debug.v1` moved to `cc.arduino.cli.commands.v1`.
845

946
The gRPC service `cc.arduino.cli.debug.v1` has been removed and all gRPC messages and rpc calls have been moved to

internal/cli/debug/debug.go

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"context"
2020
"os"
2121
"os/signal"
22-
"sort"
2322

2423
"github.com/arduino/arduino-cli/commands/debug"
2524
"github.com/arduino/arduino-cli/commands/sketch"
@@ -29,7 +28,6 @@ import (
2928
"github.com/arduino/arduino-cli/internal/cli/instance"
3029
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3130
"github.com/arduino/arduino-cli/table"
32-
"github.com/arduino/go-properties-orderedmap"
3331
"github.com/fatih/color"
3432
"github.com/sirupsen/logrus"
3533
"github.com/spf13/cobra"
@@ -96,7 +94,7 @@ func runDebugCommand(command *cobra.Command, args []string) {
9694
if res, err := debug.GetDebugConfig(context.Background(), debugConfigRequested); err != nil {
9795
feedback.Fatal(tr("Error getting Debug info: %v", err), feedback.ErrBadArgument)
9896
} else {
99-
feedback.PrintResult(&debugInfoResult{res})
97+
feedback.PrintResult(newDebugInfoResult(res))
10098
}
10199

102100
} else {
@@ -117,40 +115,83 @@ func runDebugCommand(command *cobra.Command, args []string) {
117115
}
118116

119117
type debugInfoResult struct {
120-
info *rpc.GetDebugConfigResponse
118+
Executable string `json:"executable,omitempty"`
119+
Toolchain string `json:"toolchain,omitempty"`
120+
ToolchainPath string `json:"toolchain_path,omitempty"`
121+
ToolchainPrefix string `json:"toolchain_prefix,omitempty"`
122+
ToolchainConfig any `json:"toolchain_configuration,omitempty"`
123+
Server string `json:"server,omitempty"`
124+
ServerPath string `json:"server_path,omitempty"`
125+
ServerConfig any `json:"server_configuration,omitempty"`
126+
}
127+
128+
type openOcdServerConfigResult struct {
129+
Path string `json:"path,omitempty"`
130+
ScriptsDir string `json:"scripts_dir,omitempty"`
131+
Scripts []string `json:"scripts,omitempty"`
132+
}
133+
134+
func newDebugInfoResult(info *rpc.GetDebugConfigResponse) *debugInfoResult {
135+
var toolchaingConfig interface{}
136+
var serverConfig interface{}
137+
switch info.Server {
138+
case "openocd":
139+
var openocdConf rpc.DebugOpenOCDServerConfiguration
140+
if err := info.GetServerConfiguration().UnmarshalTo(&openocdConf); err != nil {
141+
feedback.Fatal(tr("Error during Debug: %v", err), feedback.ErrGeneric)
142+
}
143+
serverConfig = &openOcdServerConfigResult{
144+
Path: openocdConf.Path,
145+
ScriptsDir: openocdConf.ScriptsDir,
146+
Scripts: openocdConf.Scripts,
147+
}
148+
}
149+
return &debugInfoResult{
150+
Executable: info.Executable,
151+
Toolchain: info.Toolchain,
152+
ToolchainPath: info.ToolchainPath,
153+
ToolchainPrefix: info.ToolchainPrefix,
154+
ToolchainConfig: toolchaingConfig,
155+
Server: info.Server,
156+
ServerPath: info.ServerPath,
157+
ServerConfig: serverConfig,
158+
}
121159
}
122160

123161
func (r *debugInfoResult) Data() interface{} {
124-
return r.info
162+
return r
125163
}
126164

127165
func (r *debugInfoResult) String() string {
128166
t := table.New()
129167
green := color.New(color.FgHiGreen)
130168
dimGreen := color.New(color.FgGreen)
131-
t.AddRow(tr("Executable to debug"), table.NewCell(r.info.GetExecutable(), green))
132-
t.AddRow(tr("Toolchain type"), table.NewCell(r.info.GetToolchain(), green))
133-
t.AddRow(tr("Toolchain path"), table.NewCell(r.info.GetToolchainPath(), dimGreen))
134-
t.AddRow(tr("Toolchain prefix"), table.NewCell(r.info.GetToolchainPrefix(), dimGreen))
135-
if len(r.info.GetToolchainConfiguration()) > 0 {
136-
conf := properties.NewFromHashmap(r.info.GetToolchainConfiguration())
137-
keys := conf.Keys()
138-
sort.Strings(keys)
139-
t.AddRow(tr("Toolchain custom configurations"))
140-
for _, k := range keys {
141-
t.AddRow(table.NewCell(" - "+k, dimGreen), table.NewCell(conf.Get(k), dimGreen))
142-
}
169+
t.AddRow(tr("Executable to debug"), table.NewCell(r.Executable, green))
170+
t.AddRow(tr("Toolchain type"), table.NewCell(r.Toolchain, green))
171+
t.AddRow(tr("Toolchain path"), table.NewCell(r.ToolchainPath, dimGreen))
172+
t.AddRow(tr("Toolchain prefix"), table.NewCell(r.ToolchainPrefix, dimGreen))
173+
switch r.Toolchain {
174+
case "gcc":
175+
// no options available at the moment...
176+
default:
143177
}
144-
t.AddRow(tr("GDB Server type"), table.NewCell(r.info.GetServer(), green))
145-
t.AddRow(tr("GDB Server path"), table.NewCell(r.info.GetServerPath(), dimGreen))
146-
if len(r.info.GetServerConfiguration()) > 0 {
147-
conf := properties.NewFromHashmap(r.info.GetServerConfiguration())
148-
keys := conf.Keys()
149-
sort.Strings(keys)
150-
t.AddRow(tr("Configuration options for %s", r.info.GetServer()))
151-
for _, k := range keys {
152-
t.AddRow(table.NewCell(" - "+k, dimGreen), table.NewCell(conf.Get(k), dimGreen))
178+
t.AddRow(tr("Server type"), table.NewCell(r.Server, green))
179+
t.AddRow(tr("Server path"), table.NewCell(r.ServerPath, dimGreen))
180+
181+
switch r.Server {
182+
case "openocd":
183+
t.AddRow(tr("Configuration options for %s", r.Server))
184+
openocdConf := r.ServerConfig.(*openOcdServerConfigResult)
185+
if openocdConf.Path != "" {
186+
t.AddRow(" - Path", table.NewCell(openocdConf.Path, dimGreen))
187+
}
188+
if openocdConf.ScriptsDir != "" {
189+
t.AddRow(" - Scripts Directory", table.NewCell(openocdConf.ScriptsDir, dimGreen))
190+
}
191+
for _, script := range openocdConf.Scripts {
192+
t.AddRow(" - Script", table.NewCell(script, dimGreen))
153193
}
194+
default:
154195
}
155196
return t.Render()
156197
}

0 commit comments

Comments
 (0)