-
-
Notifications
You must be signed in to change notification settings - Fork 403
Implement debug feature #590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
3e861b7
Implement first draft of debugger gRPC service
0119a90
Working stdio streaming
cmaglie a106a4f
Improved stdio passing via GRPC
cmaglie b16874d
Adjusted protoc definitions
cmaglie d9077eb
Handle errors gracefully
cmaglie e86ae80
Add recipe calculation to debug command
879367b
First implementation of debug
cmaglie 7648814
updated client example for testing
3960fea
Implement debug command
5228709
Implement copyStream
9d314ab
Refactor stream helpers
8d44e6f
Extract recipe creation from debug command
9923f62
Add test for debug recipe generation
378b8bf
Cosmetics here and there
74fa6df
Refreshed client example
e8d9071
Replace with utils function
3888017
Remove debug leftover
e0e07c5
Refreshed client example
c2681b3
Moved debug proto to its package
11452d5
Removed sketch.json
a85376f
Apply general cosmetics
83cf94e
Add test binaries
da07d3d
Added test case for windows path flavor
abc9353
Use path.FromSlash to test debug tool command generation cross platfo…
fa39675
Avoid pipe leaking via closing readers and writes in case of abnormal…
3650865
Update client example to better catch gdb prompt
34e7854
Error messages cosmetics
5d9be12
Use errors.Wrap instead of fmt.Errorf
cmaglie 600c1d5
Use errors.Wrap instead of fmt.Errorf
cmaglie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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 [email protected]. | ||
|
||
package utils | ||
|
||
import "io" | ||
|
||
// FeedStreamTo creates a pipe to pass data to the writer function. | ||
// FeedStreamTo returns the io.Writer side of the pipe, on which the user can write data | ||
func FeedStreamTo(writer func(data []byte)) io.Writer { | ||
r, w := io.Pipe() | ||
go func() { | ||
data := make([]byte, 1024) | ||
for { | ||
if n, err := r.Read(data); err == nil { | ||
writer(data[:n]) | ||
} else { | ||
r.Close() | ||
return | ||
} | ||
} | ||
}() | ||
return w | ||
} | ||
|
||
// ConsumeStreamFrom creates a pipe to consume data from the reader function. | ||
// ConsumeStreamFrom returns the io.Reader side of the pipe, which the user can use to consume the data | ||
func ConsumeStreamFrom(reader func() ([]byte, error)) io.Reader { | ||
r, w := io.Pipe() | ||
go func() { | ||
for { | ||
if data, err := reader(); err != nil { | ||
if err == io.EOF { | ||
w.Close() | ||
} else { | ||
w.CloseWithError(err) | ||
} | ||
return | ||
} else if _, err := w.Write(data); err != nil { | ||
w.Close() | ||
return | ||
} | ||
} | ||
}() | ||
return r | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// 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 [email protected]. | ||
|
||
package debug | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"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/go-paths-helper" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
fqbn string | ||
port string | ||
verbose bool | ||
verify bool | ||
importFile string | ||
) | ||
|
||
// NewCommand created a new `upload` command | ||
func NewCommand() *cobra.Command { | ||
debugCommand := &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", | ||
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", "", "Upload port, e.g.: COM10 or /dev/ttyACM0") | ||
debugCommand.Flags().StringVarP(&importFile, "input", "i", "", "Input file to be uploaded for debug.") | ||
|
||
return debugCommand | ||
} | ||
|
||
func run(command *cobra.Command, args []string) { | ||
instance, err := instance.CreateInstance() | ||
if err != nil { | ||
feedback.Errorf("Error during Debug: %v", err) | ||
os.Exit(errorcodes.ErrGeneric) | ||
} | ||
|
||
var path *paths.Path | ||
if len(args) > 0 { | ||
path = paths.New(args[0]) | ||
} | ||
sketchPath := initSketchPath(path) | ||
|
||
if _, err := debug.Debug(context.Background(), &dbg.DebugConfigReq{ | ||
Instance: &dbg.Instance{Id: instance.GetId()}, | ||
Fqbn: fqbn, | ||
SketchPath: sketchPath.String(), | ||
Port: port, | ||
ImportFile: importFile, | ||
}, os.Stdin, os.Stdout); err != nil { | ||
feedback.Errorf("Error during Debug: %v", err) | ||
os.Exit(errorcodes.ErrGeneric) | ||
} | ||
} | ||
|
||
// initSketchPath returns the current working directory | ||
func initSketchPath(sketchPath *paths.Path) *paths.Path { | ||
if sketchPath != nil { | ||
return sketchPath | ||
} | ||
|
||
wd, err := paths.Getwd() | ||
if err != nil { | ||
feedback.Errorf("Couldn't get current working directory: %v", err) | ||
os.Exit(errorcodes.ErrGeneric) | ||
} | ||
logrus.Infof("Reading sketch from dir: %s", wd) | ||
return wd | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This says "to be uploaded", but I did not see any code that actually uploads? Instead, I think it assumes that this .elf file is already uploaded?