Skip to content

Commit d187683

Browse files
authored
debug: Slighlty refactored custom_configs section of GetDebugConfigResponse (#2396)
1 parent 64f1853 commit d187683

File tree

5 files changed

+163
-143
lines changed

5 files changed

+163
-143
lines changed

Diff for: commands/debug/debug_info.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,22 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl
184184
}
185185
}
186186

187-
cortexDebugCustomJson := ""
187+
cortexDebugCustomJson := map[string]string{}
188188
if cortexDebugProps := debugProperties.SubTree("cortex-debug.custom"); cortexDebugProps.Size() > 0 {
189-
cortexDebugCustomJson = convertToJsonMap(cortexDebugProps)
189+
cortexDebugCustomJson["cortex-debug"] = convertToJsonMap(cortexDebugProps)
190190
}
191191
return &rpc.GetDebugConfigResponse{
192-
Executable: debugProperties.Get("executable"),
193-
Server: server,
194-
ServerPath: debugProperties.Get("server." + server + ".path"),
195-
ServerConfiguration: &serverConfiguration,
196-
SvdFile: debugProperties.Get("svd_file"),
197-
Toolchain: toolchain,
198-
ToolchainPath: debugProperties.Get("toolchain.path"),
199-
ToolchainPrefix: debugProperties.Get("toolchain.prefix"),
200-
ToolchainConfiguration: &toolchainConfiguration,
201-
CortexDebugCustomJson: cortexDebugCustomJson,
202-
Programmer: req.GetProgrammer(),
192+
Executable: debugProperties.Get("executable"),
193+
Server: server,
194+
ServerPath: debugProperties.Get("server." + server + ".path"),
195+
ServerConfiguration: &serverConfiguration,
196+
SvdFile: debugProperties.Get("svd_file"),
197+
Toolchain: toolchain,
198+
ToolchainPath: debugProperties.Get("toolchain.path"),
199+
ToolchainPrefix: debugProperties.Get("toolchain.prefix"),
200+
ToolchainConfiguration: &toolchainConfiguration,
201+
CustomConfigurationsJson: cortexDebugCustomJson,
202+
Programmer: req.GetProgrammer(),
203203
}, nil
204204
}
205205

Diff for: internal/cli/debug/debug.go

+33-30
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ func runDebugCommand(command *cobra.Command, args []string) {
116116
}
117117

118118
type debugInfoResult struct {
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-
SvdFile string `json:"svd_file,omitempty"`
128-
CortexDebugCustomConfig any `json:"cortex-debug_custom_configuration,omitempty"`
129-
Programmer string `json:"programmer"`
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+
SvdFile string `json:"svd_file,omitempty"`
128+
CustomConfigs map[string]any `json:"custom_configs,omitempty"`
129+
Programmer string `json:"programmer"`
130130
}
131131

132132
type openOcdServerConfigResult struct {
@@ -150,24 +150,25 @@ func newDebugInfoResult(info *rpc.GetDebugConfigResponse) *debugInfoResult {
150150
Scripts: openocdConf.Scripts,
151151
}
152152
}
153-
var cortexDebugCustomConfig any
154-
if info.CortexDebugCustomJson != "" {
155-
if err := json.Unmarshal([]byte(info.CortexDebugCustomJson), &cortexDebugCustomConfig); err != nil {
156-
feedback.Fatal(tr("Error during Debug: %v", err), feedback.ErrGeneric)
153+
customConfigs := map[string]any{}
154+
for id, configJson := range info.GetCustomConfigurationsJson() {
155+
var config any
156+
if err := json.Unmarshal([]byte(configJson), &config); err == nil {
157+
customConfigs[id] = config
157158
}
158159
}
159160
return &debugInfoResult{
160-
Executable: info.Executable,
161-
Toolchain: info.Toolchain,
162-
ToolchainPath: info.ToolchainPath,
163-
ToolchainPrefix: info.ToolchainPrefix,
164-
ToolchainConfig: toolchainConfig,
165-
Server: info.Server,
166-
ServerPath: info.ServerPath,
167-
ServerConfig: serverConfig,
168-
SvdFile: info.SvdFile,
169-
CortexDebugCustomConfig: cortexDebugCustomConfig,
170-
Programmer: info.Programmer,
161+
Executable: info.Executable,
162+
Toolchain: info.Toolchain,
163+
ToolchainPath: info.ToolchainPath,
164+
ToolchainPrefix: info.ToolchainPrefix,
165+
ToolchainConfig: toolchainConfig,
166+
Server: info.Server,
167+
ServerPath: info.ServerPath,
168+
ServerConfig: serverConfig,
169+
SvdFile: info.SvdFile,
170+
CustomConfigs: customConfigs,
171+
Programmer: info.Programmer,
171172
}
172173
}
173174

@@ -209,10 +210,12 @@ func (r *debugInfoResult) String() string {
209210
}
210211
default:
211212
}
212-
if r.CortexDebugCustomConfig != nil {
213-
t.AddRow(tr("Custom configuration for cortex-debug IDE plugin:"))
214-
data, _ := json.MarshalIndent(r.CortexDebugCustomConfig, " ", " ")
215-
return t.Render() + " " + string(data)
213+
if custom := r.CustomConfigs; custom != nil {
214+
for id, config := range custom {
215+
configJson, _ := json.MarshalIndent(config, "", " ")
216+
t.AddRow(tr("Custom configuration for %s:", id))
217+
return t.Render() + " " + string(configJson)
218+
}
216219
}
217220
return t.Render()
218221
}

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

