@@ -17,18 +17,23 @@ package debug
17
17
18
18
import (
19
19
"context"
20
+ "fmt"
20
21
"os"
21
22
"os/signal"
23
+ "sort"
22
24
23
25
"github.com/arduino/arduino-cli/cli/errorcodes"
24
26
"github.com/arduino/arduino-cli/cli/feedback"
25
27
"github.com/arduino/arduino-cli/cli/instance"
26
28
"github.com/arduino/arduino-cli/commands/debug"
27
- rpc "github.com/arduino/arduino-cli/rpc/commands"
28
29
dbg "github.com/arduino/arduino-cli/rpc/debug"
30
+ "github.com/arduino/arduino-cli/table"
29
31
"github.com/arduino/go-paths-helper"
32
+ "github.com/arduino/go-properties-orderedmap"
33
+ "github.com/fatih/color"
30
34
"github.com/sirupsen/logrus"
31
35
"github.com/spf13/cobra"
36
+ "google.golang.org/grpc/status"
32
37
)
33
38
34
39
var (
38
43
verify bool
39
44
interpreter string
40
45
importDir string
46
+ printInfo bool
47
+ programmer string
41
48
)
42
49
43
50
// NewCommand created a new `upload` command
@@ -46,15 +53,17 @@ func NewCommand() *cobra.Command {
46
53
Use : "debug" ,
47
54
Short : "Debug Arduino sketches." ,
48
55
Long : "Debug Arduino sketches. (this command opens an interactive gdb session)" ,
49
- Example : " " + os .Args [0 ] + " debug -b arduino:samd:mkr1000 /home/user/Arduino/MySketch" ,
56
+ Example : " " + os .Args [0 ] + " debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch" ,
50
57
Args : cobra .MaximumNArgs (1 ),
51
58
Run : run ,
52
59
}
53
60
54
61
debugCommand .Flags ().StringVarP (& fqbn , "fqbn" , "b" , "" , "Fully Qualified Board Name, e.g.: arduino:avr:uno" )
55
62
debugCommand .Flags ().StringVarP (& port , "port" , "p" , "" , "Debug port, e.g.: COM10 or /dev/ttyACM0" )
63
+ debugCommand .Flags ().StringVarP (& programmer , "programmer" , "P" , "" , "Programmer to use for debugging" )
56
64
debugCommand .Flags ().StringVar (& interpreter , "interpreter" , "console" , "Debug interpreter e.g.: console, mi, mi1, mi2, mi3" )
57
65
debugCommand .Flags ().StringVarP (& importDir , "input-dir" , "" , "" , "Directory containing binaries for debug." )
66
+ debugCommand .Flags ().BoolVarP (& printInfo , "info" , "I" , false , "Show metadata about the debug session instead of starting the debugger." )
58
67
59
68
return debugCommand
60
69
}
@@ -72,20 +81,40 @@ func run(command *cobra.Command, args []string) {
72
81
}
73
82
sketchPath := initSketchPath (path )
74
83
75
- // Intercept SIGINT and forward them to debug process
76
- ctrlc := make (chan os.Signal , 1 )
77
- signal .Notify (ctrlc , os .Interrupt )
78
-
79
- if _ , err := debug .Debug (context .Background (), & dbg.DebugConfigReq {
80
- Instance : & rpc.Instance {Id : instance .GetId ()},
84
+ debugConfigRequested := & dbg.DebugConfigReq {
85
+ Instance : instance ,
81
86
Fqbn : fqbn ,
82
87
SketchPath : sketchPath .String (),
83
88
Port : port ,
84
89
Interpreter : interpreter ,
85
90
ImportDir : importDir ,
86
- }, os .Stdin , os .Stdout , ctrlc ); err != nil {
87
- feedback .Errorf ("Error during Debug: %v" , err )
88
- os .Exit (errorcodes .ErrGeneric )
91
+ Programmer : programmer ,
92
+ }
93
+
94
+ if printInfo {
95
+
96
+ if res , err := debug .GetDebugConfig (context .Background (), debugConfigRequested ); err != nil {
97
+ if status , ok := status .FromError (err ); ok {
98
+ feedback .Errorf ("Error getting Debug info: %v" , status .Message ())
99
+ errorcodes .ExitWithGrpcStatus (status )
100
+ }
101
+ feedback .Errorf ("Error getting Debug info: %v" , err )
102
+ os .Exit (errorcodes .ErrGeneric )
103
+ } else {
104
+ feedback .PrintResult (& debugInfoResult {res })
105
+ }
106
+
107
+ } else {
108
+
109
+ // Intercept SIGINT and forward them to debug process
110
+ ctrlc := make (chan os.Signal , 1 )
111
+ signal .Notify (ctrlc , os .Interrupt )
112
+
113
+ if _ , err := debug .Debug (context .Background (), debugConfigRequested , os .Stdin , os .Stdout , ctrlc ); err != nil {
114
+ feedback .Errorf ("Error during Debug: %v" , err )
115
+ os .Exit (errorcodes .ErrGeneric )
116
+ }
117
+
89
118
}
90
119
}
91
120
@@ -103,3 +132,42 @@ func initSketchPath(sketchPath *paths.Path) *paths.Path {
103
132
logrus .Infof ("Reading sketch from dir: %s" , wd )
104
133
return wd
105
134
}
135
+
136
+ type debugInfoResult struct {
137
+ info * dbg.GetDebugConfigResp
138
+ }
139
+
140
+ func (r * debugInfoResult ) Data () interface {} {
141
+ return r .info
142
+ }
143
+
144
+ func (r * debugInfoResult ) String () string {
145
+ t := table .New ()
146
+ green := color .New (color .FgHiGreen )
147
+ dimGreen := color .New (color .FgGreen )
148
+ t .AddRow ("Executable to debug" , table .NewCell (r .info .GetExecutable (), green ))
149
+ t .AddRow ("Toolchain type" , table .NewCell (r .info .GetToolchain (), green ))
150
+ t .AddRow ("Toolchain path" , table .NewCell (r .info .GetToolchainPath (), dimGreen ))
151
+ t .AddRow ("Toolchain prefix" , table .NewCell (r .info .GetToolchainPrefix (), dimGreen ))
152
+ if len (r .info .GetToolchainConfiguration ()) > 0 {
153
+ conf := properties .NewFromHashmap (r .info .GetToolchainConfiguration ())
154
+ keys := conf .Keys ()
155
+ sort .Strings (keys )
156
+ t .AddRow ("Toolchain custom configurations" )
157
+ for _ , k := range keys {
158
+ t .AddRow (table .NewCell (" - " + k , dimGreen ), table .NewCell (conf .Get (k ), dimGreen ))
159
+ }
160
+ }
161
+ t .AddRow ("GDB Server type" , table .NewCell (r .info .GetServer (), green ))
162
+ t .AddRow ("GDB Server path" , table .NewCell (r .info .GetServerPath (), dimGreen ))
163
+ if len (r .info .GetServerConfiguration ()) > 0 {
164
+ conf := properties .NewFromHashmap (r .info .GetServerConfiguration ())
165
+ keys := conf .Keys ()
166
+ sort .Strings (keys )
167
+ t .AddRow (fmt .Sprintf ("%s custom configurations" , r .info .GetServer ()))
168
+ for _ , k := range keys {
169
+ t .AddRow (table .NewCell (" - " + k , dimGreen ), table .NewCell (conf .Get (k ), dimGreen ))
170
+ }
171
+ }
172
+ return t .Render ()
173
+ }
0 commit comments