diff --git a/src/cmd/compile/internal/gc/obj.go b/src/cmd/compile/internal/gc/obj.go index ff9889750e7..8d814f89e82 100644 --- a/src/cmd/compile/internal/gc/obj.go +++ b/src/cmd/compile/internal/gc/obj.go @@ -219,14 +219,15 @@ func dumpGlobal(n *Node) { func dumpGlobalConst(n *Node) { // only export typed constants - if n.Type == nil { + t := n.Type + if t == nil { return } if n.Sym.Pkg != localpkg { return } // only export integer constants for now - switch n.Type.Etype { + switch t.Etype { case TINT8: case TINT16: case TINT32: @@ -239,10 +240,20 @@ func dumpGlobalConst(n *Node) { case TUINT: case TUINTPTR: // ok + case TIDEAL: + if !Isconst(n, CTINT) { + return + } + x := n.Val().U.(*Mpint) + if x.Cmp(minintval[TINT]) < 0 || x.Cmp(maxintval[TINT]) > 0 { + return + } + // Ideal integers we export as int (if they fit). + t = types.Types[TINT] default: return } - Ctxt.DwarfIntConst(myimportpath, n.Sym.Name, typesymname(n.Type), n.Int64()) + Ctxt.DwarfIntConst(myimportpath, n.Sym.Name, typesymname(t), n.Int64()) } func dumpglobls() { diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go index a190aa28d1b..03194bcd58e 100644 --- a/src/runtime/runtime-gdb_test.go +++ b/src/runtime/runtime-gdb_test.go @@ -427,6 +427,7 @@ func TestGdbConst(t *testing.T) { "-ex", "print main.largeConstant", "-ex", "print main.minusOne", "-ex", "print 'runtime._MSpanInUse'", + "-ex", "print 'runtime._PageSize'", filepath.Join(dir, "a.exe"), } got, _ := exec.Command("gdb", args...).CombinedOutput() @@ -435,7 +436,7 @@ func TestGdbConst(t *testing.T) { t.Logf("output %q", sgot) - if !strings.Contains(sgot, "\n$1 = 42\n$2 = 18446744073709551615\n$3 = -1\n$4 = 1 '\\001'") { + if !strings.Contains(sgot, "\n$1 = 42\n$2 = 18446744073709551615\n$3 = -1\n$4 = 1 '\\001'\n$5 = 8192") { t.Fatalf("output mismatch") } }