main: add support for debugging qemu-user targets
This commit allows debugging like the following: GOARCH=arm tinygo gdb ./testdata/alias.go This can be very useful to debug issues on a different instruction set architecture but still on a host system. I tested the following 7 configurations to make sure it works and I didn't break anything: GOOS=amd64 GOOS=386 GOOS=arm GOOS=arm64 tinygo gdb -target=hifive1-qemu tinygo gdb -target=cortex-m-qemu tinygo gdb -target=microbit
Этот коммит содержится в:
родитель
05d2f2c412
коммит
7123941df0
2 изменённых файлов: 23 добавлений и 13 удалений
|
@ -240,7 +240,6 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
|
||||||
CFlags: []string{"--target=" + triple},
|
CFlags: []string{"--target=" + triple},
|
||||||
GDB: "gdb",
|
GDB: "gdb",
|
||||||
PortReset: "false",
|
PortReset: "false",
|
||||||
FlashMethod: "native",
|
|
||||||
}
|
}
|
||||||
if goos == "darwin" {
|
if goos == "darwin" {
|
||||||
spec.LDFlags = append(spec.LDFlags, "-Wl,-dead_strip")
|
spec.LDFlags = append(spec.LDFlags, "-Wl,-dead_strip")
|
||||||
|
@ -249,16 +248,15 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) {
|
||||||
}
|
}
|
||||||
if goarch != runtime.GOARCH {
|
if goarch != runtime.GOARCH {
|
||||||
// Some educated guesses as to how to invoke helper programs.
|
// Some educated guesses as to how to invoke helper programs.
|
||||||
|
spec.GDB = "gdb-multiarch"
|
||||||
if goarch == "arm" && goos == "linux" {
|
if goarch == "arm" && goos == "linux" {
|
||||||
spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf")
|
spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf")
|
||||||
spec.Linker = "arm-linux-gnueabihf-gcc"
|
spec.Linker = "arm-linux-gnueabihf-gcc"
|
||||||
spec.GDB = "arm-linux-gnueabihf-gdb"
|
|
||||||
spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-gnueabihf"}
|
spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-gnueabihf"}
|
||||||
}
|
}
|
||||||
if goarch == "arm64" && goos == "linux" {
|
if goarch == "arm64" && goos == "linux" {
|
||||||
spec.CFlags = append(spec.CFlags, "--sysroot=/usr/aarch64-linux-gnu")
|
spec.CFlags = append(spec.CFlags, "--sysroot=/usr/aarch64-linux-gnu")
|
||||||
spec.Linker = "aarch64-linux-gnu-gcc"
|
spec.Linker = "aarch64-linux-gnu-gcc"
|
||||||
spec.GDB = "aarch64-linux-gnu-gdb"
|
|
||||||
spec.Emulator = []string{"qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"}
|
spec.Emulator = []string{"qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"}
|
||||||
}
|
}
|
||||||
if goarch == "386" && runtime.GOARCH == "amd64" {
|
if goarch == "386" && runtime.GOARCH == "amd64" {
|
||||||
|
|
14
main.go
14
main.go
|
@ -351,13 +351,17 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
|
||||||
// Assume QEMU as an emulator.
|
// Assume QEMU as an emulator.
|
||||||
if config.Target.Emulator[0] == "mgba" {
|
if config.Target.Emulator[0] == "mgba" {
|
||||||
gdbInterface = "mgba"
|
gdbInterface = "mgba"
|
||||||
} else {
|
} else if strings.HasPrefix(config.Target.Emulator[0], "qemu-system-") {
|
||||||
gdbInterface = "qemu"
|
gdbInterface = "qemu"
|
||||||
|
} else {
|
||||||
|
gdbInterface = "qemu-user"
|
||||||
}
|
}
|
||||||
} else if openocdInterface != "" && config.Target.OpenOCDTarget != "" {
|
} else if openocdInterface != "" && config.Target.OpenOCDTarget != "" {
|
||||||
gdbInterface = "openocd"
|
gdbInterface = "openocd"
|
||||||
} else if config.Target.JLinkDevice != "" {
|
} else if config.Target.JLinkDevice != "" {
|
||||||
gdbInterface = "jlink"
|
gdbInterface = "jlink"
|
||||||
|
} else {
|
||||||
|
gdbInterface = "native"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,6 +413,14 @@ func FlashGDB(pkgName string, ocdOutput bool, options *compileopts.Options) erro
|
||||||
daemon = exec.Command(config.Target.Emulator[0], args...)
|
daemon = exec.Command(config.Target.Emulator[0], args...)
|
||||||
daemon.Stdout = os.Stdout
|
daemon.Stdout = os.Stdout
|
||||||
daemon.Stderr = os.Stderr
|
daemon.Stderr = os.Stderr
|
||||||
|
case "qemu-user":
|
||||||
|
gdbCommands = append(gdbCommands, "target remote :1234")
|
||||||
|
|
||||||
|
// Run in an emulator.
|
||||||
|
args := append(config.Target.Emulator[1:], "-g", "1234", result.Binary)
|
||||||
|
daemon = exec.Command(config.Target.Emulator[0], args...)
|
||||||
|
daemon.Stdout = os.Stdout
|
||||||
|
daemon.Stderr = os.Stderr
|
||||||
case "mgba":
|
case "mgba":
|
||||||
gdbCommands = append(gdbCommands, "target remote :2345")
|
gdbCommands = append(gdbCommands, "target remote :2345")
|
||||||
|
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче