Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ae120e9

Browse filesBrowse files
committed
Added the possibility to provide cortex-debug custom configs
1 parent 25a071c commit ae120e9
Copy full SHA for ae120e9

File tree

6 files changed

+130
-32
lines changed
Filter options

6 files changed

+130
-32
lines changed

‎commands/debug/debug_info.go

Copy file name to clipboardExpand all lines: commands/debug/debug_info.go
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package debug
1717

1818
import (
1919
"context"
20+
"encoding/json"
21+
"regexp"
2022
"strings"
2123

2224
"github.com/arduino/arduino-cli/arduino"
@@ -180,6 +182,10 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl
180182
}
181183
}
182184

185+
cortexDebugCustomJson := ""
186+
if cortexDebugProps := debugProperties.SubTree("cortex-debug.custom"); cortexDebugProps.Size() > 0 {
187+
cortexDebugCustomJson = convertToJsonMap(cortexDebugProps)
188+
}
183189
return &rpc.GetDebugConfigResponse{
184190
Executable: debugProperties.Get("executable"),
185191
Server: server,
@@ -189,5 +195,45 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl
189195
ToolchainPath: debugProperties.Get("toolchain.path"),
190196
ToolchainPrefix: debugProperties.Get("toolchain.prefix"),
191197
ToolchainConfiguration: &toolchainConfiguration,
198+
CortexDebugCustomJson: cortexDebugCustomJson,
192199
}, nil
193200
}
201+
202+
// Extract a JSON from a given properies.Map and converts key-indexed arrays
203+
// like:
204+
//
205+
// my.indexed.array.0=first
206+
// my.indexed.array.1=second
207+
// my.indexed.array.2=third
208+
//
209+
// into the corresponding JSON arrays.
210+
func convertToJsonMap(in *properties.Map) string {
211+
// XXX: Maybe this method could be a good candidate for propertis.Map?
212+
213+
// Find the values that should be kept as is, and the indexed arrays
214+
// that should be later converted into arrays.
215+
arraysKeys := map[string]bool{}
216+
stringKeys := []string{}
217+
trailingNumberMatcher := regexp.MustCompile(`^(.*)\.[0-9]+$`)
218+
for _, k := range in.Keys() {
219+
match := trailingNumberMatcher.FindAllStringSubmatch(k, -1)
220+
if len(match) > 0 && len(match[0]) > 1 {
221+
arraysKeys[match[0][1]] = true
222+
} else {
223+
stringKeys = append(stringKeys, k)
224+
}
225+
}
226+
227+
// Compose a map that can be later marshaled into JSON keeping
228+
// the arrays where they are expected to be.
229+
res := map[string]any{}
230+
for _, k := range stringKeys {
231+
res[k] = in.Get(k)
232+
}
233+
for k := range arraysKeys {
234+
res[k] = in.ExtractSubIndexLists(k)
235+
}
236+
237+
data, _ := json.MarshalIndent(res, "", " ")
238+
return string(data)
239+
}

‎internal/cli/debug/debug.go

Copy file name to clipboardExpand all lines: internal/cli/debug/debug.go
+25-16Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package debug
1717

