Commit 810a499b authored by Shenghou Ma's avatar Shenghou Ma Committed by Minux Ma

cmd/ld: restore .debug_gdb_script section after runtime reorganization

On some systems, gdb refuses to load Python plugin from arbitrary
paths, so we have to add $GOROOT/src/runtime to auto-load-safe-path
in the gdb script test.

Change-Id: Icc44baab8d04a65bd21ceac2ab8ddb13c8d083e8
Reviewed-on: https://go-review.googlesource.com/2905Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 7e43aee3
...@@ -1414,7 +1414,7 @@ movetomodule(DWDie *parent) ...@@ -1414,7 +1414,7 @@ movetomodule(DWDie *parent)
die->link = parent->child; die->link = parent->child;
} }
// If the pcln table contains runtime/string.goc, use that to set gdbscript path. // If the pcln table contains runtime/runtime.go, use that to set gdbscript path.
static void static void
finddebugruntimepath(LSym *s) finddebugruntimepath(LSym *s)
{ {
...@@ -1427,7 +1427,7 @@ finddebugruntimepath(LSym *s) ...@@ -1427,7 +1427,7 @@ finddebugruntimepath(LSym *s)
for(i=0; i<s->pcln->nfile; i++) { for(i=0; i<s->pcln->nfile; i++) {
f = s->pcln->file[i]; f = s->pcln->file[i];
if((p = strstr(f->name, "runtime/string.goc")) != nil) { if((p = strstr(f->name, "runtime/runtime.go")) != nil) {
*p = '\0'; *p = '\0';
snprint(gdbscript, sizeof gdbscript, "%sruntime/runtime-gdb.py", f->name); snprint(gdbscript, sizeof gdbscript, "%sruntime/runtime-gdb.py", f->name);
*p = 'r'; *p = 'r';
......
package runtime_test package runtime_test
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime"
"testing" "testing"
) )
func checkGdbPython(t *testing.T) { func checkGdbPython(t *testing.T) {
cmd := exec.Command("gdb", "-nx", "-q", "--batch", "-ex", "python import sys; print('golang gdb python support')") cmd := exec.Command("gdb", "-nx", "-q", "--batch", "-ex", "python import sys; print('go gdb python support')")
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
t.Skipf("skipping due to issue running gdb%v", err) t.Skipf("skipping due to issue running gdb: %v", err)
} }
if string(out) != "golang gdb python support\n" { if string(out) != "go gdb python support\n" {
t.Skipf("skipping due to lack of python gdb support: %s", out) t.Skipf("skipping due to lack of python gdb support: %s", out)
} }
} }
...@@ -29,7 +31,6 @@ func main() { ...@@ -29,7 +31,6 @@ func main() {
` `
func TestGdbLoadRuntimeSupport(t *testing.T) { func TestGdbLoadRuntimeSupport(t *testing.T) {
checkGdbPython(t) checkGdbPython(t)
dir, err := ioutil.TempDir("", "go-build") dir, err := ioutil.TempDir("", "go-build")
...@@ -51,7 +52,8 @@ func TestGdbLoadRuntimeSupport(t *testing.T) { ...@@ -51,7 +52,8 @@ func TestGdbLoadRuntimeSupport(t *testing.T) {
t.Fatalf("building source %v\n%s", err, out) t.Fatalf("building source %v\n%s", err, out)
} }
got, _ := exec.Command("gdb", "-nx", "-q", "--batch", "-ex", "source runtime-gdb.py", got, _ := exec.Command("gdb", "-nx", "-q", "--batch", "-iex",
fmt.Sprintf("add-auto-load-safe-path %s/src/runtime", runtime.GOROOT()),
filepath.Join(dir, "a.exe")).CombinedOutput() filepath.Join(dir, "a.exe")).CombinedOutput()
if string(got) != "Loading Go Runtime support.\n" { if string(got) != "Loading Go Runtime support.\n" {
t.Fatalf("%s", got) t.Fatalf("%s", got)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment