Skip to content

Commit

Permalink
debug: Slighlty refactored custom_configs section of GetDebugConfigRe…
Browse files Browse the repository at this point in the history
…sponse (#2396)
  • Loading branch information
cmaglie authored Oct 31, 2023
1 parent 64f1853 commit d187683
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 143 deletions.
26 changes: 13 additions & 13 deletions commands/debug/debug_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,22 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl
}
}

cortexDebugCustomJson := ""
cortexDebugCustomJson := map[string]string{}
if cortexDebugProps := debugProperties.SubTree("cortex-debug.custom"); cortexDebugProps.Size() > 0 {
cortexDebugCustomJson = convertToJsonMap(cortexDebugProps)
cortexDebugCustomJson["cortex-debug"] = convertToJsonMap(cortexDebugProps)
}
return &rpc.GetDebugConfigResponse{
Executable: debugProperties.Get("executable"),
Server: server,
ServerPath: debugProperties.Get("server." + server + ".path"),
ServerConfiguration: &serverConfiguration,
SvdFile: debugProperties.Get("svd_file"),
Toolchain: toolchain,
ToolchainPath: debugProperties.Get("toolchain.path"),
ToolchainPrefix: debugProperties.Get("toolchain.prefix"),
ToolchainConfiguration: &toolchainConfiguration,
CortexDebugCustomJson: cortexDebugCustomJson,
Programmer: req.GetProgrammer(),
Executable: debugProperties.Get("executable"),
Server: server,
ServerPath: debugProperties.Get("server." + server + ".path"),
ServerConfiguration: &serverConfiguration,
SvdFile: debugProperties.Get("svd_file"),
Toolchain: toolchain,
ToolchainPath: debugProperties.Get("toolchain.path"),
ToolchainPrefix: debugProperties.Get("toolchain.prefix"),
ToolchainConfiguration: &toolchainConfiguration,
CustomConfigurationsJson: cortexDebugCustomJson,
Programmer: req.GetProgrammer(),
}, nil
}

Expand Down
63 changes: 33 additions & 30 deletions internal/cli/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ func runDebugCommand(command *cobra.Command, args []string) {
}

type debugInfoResult struct {
Executable string `json:"executable,omitempty"`
Toolchain string `json:"toolchain,omitempty"`
ToolchainPath string `json:"toolchain_path,omitempty"`
ToolchainPrefix string `json:"toolchain_prefix,omitempty"`
ToolchainConfig any `json:"toolchain_configuration,omitempty"`
Server string `json:"server,omitempty"`
ServerPath string `json:"server_path,omitempty"`
ServerConfig any `json:"server_configuration,omitempty"`
SvdFile string `json:"svd_file,omitempty"`
CortexDebugCustomConfig any `json:"cortex-debug_custom_configuration,omitempty"`
Programmer string `json:"programmer"`
Executable string `json:"executable,omitempty"`
Toolchain string `json:"toolchain,omitempty"`
ToolchainPath string `json:"toolchain_path,omitempty"`
ToolchainPrefix string `json:"toolchain_prefix,omitempty"`
ToolchainConfig any `json:"toolchain_configuration,omitempty"`
Server string `json:"server,omitempty"`
ServerPath string `json:"server_path,omitempty"`
ServerConfig any `json:"server_configuration,omitempty"`
SvdFile string `json:"svd_file,omitempty"`
CustomConfigs map[string]any `json:"custom_configs,omitempty"`
Programmer string `json:"programmer"`
}

