From aa2bb9ac224c4e8e860b8e75719594febced11d6 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 14 Oct 2020 10:48:03 +0200 Subject: [PATCH 01/11] Added 'debug --info/-I' flag to get debug metadata --- cli/debug/debug.go | 63 ++++-- commands/daemon/debug.go | 7 + commands/debug/debug.go | 103 +--------- commands/debug/debug_info.go | 159 +++++++++++++++ rpc/debug/debug.pb.go | 369 ++++++++++++++++++++++++++++++++--- rpc/debug/debug.proto | 40 +++- 6 files changed, 602 insertions(+), 139 deletions(-) create mode 100644 commands/debug/debug_info.go diff --git a/cli/debug/debug.go b/cli/debug/debug.go index d7ca207dd42..488a4dc146d 100644 --- a/cli/debug/debug.go +++ b/cli/debug/debug.go @@ -17,6 +17,7 @@ package debug import ( "context" + "fmt" "os" "os/signal" @@ -24,7 +25,6 @@ import ( "github.com/arduino/arduino-cli/cli/feedback" "github.com/arduino/arduino-cli/cli/instance" "github.com/arduino/arduino-cli/commands/debug" - rpc "github.com/arduino/arduino-cli/rpc/commands" dbg "github.com/arduino/arduino-cli/rpc/debug" "github.com/arduino/go-paths-helper" "github.com/sirupsen/logrus" @@ -38,6 +38,7 @@ var ( verify bool interpreter string importDir string + printInfo bool ) // NewCommand created a new `upload` command @@ -55,6 +56,7 @@ func NewCommand() *cobra.Command { debugCommand.Flags().StringVarP(&port, "port", "p", "", "Debug port, e.g.: COM10 or /dev/ttyACM0") debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", "Debug interpreter e.g.: console, mi, mi1, mi2, mi3") debugCommand.Flags().StringVarP(&importDir, "input-dir", "", "", "Directory containing binaries for debug.") + debugCommand.Flags().BoolVarP(&printInfo, "info", "I", false, "Show metadata about the debug session instead of starting the debugger.") return debugCommand } @@ -72,20 +74,39 @@ func run(command *cobra.Command, args []string) { } sketchPath := initSketchPath(path) - // Intercept SIGINT and forward them to debug process - ctrlc := make(chan os.Signal, 1) - signal.Notify(ctrlc, os.Interrupt) - - if _, err := debug.Debug(context.Background(), &dbg.DebugConfigReq{ - Instance: &rpc.Instance{Id: instance.GetId()}, - Fqbn: fqbn, - SketchPath: sketchPath.String(), - Port: port, - Interpreter: interpreter, - ImportDir: importDir, - }, os.Stdin, os.Stdout, ctrlc); err != nil { - feedback.Errorf("Error during Debug: %v", err) - os.Exit(errorcodes.ErrGeneric) + if printInfo { + + if res, err := debug.GetDebugInfo(context.Background(), &dbg.GetDebugInfoReq{ + Instance: instance, + Fqbn: fqbn, + SketchPath: sketchPath.String(), + Port: port, + ImportDir: importDir, + }); err != nil { + feedback.Errorf("Error getting Debug info: %v", err) + os.Exit(errorcodes.ErrGeneric) + } else { + feedback.PrintResult(&debugInfoResult{res}) + } + + } else { + + // Intercept SIGINT and forward them to debug process + ctrlc := make(chan os.Signal, 1) + signal.Notify(ctrlc, os.Interrupt) + + if _, err := debug.Debug(context.Background(), &dbg.DebugConfigReq{ + Instance: instance, + Fqbn: fqbn, + SketchPath: sketchPath.String(), + Port: port, + Interpreter: interpreter, + ImportDir: importDir, + }, os.Stdin, os.Stdout, ctrlc); err != nil { + feedback.Errorf("Error during Debug: %v", err) + os.Exit(errorcodes.ErrGeneric) + } + } } @@ -103,3 +124,15 @@ func initSketchPath(sketchPath *paths.Path) *paths.Path { logrus.Infof("Reading sketch from dir: %s", wd) return wd } + +type debugInfoResult struct { + info *dbg.GetDebugInfoResp +} + +func (r *debugInfoResult) Data() interface{} { + return r.info +} + +func (r *debugInfoResult) String() string { + return fmt.Sprintf("%+v", r.info) +} diff --git a/commands/daemon/debug.go b/commands/daemon/debug.go index b3ecef435a7..c2bba9a658c 100644 --- a/commands/daemon/debug.go +++ b/commands/daemon/debug.go @@ -16,10 +16,12 @@ package daemon import ( + "context" "os" "github.com/arduino/arduino-cli/arduino/utils" cmd "github.com/arduino/arduino-cli/commands/debug" + "github.com/arduino/arduino-cli/rpc/debug" dbg "github.com/arduino/arduino-cli/rpc/debug" "github.com/pkg/errors" ) @@ -64,3 +66,8 @@ func (s *DebugService) Debug(stream dbg.Debug_DebugServer) error { } return stream.Send(resp) } + +// GetDebugInfo return metadata about a debug session +func (s *DebugService) GetDebugInfo(ctx context.Context, req *debug.GetDebugInfoReq) (*debug.GetDebugInfoResp, error) { + return cmd.GetDebugInfo(ctx, req) +} diff --git a/commands/debug/debug.go b/commands/debug/debug.go index 3a51c10f041..468a9d7a544 100644 --- a/commands/debug/debug.go +++ b/commands/debug/debug.go @@ -21,16 +21,12 @@ import ( "io" "os" "path/filepath" - "strings" "time" - "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/arduino/cores/packagemanager" - "github.com/arduino/arduino-cli/arduino/sketches" "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/executils" dbg "github.com/arduino/arduino-cli/rpc/debug" - "github.com/arduino/go-paths-helper" "github.com/arduino/go-properties-orderedmap" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -119,104 +115,9 @@ func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager) return nil, errors.New("the ImportFile parameter has been deprecated, use ImportDir instead") } - // TODO: make a generic function to extract sketch from request - // and remove duplication in commands/compile.go - if req.GetSketchPath() == "" { - return nil, fmt.Errorf("missing sketchPath") - } - sketchPath := paths.New(req.GetSketchPath()) - sketch, err := sketches.NewSketchFromPath(sketchPath) - if err != nil { - return nil, errors.Wrap(err, "opening sketch") - } - - fqbnIn := req.GetFqbn() - if fqbnIn == "" && sketch != nil && sketch.Metadata != nil { - fqbnIn = sketch.Metadata.CPU.Fqbn - } - if fqbnIn == "" { - return nil, fmt.Errorf("no Fully Qualified Board Name provided") - } - fqbn, err := cores.ParseFQBN(fqbnIn) + toolProperties, err := getDebugProperties(req, pm) if err != nil { - return nil, errors.Wrap(err, "error parsing FQBN") - } - - // Find target board and board properties - _, _, board, boardProperties, _, err := pm.ResolveFQBN(fqbn) - if err != nil { - return nil, errors.Wrap(err, "error resolving FQBN") - } - - // Load programmer tool - toolName, have := boardProperties.GetOk("debug.tool") - if !have || toolName == "" { - return nil, fmt.Errorf("cannot get programmer tool: undefined 'debug.tool' property") - } - - var referencedPlatformRelease *cores.PlatformRelease - if split := strings.Split(toolName, ":"); len(split) > 2 { - return nil, fmt.Errorf("invalid 'debug.tool' property: %s", toolName) - } else if len(split) == 2 { - referencedPackageName := split[0] - toolName = split[1] - architecture := board.PlatformRelease.Platform.Architecture - - if referencedPackage := pm.Packages[referencedPackageName]; referencedPackage == nil { - return nil, fmt.Errorf("required platform %s:%s not installed", referencedPackageName, architecture) - } else if referencedPlatform := referencedPackage.Platforms[architecture]; referencedPlatform == nil { - return nil, fmt.Errorf("required platform %s:%s not installed", referencedPackageName, architecture) - } else { - referencedPlatformRelease = pm.GetInstalledPlatformRelease(referencedPlatform) - } - } - - // Build configuration for debug - toolProperties := properties.NewMap() - if referencedPlatformRelease != nil { - toolProperties.Merge(referencedPlatformRelease.Properties) - } - toolProperties.Merge(board.PlatformRelease.Properties) - toolProperties.Merge(board.PlatformRelease.RuntimeProperties()) - toolProperties.Merge(boardProperties) - - requestedToolProperties := toolProperties.SubTree("tools." + toolName) - toolProperties.Merge(requestedToolProperties) - if requiredTools, err := pm.FindToolsRequiredForBoard(board); err == nil { - for _, requiredTool := range requiredTools { - logrus.WithField("tool", requiredTool).Info("Tool required for debug") - toolProperties.Merge(requiredTool.RuntimeProperties()) - } - } - - var importPath *paths.Path - if importDir := req.GetImportDir(); importDir != "" { - importPath = paths.New(importDir) - } else { - // TODO: Create a function to obtain importPath from sketch - importPath = sketch.FullPath - // Add FQBN (without configs part) to export path - fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1) - importPath = importPath.Join("build").Join(fqbnSuffix) - } - if !importPath.Exist() { - return nil, fmt.Errorf("compiled sketch not found in %s", importPath) - } - if !importPath.IsDir() { - return nil, fmt.Errorf("expected compiled sketch in directory %s, but is a file instead", importPath) - } - toolProperties.SetPath("build.path", importPath) - toolProperties.Set("build.project_name", sketch.Name+".ino") - - // Set debug port property - port := req.GetPort() - if port != "" { - toolProperties.Set("debug.port", port) - if strings.HasPrefix(port, "/dev/") { - toolProperties.Set("debug.port.file", port[5:]) - } else { - toolProperties.Set("debug.port.file", port) - } + return nil, err } // Set debugger interpreter (default value should be "console") diff --git a/commands/debug/debug_info.go b/commands/debug/debug_info.go new file mode 100644 index 00000000000..b2f3d01e0ae --- /dev/null +++ b/commands/debug/debug_info.go @@ -0,0 +1,159 @@ +// This file is part of arduino-cli. +// +// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package debug + +import ( + "context" + "fmt" + "sort" + "strings" + + "github.com/arduino/arduino-cli/arduino/cores" + "github.com/arduino/arduino-cli/arduino/cores/packagemanager" + "github.com/arduino/arduino-cli/arduino/sketches" + "github.com/arduino/arduino-cli/commands" + "github.com/arduino/arduino-cli/rpc/debug" + "github.com/arduino/go-paths-helper" + "github.com/arduino/go-properties-orderedmap" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" +) + +// GetDebugInfo returns metadata to start debugging with the specified board +func GetDebugInfo(ctx context.Context, req *debug.GetDebugInfoReq) (*debug.GetDebugInfoResp, error) { + pm := commands.GetPackageManager(req.GetInstance().GetId()) + + props, err := getDebugProperties(req, pm) + if err != nil { + return nil, err + } + + keys := props.Keys() + sort.StringSlice(keys).Sort() + for _, k := range keys { + fmt.Printf("%s=%s\n", k, props.Get(k)) + } + + server := props.Get("server") + toolchain := props.Get("toolchain") + resp := &debug.GetDebugInfoResp{ + Executable: props.Get("executable"), + Server: server, + ServerPath: props.Get("server." + server + ".path"), + ServerConfiguration: props.SubTree("server." + server).AsMap(), + Toolchain: toolchain, + ToolchainPath: props.Get("toolchain.path"), + ToolchainPrefix: props.Get("toolchain.prefix"), + ToolchainConfiguration: props.SubTree("toolchain." + toolchain).AsMap(), + } + return resp, nil +} + +// Target represents a target for a debug action +type Target interface { + GetSketchPath() string + GetFqbn() string + GetImportDir() string + GetPort() string +} + +func getDebugProperties(req Target, pm *packagemanager.PackageManager) (*properties.Map, error) { + // TODO: make a generic function to extract sketch from request + // and remove duplication in commands/compile.go + if req.GetSketchPath() == "" { + return nil, fmt.Errorf("missing sketchPath") + } + sketchPath := paths.New(req.GetSketchPath()) + sketch, err := sketches.NewSketchFromPath(sketchPath) + if err != nil { + return nil, errors.Wrap(err, "opening sketch") + } + + // XXX Remove this code duplication!! + fqbnIn := req.GetFqbn() + if fqbnIn == "" && sketch != nil && sketch.Metadata != nil { + fqbnIn = sketch.Metadata.CPU.Fqbn + } + if fqbnIn == "" { + return nil, fmt.Errorf("no Fully Qualified Board Name provided") + } + fqbn, err := cores.ParseFQBN(fqbnIn) + if err != nil { + return nil, errors.Wrap(err, "error parsing FQBN") + } + + // Find target board and board properties + _, platformRelease, board, boardProperties, referencedPlatformRelease, err := pm.ResolveFQBN(fqbn) + if err != nil { + return nil, errors.Wrap(err, "error resolving FQBN") + } + + // Build configuration for debug + toolProperties := properties.NewMap() + if referencedPlatformRelease != nil { + toolProperties.Merge(referencedPlatformRelease.Properties) + } + toolProperties.Merge(platformRelease.Properties) + toolProperties.Merge(platformRelease.RuntimeProperties()) + toolProperties.Merge(boardProperties) + + for _, tool := range pm.GetAllInstalledToolsReleases() { + toolProperties.Merge(tool.RuntimeProperties()) + } + if requiredTools, err := pm.FindToolsRequiredForBoard(board); err == nil { + for _, requiredTool := range requiredTools { + logrus.WithField("tool", requiredTool).Info("Tool required for debug") + toolProperties.Merge(requiredTool.RuntimeProperties()) + } + } + + var importPath *paths.Path + if importDir := req.GetImportDir(); importDir != "" { + importPath = paths.New(importDir) + } else { + // TODO: Create a function to obtain importPath from sketch + importPath = sketch.FullPath + // Add FQBN (without configs part) to export path + fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1) + importPath = importPath.Join("build").Join(fqbnSuffix) + } + if !importPath.Exist() { + return nil, fmt.Errorf("compiled sketch not found in %s", importPath) + } + if !importPath.IsDir() { + return nil, fmt.Errorf("expected compiled sketch in directory %s, but is a file instead", importPath) + } + toolProperties.SetPath("build.path", importPath) + toolProperties.Set("build.project_name", sketch.Name+".ino") + + // Set debug port property + port := req.GetPort() + if port != "" { + toolProperties.Set("debug.port", port) + if strings.HasPrefix(port, "/dev/") { + toolProperties.Set("debug.port.file", port[5:]) + } else { + toolProperties.Set("debug.port.file", port) + } + } + + // Extract and expand all debugging properties + debugProperties := properties.NewMap() + for k, v := range toolProperties.SubTree("debug").AsMap() { + debugProperties.Set(k, toolProperties.ExpandPropsInString(v)) + } + return debugProperties, nil +} diff --git a/rpc/debug/debug.pb.go b/rpc/debug/debug.pb.go index 78459b85514..a887e664b83 100644 --- a/rpc/debug/debug.pb.go +++ b/rpc/debug/debug.pb.go @@ -132,7 +132,7 @@ type DebugConfigReq struct { // Path to the sketch that is running on the board. The compiled executable // is expected to be located under this path. SketchPath string `protobuf:"bytes,3,opt,name=sketch_path,json=sketchPath,proto3" json:"sketch_path,omitempty"` - // Port of the debugger. Set to `none` if the debugger doesn't use a port. + // Port of the debugger (optional). Port string `protobuf:"bytes,4,opt,name=port,proto3" json:"port,omitempty"` // Which GDB command interpreter to use. Interpreter string `protobuf:"bytes,5,opt,name=interpreter,proto3" json:"interpreter,omitempty"` @@ -286,6 +286,205 @@ func (x *DebugResp) GetError() string { return "" } +type GetDebugInfoReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Arduino Core Service instance from the `Init` response. + Instance *commands.Instance `protobuf:"bytes,1,opt,name=instance,proto3" json:"instance,omitempty"` + // Fully qualified board name of the board in use + // (e.g., `arduino:samd:mkr1000`). If this is omitted, the FQBN attached to + // the sketch will be used. + Fqbn string `protobuf:"bytes,2,opt,name=fqbn,proto3" json:"fqbn,omitempty"` + // Path to the sketch that is running on the board. The compiled executable + // is expected to be located under this path. + SketchPath string `protobuf:"bytes,3,opt,name=sketch_path,json=sketchPath,proto3" json:"sketch_path,omitempty"` + // Port of the debugger (optional). + Port string `protobuf:"bytes,4,opt,name=port,proto3" json:"port,omitempty"` + // Directory containing the compiled executable. If `import_dir` is not + // specified, the executable is assumed to be in `{sketch_path}/build/{fqbn}/`. + ImportDir string `protobuf:"bytes,5,opt,name=import_dir,json=importDir,proto3" json:"import_dir,omitempty"` +} + +func (x *GetDebugInfoReq) Reset() { + *x = GetDebugInfoReq{} + if protoimpl.UnsafeEnabled { + mi := &file_debug_debug_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetDebugInfoReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetDebugInfoReq) ProtoMessage() {} + +func (x *GetDebugInfoReq) ProtoReflect() protoreflect.Message { + mi := &file_debug_debug_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetDebugInfoReq.ProtoReflect.Descriptor instead. +func (*GetDebugInfoReq) Descriptor() ([]byte, []int) { + return file_debug_debug_proto_rawDescGZIP(), []int{3} +} + +func (x *GetDebugInfoReq) GetInstance() *commands.Instance { + if x != nil { + return x.Instance + } + return nil +} + +func (x *GetDebugInfoReq) GetFqbn() string { + if x != nil { + return x.Fqbn + } + return "" +} + +func (x *GetDebugInfoReq) GetSketchPath() string { + if x != nil { + return x.SketchPath + } + return "" +} + +func (x *GetDebugInfoReq) GetPort() string { + if x != nil { + return x.Port + } + return "" +} + +func (x *GetDebugInfoReq) GetImportDir() string { + if x != nil { + return x.ImportDir + } + return "" +} + +type GetDebugInfoResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The executable binary to debug + Executable string `protobuf:"bytes,1,opt,name=executable,proto3" json:"executable,omitempty"` + // The toolchain type used for the build (for example "gcc") + Toolchain string `protobuf:"bytes,2,opt,name=toolchain,proto3" json:"toolchain,omitempty"` + // The toolchain directory + ToolchainPath string `protobuf:"bytes,3,opt,name=toolchain_path,json=toolchainPath,proto3" json:"toolchain_path,omitempty"` + // The toolchain architecture prefix (for example "arm-none-eabi-") + ToolchainPrefix string `protobuf:"bytes,4,opt,name=toolchain_prefix,json=toolchainPrefix,proto3" json:"toolchain_prefix,omitempty"` + // The GDB server type used to connect to the programmer/board (for example "openocd") + Server string `protobuf:"bytes,5,opt,name=server,proto3" json:"server,omitempty"` + // The GDB server directory + ServerPath string `protobuf:"bytes,6,opt,name=server_path,json=serverPath,proto3" json:"server_path,omitempty"` + // Extra configuration parameters wrt toolchain + ToolchainConfiguration map[string]string `protobuf:"bytes,7,rep,name=toolchain_configuration,json=toolchainConfiguration,proto3" json:"toolchain_configuration,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + // Extra configuration parameters wrt GDB server + ServerConfiguration map[string]string `protobuf:"bytes,8,rep,name=server_configuration,json=serverConfiguration,proto3" json:"server_configuration,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *GetDebugInfoResp) Reset() { + *x = GetDebugInfoResp{} + if protoimpl.UnsafeEnabled { + mi := &file_debug_debug_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetDebugInfoResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetDebugInfoResp) ProtoMessage() {} + +func (x *GetDebugInfoResp) ProtoReflect() protoreflect.Message { + mi := &file_debug_debug_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetDebugInfoResp.ProtoReflect.Descriptor instead. +func (*GetDebugInfoResp) Descriptor() ([]byte, []int) { + return file_debug_debug_proto_rawDescGZIP(), []int{4} +} + +func (x *GetDebugInfoResp) GetExecutable() string { + if x != nil { + return x.Executable + } + return "" +} + +func (x *GetDebugInfoResp) GetToolchain() string { + if x != nil { + return x.Toolchain + } + return "" +} + +func (x *GetDebugInfoResp) GetToolchainPath() string { + if x != nil { + return x.ToolchainPath + } + return "" +} + +func (x *GetDebugInfoResp) GetToolchainPrefix() string { + if x != nil { + return x.ToolchainPrefix + } + return "" +} + +func (x *GetDebugInfoResp) GetServer() string { + if x != nil { + return x.Server + } + return "" +} + +func (x *GetDebugInfoResp) GetServerPath() string { + if x != nil { + return x.ServerPath + } + return "" +} + +func (x *GetDebugInfoResp) GetToolchainConfiguration() map[string]string { + if x != nil { + return x.ToolchainConfiguration + } + return nil +} + +func (x *GetDebugInfoResp) GetServerConfiguration() map[string]string { + if x != nil { + return x.ServerConfiguration + } + return nil +} + var File_debug_debug_proto protoreflect.FileDescriptor var file_debug_debug_proto_rawDesc = []byte{ @@ -321,15 +520,71 @@ var file_debug_debug_proto_rawDesc = []byte{ 0x65, 0x62, 0x75, 0x67, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, - 0x6f, 0x72, 0x32, 0x57, 0x0a, 0x05, 0x44, 0x65, 0x62, 0x75, 0x67, 0x12, 0x4e, 0x0a, 0x05, 0x44, - 0x65, 0x62, 0x75, 0x67, 0x12, 0x1e, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, - 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x44, 0x65, 0x62, 0x75, - 0x67, 0x52, 0x65, 0x71, 0x1a, 0x1f, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, - 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x44, 0x65, 0x62, 0x75, - 0x67, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0x2a, 0x5a, 0x28, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, - 0x6f, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, - 0x63, 0x2f, 0x64, 0x65, 0x62, 0x75, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6f, 0x72, 0x22, 0xb8, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, + 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, + 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, + 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, + 0x64, 0x73, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, + 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x6b, 0x65, + 0x74, 0x63, 0x68, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x73, 0x6b, 0x65, 0x74, 0x63, 0x68, 0x50, 0x61, 0x74, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, + 0x72, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1d, + 0x0a, 0x0a, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x09, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x22, 0xdf, 0x04, + 0x0a, 0x10, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, + 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x61, 0x62, + 0x6c, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, + 0x12, 0x25, 0x0a, 0x0e, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x70, 0x61, + 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, + 0x61, 0x69, 0x6e, 0x50, 0x61, 0x74, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x74, 0x6f, 0x6f, 0x6c, 0x63, + 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0f, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x50, 0x72, 0x65, 0x66, + 0x69, 0x78, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x50, 0x61, 0x74, 0x68, 0x12, 0x7b, 0x0a, 0x17, 0x74, + 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x42, 0x2e, 0x63, + 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, + 0x62, 0x75, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, + 0x52, 0x65, 0x73, 0x70, 0x2e, 0x54, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, + 0x52, 0x16, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x72, 0x0a, 0x14, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x3f, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, + 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x47, 0x65, + 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x2e, 0x53, + 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x13, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x49, 0x0a, 0x1b, + 0x54, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, + 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x46, 0x0a, 0x18, 0x53, 0x65, 0x72, 0x76, 0x65, + 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, + 0xb8, 0x01, 0x0a, 0x05, 0x44, 0x65, 0x62, 0x75, 0x67, 0x12, 0x4e, 0x0a, 0x05, 0x44, 0x65, 0x62, + 0x75, 0x67, 0x12, 0x1e, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, + 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, + 0x65, 0x71, 0x1a, 0x1f, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, + 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, + 0x65, 0x73, 0x70, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x5f, 0x0a, 0x0c, 0x47, 0x65, 0x74, + 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x25, 0x2e, 0x63, 0x63, 0x2e, 0x61, + 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, + 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, + 0x1a, 0x26, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, + 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, + 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, + 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, + 0x2f, 0x64, 0x65, 0x62, 0x75, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -344,23 +599,32 @@ func file_debug_debug_proto_rawDescGZIP() []byte { return file_debug_debug_proto_rawDescData } -var file_debug_debug_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_debug_debug_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_debug_debug_proto_goTypes = []interface{}{ (*DebugReq)(nil), // 0: cc.arduino.cli.debug.DebugReq (*DebugConfigReq)(nil), // 1: cc.arduino.cli.debug.DebugConfigReq (*DebugResp)(nil), // 2: cc.arduino.cli.debug.DebugResp - (*commands.Instance)(nil), // 3: cc.arduino.cli.commands.Instance + (*GetDebugInfoReq)(nil), // 3: cc.arduino.cli.debug.GetDebugInfoReq + (*GetDebugInfoResp)(nil), // 4: cc.arduino.cli.debug.GetDebugInfoResp + nil, // 5: cc.arduino.cli.debug.GetDebugInfoResp.ToolchainConfigurationEntry + nil, // 6: cc.arduino.cli.debug.GetDebugInfoResp.ServerConfigurationEntry + (*commands.Instance)(nil), // 7: cc.arduino.cli.commands.Instance } var file_debug_debug_proto_depIdxs = []int32{ 1, // 0: cc.arduino.cli.debug.DebugReq.debugReq:type_name -> cc.arduino.cli.debug.DebugConfigReq - 3, // 1: cc.arduino.cli.debug.DebugConfigReq.instance:type_name -> cc.arduino.cli.commands.Instance - 0, // 2: cc.arduino.cli.debug.Debug.Debug:input_type -> cc.arduino.cli.debug.DebugReq - 2, // 3: cc.arduino.cli.debug.Debug.Debug:output_type -> cc.arduino.cli.debug.DebugResp - 3, // [3:4] is the sub-list for method output_type - 2, // [2:3] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 7, // 1: cc.arduino.cli.debug.DebugConfigReq.instance:type_name -> cc.arduino.cli.commands.Instance + 7, // 2: cc.arduino.cli.debug.GetDebugInfoReq.instance:type_name -> cc.arduino.cli.commands.Instance + 5, // 3: cc.arduino.cli.debug.GetDebugInfoResp.toolchain_configuration:type_name -> cc.arduino.cli.debug.GetDebugInfoResp.ToolchainConfigurationEntry + 6, // 4: cc.arduino.cli.debug.GetDebugInfoResp.server_configuration:type_name -> cc.arduino.cli.debug.GetDebugInfoResp.ServerConfigurationEntry + 0, // 5: cc.arduino.cli.debug.Debug.Debug:input_type -> cc.arduino.cli.debug.DebugReq + 3, // 6: cc.arduino.cli.debug.Debug.GetDebugInfo:input_type -> cc.arduino.cli.debug.GetDebugInfoReq + 2, // 7: cc.arduino.cli.debug.Debug.Debug:output_type -> cc.arduino.cli.debug.DebugResp + 4, // 8: cc.arduino.cli.debug.Debug.GetDebugInfo:output_type -> cc.arduino.cli.debug.GetDebugInfoResp + 7, // [7:9] is the sub-list for method output_type + 5, // [5:7] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_debug_debug_proto_init() } @@ -405,6 +669,30 @@ func file_debug_debug_proto_init() { return nil } } + file_debug_debug_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetDebugInfoReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_debug_debug_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetDebugInfoResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -412,7 +700,7 @@ func file_debug_debug_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_debug_debug_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 7, NumExtensions: 0, NumServices: 1, }, @@ -440,6 +728,7 @@ const _ = grpc.SupportPackageIsVersion6 type DebugClient interface { // Start a debug session and communicate with the debugger tool. Debug(ctx context.Context, opts ...grpc.CallOption) (Debug_DebugClient, error) + GetDebugInfo(ctx context.Context, in *GetDebugInfoReq, opts ...grpc.CallOption) (*GetDebugInfoResp, error) } type debugClient struct { @@ -481,10 +770,20 @@ func (x *debugDebugClient) Recv() (*DebugResp, error) { return m, nil } +func (c *debugClient) GetDebugInfo(ctx context.Context, in *GetDebugInfoReq, opts ...grpc.CallOption) (*GetDebugInfoResp, error) { + out := new(GetDebugInfoResp) + err := c.cc.Invoke(ctx, "/cc.arduino.cli.debug.Debug/GetDebugInfo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // DebugServer is the server API for Debug service. type DebugServer interface { // Start a debug session and communicate with the debugger tool. Debug(Debug_DebugServer) error + GetDebugInfo(context.Context, *GetDebugInfoReq) (*GetDebugInfoResp, error) } // UnimplementedDebugServer can be embedded to have forward compatible implementations. @@ -494,6 +793,9 @@ type UnimplementedDebugServer struct { func (*UnimplementedDebugServer) Debug(Debug_DebugServer) error { return status.Errorf(codes.Unimplemented, "method Debug not implemented") } +func (*UnimplementedDebugServer) GetDebugInfo(context.Context, *GetDebugInfoReq) (*GetDebugInfoResp, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetDebugInfo not implemented") +} func RegisterDebugServer(s *grpc.Server, srv DebugServer) { s.RegisterService(&_Debug_serviceDesc, srv) @@ -525,10 +827,33 @@ func (x *debugDebugServer) Recv() (*DebugReq, error) { return m, nil } +func _Debug_GetDebugInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetDebugInfoReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(DebugServer).GetDebugInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cc.arduino.cli.debug.Debug/GetDebugInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(DebugServer).GetDebugInfo(ctx, req.(*GetDebugInfoReq)) + } + return interceptor(ctx, in, info, handler) +} + var _Debug_serviceDesc = grpc.ServiceDesc{ ServiceName: "cc.arduino.cli.debug.Debug", HandlerType: (*DebugServer)(nil), - Methods: []grpc.MethodDesc{}, + Methods: []grpc.MethodDesc{ + { + MethodName: "GetDebugInfo", + Handler: _Debug_GetDebugInfo_Handler, + }, + }, Streams: []grpc.StreamDesc{ { StreamName: "Debug", diff --git a/rpc/debug/debug.proto b/rpc/debug/debug.proto index 8d478089176..b7d0ef2b795 100644 --- a/rpc/debug/debug.proto +++ b/rpc/debug/debug.proto @@ -26,6 +26,8 @@ service Debug { // Start a debug session and communicate with the debugger tool. rpc Debug (stream DebugReq) returns (stream DebugResp) { } + + rpc GetDebugInfo(GetDebugInfoReq) returns (GetDebugInfoResp) {} } // The top-level message sent by the client for the `Debug` method. @@ -58,7 +60,7 @@ message DebugConfigReq { // Path to the sketch that is running on the board. The compiled executable // is expected to be located under this path. string sketch_path = 3; - // Port of the debugger. Set to `none` if the debugger doesn't use a port. + // Port of the debugger (optional). string port = 4; // Which GDB command interpreter to use. string interpreter = 5; @@ -77,3 +79,39 @@ message DebugResp { // Incoming error output from the debugger tool. string error = 2; } + +message GetDebugInfoReq { + // Arduino Core Service instance from the `Init` response. + cc.arduino.cli.commands.Instance instance = 1; + // Fully qualified board name of the board in use + // (e.g., `arduino:samd:mkr1000`). If this is omitted, the FQBN attached to + // the sketch will be used. + string fqbn = 2; + // Path to the sketch that is running on the board. The compiled executable + // is expected to be located under this path. + string sketch_path = 3; + // Port of the debugger (optional). + string port = 4; + // Directory containing the compiled executable. If `import_dir` is not + // specified, the executable is assumed to be in `{sketch_path}/build/{fqbn}/`. + string import_dir = 5; +} + +message GetDebugInfoResp { + // The executable binary to debug + string executable = 1; + // The toolchain type used for the build (for example "gcc") + string toolchain = 2; + // The toolchain directory + string toolchain_path = 3; + // The toolchain architecture prefix (for example "arm-none-eabi-") + string toolchain_prefix = 4; + // The GDB server type used to connect to the programmer/board (for example "openocd") + string server = 5; + // The GDB server directory + string server_path = 6; + // Extra configuration parameters wrt toolchain + map toolchain_configuration = 7; + // Extra configuration parameters wrt GDB server + map server_configuration = 8; +} From 79b8b9a9fdeedf8d6b682e31c17c3b26e3821054 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 15 Oct 2020 14:31:58 +0200 Subject: [PATCH 02/11] Debugger: do not use anymore pre-made recipes --- commands/debug/debug.go | 85 +++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 21 deletions(-) diff --git a/commands/debug/debug.go b/commands/debug/debug.go index 468a9d7a544..22c5e3ef559 100644 --- a/commands/debug/debug.go +++ b/commands/debug/debug.go @@ -27,7 +27,7 @@ import ( "github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/executils" dbg "github.com/arduino/arduino-cli/rpc/debug" - "github.com/arduino/go-properties-orderedmap" + "github.com/arduino/go-paths-helper" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -40,17 +40,15 @@ import ( // It also implements tool process lifecycle management func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream io.Reader, out io.Writer, interrupt <-chan os.Signal) (*dbg.DebugResp, error) { - // Get tool commandLine from core recipe + // Get debugging command line to run debugger pm := commands.GetPackageManager(req.GetInstance().GetId()) commandLine, err := getCommandLine(req, pm) if err != nil { return nil, errors.Wrap(err, "Cannot get command line for tool") } - // Transform every path to forward slashes (on Windows some tools further - // escapes the command line so the backslash "\" gets in the way). - for i, param := range commandLine { - commandLine[i] = filepath.ToSlash(param) + for i, arg := range commandLine { + fmt.Printf("%2d: %s\n", i, arg) } // Run Tool @@ -115,31 +113,76 @@ func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager) return nil, errors.New("the ImportFile parameter has been deprecated, use ImportDir instead") } - toolProperties, err := getDebugProperties(req, pm) + debugInfo, err := GetDebugInfo(context.Background(), &dbg.GetDebugInfoReq{ + Instance: req.GetInstance(), + Fqbn: req.GetFqbn(), + SketchPath: req.GetSketchPath(), + ImportDir: req.GetImportDir(), + Port: req.GetPort(), + }) if err != nil { return nil, err } - // Set debugger interpreter (default value should be "console") - interpreter := req.GetInterpreter() - if interpreter != "" { - toolProperties.Set("interpreter", interpreter) + cmdArgs := []string{} + add := func(s string) { cmdArgs = append(cmdArgs, s) } + + // Add path to GDB Client to command line + var gdbPath *paths.Path + switch debugInfo.GetToolchain() { + case "gcc": + gdbPath = paths.New(debugInfo.ToolchainPath).Join(debugInfo.ToolchainPrefix + "gdb") + default: + return nil, errors.Errorf("unsupported toolchain '%s'", debugInfo.GetToolchain()) + } + add(gdbPath.String()) + + // Set GDB interpreter (default value should be "console") + gdbInterpreter := req.GetInterpreter() + if gdbInterpreter == "" { + gdbInterpreter = "console" } else { - toolProperties.Set("interpreter", "console") + add("--interpreter=" + gdbInterpreter) + add("-ex") + add("set pagination off") } - // Build recipe for tool - recipe := toolProperties.Get("debug.pattern") + // Add extra GDB execution commands + add("-ex") + add("set remotetimeout 5") + + // Extract path to GDB Server + switch debugInfo.GetServer() { + case "openocd": + openocd := paths.New(debugInfo.ServerPath).Join("openocd") + serverCmd := fmt.Sprintf(`target extended-remote | "%s"`, openocd) + + if cfg := debugInfo.ServerConfiguration["scripts_dir"]; cfg != "" { + serverCmd += fmt.Sprintf(` -s "%s"`, cfg) + } - // REMOVEME: hotfix for samd core 1.8.5/1.8.6 - if recipe == `"{path}/{cmd}" --interpreter=mi2 -ex "set pagination off" -ex 'target extended-remote | {tools.openocd.path}/{tools.openocd.cmd} -s "{tools.openocd.path}/share/openocd/scripts/" --file "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "gdb_port pipe" -c "telnet_port 0"' {build.path}/{build.project_name}.elf` { - recipe = `"{path}/{cmd}" --interpreter={interpreter} -ex "set remotetimeout 5" -ex "set pagination off" -ex 'target extended-remote | "{tools.openocd.path}/{tools.openocd.cmd}" -s "{tools.openocd.path}/share/openocd/scripts/" --file "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "gdb_port pipe" -c "telnet_port 0"' "{build.path}/{build.project_name}.elf"` + if script := debugInfo.ServerConfiguration["script"]; script != "" { + serverCmd += fmt.Sprintf(` --file "%s"`, script) + } + + serverCmd += ` -c "gdb_port pipe"` + serverCmd += ` -c "telnet_port 0"` + + add("-ex") + add(serverCmd) + + default: + return nil, errors.Errorf("unsupported gdb server '%s'", debugInfo.GetServer()) } - cmdLine := toolProperties.ExpandPropsInString(recipe) - cmdArgs, err := properties.SplitQuotedString(cmdLine, `"'`, false) - if err != nil { - return nil, fmt.Errorf("invalid recipe '%s': %s", recipe, err) + // Add executable + add(debugInfo.Executable) + + // Transform every path to forward slashes (on Windows some tools further + // escapes the command line so the backslash "\" gets in the way). + for i, param := range cmdArgs { + cmdArgs[i] = filepath.ToSlash(param) } + return cmdArgs, nil } From 09840b826e486a3252efe5cec7884ded4857e0bd Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 15 Oct 2020 23:57:50 +0200 Subject: [PATCH 03/11] Added nicer color ouput for 'debug --info' --- cli/debug/debug.go | 33 ++++++++++++++++++++++++++++++++- commands/debug/debug_info.go | 7 ------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/cli/debug/debug.go b/cli/debug/debug.go index 488a4dc146d..6bda3c35c26 100644 --- a/cli/debug/debug.go +++ b/cli/debug/debug.go @@ -20,13 +20,17 @@ import ( "fmt" "os" "os/signal" + "sort" "github.com/arduino/arduino-cli/cli/errorcodes" "github.com/arduino/arduino-cli/cli/feedback" "github.com/arduino/arduino-cli/cli/instance" "github.com/arduino/arduino-cli/commands/debug" dbg "github.com/arduino/arduino-cli/rpc/debug" + "github.com/arduino/arduino-cli/table" "github.com/arduino/go-paths-helper" + "github.com/arduino/go-properties-orderedmap" + "github.com/fatih/color" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -134,5 +138,32 @@ func (r *debugInfoResult) Data() interface{} { } func (r *debugInfoResult) String() string { - return fmt.Sprintf("%+v", r.info) + t := table.New() + green := color.New(color.FgHiGreen) + dimGreen := color.New(color.FgGreen) + t.AddRow("Executable to debug", table.NewCell(r.info.GetExecutable(), green)) + t.AddRow("Toolchain type", table.NewCell(r.info.GetToolchain(), green)) + t.AddRow("Toolchain path", table.NewCell(r.info.GetToolchainPath(), dimGreen)) + t.AddRow("Toolchain prefix", table.NewCell(r.info.GetToolchainPrefix(), dimGreen)) + if len(r.info.GetToolchainConfiguration()) > 0 { + conf := properties.NewFromHashmap(r.info.GetToolchainConfiguration()) + keys := conf.Keys() + sort.Strings(keys) + t.AddRow("Toolchain custom configurations") + for _, k := range keys { + t.AddRow(table.NewCell(" - "+k, dimGreen), table.NewCell(conf.Get(k), dimGreen)) + } + } + t.AddRow("GDB Server type", table.NewCell(r.info.GetServer(), green)) + t.AddRow("GDB Server path", table.NewCell(r.info.GetServerPath(), dimGreen)) + if len(r.info.GetServerConfiguration()) > 0 { + conf := properties.NewFromHashmap(r.info.GetServerConfiguration()) + keys := conf.Keys() + sort.Strings(keys) + t.AddRow(fmt.Sprintf("%s custom configurations", r.info.GetServer())) + for _, k := range keys { + t.AddRow(table.NewCell(" - "+k, dimGreen), table.NewCell(conf.Get(k), dimGreen)) + } + } + return t.Render() } diff --git a/commands/debug/debug_info.go b/commands/debug/debug_info.go index b2f3d01e0ae..01c49115272 100644 --- a/commands/debug/debug_info.go +++ b/commands/debug/debug_info.go @@ -18,7 +18,6 @@ package debug import ( "context" "fmt" - "sort" "strings" "github.com/arduino/arduino-cli/arduino/cores" @@ -41,12 +40,6 @@ func GetDebugInfo(ctx context.Context, req *debug.GetDebugInfoReq) (*debug.GetDe return nil, err } - keys := props.Keys() - sort.StringSlice(keys).Sort() - for _, k := range keys { - fmt.Printf("%s=%s\n", k, props.Get(k)) - } - server := props.Get("server") toolchain := props.Get("toolchain") resp := &debug.GetDebugInfoResp{ From 3fa8d4cf23a47811e6f4d42ae6bd26b51dd1ae70 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 16 Oct 2020 00:01:58 +0200 Subject: [PATCH 04/11] Removed deprecated field --- commands/debug/debug.go | 4 -- rpc/debug/debug.pb.go | 156 ++++++++++++++++++---------------------- rpc/debug/debug.proto | 2 - 3 files changed, 71 insertions(+), 91 deletions(-) diff --git a/commands/debug/debug.go b/commands/debug/debug.go index 22c5e3ef559..cb4ecd0d115 100644 --- a/commands/debug/debug.go +++ b/commands/debug/debug.go @@ -109,10 +109,6 @@ func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream io.Reader, out // getCommandLine compose a debug command represented by a core recipe func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager) ([]string, error) { - if req.GetImportFile() != "" { - return nil, errors.New("the ImportFile parameter has been deprecated, use ImportDir instead") - } - debugInfo, err := GetDebugInfo(context.Background(), &dbg.GetDebugInfoReq{ Instance: req.GetInstance(), Fqbn: req.GetFqbn(), diff --git a/rpc/debug/debug.pb.go b/rpc/debug/debug.pb.go index a887e664b83..12a78d40fe7 100644 --- a/rpc/debug/debug.pb.go +++ b/rpc/debug/debug.pb.go @@ -136,10 +136,6 @@ type DebugConfigReq struct { Port string `protobuf:"bytes,4,opt,name=port,proto3" json:"port,omitempty"` // Which GDB command interpreter to use. Interpreter string `protobuf:"bytes,5,opt,name=interpreter,proto3" json:"interpreter,omitempty"` - // DEPRECATED: use import_dir instead - // - // Deprecated: Do not use. - ImportFile string `protobuf:"bytes,7,opt,name=import_file,json=importFile,proto3" json:"import_file,omitempty"` // Directory containing the compiled executable. If `import_dir` is not // specified, the executable is assumed to be in // `{sketch_path}/build/{fqbn}/`. @@ -213,14 +209,6 @@ func (x *DebugConfigReq) GetInterpreter() string { return "" } -// Deprecated: Do not use. -func (x *DebugConfigReq) GetImportFile() string { - if x != nil { - return x.ImportFile - } - return "" -} - func (x *DebugConfigReq) GetImportDir() string { if x != nil { return x.ImportDir @@ -500,7 +488,7 @@ var file_debug_debug_proto_rawDesc = []byte{ 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x65, 0x6e, 0x64, 0x5f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x72, 0x75, 0x70, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x73, 0x65, 0x6e, - 0x64, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x72, 0x75, 0x70, 0x74, 0x22, 0xfe, 0x01, 0x0a, 0x0e, 0x44, + 0x64, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x72, 0x75, 0x70, 0x74, 0x22, 0xd9, 0x01, 0x0a, 0x0e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, @@ -512,79 +500,77 @@ var file_debug_debug_proto_rawDesc = []byte{ 0x68, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x69, 0x6e, 0x74, 0x65, - 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x72, 0x12, 0x23, 0x0a, 0x0b, 0x69, 0x6d, 0x70, 0x6f, 0x72, - 0x74, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x42, 0x02, 0x18, 0x01, - 0x52, 0x0a, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x1d, 0x0a, 0x0a, - 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x09, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x22, 0x35, 0x0a, 0x09, 0x44, - 0x65, 0x62, 0x75, 0x67, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, - 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, - 0x6f, 0x72, 0x22, 0xb8, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, - 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, - 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, - 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, - 0x64, 0x73, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, - 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x6b, 0x65, - 0x74, 0x63, 0x68, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, - 0x73, 0x6b, 0x65, 0x74, 0x63, 0x68, 0x50, 0x61, 0x74, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, - 0x72, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1d, - 0x0a, 0x0a, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x22, 0xdf, 0x04, - 0x0a, 0x10, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, - 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x61, 0x62, - 0x6c, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, - 0x12, 0x25, 0x0a, 0x0e, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x70, 0x61, - 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x50, 0x61, 0x74, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x74, 0x6f, 0x6f, 0x6c, 0x63, - 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0f, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x50, 0x72, 0x65, 0x66, - 0x69, 0x78, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, - 0x72, 0x76, 0x65, 0x72, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x50, 0x61, 0x74, 0x68, 0x12, 0x7b, 0x0a, 0x17, 0x74, - 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x42, 0x2e, 0x63, - 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, - 0x62, 0x75, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, - 0x52, 0x65, 0x73, 0x70, 0x2e, 0x54, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x43, 0x6f, - 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, - 0x52, 0x16, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x72, 0x0a, 0x14, 0x73, 0x65, 0x72, 0x76, - 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x3f, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, - 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x47, 0x65, - 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x2e, 0x53, - 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x13, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, - 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x49, 0x0a, 0x1b, + 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x72, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x6d, 0x70, 0x6f, 0x72, + 0x74, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, 0x6d, 0x70, + 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x22, 0x35, 0x0a, 0x09, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, + 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0xb8, 0x01, + 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, + 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, + 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x49, 0x6e, + 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, + 0x12, 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x66, 0x71, 0x62, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x6b, 0x65, 0x74, 0x63, 0x68, 0x5f, 0x70, + 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x6b, 0x65, 0x74, 0x63, + 0x68, 0x50, 0x61, 0x74, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x6d, 0x70, + 0x6f, 0x72, 0x74, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, + 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x22, 0xdf, 0x04, 0x0a, 0x10, 0x47, 0x65, 0x74, + 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, + 0x0a, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x1c, 0x0a, + 0x09, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x09, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x74, + 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0d, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x50, 0x61, + 0x74, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, + 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x74, 0x6f, + 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x12, 0x16, 0x0a, + 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, + 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, + 0x70, 0x61, 0x74, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x72, 0x50, 0x61, 0x74, 0x68, 0x12, 0x7b, 0x0a, 0x17, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, + 0x61, 0x69, 0x6e, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x42, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, + 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x47, + 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x2e, 0x54, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, - 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x46, 0x0a, 0x18, 0x53, 0x65, 0x72, 0x76, 0x65, - 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, - 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, - 0xb8, 0x01, 0x0a, 0x05, 0x44, 0x65, 0x62, 0x75, 0x67, 0x12, 0x4e, 0x0a, 0x05, 0x44, 0x65, 0x62, - 0x75, 0x67, 0x12, 0x1e, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, - 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, - 0x65, 0x71, 0x1a, 0x1f, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, - 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, - 0x65, 0x73, 0x70, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x5f, 0x0a, 0x0c, 0x47, 0x65, 0x74, - 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x25, 0x2e, 0x63, 0x63, 0x2e, 0x61, - 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, - 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, - 0x1a, 0x26, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, - 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, - 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, - 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, - 0x2f, 0x64, 0x65, 0x62, 0x75, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x16, 0x74, 0x6f, 0x6f, + 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x12, 0x72, 0x0a, 0x14, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x63, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x08, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x3f, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, + 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, + 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, + 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x52, 0x13, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x49, 0x0a, 0x1b, 0x54, 0x6f, 0x6f, 0x6c, 0x63, + 0x68, 0x61, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, + 0x38, 0x01, 0x1a, 0x46, 0x0a, 0x18, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, + 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, + 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0xb8, 0x01, 0x0a, 0x05, 0x44, + 0x65, 0x62, 0x75, 0x67, 0x12, 0x4e, 0x0a, 0x05, 0x44, 0x65, 0x62, 0x75, 0x67, 0x12, 0x1e, 0x2e, + 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, + 0x65, 0x62, 0x75, 0x67, 0x2e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x1f, 0x2e, + 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, + 0x65, 0x62, 0x75, 0x67, 0x2e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, + 0x28, 0x01, 0x30, 0x01, 0x12, 0x5f, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, + 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x25, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, + 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, + 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x1a, 0x26, 0x2e, 0x63, 0x63, + 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, + 0x75, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, + 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x72, 0x64, 0x75, + 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x64, 0x65, 0x62, 0x75, + 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/rpc/debug/debug.proto b/rpc/debug/debug.proto index b7d0ef2b795..394377f91b2 100644 --- a/rpc/debug/debug.proto +++ b/rpc/debug/debug.proto @@ -64,8 +64,6 @@ message DebugConfigReq { string port = 4; // Which GDB command interpreter to use. string interpreter = 5; - // DEPRECATED: use import_dir instead - string import_file = 7 [deprecated = true]; // Directory containing the compiled executable. If `import_dir` is not // specified, the executable is assumed to be in // `{sketch_path}/build/{fqbn}/`. From f60193ca5306a3d788ceaca7206ef5fcc36d5f3c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 16 Oct 2020 00:09:09 +0200 Subject: [PATCH 05/11] Merged together DebugConfigReq protoc type It makes no sense to have two separate types to create a debug session or to create a debug configuration. --- cli/debug/debug.go | 28 ++- commands/daemon/debug.go | 6 +- commands/debug/debug.go | 2 +- commands/debug/debug_info.go | 16 +- rpc/debug/debug.pb.go | 333 ++++++++++++----------------------- rpc/debug/debug.proto | 23 +-- 6 files changed, 133 insertions(+), 275 deletions(-) diff --git a/cli/debug/debug.go b/cli/debug/debug.go index 6bda3c35c26..c1bf9394cd7 100644 --- a/cli/debug/debug.go +++ b/cli/debug/debug.go @@ -78,15 +78,18 @@ func run(command *cobra.Command, args []string) { } sketchPath := initSketchPath(path) + debugConfigRequested := &dbg.DebugConfigReq{ + Instance: instance, + Fqbn: fqbn, + SketchPath: sketchPath.String(), + Port: port, + Interpreter: interpreter, + ImportDir: importDir, + } + if printInfo { - if res, err := debug.GetDebugInfo(context.Background(), &dbg.GetDebugInfoReq{ - Instance: instance, - Fqbn: fqbn, - SketchPath: sketchPath.String(), - Port: port, - ImportDir: importDir, - }); err != nil { + if res, err := debug.GetDebugConfig(context.Background(), debugConfigRequested); err != nil { feedback.Errorf("Error getting Debug info: %v", err) os.Exit(errorcodes.ErrGeneric) } else { @@ -99,14 +102,7 @@ func run(command *cobra.Command, args []string) { ctrlc := make(chan os.Signal, 1) signal.Notify(ctrlc, os.Interrupt) - if _, err := debug.Debug(context.Background(), &dbg.DebugConfigReq{ - Instance: instance, - Fqbn: fqbn, - SketchPath: sketchPath.String(), - Port: port, - Interpreter: interpreter, - ImportDir: importDir, - }, os.Stdin, os.Stdout, ctrlc); err != nil { + if _, err := debug.Debug(context.Background(), debugConfigRequested, os.Stdin, os.Stdout, ctrlc); err != nil { feedback.Errorf("Error during Debug: %v", err) os.Exit(errorcodes.ErrGeneric) } @@ -130,7 +126,7 @@ func initSketchPath(sketchPath *paths.Path) *paths.Path { } type debugInfoResult struct { - info *dbg.GetDebugInfoResp + info *dbg.GetDebugConfigResp } func (r *debugInfoResult) Data() interface{} { diff --git a/commands/daemon/debug.go b/commands/daemon/debug.go index c2bba9a658c..88ea30eec9e 100644 --- a/commands/daemon/debug.go +++ b/commands/daemon/debug.go @@ -67,7 +67,7 @@ func (s *DebugService) Debug(stream dbg.Debug_DebugServer) error { return stream.Send(resp) } -// GetDebugInfo return metadata about a debug session -func (s *DebugService) GetDebugInfo(ctx context.Context, req *debug.GetDebugInfoReq) (*debug.GetDebugInfoResp, error) { - return cmd.GetDebugInfo(ctx, req) +// GetDebugConfig return metadata about a debug session +func (s *DebugService) GetDebugConfig(ctx context.Context, req *debug.DebugConfigReq) (*debug.GetDebugConfigResp, error) { + return cmd.GetDebugConfig(ctx, req) } diff --git a/commands/debug/debug.go b/commands/debug/debug.go index cb4ecd0d115..800fea5fe95 100644 --- a/commands/debug/debug.go +++ b/commands/debug/debug.go @@ -109,7 +109,7 @@ func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream io.Reader, out // getCommandLine compose a debug command represented by a core recipe func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager) ([]string, error) { - debugInfo, err := GetDebugInfo(context.Background(), &dbg.GetDebugInfoReq{ + debugInfo, err := GetDebugConfig(context.Background(), &dbg.DebugConfigReq{ Instance: req.GetInstance(), Fqbn: req.GetFqbn(), SketchPath: req.GetSketchPath(), diff --git a/commands/debug/debug_info.go b/commands/debug/debug_info.go index 01c49115272..60bb17ae561 100644 --- a/commands/debug/debug_info.go +++ b/commands/debug/debug_info.go @@ -31,8 +31,8 @@ import ( "github.com/sirupsen/logrus" ) -// GetDebugInfo returns metadata to start debugging with the specified board -func GetDebugInfo(ctx context.Context, req *debug.GetDebugInfoReq) (*debug.GetDebugInfoResp, error) { +// GetDebugConfig returns metadata to start debugging with the specified board +func GetDebugConfig(ctx context.Context, req *debug.DebugConfigReq) (*debug.GetDebugConfigResp, error) { pm := commands.GetPackageManager(req.GetInstance().GetId()) props, err := getDebugProperties(req, pm) @@ -42,7 +42,7 @@ func GetDebugInfo(ctx context.Context, req *debug.GetDebugInfoReq) (*debug.GetDe server := props.Get("server") toolchain := props.Get("toolchain") - resp := &debug.GetDebugInfoResp{ + resp := &debug.GetDebugConfigResp{ Executable: props.Get("executable"), Server: server, ServerPath: props.Get("server." + server + ".path"), @@ -55,15 +55,7 @@ func GetDebugInfo(ctx context.Context, req *debug.GetDebugInfoReq) (*debug.GetDe return resp, nil } -// Target represents a target for a debug action -type Target interface { - GetSketchPath() string - GetFqbn() string - GetImportDir() string - GetPort() string -} - -func getDebugProperties(req Target, pm *packagemanager.PackageManager) (*properties.Map, error) { +func getDebugProperties(req *debug.DebugConfigReq, pm *packagemanager.PackageManager) (*properties.Map, error) { // TODO: make a generic function to extract sketch from request // and remove duplication in commands/compile.go if req.GetSketchPath() == "" { diff --git a/rpc/debug/debug.pb.go b/rpc/debug/debug.pb.go index 12a78d40fe7..ccb02cf0862 100644 --- a/rpc/debug/debug.pb.go +++ b/rpc/debug/debug.pb.go @@ -47,7 +47,7 @@ const _ = proto.ProtoPackageIsVersion4 // The top-level message sent by the client for the `Debug` method. // Multiple `DebugReq` messages can be sent but the first message -// must contain a `DebugReq` message to initialize the debug session. +// must contain a `DebugConfigReq` message to initialize the debug session. // All subsequent messages must contain bytes to be sent to the debug session // and must not contain a `DebugReq` message. type DebugReq struct { @@ -274,95 +274,7 @@ func (x *DebugResp) GetError() string { return "" } -type GetDebugInfoReq struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // Arduino Core Service instance from the `Init` response. - Instance *commands.Instance `protobuf:"bytes,1,opt,name=instance,proto3" json:"instance,omitempty"` - // Fully qualified board name of the board in use - // (e.g., `arduino:samd:mkr1000`). If this is omitted, the FQBN attached to - // the sketch will be used. - Fqbn string `protobuf:"bytes,2,opt,name=fqbn,proto3" json:"fqbn,omitempty"` - // Path to the sketch that is running on the board. The compiled executable - // is expected to be located under this path. - SketchPath string `protobuf:"bytes,3,opt,name=sketch_path,json=sketchPath,proto3" json:"sketch_path,omitempty"` - // Port of the debugger (optional). - Port string `protobuf:"bytes,4,opt,name=port,proto3" json:"port,omitempty"` - // Directory containing the compiled executable. If `import_dir` is not - // specified, the executable is assumed to be in `{sketch_path}/build/{fqbn}/`. - ImportDir string `protobuf:"bytes,5,opt,name=import_dir,json=importDir,proto3" json:"import_dir,omitempty"` -} - -func (x *GetDebugInfoReq) Reset() { - *x = GetDebugInfoReq{} - if protoimpl.UnsafeEnabled { - mi := &file_debug_debug_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *GetDebugInfoReq) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetDebugInfoReq) ProtoMessage() {} - -func (x *GetDebugInfoReq) ProtoReflect() protoreflect.Message { - mi := &file_debug_debug_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetDebugInfoReq.ProtoReflect.Descriptor instead. -func (*GetDebugInfoReq) Descriptor() ([]byte, []int) { - return file_debug_debug_proto_rawDescGZIP(), []int{3} -} - -func (x *GetDebugInfoReq) GetInstance() *commands.Instance { - if x != nil { - return x.Instance - } - return nil -} - -func (x *GetDebugInfoReq) GetFqbn() string { - if x != nil { - return x.Fqbn - } - return "" -} - -func (x *GetDebugInfoReq) GetSketchPath() string { - if x != nil { - return x.SketchPath - } - return "" -} - -func (x *GetDebugInfoReq) GetPort() string { - if x != nil { - return x.Port - } - return "" -} - -func (x *GetDebugInfoReq) GetImportDir() string { - if x != nil { - return x.ImportDir - } - return "" -} - -type GetDebugInfoResp struct { +type GetDebugConfigResp struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields @@ -385,23 +297,23 @@ type GetDebugInfoResp struct { ServerConfiguration map[string]string `protobuf:"bytes,8,rep,name=server_configuration,json=serverConfiguration,proto3" json:"server_configuration,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } -func (x *GetDebugInfoResp) Reset() { - *x = GetDebugInfoResp{} +func (x *GetDebugConfigResp) Reset() { + *x = GetDebugConfigResp{} if protoimpl.UnsafeEnabled { - mi := &file_debug_debug_proto_msgTypes[4] + mi := &file_debug_debug_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } } -func (x *GetDebugInfoResp) String() string { +func (x *GetDebugConfigResp) String() string { return protoimpl.X.MessageStringOf(x) } -func (*GetDebugInfoResp) ProtoMessage() {} +func (*GetDebugConfigResp) ProtoMessage() {} -func (x *GetDebugInfoResp) ProtoReflect() protoreflect.Message { - mi := &file_debug_debug_proto_msgTypes[4] +func (x *GetDebugConfigResp) ProtoReflect() protoreflect.Message { + mi := &file_debug_debug_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -412,61 +324,61 @@ func (x *GetDebugInfoResp) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use GetDebugInfoResp.ProtoReflect.Descriptor instead. -func (*GetDebugInfoResp) Descriptor() ([]byte, []int) { - return file_debug_debug_proto_rawDescGZIP(), []int{4} +// Deprecated: Use GetDebugConfigResp.ProtoReflect.Descriptor instead. +func (*GetDebugConfigResp) Descriptor() ([]byte, []int) { + return file_debug_debug_proto_rawDescGZIP(), []int{3} } -func (x *GetDebugInfoResp) GetExecutable() string { +func (x *GetDebugConfigResp) GetExecutable() string { if x != nil { return x.Executable } return "" } -func (x *GetDebugInfoResp) GetToolchain() string { +func (x *GetDebugConfigResp) GetToolchain() string { if x != nil { return x.Toolchain } return "" } -func (x *GetDebugInfoResp) GetToolchainPath() string { +func (x *GetDebugConfigResp) GetToolchainPath() string { if x != nil { return x.ToolchainPath } return "" } -func (x *GetDebugInfoResp) GetToolchainPrefix() string { +func (x *GetDebugConfigResp) GetToolchainPrefix() string { if x != nil { return x.ToolchainPrefix } return "" } -func (x *GetDebugInfoResp) GetServer() string { +func (x *GetDebugConfigResp) GetServer() string { if x != nil { return x.Server } return "" } -func (x *GetDebugInfoResp) GetServerPath() string { +func (x *GetDebugConfigResp) GetServerPath() string { if x != nil { return x.ServerPath } return "" } -func (x *GetDebugInfoResp) GetToolchainConfiguration() map[string]string { +func (x *GetDebugConfigResp) GetToolchainConfiguration() map[string]string { if x != nil { return x.ToolchainConfiguration } return nil } -func (x *GetDebugInfoResp) GetServerConfiguration() map[string]string { +func (x *GetDebugConfigResp) GetServerConfiguration() map[string]string { if x != nil { return x.ServerConfiguration } @@ -505,72 +417,61 @@ var file_debug_debug_proto_rawDesc = []byte{ 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x22, 0x35, 0x0a, 0x09, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0xb8, 0x01, - 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, - 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, - 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x49, 0x6e, - 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, - 0x12, 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, - 0x66, 0x71, 0x62, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x6b, 0x65, 0x74, 0x63, 0x68, 0x5f, 0x70, - 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x6b, 0x65, 0x74, 0x63, - 0x68, 0x50, 0x61, 0x74, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x6d, 0x70, - 0x6f, 0x72, 0x74, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, - 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x22, 0xdf, 0x04, 0x0a, 0x10, 0x47, 0x65, 0x74, - 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, - 0x0a, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x1c, 0x0a, - 0x09, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x09, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x74, - 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0d, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x50, 0x61, - 0x74, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, - 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x74, 0x6f, - 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x12, 0x16, 0x0a, - 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, - 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, - 0x70, 0x61, 0x74, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, - 0x65, 0x72, 0x50, 0x61, 0x74, 0x68, 0x12, 0x7b, 0x0a, 0x17, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x42, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0xe5, 0x04, + 0x0a, 0x12, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x61, 0x62, + 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, + 0x61, 0x62, 0x6c, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, + 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, + 0x69, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, + 0x70, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x74, 0x6f, 0x6f, 0x6c, + 0x63, 0x68, 0x61, 0x69, 0x6e, 0x50, 0x61, 0x74, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x74, 0x6f, 0x6f, + 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0f, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x50, 0x72, + 0x65, 0x66, 0x69, 0x78, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x0b, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x50, 0x61, 0x74, 0x68, 0x12, 0x7d, 0x0a, + 0x17, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x44, + 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, + 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x2e, 0x54, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, + 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x52, 0x16, 0x74, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x74, 0x0a, 0x14, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x41, 0x2e, 0x63, 0x63, 0x2e, + 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, + 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x52, 0x65, 0x73, 0x70, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x13, 0x73, + 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x1a, 0x49, 0x0a, 0x1b, 0x54, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x46, 0x0a, + 0x18, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0xbb, 0x01, 0x0a, 0x05, 0x44, 0x65, 0x62, 0x75, 0x67, 0x12, + 0x4e, 0x0a, 0x05, 0x44, 0x65, 0x62, 0x75, 0x67, 0x12, 0x1e, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, + 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, + 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x1f, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, + 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, + 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, + 0x62, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x43, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x12, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, + 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x28, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x47, - 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x2e, - 0x54, 0x6f, 0x6f, 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x16, 0x74, 0x6f, 0x6f, - 0x6c, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x12, 0x72, 0x0a, 0x14, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x63, 0x6f, - 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x08, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x3f, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, - 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, - 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x52, 0x13, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x49, 0x0a, 0x1b, 0x54, 0x6f, 0x6f, 0x6c, 0x63, - 0x68, 0x61, 0x69, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, - 0x38, 0x01, 0x1a, 0x46, 0x0a, 0x18, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, - 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, - 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0xb8, 0x01, 0x0a, 0x05, 0x44, - 0x65, 0x62, 0x75, 0x67, 0x12, 0x4e, 0x0a, 0x05, 0x44, 0x65, 0x62, 0x75, 0x67, 0x12, 0x1e, 0x2e, - 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, - 0x65, 0x62, 0x75, 0x67, 0x2e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, 0x65, 0x71, 0x1a, 0x1f, 0x2e, - 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, - 0x65, 0x62, 0x75, 0x67, 0x2e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, - 0x28, 0x01, 0x30, 0x01, 0x12, 0x5f, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, - 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x25, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, - 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, 0x75, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, - 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x1a, 0x26, 0x2e, 0x63, 0x63, - 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x64, 0x65, 0x62, - 0x75, 0x67, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, - 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x72, 0x64, 0x75, - 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x64, 0x65, 0x62, 0x75, - 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x74, 0x44, 0x65, 0x62, 0x75, 0x67, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, + 0x70, 0x22, 0x00, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, + 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x64, 0x65, 0x62, 0x75, 0x67, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -585,32 +486,30 @@ func file_debug_debug_proto_rawDescGZIP() []byte { return file_debug_debug_proto_rawDescData } -var file_debug_debug_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_debug_debug_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_debug_debug_proto_goTypes = []interface{}{ - (*DebugReq)(nil), // 0: cc.arduino.cli.debug.DebugReq - (*DebugConfigReq)(nil), // 1: cc.arduino.cli.debug.DebugConfigReq - (*DebugResp)(nil), // 2: cc.arduino.cli.debug.DebugResp - (*GetDebugInfoReq)(nil), // 3: cc.arduino.cli.debug.GetDebugInfoReq - (*GetDebugInfoResp)(nil), // 4: cc.arduino.cli.debug.GetDebugInfoResp - nil, // 5: cc.arduino.cli.debug.GetDebugInfoResp.ToolchainConfigurationEntry - nil, // 6: cc.arduino.cli.debug.GetDebugInfoResp.ServerConfigurationEntry - (*commands.Instance)(nil), // 7: cc.arduino.cli.commands.Instance + (*DebugReq)(nil), // 0: cc.arduino.cli.debug.DebugReq + (*DebugConfigReq)(nil), // 1: cc.arduino.cli.debug.DebugConfigReq + (*DebugResp)(nil), // 2: cc.arduino.cli.debug.DebugResp + (*GetDebugConfigResp)(nil), // 3: cc.arduino.cli.debug.GetDebugConfigResp + nil, // 4: cc.arduino.cli.debug.GetDebugConfigResp.ToolchainConfigurationEntry + nil, // 5: cc.arduino.cli.debug.GetDebugConfigResp.ServerConfigurationEntry + (*commands.Instance)(nil), // 6: cc.arduino.cli.commands.Instance } var file_debug_debug_proto_depIdxs = []int32{ 1, // 0: cc.arduino.cli.debug.DebugReq.debugReq:type_name -> cc.arduino.cli.debug.DebugConfigReq - 7, // 1: cc.arduino.cli.debug.DebugConfigReq.instance:type_name -> cc.arduino.cli.commands.Instance - 7, // 2: cc.arduino.cli.debug.GetDebugInfoReq.instance:type_name -> cc.arduino.cli.commands.Instance - 5, // 3: cc.arduino.cli.debug.GetDebugInfoResp.toolchain_configuration:type_name -> cc.arduino.cli.debug.GetDebugInfoResp.ToolchainConfigurationEntry - 6, // 4: cc.arduino.cli.debug.GetDebugInfoResp.server_configuration:type_name -> cc.arduino.cli.debug.GetDebugInfoResp.ServerConfigurationEntry - 0, // 5: cc.arduino.cli.debug.Debug.Debug:input_type -> cc.arduino.cli.debug.DebugReq - 3, // 6: cc.arduino.cli.debug.Debug.GetDebugInfo:input_type -> cc.arduino.cli.debug.GetDebugInfoReq - 2, // 7: cc.arduino.cli.debug.Debug.Debug:output_type -> cc.arduino.cli.debug.DebugResp - 4, // 8: cc.arduino.cli.debug.Debug.GetDebugInfo:output_type -> cc.arduino.cli.debug.GetDebugInfoResp - 7, // [7:9] is the sub-list for method output_type - 5, // [5:7] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name + 6, // 1: cc.arduino.cli.debug.DebugConfigReq.instance:type_name -> cc.arduino.cli.commands.Instance + 4, // 2: cc.arduino.cli.debug.GetDebugConfigResp.toolchain_configuration:type_name -> cc.arduino.cli.debug.GetDebugConfigResp.ToolchainConfigurationEntry + 5, // 3: cc.arduino.cli.debug.GetDebugConfigResp.server_configuration:type_name -> cc.arduino.cli.debug.GetDebugConfigResp.ServerConfigurationEntry + 0, // 4: cc.arduino.cli.debug.Debug.Debug:input_type -> cc.arduino.cli.debug.DebugReq + 1, // 5: cc.arduino.cli.debug.Debug.GetDebugConfig:input_type -> cc.arduino.cli.debug.DebugConfigReq + 2, // 6: cc.arduino.cli.debug.Debug.Debug:output_type -> cc.arduino.cli.debug.DebugResp + 3, // 7: cc.arduino.cli.debug.Debug.GetDebugConfig:output_type -> cc.arduino.cli.debug.GetDebugConfigResp + 6, // [6:8] is the sub-list for method output_type + 4, // [4:6] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_debug_debug_proto_init() } @@ -656,19 +555,7 @@ func file_debug_debug_proto_init() { } } file_debug_debug_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetDebugInfoReq); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_debug_debug_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetDebugInfoResp); i { + switch v := v.(*GetDebugConfigResp); i { case 0: return &v.state case 1: @@ -686,7 +573,7 @@ func file_debug_debug_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_debug_debug_proto_rawDesc, NumEnums: 0, - NumMessages: 7, + NumMessages: 6, NumExtensions: 0, NumServices: 1, }, @@ -714,7 +601,7 @@ const _ = grpc.SupportPackageIsVersion6 type DebugClient interface { // Start a debug session and communicate with the debugger tool. Debug(ctx context.Context, opts ...grpc.CallOption) (Debug_DebugClient, error) - GetDebugInfo(ctx context.Context, in *GetDebugInfoReq, opts ...grpc.CallOption) (*GetDebugInfoResp, error) + GetDebugConfig(ctx context.Context, in *DebugConfigReq, opts ...grpc.CallOption) (*GetDebugConfigResp, error) } type debugClient struct { @@ -756,9 +643,9 @@ func (x *debugDebugClient) Recv() (*DebugResp, error) { return m, nil } -func (c *debugClient) GetDebugInfo(ctx context.Context, in *GetDebugInfoReq, opts ...grpc.CallOption) (*GetDebugInfoResp, error) { - out := new(GetDebugInfoResp) - err := c.cc.Invoke(ctx, "/cc.arduino.cli.debug.Debug/GetDebugInfo", in, out, opts...) +func (c *debugClient) GetDebugConfig(ctx context.Context, in *DebugConfigReq, opts ...grpc.CallOption) (*GetDebugConfigResp, error) { + out := new(GetDebugConfigResp) + err := c.cc.Invoke(ctx, "/cc.arduino.cli.debug.Debug/GetDebugConfig", in, out, opts...) if err != nil { return nil, err } @@ -769,7 +656,7 @@ func (c *debugClient) GetDebugInfo(ctx context.Context, in *GetDebugInfoReq, opt type DebugServer interface { // Start a debug session and communicate with the debugger tool. Debug(Debug_DebugServer) error - GetDebugInfo(context.Context, *GetDebugInfoReq) (*GetDebugInfoResp, error) + GetDebugConfig(context.Context, *DebugConfigReq) (*GetDebugConfigResp, error) } // UnimplementedDebugServer can be embedded to have forward compatible implementations. @@ -779,8 +666,8 @@ type UnimplementedDebugServer struct { func (*UnimplementedDebugServer) Debug(Debug_DebugServer) error { return status.Errorf(codes.Unimplemented, "method Debug not implemented") } -func (*UnimplementedDebugServer) GetDebugInfo(context.Context, *GetDebugInfoReq) (*GetDebugInfoResp, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetDebugInfo not implemented") +func (*UnimplementedDebugServer) GetDebugConfig(context.Context, *DebugConfigReq) (*GetDebugConfigResp, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetDebugConfig not implemented") } func RegisterDebugServer(s *grpc.Server, srv DebugServer) { @@ -813,20 +700,20 @@ func (x *debugDebugServer) Recv() (*DebugReq, error) { return m, nil } -func _Debug_GetDebugInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetDebugInfoReq) +func _Debug_GetDebugConfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DebugConfigReq) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(DebugServer).GetDebugInfo(ctx, in) + return srv.(DebugServer).GetDebugConfig(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cc.arduino.cli.debug.Debug/GetDebugInfo", + FullMethod: "/cc.arduino.cli.debug.Debug/GetDebugConfig", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(DebugServer).GetDebugInfo(ctx, req.(*GetDebugInfoReq)) + return srv.(DebugServer).GetDebugConfig(ctx, req.(*DebugConfigReq)) } return interceptor(ctx, in, info, handler) } @@ -836,8 +723,8 @@ var _Debug_serviceDesc = grpc.ServiceDesc{ HandlerType: (*DebugServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "GetDebugInfo", - Handler: _Debug_GetDebugInfo_Handler, + MethodName: "GetDebugConfig", + Handler: _Debug_GetDebugConfig_Handler, }, }, Streams: []grpc.StreamDesc{ diff --git a/rpc/debug/debug.proto b/rpc/debug/debug.proto index 394377f91b2..c0a5a313c60 100644 --- a/rpc/debug/debug.proto +++ b/rpc/debug/debug.proto @@ -27,12 +27,12 @@ service Debug { rpc Debug (stream DebugReq) returns (stream DebugResp) { } - rpc GetDebugInfo(GetDebugInfoReq) returns (GetDebugInfoResp) {} + rpc GetDebugConfig(DebugConfigReq) returns (GetDebugConfigResp) {} } // The top-level message sent by the client for the `Debug` method. // Multiple `DebugReq` messages can be sent but the first message -// must contain a `DebugReq` message to initialize the debug session. +// must contain a `DebugConfigReq` message to initialize the debug session. // All subsequent messages must contain bytes to be sent to the debug session // and must not contain a `DebugReq` message. message DebugReq { @@ -78,24 +78,7 @@ message DebugResp { string error = 2; } -message GetDebugInfoReq { - // Arduino Core Service instance from the `Init` response. - cc.arduino.cli.commands.Instance instance = 1; - // Fully qualified board name of the board in use - // (e.g., `arduino:samd:mkr1000`). If this is omitted, the FQBN attached to - // the sketch will be used. - string fqbn = 2; - // Path to the sketch that is running on the board. The compiled executable - // is expected to be located under this path. - string sketch_path = 3; - // Port of the debugger (optional). - string port = 4; - // Directory containing the compiled executable. If `import_dir` is not - // specified, the executable is assumed to be in `{sketch_path}/build/{fqbn}/`. - string import_dir = 5; -} - -message GetDebugInfoResp { +message GetDebugConfigResp { // The executable binary to debug string executable = 1; // The toolchain type used for the build (for example "gcc") From ee03f7b12be0e725ef6006b7670339008ac64908 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 16 Oct 2020 09:49:01 +0200 Subject: [PATCH 06/11] Debug: added programmer selection flag --- cli/debug/debug.go | 5 ++++- commands/debug/debug_info.go | 10 ++++++++++ rpc/debug/debug.pb.go | 15 +++++++++++++-- rpc/debug/debug.proto | 2 ++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cli/debug/debug.go b/cli/debug/debug.go index c1bf9394cd7..34ed29d1d92 100644 --- a/cli/debug/debug.go +++ b/cli/debug/debug.go @@ -43,6 +43,7 @@ var ( interpreter string importDir string printInfo bool + programmer string ) // NewCommand created a new `upload` command @@ -51,13 +52,14 @@ func NewCommand() *cobra.Command { Use: "debug", Short: "Debug Arduino sketches.", Long: "Debug Arduino sketches. (this command opens an interactive gdb session)", - Example: " " + os.Args[0] + " debug -b arduino:samd:mkr1000 /home/user/Arduino/MySketch", + Example: " " + os.Args[0] + " debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch", Args: cobra.MaximumNArgs(1), Run: run, } debugCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno") debugCommand.Flags().StringVarP(&port, "port", "p", "", "Debug port, e.g.: COM10 or /dev/ttyACM0") + debugCommand.Flags().StringVarP(&programmer, "programmer", "P", "", "Programmer to use for debugging") debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", "Debug interpreter e.g.: console, mi, mi1, mi2, mi3") debugCommand.Flags().StringVarP(&importDir, "input-dir", "", "", "Directory containing binaries for debug.") debugCommand.Flags().BoolVarP(&printInfo, "info", "I", false, "Show metadata about the debug session instead of starting the debugger.") @@ -85,6 +87,7 @@ func run(command *cobra.Command, args []string) { Port: port, Interpreter: interpreter, ImportDir: importDir, + Programmer: programmer, } if printInfo { diff --git a/commands/debug/debug_info.go b/commands/debug/debug_info.go index 60bb17ae561..2de0ecf58a5 100644 --- a/commands/debug/debug_info.go +++ b/commands/debug/debug_info.go @@ -105,6 +105,16 @@ func getDebugProperties(req *debug.DebugConfigReq, pm *packagemanager.PackageMan } } + if req.GetProgrammer() != "" { + if p, ok := platformRelease.Programmers[req.GetProgrammer()]; ok { + toolProperties.Merge(p.Properties) + } else if refP, ok := referencedPlatformRelease.Programmers[req.GetProgrammer()]; ok { + toolProperties.Merge(refP.Properties) + } else { + return nil, fmt.Errorf("programmer '%s' not found", req.GetProgrammer()) + } + } + var importPath *paths.Path if importDir := req.GetImportDir(); importDir != "" { importPath = paths.New(importDir) diff --git a/rpc/debug/debug.pb.go b/rpc/debug/debug.pb.go index ccb02cf0862..30f042c2af2 100644 --- a/rpc/debug/debug.pb.go +++ b/rpc/debug/debug.pb.go @@ -140,6 +140,8 @@ type DebugConfigReq struct { // specified, the executable is assumed to be in // `{sketch_path}/build/{fqbn}/`. ImportDir string `protobuf:"bytes,8,opt,name=import_dir,json=importDir,proto3" json:"import_dir,omitempty"` + // The programmer to use for debugging. + Programmer string `protobuf:"bytes,9,opt,name=programmer,proto3" json:"programmer,omitempty"` } func (x *DebugConfigReq) Reset() { @@ -216,6 +218,13 @@ func (x *DebugConfigReq) GetImportDir() string { return "" } +func (x *DebugConfigReq) GetProgrammer() string { + if x != nil { + return x.Programmer + } + return "" +} + // type DebugResp struct { state protoimpl.MessageState @@ -400,7 +409,7 @@ var file_debug_debug_proto_rawDesc = []byte{ 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x65, 0x6e, 0x64, 0x5f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x72, 0x75, 0x70, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x73, 0x65, 0x6e, - 0x64, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x72, 0x75, 0x70, 0x74, 0x22, 0xd9, 0x01, 0x0a, 0x0e, 0x44, + 0x64, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x72, 0x75, 0x70, 0x74, 0x22, 0xf9, 0x01, 0x0a, 0x0e, 0x44, 0x65, 0x62, 0x75, 0x67, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x12, 0x3d, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, @@ -414,7 +423,9 @@ var file_debug_debug_proto_rawDesc = []byte{ 0x65, 0x74, 0x65, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x70, 0x72, 0x65, 0x74, 0x65, 0x72, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, 0x6d, 0x70, - 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x22, 0x35, 0x0a, 0x09, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, + 0x6f, 0x72, 0x74, 0x44, 0x69, 0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x61, + 0x6d, 0x6d, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x67, + 0x72, 0x61, 0x6d, 0x6d, 0x65, 0x72, 0x22, 0x35, 0x0a, 0x09, 0x44, 0x65, 0x62, 0x75, 0x67, 0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0xe5, 0x04, diff --git a/rpc/debug/debug.proto b/rpc/debug/debug.proto index c0a5a313c60..087022173a3 100644 --- a/rpc/debug/debug.proto +++ b/rpc/debug/debug.proto @@ -68,6 +68,8 @@ message DebugConfigReq { // specified, the executable is assumed to be in // `{sketch_path}/build/{fqbn}/`. string import_dir = 8; + // The programmer to use for debugging. + string programmer = 9; } // From e2c4b8985f762ec933d950cce4273bdc7f77d6b0 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 19 Oct 2020 14:55:48 +0200 Subject: [PATCH 07/11] debug: return error if debugging is not supported by the platform --- cli/debug/debug.go | 5 +++++ cli/errorcodes/errorcodes.go | 18 ++++++++++++++++++ commands/debug/debug_info.go | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/cli/debug/debug.go b/cli/debug/debug.go index 34ed29d1d92..8e7c16b6134 100644 --- a/cli/debug/debug.go +++ b/cli/debug/debug.go @@ -33,6 +33,7 @@ import ( "github.com/fatih/color" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "google.golang.org/grpc/status" ) var ( @@ -93,6 +94,10 @@ func run(command *cobra.Command, args []string) { if printInfo { if res, err := debug.GetDebugConfig(context.Background(), debugConfigRequested); err != nil { + if status, ok := status.FromError(err); ok { + feedback.Errorf("Error getting Debug info: %v", status.Message()) + errorcodes.ExitWithGrpcStatus(status) + } feedback.Errorf("Error getting Debug info: %v", err) os.Exit(errorcodes.ErrGeneric) } else { diff --git a/cli/errorcodes/errorcodes.go b/cli/errorcodes/errorcodes.go index 777967e9460..529aead1efd 100644 --- a/cli/errorcodes/errorcodes.go +++ b/cli/errorcodes/errorcodes.go @@ -15,6 +15,13 @@ package errorcodes +import ( + "os" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + // Error codes to be used for os.Exit(). const ( _ = iota // 0 is not a valid exit error code @@ -29,3 +36,14 @@ const ( ErrCoreConfig ErrBadArgument ) + +// ExitWithGrpcStatus will terminate the current process by returing the correct +// error code closest matching the gRPC status. +func ExitWithGrpcStatus(s *status.Status) { + switch s.Code() { + case codes.Unimplemented: + os.Exit(ErrBadArgument) + default: + os.Exit(ErrGeneric) + } +} diff --git a/commands/debug/debug_info.go b/commands/debug/debug_info.go index 2de0ecf58a5..0b2a44407a1 100644 --- a/commands/debug/debug_info.go +++ b/commands/debug/debug_info.go @@ -29,6 +29,8 @@ import ( "github.com/arduino/go-properties-orderedmap" "github.com/pkg/errors" "github.com/sirupsen/logrus" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) // GetDebugConfig returns metadata to start debugging with the specified board @@ -150,5 +152,10 @@ func getDebugProperties(req *debug.DebugConfigReq, pm *packagemanager.PackageMan for k, v := range toolProperties.SubTree("debug").AsMap() { debugProperties.Set(k, toolProperties.ExpandPropsInString(v)) } + + if !debugProperties.ContainsKey("executable") { + return nil, status.Error(codes.Unimplemented, fmt.Sprintf("debugging not supported for board %s", req.GetFqbn())) + } + return debugProperties, nil } From d28f6dfe5dab0e2ff40fa81181a73fe9985dba88 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 19 Oct 2020 15:18:46 +0200 Subject: [PATCH 08/11] debug: openocd server now require full path to openocd executable --- commands/debug/debug.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/commands/debug/debug.go b/commands/debug/debug.go index 800fea5fe95..a150c1b8171 100644 --- a/commands/debug/debug.go +++ b/commands/debug/debug.go @@ -150,8 +150,7 @@ func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager) // Extract path to GDB Server switch debugInfo.GetServer() { case "openocd": - openocd := paths.New(debugInfo.ServerPath).Join("openocd") - serverCmd := fmt.Sprintf(`target extended-remote | "%s"`, openocd) + serverCmd := fmt.Sprintf(`target extended-remote | "%s"`, debugInfo.ServerPath) if cfg := debugInfo.ServerConfiguration["scripts_dir"]; cfg != "" { serverCmd += fmt.Sprintf(` -s "%s"`, cfg) From 80654552b351cca5e9e2cad931f70ebbc19e1907 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 19 Oct 2020 15:36:21 +0200 Subject: [PATCH 09/11] debug: fixed test runner --- commands/debug/debug.go | 8 +------- commands/debug/debug_info.go | 34 ++++++++++++++-------------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/commands/debug/debug.go b/commands/debug/debug.go index a150c1b8171..f40e1c7a2aa 100644 --- a/commands/debug/debug.go +++ b/commands/debug/debug.go @@ -109,13 +109,7 @@ func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream io.Reader, out // getCommandLine compose a debug command represented by a core recipe func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager) ([]string, error) { - debugInfo, err := GetDebugConfig(context.Background(), &dbg.DebugConfigReq{ - Instance: req.GetInstance(), - Fqbn: req.GetFqbn(), - SketchPath: req.GetSketchPath(), - ImportDir: req.GetImportDir(), - Port: req.GetPort(), - }) + debugInfo, err := getDebugProperties(req, pm) if err != nil { return nil, err } diff --git a/commands/debug/debug_info.go b/commands/debug/debug_info.go index 0b2a44407a1..cbec3ee8a50 100644 --- a/commands/debug/debug_info.go +++ b/commands/debug/debug_info.go @@ -37,27 +37,10 @@ import ( func GetDebugConfig(ctx context.Context, req *debug.DebugConfigReq) (*debug.GetDebugConfigResp, error) { pm := commands.GetPackageManager(req.GetInstance().GetId()) - props, err := getDebugProperties(req, pm) - if err != nil { - return nil, err - } - - server := props.Get("server") - toolchain := props.Get("toolchain") - resp := &debug.GetDebugConfigResp{ - Executable: props.Get("executable"), - Server: server, - ServerPath: props.Get("server." + server + ".path"), - ServerConfiguration: props.SubTree("server." + server).AsMap(), - Toolchain: toolchain, - ToolchainPath: props.Get("toolchain.path"), - ToolchainPrefix: props.Get("toolchain.prefix"), - ToolchainConfiguration: props.SubTree("toolchain." + toolchain).AsMap(), - } - return resp, nil + return getDebugProperties(req, pm) } -func getDebugProperties(req *debug.DebugConfigReq, pm *packagemanager.PackageManager) (*properties.Map, error) { +func getDebugProperties(req *debug.DebugConfigReq, pm *packagemanager.PackageManager) (*debug.GetDebugConfigResp, error) { // TODO: make a generic function to extract sketch from request // and remove duplication in commands/compile.go if req.GetSketchPath() == "" { @@ -157,5 +140,16 @@ func getDebugProperties(req *debug.DebugConfigReq, pm *packagemanager.PackageMan return nil, status.Error(codes.Unimplemented, fmt.Sprintf("debugging not supported for board %s", req.GetFqbn())) } - return debugProperties, nil + server := debugProperties.Get("server") + toolchain := debugProperties.Get("toolchain") + return &debug.GetDebugConfigResp{ + Executable: debugProperties.Get("executable"), + Server: server, + ServerPath: debugProperties.Get("server." + server + ".path"), + ServerConfiguration: debugProperties.SubTree("server." + server).AsMap(), + Toolchain: toolchain, + ToolchainPath: debugProperties.Get("toolchain.path"), + ToolchainPrefix: debugProperties.Get("toolchain.prefix"), + ToolchainConfiguration: debugProperties.SubTree("toolchain." + toolchain).AsMap(), + }, nil } From 60109a107b0890855c1f6210474230db0358f975 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 19 Oct 2020 15:47:50 +0200 Subject: [PATCH 10/11] debugger: Fixed command line tests --- commands/debug/debug.go | 12 ++++++--- commands/debug/debug_test.go | 16 ++++++------ .../arduino-test/samd/boards.txt | 2 -- .../arduino-test/samd/platform.txt | 26 ++++++++++++------- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/commands/debug/debug.go b/commands/debug/debug.go index f40e1c7a2aa..b35cc0c6eb2 100644 --- a/commands/debug/debug.go +++ b/commands/debug/debug.go @@ -21,6 +21,7 @@ import ( "io" "os" "path/filepath" + "runtime" "time" "github.com/arduino/arduino-cli/arduino/cores/packagemanager" @@ -121,7 +122,11 @@ func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager) var gdbPath *paths.Path switch debugInfo.GetToolchain() { case "gcc": - gdbPath = paths.New(debugInfo.ToolchainPath).Join(debugInfo.ToolchainPrefix + "gdb") + gdbexecutable := debugInfo.ToolchainPrefix + "gdb" + if runtime.GOOS == "windows" { + gdbexecutable += ".exe" + } + gdbPath = paths.New(debugInfo.ToolchainPath).Join(gdbexecutable) default: return nil, errors.Errorf("unsupported toolchain '%s'", debugInfo.GetToolchain()) } @@ -131,8 +136,9 @@ func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager) gdbInterpreter := req.GetInterpreter() if gdbInterpreter == "" { gdbInterpreter = "console" - } else { - add("--interpreter=" + gdbInterpreter) + } + add("--interpreter=" + gdbInterpreter) + if gdbInterpreter != "console" { add("-ex") add("set pagination off") } diff --git a/commands/debug/debug_test.go b/commands/debug/debug_test.go index 8d0fd57ad7f..7712ad455a9 100644 --- a/commands/debug/debug_test.go +++ b/commands/debug/debug_test.go @@ -53,12 +53,12 @@ func TestGetCommandLine(t *testing.T) { SketchPath: sketchPath.String(), } - goldCommand := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin//arm-none-eabi-gdb%s", dataDir, toolExtension) + - " --interpreter=console -ex target extended-remote |" + - fmt.Sprintf(" %s/arduino-test/tools/openocd/0.10.0-arduino7/bin/openocd%s", dataDir, toolExtension) + + goldCommand := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-gdb%s", dataDir, toolExtension) + + " --interpreter=console -ex set remotetimeout 5 -ex target extended-remote |" + + fmt.Sprintf(" \"%s/arduino-test/tools/openocd/0.10.0-arduino7/bin/openocd%s\"", dataDir, toolExtension) + fmt.Sprintf(" -s \"%s/arduino-test/tools/openocd/0.10.0-arduino7/share/openocd/scripts/\"", dataDir) + fmt.Sprintf(" --file \"%s/arduino-test/samd/variants/arduino_zero/openocd_scripts/arduino_zero.cfg\"", customHardware) + - fmt.Sprintf(" -c \"gdb_port pipe\" -c \"telnet_port 0\" -c init -c halt %s/build/arduino-test.samd.arduino_zero_edbg/hello.ino.elf", sketchPath) + fmt.Sprintf(" -c \"gdb_port pipe\" -c \"telnet_port 0\" %s/build/arduino-test.samd.arduino_zero_edbg/hello.ino.elf", sketchPath) command, err := getCommandLine(req, pm) require.Nil(t, err) @@ -74,12 +74,12 @@ func TestGetCommandLine(t *testing.T) { Interpreter: "mi1", } - goldCommand2 := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin//arm-none-eabi-gdb%s", dataDir, toolExtension) + - " --interpreter=mi1 -ex target extended-remote |" + - fmt.Sprintf(" %s/arduino-test/tools/openocd/0.10.0-arduino7/bin/openocd%s", dataDir, toolExtension) + + goldCommand2 := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-gdb%s", dataDir, toolExtension) + + " --interpreter=mi1 -ex set pagination off -ex set remotetimeout 5 -ex target extended-remote |" + + fmt.Sprintf(" \"%s/arduino-test/tools/openocd/0.10.0-arduino7/bin/openocd%s\"", dataDir, toolExtension) + fmt.Sprintf(" -s \"%s/arduino-test/tools/openocd/0.10.0-arduino7/share/openocd/scripts/\"", dataDir) + fmt.Sprintf(" --file \"%s/arduino-test/samd/variants/mkr1000/openocd_scripts/arduino_zero.cfg\"", customHardware) + - fmt.Sprintf(" -c \"gdb_port pipe\" -c \"telnet_port 0\" -c init -c halt %s/build/arduino-test.samd.mkr1000/hello.ino.elf", sketchPath) + fmt.Sprintf(" -c \"gdb_port pipe\" -c \"telnet_port 0\" %s/build/arduino-test.samd.mkr1000/hello.ino.elf", sketchPath) command2, err := getCommandLine(req2, pm) assert.Nil(t, err) diff --git a/commands/debug/testdata/custom_hardware/arduino-test/samd/boards.txt b/commands/debug/testdata/custom_hardware/arduino-test/samd/boards.txt index 033fb584fa7..ea2b1c6d3ff 100644 --- a/commands/debug/testdata/custom_hardware/arduino-test/samd/boards.txt +++ b/commands/debug/testdata/custom_hardware/arduino-test/samd/boards.txt @@ -20,7 +20,6 @@ arduino_zero_edbg.name=Arduino Zero (Programming Port) arduino_zero_edbg.vid.0=0x03eb arduino_zero_edbg.pid.0=0x2157 -arduino_zero_edbg.debug.tool=gdb-openocd arduino_zero_edbg.upload.tool=openocd arduino_zero_edbg.upload.protocol=sam-ba arduino_zero_edbg.upload.maximum_size=262144 @@ -55,7 +54,6 @@ mkr1000.pid.2=0x824e mkr1000.vid.3=0x2341 mkr1000.pid.3=0x024e -mkr1000.debug.tool=gdb-openocd mkr1000.upload.tool=bossac mkr1000.upload.protocol=sam-ba mkr1000.upload.maximum_size=262144 diff --git a/commands/debug/testdata/custom_hardware/arduino-test/samd/platform.txt b/commands/debug/testdata/custom_hardware/arduino-test/samd/platform.txt index 5e61eb4db44..13a012118e8 100644 --- a/commands/debug/testdata/custom_hardware/arduino-test/samd/platform.txt +++ b/commands/debug/testdata/custom_hardware/arduino-test/samd/platform.txt @@ -113,6 +113,22 @@ recipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_ou recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" recipe.size.regex=\.text\s+([0-9]+).* + +# Debugger configuration (general options) +# ---------------------------------------- +# EXPERIMENTAL feature: +# - this is alpha and may be subject to change without notice +debug.executable={build.path}/{build.project_name}.elf +debug.toolchain=gcc +debug.toolchain.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/ +debug.toolchain.prefix=arm-none-eabi- +debug.server=openocd +debug.server.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}/bin/openocd +debug.server.openocd.path.windows={runtime.tools.openocd-0.10.0-arduino7.path}/bin/openocd.exe +debug.server.openocd.scripts_dir={runtime.tools.openocd-0.10.0-arduino7.path}/share/openocd/scripts/ +debug.server.openocd.script={runtime.platform.path}/variants/{build.variant}/{build.openocdscript} + + # Upload/Debug tools # ------------------ @@ -219,13 +235,3 @@ tools.openocd-withbootsize.erase.pattern= tools.openocd-withbootsize.bootloader.params.verbose=-d2 tools.openocd-withbootsize.bootloader.params.quiet=-d0 tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown" - -# -# GDB (Debugger) -# - -tools.gdb-openocd.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/ -tools.gdb-openocd.cmd=arm-none-eabi-gdb -tools.gdb-openocd.cmd.windows=arm-none-eabi-gdb.exe -tools.gdb-openocd.interpreter=console -tools.gdb-openocd.debug.pattern="{path}/{cmd}" --interpreter={interpreter} -ex 'target extended-remote | {tools.openocd.path}/{tools.openocd.cmd} -s "{tools.openocd.path}/share/openocd/scripts/" --file "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "gdb_port pipe" -c "telnet_port 0" -c init -c halt' {build.path}/{build.project_name}.elf From 342ed72d1114aead03a4a61f359cc0384129c6f6 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 28 Oct 2020 16:32:00 +0100 Subject: [PATCH 11/11] debugger: hotfix for samd platforms 1.8.8 and 1.8.9 --- commands/debug/debug_info.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/commands/debug/debug_info.go b/commands/debug/debug_info.go index cbec3ee8a50..faad0987458 100644 --- a/commands/debug/debug_info.go +++ b/commands/debug/debug_info.go @@ -80,6 +80,20 @@ func getDebugProperties(req *debug.DebugConfigReq, pm *packagemanager.PackageMan toolProperties.Merge(platformRelease.RuntimeProperties()) toolProperties.Merge(boardProperties) + // HOTFIX: Remove me when the `arduino:samd` core is updated + if !toolProperties.ContainsKey("debug.executable") { + if platformRelease.String() == "arduino:samd@1.8.9" || platformRelease.String() == "arduino:samd@1.8.8" { + toolProperties.Set("debug.executable", "{build.path}/{build.project_name}.elf") + toolProperties.Set("debug.toolchain", "gcc") + toolProperties.Set("debug.toolchain.path", "{runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/") + toolProperties.Set("debug.toolchain.prefix", "arm-none-eabi-") + toolProperties.Set("debug.server", "openocd") + toolProperties.Set("debug.server.openocd.path", "{runtime.tools.openocd-0.10.0-arduino7.path}/bin/openocd") + toolProperties.Set("debug.server.openocd.scripts_dir", "{runtime.tools.openocd-0.10.0-arduino7.path}/share/openocd/scripts/") + toolProperties.Set("debug.server.openocd.script", "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}") + } + } + for _, tool := range pm.GetAllInstalledToolsReleases() { toolProperties.Merge(tool.RuntimeProperties()) }