diff options
| author | Lee Packham <lpackham@gmail.com> | 2015-03-30 17:36:49 +0100 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2015-03-30 23:59:24 +0000 |
| commit | c45751e8a50d6050c6090d654364d69599b2e97a (patch) | |
| tree | 04ebb4f8d4ea3aae7107de5acaf915b745c53a5f /src | |
| parent | 6ca91d264f521a132e5b4c3232bb3850f017d021 (diff) | |
| download | go-c45751e8a50d6050c6090d654364d69599b2e97a.tar.xz | |
runtime: allow pointers to strings to be printed
Being able to printer pointers to strings means one will able to output
the result of things like the flag library and other components that use
string pointers.
While here, adjusted the tests for gdb to test original string pretty
printing as well as pointers to them. It was doing it via the map before
but for completeness this ensures it's tested as a unit.
Change-Id: I4926547ae4fa6c85ef74301e7d96d49ba4a7b0c6
Reviewed-on: https://go-review.googlesource.com/8217
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/runtime/runtime-gdb.py | 2 | ||||
| -rw-r--r-- | src/runtime/runtime-gdb_test.go | 22 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/runtime/runtime-gdb.py b/src/runtime/runtime-gdb.py index 9f2ba9f934..c70aea71bb 100644 --- a/src/runtime/runtime-gdb.py +++ b/src/runtime/runtime-gdb.py @@ -60,7 +60,7 @@ class SliceValue: class StringTypePrinter: "Pretty print Go strings." - pattern = re.compile(r'^struct string$') + pattern = re.compile(r'^struct string( \*)?$') def __init__(self, val): self.val = val diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go index 7184120122..7569d07466 100644 --- a/src/runtime/runtime-gdb_test.go +++ b/src/runtime/runtime-gdb_test.go @@ -31,7 +31,10 @@ func main() { mapvar := make(map[string]string,5) mapvar["abc"] = "def" mapvar["ghi"] = "jkl" - fmt.Println("hi") // line 8 + strvar := "abc" + ptrvar := &strvar + fmt.Println("hi") // line 10 + _ = ptrvar } ` @@ -63,7 +66,7 @@ func TestGdbPython(t *testing.T) { got, _ := exec.Command("gdb", "-nx", "-q", "--batch", "-iex", fmt.Sprintf("add-auto-load-safe-path %s/src/runtime", runtime.GOROOT()), - "-ex", "br main.go:8", + "-ex", "br main.go:10", "-ex", "run", "-ex", "echo BEGIN info goroutines\n", "-ex", "info goroutines", @@ -71,6 +74,12 @@ func TestGdbPython(t *testing.T) { "-ex", "echo BEGIN print mapvar\n", "-ex", "print mapvar", "-ex", "echo END\n", + "-ex", "echo BEGIN print strvar\n", + "-ex", "print strvar", + "-ex", "echo END\n", + "-ex", "echo BEGIN print ptrvar\n", + "-ex", "print ptrvar", + "-ex", "echo END\n", filepath.Join(dir, "a.exe")).CombinedOutput() firstLine := bytes.SplitN(got, []byte("\n"), 2)[0] @@ -94,4 +103,13 @@ func TestGdbPython(t *testing.T) { if bl := blocks["print mapvar"]; !printMapvarRe.MatchString(bl) { t.Fatalf("print mapvar failed: %s", bl) } + + strVarRe := regexp.MustCompile(`\Q = "abc"\E$`) + if bl := blocks["print strvar"]; !strVarRe.MatchString(bl) { + t.Fatalf("print strvar failed: %s", bl) + } + + if bl := blocks["print ptrvar"]; !strVarRe.MatchString(bl) { + t.Fatalf("print ptrvar failed: %s", bl) + } } |
