gdb: enable to specify multiple candidates for gdb

Этот коммит содержится в:
sago35 2021-02-28 12:24:23 +09:00 коммит произвёл Ron Evans
родитель f23ba3b023
коммит 16e7dd83a3
7 изменённых файлов: 27 добавлений и 12 удалений

Просмотреть файл

@ -7,6 +7,7 @@ import (
"errors"
"io"
"os"
"os/exec"
"path/filepath"
"reflect"
"runtime"
@ -42,7 +43,7 @@ type TargetSpec struct {
ExtraFiles []string `json:"extra-files"`
Emulator []string `json:"emulator" override:"copy"` // inherited Emulator must not be append
FlashCommand string `json:"flash-command"`
GDB string `json:"gdb"`
GDB []string `json:"gdb"`
PortReset string `json:"flash-1200-bps-reset"`
FlashMethod string `json:"flash-method"`
FlashVolume string `json:"msd-volume-name"`
@ -240,7 +241,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
Compiler: "clang",
Linker: "cc",
CFlags: []string{"--target=" + triple},
GDB: "gdb",
GDB: []string{"gdb"},
PortReset: "false",
}
if goos == "darwin" {
@ -253,7 +254,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
}
if goarch != runtime.GOARCH {
// Some educated guesses as to how to invoke helper programs.
spec.GDB = "gdb-multiarch"
spec.GDB = []string{"gdb-multiarch"}
if goarch == "arm" && goos == "linux" {
spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf")
spec.Linker = "arm-linux-gnueabihf-gcc"
@ -271,3 +272,17 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
}
return &spec, nil
}
// LookupGDB looks up a gdb executable.
func (spec *TargetSpec) LookupGDB() (string, error) {
if len(spec.GDB) == 0 {
return "", errors.New("gdb not configured in the target specification")
}
for _, d := range spec.GDB {
_, err := exec.LookPath(d)
if err == nil {
return d, nil
}
}
return "", errors.New("no gdb found configured in the target specification (" + strings.Join(spec.GDB, ", ") + ")")
}

Просмотреть файл

@ -344,8 +344,9 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
if err != nil {
return err
}
if config.Target.GDB == "" {
return errors.New("gdb not configured in the target specification")
gdb, err := config.Target.LookupGDB()
if err != nil {
return err
}
return builder.Build(pkgName, "", config, func(result builder.BuildResult) error {
@ -490,7 +491,7 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
for _, cmd := range gdbCommands {
params = append(params, "-ex", cmd)
}
cmd := executeCommand(config.Options, config.Target.GDB, params...)
cmd := executeCommand(config.Options, gdb, params...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

Просмотреть файл

@ -19,5 +19,5 @@
"src/internal/task/task_stack_avr.S",
"src/runtime/gc_avr.S"
],
"gdb": "avr-gdb"
"gdb": ["avr-gdb"]
}

Просмотреть файл

@ -28,5 +28,5 @@
"src/internal/task/task_stack_cortexm.S",
"src/runtime/gc_arm.S"
],
"gdb": "gdb-multiarch"
"gdb": ["gdb-multiarch", "arm-none-eabi-gdb"]
}

Просмотреть файл

@ -4,6 +4,5 @@
"cflags": [
"--target=armv7em-none-eabi",
"-Qunused-arguments"
],
"gdb": "arm-none-eabi-gdb"
]
}

Просмотреть файл

@ -27,6 +27,6 @@
"targets/gameboy-advance.s",
"src/runtime/gc_arm.S"
],
"gdb": "gdb-multiarch",
"gdb": ["gdb-multiarch"],
"emulator": ["mgba", "-3"]
}

Просмотреть файл

@ -21,5 +21,5 @@
"src/runtime/gc_riscv.S",
"src/device/riscv/handleinterrupt.S"
],
"gdb": "riscv64-unknown-elf-gdb"
"gdb": ["riscv64-unknown-elf-gdb"]
}