gdb: No struct type named runtime.rtype #9326

Closed
andredasilvapinto opened this Issue Dec 15, 2014 · 19 comments

Projects

None yet
@andredasilvapinto

I'm having an error while trying to manually load runtime-gdb.py on GDB.

go1.4 linux/amd64
gdb 7.8
Ubuntu 14.04.1 LTS

gdb ./collect-jmx.test -d $GOROOT
...
(gdb) source /usr/local/go/src/runtime/runtime-gdb.py 
Loading Go Runtime support.
Traceback (most recent call last):
  File "/usr/local/go/src/runtime/runtime-gdb.py", line 205, in <module>
    _rctp_type = gdb.lookup_type("struct runtime.rtype").pointer()
gdb.error: No struct type named runtime.rtype.
@ianlancetaylor ianlancetaylor changed the title from GDB - No struct type named runtime.rtype to gdb: No struct type named runtime.rtype Dec 15, 2014
@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@bradfitz bradfitz removed the release-go1.5 label Dec 16, 2014
@pnasrat
pnasrat commented Dec 16, 2014

Replicated using https://github.com/golang/example/tree/master/stringutil

go test -c .

Using GDB:

gdb -q ./stringutil.test
Reading symbols from ./stringutil.test...done.
(gdb) source /usr/src/go/src/runtime/runtime-gdb.py
Loading Go Runtime support.
Traceback (most recent call last):
  File "/usr/src/go/src/runtime/runtime-gdb.py", line 205, in <module>
    _rctp_type = gdb.lookup_type("struct runtime.rtype").pointer()
gdb.error: No struct type named runtime.rtype.
(gdb) set pagination off
(gdb) set logging on
Copying output to gdb.txt.
(gdb) info types
# much output
(gdb) quit

Examining the types we see

grep runtime gdb.txt   | grep type;
struct []*runtime._type;
typedef struct runtime.iface error;
typedef struct runtime.iface flag.Value;
typedef struct runtime.iface flag.boolFlag;
typedef struct runtime.iface fmt.Formatter;
typedef struct runtime.iface fmt.GoStringer;
typedef struct runtime.iface fmt.Scanner;
typedef struct runtime.iface fmt.Stringer;
typedef struct runtime.iface fmt.runeUnreader;
typedef void (struct runtime.g *) func(*runtime.g);
typedef void (struct runtime.stkframe *, void *, bool *) func(*runtime.stkframe, unsafe.Pointer) bool;
typedef void (struct []runtime.StackRecord, int *, bool *) func([]runtime.StackRecord) (int, bool);
typedef struct runtime.iface interface { runtime.f() };
typedef struct runtime.eface interface {};
typedef struct runtime.iface io.Reader;
typedef struct runtime.iface io.ReaderFrom;
typedef struct runtime.iface io.RuneReader;
typedef struct runtime.iface io.Writer;
typedef struct runtime.iface io.WriterTo;
typedef struct hash<string,*runtime/pprof.Profile> * map[string]*runtime/pprof.Profile;
typedef struct runtime.iface os.FileInfo;
typedef struct runtime.iface os.Signal;
typedef struct runtime.iface reflect.Type;
typedef struct runtime.iface regexp.input;
struct runtime._type;
typedef runtime.bucketType;
struct runtime.chantype;
typedef struct runtime.iface runtime.fInterface;
struct runtime.functype;
struct runtime.interfacetype;
typedef runtime.intptr;
struct runtime.maptype;
typedef runtime.pageID;
struct runtime.ptrtype;
struct runtime.slicetype;
typedef struct runtime.iface runtime.stringer;
struct runtime.typeAlg;
typedef runtime.uintreg;
struct runtime.uncommontype;
typedef struct runtime.iface runtime/pprof.countProfile;
typedef struct runtime.iface sort.Interface;
typedef struct runtime.iface sync.Locker;
@pnasrat
pnasrat commented Dec 16, 2014

Looking at the dist source http://golang.org/src/runtime/type.h versus https://github.com/golang/go/blob/master/src/reflect/type.go

It kind of works (there seems to be some issue still) if I change runtime-gdb.py to lookup reflect.rtype. I can set a breakpoint and list and use next.

(gdb) break reverse.go:21
Breakpoint 1 at 0x45a4e0: file /go/src/stringutil/reverse.go, line 21.
Starting program: /go/src/stringutil/stringutil.test



