@@ -19,7 +19,6 @@ import (
19
19
"context"
20
20
"os"
21
21
"os/signal"
22
- "sort"
23
22
24
23
"github.com/arduino/arduino-cli/commands/debug"
25
24
"github.com/arduino/arduino-cli/commands/sketch"
@@ -29,7 +28,6 @@ import (
29
28
"github.com/arduino/arduino-cli/internal/cli/instance"
30
29
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
31
30
"github.com/arduino/arduino-cli/table"
32
- "github.com/arduino/go-properties-orderedmap"
33
31
"github.com/fatih/color"
34
32
"github.com/sirupsen/logrus"
35
33
"github.com/spf13/cobra"
@@ -96,7 +94,7 @@ func runDebugCommand(command *cobra.Command, args []string) {
96
94
if res , err := debug .GetDebugConfig (context .Background (), debugConfigRequested ); err != nil {
97
95
feedback .Fatal (tr ("Error getting Debug info: %v" , err ), feedback .ErrBadArgument )
98
96
} else {
99
- feedback .PrintResult (& debugInfoResult { res } )
97
+ feedback .PrintResult (newDebugInfoResult ( res ) )
100
98
}
101
99
102
100
} else {
@@ -117,40 +115,83 @@ func runDebugCommand(command *cobra.Command, args []string) {
117
115
}
118
116
119
117
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
+ }
121
159
}
122
160
123
161
func (r * debugInfoResult ) Data () interface {} {
124
- return r . info
162
+ return r
125
163
}
126
164
127
165
func (r * debugInfoResult ) String () string {
128
166
t := table .New ()
129
167
green := color .New (color .FgHiGreen )
130
168
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 :
143
177
}
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 ))
153
193
}
194
+ default :
154
195
}
155
196
return t .Render ()
156
197
}
0 commit comments