+58-54
Original file line numberDiff line numberDiff line change
@@ -132,34 +132,36 @@ func testAllDebugInformation(t *testing.T, env *integrationtest.Environment, cli
132132
]
133133
},
134134
"svd_file": "svd-file",
135-
"cortex-debug_custom_configuration": {
136-
"aBoolean": true,
137-
"aStringBoolean": "true",
138-
"aStringNumber": "10",
139-
"aNumber": 10,
140-
"anotherNumber": 10.2,
141-
"anObject": {
142-
"boolean": true,
143-
"key": "value"
144-
},
145-
"anotherObject": {
146-
"boolean": true,
147-
"key": "value"
135+
"custom_configs": {
136+
"cortex-debug": {
137+
"aBoolean": true,
138+
"aStringBoolean": "true",
139+
"aStringNumber": "10",
140+
"aNumber": 10,
141+
"anotherNumber": 10.2,
142+
"anObject": {
143+
"boolean": true,
144+
"key": "value"
145+
},
146+
"anotherObject": {
147+
"boolean": true,
148+
"key": "value"
149+
},
150+
"anotherStringParamer": "hellooo",
151+
"overrideRestartCommands": [
152+
"monitor reset halt",
153+
"monitor gdb_sync",
154+
"thb setup",
155+
"c"
156+
],
157+
"postAttachCommands": [
158+
"set remote hardware-watchpoint-limit 2",
159+
"monitor reset halt",
160+
"monitor gdb_sync",
161+
"thb setup",
162+
"c"
163+
]
148164
},
149-
"anotherStringParamer": "hellooo",
150-
"overrideRestartCommands": [
151-
"monitor reset halt",
152-
"monitor gdb_sync",
153-
"thb setup",
154-
"c"
155-
],
156-
"postAttachCommands": [
157-
"set remote hardware-watchpoint-limit 2",
158-
"monitor reset halt",
159-
"monitor gdb_sync",
160-
"thb setup",
161-
"c"
162-
]
163165
},
164166
"programmer": "atmel_ice"
165167
}`)
@@ -188,34 +190,36 @@ func testAllDebugInformation(t *testing.T, env *integrationtest.Environment, cli
188190
]
189191
},
190192
"svd_file": "svd-file",
191-
"cortex-debug_custom_configuration": {
192-
"aBoolean": true,
193-
"aStringBoolean": "true",
194-
"aStringNumber": "10",
195-
"aNumber": 10,
196-
"anotherNumber": 10.2,
197-
"anObject": {
198-
"boolean": true,
199-
"key": "value"
200-
},
201-
"anotherObject": {
202-
"boolean": true,
203-
"key": "value"
193+
"custom_configs": {
194+
"cortex-debug": {
195+
"aBoolean": true,
196+
"aStringBoolean": "true",
197+
"aStringNumber": "10",
198+
"aNumber": 10,
199+
"anotherNumber": 10.2,
200+
"anObject": {
201+
"boolean": true,
202+
"key": "value"
203+
},
204+
"anotherObject": {
205+
"boolean": true,
206+
"key": "value"
207+
},
208+
"anotherStringParamer": "hellooo",
209+
"overrideRestartCommands": [
210+
"monitor reset halt",
211+
"monitor gdb_sync",
212+
"thb setup",
213+
"c"
214+
],
215+
"postAttachCommands": [
216+
"set remote hardware-watchpoint-limit 2",
217+
"monitor reset halt",
218+
"monitor gdb_sync",
219+
"thb setup",
220+
"c"
221+
]
204222
},
205-
"anotherStringParamer": "hellooo",
206-
"overrideRestartCommands": [
207-
"monitor reset halt",
208-
"monitor gdb_sync",
209-
"thb setup",
210-
"c"
211-
],
212-
"postAttachCommands": [
213-
"set remote hardware-watchpoint-limit 2",
214-
"monitor reset halt",
215-
"monitor gdb_sync",
216-
"thb setup",
217-
"c"
218-
]
219223
},
220224
"programmer": "my_cold_ice"
221225
}`)

0 commit comments

Comments
 (0)