Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved function and removed useless file
  • Loading branch information
cmaglie committed Aug 7, 2024
commit d14711ed629d0fa1f38f16f4da7b98f3f3657c1f
82 changes: 82 additions & 0 deletions commands/service_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import (
"context"
"errors"
"os"
"path/filepath"
"runtime"
"sync/atomic"

"github.com/arduino/arduino-cli/internal/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/internal/i18n"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -178,3 +181,82 @@ func (s *arduinoCoreServerImpl) Debug(stream rpc.ArduinoCoreService_DebugServer)
}
return sendResult(&rpc.DebugResponse_Result{})
}

// getCommandLine compose a debug command represented by a core recipe
func getCommandLine(req *rpc.GetDebugConfigRequest, pme *packagemanager.Explorer) ([]string, error) {
debugInfo, err := getDebugProperties(req, pme, false)
if err != nil {
return nil, err
}

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":
gdbexecutable := debugInfo.GetToolchainPrefix() + "-gdb"
if runtime.GOOS == "windows" {
gdbexecutable += ".exe"
}
gdbPath = paths.New(debugInfo.GetToolchainPath()).Join(gdbexecutable)
default:
return nil, &cmderrors.FailedDebugError{Message: i18n.Tr("Toolchain '%s' is not supported", debugInfo.GetToolchain())}
}
add(gdbPath.String())

// Set GDB interpreter (default value should be "console")
gdbInterpreter := req.GetInterpreter()
if gdbInterpreter == "" {
gdbInterpreter = "console"
}
add("--interpreter=" + gdbInterpreter)
if gdbInterpreter != "console" {
add("-ex")
add("set pagination off")
}

// Add extra GDB execution commands
add("-ex")
add("set remotetimeout 5")

// Extract path to GDB Server
switch debugInfo.GetServer() {
case "openocd":
var openocdConf rpc.DebugOpenOCDServerConfiguration
if err := debugInfo.GetServerConfiguration().UnmarshalTo(&openocdConf); err != nil {
return nil, err
}

serverCmd := fmt.Sprintf(`target extended-remote | "%s"`, debugInfo.GetServerPath())

if cfg := openocdConf.GetScriptsDir(); cfg != "" {
serverCmd += fmt.Sprintf(` -s "%s"`, cfg)
}

for _, script := range openocdConf.GetScripts() {
serverCmd += fmt.Sprintf(` --file "%s"`, script)
}

serverCmd += ` -c "gdb_port pipe"`
serverCmd += ` -c "telnet_port 0"`

add("-ex")
add(serverCmd)

default:
return nil, &cmderrors.FailedDebugError{Message: i18n.Tr("GDB server '%s' is not supported", debugInfo.GetServer())}
}

// Add executable
add(debugInfo.GetExecutable())

// 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
}
107 changes: 0 additions & 107 deletions commands/service_debug_run.go

This file was deleted.