type openOcdServerConfigResult struct {
Expand All @@ -150,24 +150,25 @@ func newDebugInfoResult(info *rpc.GetDebugConfigResponse) *debugInfoResult {
Scripts: openocdConf.Scripts,
}
}
var cortexDebugCustomConfig any
if info.CortexDebugCustomJson != "" {
if err := json.Unmarshal([]byte(info.CortexDebugCustomJson), &cortexDebugCustomConfig); err != nil {
feedback.Fatal(tr("Error during Debug: %v", err), feedback.ErrGeneric)
customConfigs := map[string]any{}
for id, configJson := range info.GetCustomConfigurationsJson() {
var config any
if err := json.Unmarshal([]byte(configJson), &config); err == nil {
customConfigs[id] = config
}
}
return &debugInfoResult{
Executable: info.Executable,
Toolchain: info.Toolchain,
ToolchainPath: info.ToolchainPath,
ToolchainPrefix: info.ToolchainPrefix,
ToolchainConfig: toolchainConfig,
Server: info.Server,
ServerPath: info.ServerPath,
ServerConfig: serverConfig,
SvdFile: info.SvdFile,
CortexDebugCustomConfig: cortexDebugCustomConfig,
Programmer: info.Programmer,
Executable: info.Executable,
Toolchain: info.Toolchain,
ToolchainPath: info.ToolchainPath,
ToolchainPrefix: info.ToolchainPrefix,
ToolchainConfig: toolchainConfig,
Server: info.Server,
ServerPath: info.ServerPath,
ServerConfig: serverConfig,
SvdFile: info.SvdFile,
CustomConfigs: customConfigs,
Programmer: info.Programmer,
}
}

Expand Down Expand Up @@ -209,10 +210,12 @@ func (r *debugInfoResult) String() string {
}
default:
}
if r.CortexDebugCustomConfig != nil {
t.AddRow(tr("Custom configuration for cortex-debug IDE plugin:"))
data, _ := json.MarshalIndent(r.CortexDebugCustomConfig, " ", " ")
return t.Render() + " " + string(data)
if custom := r.CustomConfigs; custom != nil {
for id, config := range custom {
configJson, _ := json.MarshalIndent(config, "", " ")
t.AddRow(tr("Custom configuration for %s:", id))
return t.Render() + " " + string(configJson)
}
}
return t.Render()
}
112 changes: 58 additions & 54 deletions internal/integrationtest/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,34 +132,36 @@ func testAllDebugInformation(t *testing.T, env *integrationtest.Environment, cli
]
},
"svd_file": "svd-file",
"cortex-debug_custom_configuration": {
"aBoolean": true,
"aStringBoolean": "true",
"aStringNumber": "10",
"aNumber": 10,
"anotherNumber": 10.2,
"anObject": {
"boolean": true,
"key": "value"
},
"anotherObject": {
"boolean": true,
"key": "value"
"custom_configs": {
"cortex-debug": {
"aBoolean": true,
"aStringBoolean": "true",
"aStringNumber": "10",
"aNumber": 10,
"anotherNumber": 10.2,
"anObject": {
"boolean": true,
"key": "value"
},
"anotherObject": {
"boolean": true,
"key": "value"
},
"anotherStringParamer": "hellooo",
"overrideRestartCommands": [
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
],
"postAttachCommands": [
"set remote hardware-watchpoint-limit 2",
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
]
},
"anotherStringParamer": "hellooo",
"overrideRestartCommands": [
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
],
"postAttachCommands": [
"set remote hardware-watchpoint-limit 2",
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
]
},
"programmer": "atmel_ice"
}`)
Expand Down Expand Up @@ -188,34 +190,36 @@ func testAllDebugInformation(t *testing.T, env *integrationtest.Environment, cli
]
},
"svd_file": "svd-file",
"cortex-debug_custom_configuration": {
"aBoolean": true,
"aStringBoolean": "true",
"aStringNumber": "10",
"aNumber": 10,
"anotherNumber": 10.2,
"anObject": {
"boolean": true,
"key": "value"
},
"anotherObject": {
"boolean": true,
"key": "value"
"custom_configs": {
"cortex-debug": {
"aBoolean": true,
"aStringBoolean": "true",
"aStringNumber": "10",
"aNumber": 10,
"anotherNumber": 10.2,
"anObject": {
"boolean": true,
"key": "value"
},
"anotherObject": {
"boolean": true,
"key": "value"
},
"anotherStringParamer": "hellooo",
"overrideRestartCommands": [
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
],
"postAttachCommands": [
"set remote hardware-watchpoint-limit 2",
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
]
},
"anotherStringParamer": "hellooo",
"overrideRestartCommands": [
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
],
"postAttachCommands": [
"set remote hardware-watchpoint-limit 2",
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
]
},
"programmer": "my_cold_ice"
}`)
Expand Down
Loading

0 comments on commit d187683

Please sign in to comment.