1818
import (
1919
"context"
20+
"encoding/json"
2021
"os"
2122
"os/signal"
2223

@@ -115,14 +116,15 @@ func runDebugCommand(command *cobra.Command, args []string) {
115116
}
116117

117118
type debugInfoResult struct {
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"`
119+
Executable string `json:"executable,omitempty"`
120+
Toolchain string `json:"toolchain,omitempty"`
121+
ToolchainPath string `json:"toolchain_path,omitempty"`
122+
ToolchainPrefix string `json:"toolchain_prefix,omitempty"`
123+
ToolchainConfig any `json:"toolchain_configuration,omitempty"`
124+
Server string `json:"server,omitempty"`
125+
ServerPath string `json:"server_path,omitempty"`
126+
ServerConfig any `json:"server_configuration,omitempty"`
127+
CortexDebugCustomConfig any `json:"cortex-debug_custom_configuration,omitempty"`
126128
}
127129

128130
type openOcdServerConfigResult struct {
@@ -146,15 +148,22 @@ func newDebugInfoResult(info *rpc.GetDebugConfigResponse) *debugInfoResult {
146148
Scripts: openocdConf.Scripts,
147149
}
148150
}
151+
var cortexDebugCustomConfig any
152+
if info.CortexDebugCustomJson != "" {
153+
if err := json.Unmarshal([]byte(info.CortexDebugCustomJson), &cortexDebugCustomConfig); err != nil {
154+
feedback.Fatal(tr("Error during Debug: %v", err), feedback.ErrGeneric)
155+
}
156+
}
149157
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+
Executable: info.Executable,
159+
Toolchain: info.Toolchain,
160+
ToolchainPath: info.ToolchainPath,
161+
ToolchainPrefix: info.ToolchainPrefix,
162+
ToolchainConfig: toolchaingConfig,
163+
Server: info.Server,
164+
ServerPath: info.ServerPath,
165+
ServerConfig: serverConfig,
166+
CortexDebugCustomConfig: cortexDebugCustomConfig,
158167
}
159168
}
160169

‎internal/integrationtest/debug/debug_test.go

Copy file name to clipboardExpand all lines: internal/integrationtest/debug/debug_test.go
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ func testAllDebugInformation(t *testing.T, env *integrationtest.Environment, cli
129129
"second",
130130
"third"
131131
]
132+
},
133+
"cortex-debug_custom_configuration": {
134+
"anotherStringParamer": "hellooo",
135+
"overrideRestartCommands": [
136+
"monitor reset halt",
137+
"monitor gdb_sync",
138+
"thb setup",
139+
"c"
140+
],
141+
"postAttachCommands": [
142+
"set remote hardware-watchpoint-limit 2",
143+
"monitor reset halt",
144+
"monitor gdb_sync",
145+
"thb setup",
146+
"c"
147+
]
132148
}
133149
}`)
134150
}

‎internal/integrationtest/debug/testdata/hardware/my/samd/boards.txt

Copy file name to clipboardExpand all lines: internal/integrationtest/debug/testdata/hardware/my/samd/boards.txt
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,13 @@ my.debug.server.openocd.script=
3333
my.debug.server.openocd.scripts.0=first
3434
my.debug.server.openocd.scripts.1=second
3535
my.debug.server.openocd.scripts.2=third
36+
my.debug.cortex-debug.custom.postAttachCommands.0=set remote hardware-watchpoint-limit 2
37+
my.debug.cortex-debug.custom.postAttachCommands.1=monitor reset halt
38+
my.debug.cortex-debug.custom.postAttachCommands.2=monitor gdb_sync
39+
my.debug.cortex-debug.custom.postAttachCommands.3=thb setup
40+
my.debug.cortex-debug.custom.postAttachCommands.4=c
41+
my.debug.cortex-debug.custom.overrideRestartCommands.0=monitor reset halt
42+
my.debug.cortex-debug.custom.overrideRestartCommands.1=monitor gdb_sync
43+
my.debug.cortex-debug.custom.overrideRestartCommands.2=thb setup
44+
my.debug.cortex-debug.custom.overrideRestartCommands.3=c
45+
my.debug.cortex-debug.custom.anotherStringParamer=hellooo

‎rpc/cc/arduino/cli/commands/v1/debug.pb.go

Copy file name to clipboardExpand all lines: rpc/cc/arduino/cli/commands/v1/debug.pb.go
+30-16Lines changed: 30 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rpc/cc/arduino/cli/commands/v1/debug.proto

Copy file name to clipboardExpand all lines: rpc/cc/arduino/cli/commands/v1/debug.proto
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ message GetDebugConfigResponse {
9191
google.protobuf.Any toolchain_configuration = 7;
9292
// Extra configuration parameters wrt GDB server
9393
google.protobuf.Any server_configuration = 8;
94+
// cortex-debug custom JSON configuration, it is provided as is from
95+
// the platform developers.
96+
string cortex_debug_custom_json = 9;
9497
}
9598

9699
// Configurations specific for the 'gcc' toolchain

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.