aboutsummaryrefslogtreecommitdiffhomepage
path: root/compileopts/target.go
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 /compileopts/target.go
parentf23ba3b02388fb9cac487c3db4053fab7c64dd5d (diff)
downloadtinygo-16e7dd83a309de207881e529e5f0e72978b05bc1.tar.gz
tinygo-16e7dd83a309de207881e529e5f0e72978b05bc1.zip
gdb: enable to specify multiple candidates for gdb
Diffstat (limited to 'compileopts/target.go')
-rw-r--r--compileopts/target.go21
1 files changed, 18 insertions, 3 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, ", ") + ")")
+}