^CPython Exception <class 'KeyboardInterrupt'> Quit:
Breakpoint 1, stringutil.Reverse (s="Hello, world", ~r1=) at /go/src/stringutil/reverse.go:21
21  func Reverse(s string) string {
(gdb) p s
$1 = "Hello, world"
@randall77
Contributor

Did you also try runtime._type? That's what runtime.type is now called.

@pnasrat
pnasrat commented Dec 16, 2014

@randall77 it's looking for runtime.rtype which was copied from reflect.rtype for gdb not _type

@pnasrat
pnasrat commented Dec 16, 2014

Would it be helpful to have some test cases for the python gdb support that could be run?

@ianlancetaylor
Contributor

Yes, I think some test cases would be helpful. We couldn't run them in all cases, but perhaps we could run them if a suitable version of gdb was installed.

@pnasrat
pnasrat commented Dec 16, 2014

OK I'll take a look at doing this but it may not be until next week.

@hustcat
hustcat commented Dec 30, 2014

+1 When I use gdb to debug docker, and I encountered the same problem.

Linux/CentOS 6.5
golang 1.3
gdb 7.2

@ianlancetaylor ianlancetaylor added a commit that closed this issue Jan 15, 2015
@pnasrat @ianlancetaylor pnasrat + ianlancetaylor runtime: fix runtime-gdb script loading
runtime.rtype was a copy of reflect.rtype - update script to use that directly.
Introduces a basic test which will skip on systems without appropriate GDB.

Fixes #9326

Change-Id: I6ec74e947bd2e1295492ca34b3a8c1b49315a8cb
Reviewed-on: https://go-review.googlesource.com/2821
Reviewed-by: Ian Lance Taylor <iant@golang.org>
a25af2e
@zhengzhiren

I have the same issue.
CentOS 6.5
gdb 7.9
golang 1.4.2

(gdb) source ~/go/src/runtime/runtime-gdb.py
Loading Go Runtime support.
Traceback (most recent call last):
  File "~/go/src/runtime/runtime-gdb.py", line 205, in <module>
gdb.error: No struct type named runtime.rtype.
@cevaris
cevaris commented Mar 8, 2015

👍

(gdb) source /go/src/runtime/runtime-gdb.py
Loading Go Runtime support.
Traceback (most recent call last):
  File "/go/src/runtime/runtime-gdb.py", line 205, in <module>
    _rctp_type = gdb.lookup_type("struct runtime.rtype").pointer()
gdb.error: No struct type named runtime.rtype.
(gdb)
@qingfeng-fy

you shold modify runtime-gdb.py:
205 _rctp_type = gdb.lookup_type("struct runtime.rtype").pointer()
206
207
208 def iface_commontype(obj):
209 if is_iface(obj):
210 go_type_ptr = obj['tab']['_type']
211 elif is_eface(obj):
212 go_type_ptr = obj['_type']
213 else:
214 return
215
216 return go_type_ptr.cast(_rctp_type).dereference()

to:
205 #_rctp_type = gdb.lookup_type("struct runtime.rtype").pointer()
206
207
208 def iface_commontype(obj):
209 if is_iface(obj):
210 go_type_ptr = obj['tab']['_type']
211 elif is_eface(obj):
212 go_type_ptr = obj['_type']
213 else:
214 return
215
216 # return go_type_ptr.cast(_rctp_type).dereference()
217 return go_type_ptr.cast(gdb.lookup_type("struct runtime.rtype").pointer()).dereference()

@anacrolix
Contributor

@qingfeng-fy Thanks for the suggestion, I recommend a diff next time. Unfortunately this only moves the error to later:

(gdb) info goroutine
Python Exception <class 'gdb.error'> There is no member named status.:
Error occurred in Python command: There is no member named status.

(gdb) goroutine 1
Python Exception <class 'ValueError'> need more than 1 value to unpack:
Error occurred in Python command: need more than 1 value to unpack

This makes it difficult to use gdb in addressing #5838

@minux
Member
minux commented May 23, 2015
@anacrolix
Contributor

I will give it a try, thank you. Have you considered backporting the fix to 1.4.3?

@minux
Member
minux commented May 24, 2015
@anacrolix
Contributor

It works for me on tip.

@MironWong

@anacrolix, i meet the same problem with you. i have run the stringutil.test in my platform and modify the runtime-gdb.py . who can tell me how to solve it?

Linux/CentOS 7.1
golang 1.4.2
gdb GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-64.el7

@davecheney
Contributor

@huangminlong this issue is fixed in Go 1.5 or later. Please open a new issue if you are still experiencing problems after upgrading to Go 1.5

@gopherbot gopherbot locked and limited conversation to collaborators Nov 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.