aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorsago35 <[email protected]>2021-02-28 12:24:23 +0900
committerRon Evans <[email protected]>2021-03-29 00:21:38 +0200
commit16e7dd83a309de207881e529e5f0e72978b05bc1 (patch)
treefc3e4605ed766376339d4fd8ae1827981ada1122
parentf23ba3b02388fb9cac487c3db4053fab7c64dd5d (diff)
downloadtinygo-16e7dd83a309de207881e529e5f0e72978b05bc1.tar.gz
tinygo-16e7dd83a309de207881e529e5f0e72978b05bc1.zip
gdb: enable to specify multiple candidates for gdb
-rw-r--r--compileopts/target.go21
-rw-r--r--main.go7
-rw-r--r--targets/avr.json2
-rw-r--r--targets/cortex-m.json2
-rw-r--r--targets/cortex-m7.json3
-rw-r--r--targets/gameboy-advance.json2
-rw-r--r--targets/riscv.json2
7 files changed, 27 insertions, 12 deletions
diff --git a/compileopts/target.go b/compileopts/target.go
index 6ca0a0fc5..acff0e023 100644
--- a/compileopts/target.go
+++ b/compileopts/target.go
@@ -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, ", ") + ")")
+}
diff --git a/main.go b/main.go
index dbcbc4d83..e095d2168 100644
--- a/main.go
+++ b/main.go
@@ -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
diff --git a/targets/avr.json b/targets/avr.json
index 6c465176e..10aca60f1 100644
--- a/targets/avr.json
+++ b/targets/avr.json
@@ -19,5 +19,5 @@
"src/internal/task/task_stack_avr.S",
"src/runtime/gc_avr.S"
],
- "gdb": "avr-gdb"
+ "gdb": ["avr-gdb"]
}
diff --git a/targets/cortex-m.json b/targets/cortex-m.json
index 6f031546c..bdff605fb 100644
--- a/targets/cortex-m.json
+++ b/targets/cortex-m.json
@@ -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"]
}
diff --git a/targets/cortex-m7.json b/targets/cortex-m7.json
index 427808669..9b0097581 100644
--- a/targets/cortex-m7.json
+++ b/targets/cortex-m7.json
@@ -4,6 +4,5 @@
"cflags": [
"--target=armv7em-none-eabi",
"-Qunused-arguments"
- ],
- "gdb": "arm-none-eabi-gdb"
+ ]
}
diff --git a/targets/gameboy-advance.json b/targets/gameboy-advance.json
index 0675622c4..9fcdb30af 100644
--- a/targets/gameboy-advance.json
+++ b/targets/gameboy-advance.json
@@ -27,6 +27,6 @@
"targets/gameboy-advance.s",
"src/runtime/gc_arm.S"
],
- "gdb": "gdb-multiarch",
+ "gdb": ["gdb-multiarch"],
"emulator": ["mgba", "-3"]
}
diff --git a/targets/riscv.json b/targets/riscv.json
index 3b727992c..c2313e57d 100644
--- a/targets/riscv.json
+++ b/targets/riscv.json
@@ -21,5 +21,5 @@
"src/runtime/gc_riscv.S",
"src/device/riscv/handleinterrupt.S"
],
- "gdb": "riscv64-unknown-elf-gdb"
+ "gdb": ["riscv64-unknown-elf-gdb"]
}