2008-06-21 16:36:23 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "runtime.h"
|
2010-03-23 18:01:17 -06:00
|
|
|
#include "malloc.h"
|
2008-06-21 16:36:23 -06:00
|
|
|
|
2010-05-21 15:40:21 -06:00
|
|
|
static uintptr isclosureentry(uintptr);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
void runtime·deferproc(void);
|
|
|
|
void runtime·newproc(void);
|
2010-05-21 15:40:21 -06:00
|
|
|
|
2010-03-23 18:01:17 -06:00
|
|
|
// This code is also used for the 386 tracebacks.
|
|
|
|
// Use uintptr for an appropriate word-sized integer.
|
|
|
|
|
|
|
|
// Generic traceback. Handles runtime stack prints (pcbuf == nil)
|
|
|
|
// as well as the runtime.Callers function (pcbuf != nil).
|
|
|
|
// A little clunky to merge the two but avoids duplicating
|
|
|
|
// the code and all its subtlety.
|
|
|
|
static int32
|
|
|
|
gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m)
|
2008-06-21 16:36:23 -06:00
|
|
|
{
|
2010-03-23 18:01:17 -06:00
|
|
|
byte *p;
|
2010-05-21 15:40:21 -06:00
|
|
|
int32 i, n, iter, nascent;
|
2010-10-07 04:45:40 -06:00
|
|
|
uintptr pc, tracepc, *fp;
|
clean stack trace code.
format is unchanged but shows all frames
(old loop stopped one frame early).
wreck=; 6.out
cannot convert type *main.S·interface2 to interface main.I·interface2: missing method Foo
throw: interface conversion
SIGSEGV: segmentation violation
Faulting address: 0x0
pc: 0x256d
throw+0x46 /home/rsc/go/src/runtime/runtime.c:68
throw(0x863a, 0x0)
hashmap+0x188 /home/rsc/go/src/runtime/iface.c:167
hashmap(0x8760, 0x0, 0x85b0, 0x0, 0x0, ...)
sys·ifaceT2I+0xa8 /home/rsc/go/src/runtime/iface.c:201
sys·ifaceT2I(0x8760, 0x0, 0x85b0, 0x0, 0x0, ...)
main·main+0x4e /home/rsc/go/src/runtime/rt0_amd64_darwin.s:87
main·main()
mainstart+0xf /home/rsc/go/src/runtime/rt0_amd64.s:70
mainstart()
sys·goexit /home/rsc/go/src/runtime/proc.c:110
sys·goexit()
R=r
DELTA=44 (5 added, 15 deleted, 24 changed)
OCL=20358
CL=20368
2008-12-03 15:20:23 -07:00
|
|
|
Stktop *stk;
|
2008-11-23 18:08:55 -07:00
|
|
|
Func *f;
|
2010-03-23 18:01:17 -06:00
|
|
|
|
|
|
|
pc = (uintptr)pc0;
|
2008-06-21 16:36:23 -06:00
|
|
|
|
clean stack trace code.
format is unchanged but shows all frames
(old loop stopped one frame early).
wreck=; 6.out
cannot convert type *main.S·interface2 to interface main.I·interface2: missing method Foo
throw: interface conversion
SIGSEGV: segmentation violation
Faulting address: 0x0
pc: 0x256d
throw+0x46 /home/rsc/go/src/runtime/runtime.c:68
throw(0x863a, 0x0)
hashmap+0x188 /home/rsc/go/src/runtime/iface.c:167
hashmap(0x8760, 0x0, 0x85b0, 0x0, 0x0, ...)
sys·ifaceT2I+0xa8 /home/rsc/go/src/runtime/iface.c:201
sys·ifaceT2I(0x8760, 0x0, 0x85b0, 0x0, 0x0, ...)
main·main+0x4e /home/rsc/go/src/runtime/rt0_amd64_darwin.s:87
main·main()
mainstart+0xf /home/rsc/go/src/runtime/rt0_amd64.s:70
mainstart()
sys·goexit /home/rsc/go/src/runtime/proc.c:110
sys·goexit()
R=r
DELTA=44 (5 added, 15 deleted, 24 changed)
OCL=20358
CL=20368
2008-12-03 15:20:23 -07:00
|
|
|
// If the PC is zero, it's likely a nil function call.
|
|
|
|
// Start in the caller's frame.
|
|
|
|
if(pc == 0) {
|
2010-03-23 18:01:17 -06:00
|
|
|
pc = *(uintptr*)sp;
|
|
|
|
sp += sizeof(uintptr);
|
2008-11-03 16:22:15 -07:00
|
|
|
}
|
2010-03-23 18:01:17 -06:00
|
|
|
|
2010-05-21 15:40:21 -06:00
|
|
|
nascent = 0;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(pc0 == g->sched.pc && sp == g->sched.sp && pc0 == (byte*)runtime·goexit) {
|
2010-05-21 15:40:21 -06:00
|
|
|
// Hasn't started yet. g->sched is set up for goexit
|
|
|
|
// but goroutine will start at g->entry.
|
|
|
|
nascent = 1;
|
|
|
|
pc = (uintptr)g->entry;
|
|
|
|
}
|
|
|
|
|
2010-03-23 18:01:17 -06:00
|
|
|
n = 0;
|
clean stack trace code.
format is unchanged but shows all frames
(old loop stopped one frame early).
wreck=; 6.out
cannot convert type *main.S·interface2 to interface main.I·interface2: missing method Foo
throw: interface conversion
SIGSEGV: segmentation violation
Faulting address: 0x0
pc: 0x256d
throw+0x46 /home/rsc/go/src/runtime/runtime.c:68
throw(0x863a, 0x0)
hashmap+0x188 /home/rsc/go/src/runtime/iface.c:167
hashmap(0x8760, 0x0, 0x85b0, 0x0, 0x0, ...)
sys·ifaceT2I+0xa8 /home/rsc/go/src/runtime/iface.c:201
sys·ifaceT2I(0x8760, 0x0, 0x85b0, 0x0, 0x0, ...)
main·main+0x4e /home/rsc/go/src/runtime/rt0_amd64_darwin.s:87
main·main()
mainstart+0xf /home/rsc/go/src/runtime/rt0_amd64.s:70
mainstart()
sys·goexit /home/rsc/go/src/runtime/proc.c:110
sys·goexit()
R=r
DELTA=44 (5 added, 15 deleted, 24 changed)
OCL=20358
CL=20368
2008-12-03 15:20:23 -07:00
|
|
|
stk = (Stktop*)g->stackbase;
|
2010-03-23 18:01:17 -06:00
|
|
|
for(iter = 0; iter < 100 && n < m; iter++) { // iter avoids looping forever
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(pc == (uintptr)runtime·lessstack) {
|
2010-03-23 18:01:17 -06:00
|
|
|
// Hit top of stack segment. Unwind to next segment.
|
2009-06-17 16:12:16 -06:00
|
|
|
pc = (uintptr)stk->gobuf.pc;
|
|
|
|
sp = stk->gobuf.sp;
|
|
|
|
stk = (Stktop*)stk->stackbase;
|
2010-03-23 18:01:17 -06:00
|
|
|
continue;
|
2008-06-30 15:39:47 -06:00
|
|
|
}
|
2010-03-23 18:01:17 -06:00
|
|
|
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(pc <= 0x1000 || (f = runtime·findfunc(pc)) == nil) {
|
2010-03-23 18:01:17 -06:00
|
|
|
// Dangerous, but worthwhile: see if this is a closure:
|
|
|
|
// ADDQ $wwxxyyzz, SP; RET
|
|
|
|
// [48] 81 c4 zz yy xx ww c3
|
|
|
|
// The 0x48 byte is only on amd64.
|
|
|
|
p = (byte*)pc;
|
2010-09-08 22:28:56 -06:00
|
|
|
// We check p < p+8 to avoid wrapping and faulting if we lose track.
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(runtime·mheap.min < p && p < p+8 && p+8 < runtime·mheap.max && // pointer in allocated memory
|
2010-03-23 18:01:17 -06:00
|
|
|
(sizeof(uintptr) != 8 || *p++ == 0x48) && // skip 0x48 byte on amd64
|
|
|
|
p[0] == 0x81 && p[1] == 0xc4 && p[6] == 0xc3) {
|
|
|
|
sp += *(uint32*)(p+2);
|
|
|
|
pc = *(uintptr*)sp;
|
|
|
|
sp += sizeof(uintptr);
|
2009-02-06 14:46:56 -07:00
|
|
|
continue;
|
|
|
|
}
|
2010-05-21 15:40:21 -06:00
|
|
|
|
|
|
|
if(nascent && (pc = isclosureentry(pc)) != 0)
|
|
|
|
continue;
|
|
|
|
|
2010-03-23 18:01:17 -06:00
|
|
|
// Unknown pc; stop.
|
|
|
|
break;
|
2008-11-25 18:17:54 -07:00
|
|
|
}
|
2008-06-30 15:39:47 -06:00
|
|
|
|
2010-03-23 18:01:17 -06:00
|
|
|
// Found an actual function worth reporting.
|
|
|
|
if(skip > 0)
|
|
|
|
skip--;
|
|
|
|
else if(pcbuf != nil)
|
|
|
|
pcbuf[n++] = pc;
|
|
|
|
else {
|
|
|
|
// Print during crash.
|
|
|
|
// main+0xf /home/rsc/go/src/runtime/x.go:23
|
|
|
|
// main(0x1, 0x2, 0x3)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("%S", f->name);
|
2010-03-23 18:01:17 -06:00
|
|
|
if(pc > f->entry)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf("+%p", (uintptr)(pc - f->entry));
|
2010-03-23 18:01:17 -06:00
|
|
|
tracepc = pc; // back up to CALL instruction for funcline.
|
|
|
|
if(n > 0 && pc > f->entry)
|
|
|
|
tracepc--;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·printf(" %S:%d\n", f->src, runtime·funcline(f, tracepc));
|
|
|
|
runtime·printf("\t%S(", f->name);
|
2010-10-07 04:45:40 -06:00
|
|
|
fp = (uintptr*)sp;
|
|
|
|
if(f->frame < sizeof(uintptr))
|
|
|
|
fp++;
|
|
|
|
else
|
|
|
|
fp += f->frame/sizeof(uintptr);
|
2010-03-23 18:01:17 -06:00
|
|
|
for(i = 0; i < f->args; i++) {
|
|
|
|
if(i != 0)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·prints(", ");
|
|
|
|
runtime·printhex(fp[i]);
|
2010-03-23 18:01:17 -06:00
|
|
|
if(i >= 4) {
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·prints(", ...");
|
2010-03-23 18:01:17 -06:00
|
|
|
break;
|
|
|
|
}
|
2008-11-25 18:17:54 -07:00
|
|
|
}
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·prints(")\n");
|
2010-03-23 18:01:17 -06:00
|
|
|
n++;
|
2008-06-21 16:36:23 -06:00
|
|
|
}
|
2010-03-23 18:01:17 -06:00
|
|
|
|
2010-05-21 15:40:21 -06:00
|
|
|
if(nascent) {
|
|
|
|
pc = (uintptr)g->sched.pc;
|
|
|
|
sp = g->sched.sp;
|
|
|
|
nascent = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-03-23 18:01:17 -06:00
|
|
|
if(f->frame < sizeof(uintptr)) // assembly functions lie
|
|
|
|
sp += sizeof(uintptr);
|
|
|
|
else
|
|
|
|
sp += f->frame;
|
|
|
|
pc = *((uintptr*)sp - 1);
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(f->entry == (uintptr)runtime·deferproc || f->entry == (uintptr)runtime·newproc)
|
2010-09-08 22:28:56 -06:00
|
|
|
sp += 2*sizeof(uintptr);
|
2008-06-21 16:36:23 -06:00
|
|
|
}
|
2010-03-23 18:01:17 -06:00
|
|
|
return n;
|
2008-06-21 16:36:23 -06:00
|
|
|
}
|
2009-01-09 16:52:43 -07:00
|
|
|
|
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·traceback(byte *pc0, byte *sp, byte*, G *g)
|
2009-01-09 16:52:43 -07:00
|
|
|
{
|
2010-03-23 18:01:17 -06:00
|
|
|
gentraceback(pc0, sp, g, 0, nil, 100);
|
|
|
|
}
|
2009-01-09 16:52:43 -07:00
|
|
|
|
2010-03-23 18:01:17 -06:00
|
|
|
int32
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·callers(int32 skip, uintptr *pcbuf, int32 m)
|
2010-03-23 18:01:17 -06:00
|
|
|
{
|
|
|
|
byte *pc, *sp;
|
2009-01-09 16:52:43 -07:00
|
|
|
|
2010-03-23 18:01:17 -06:00
|
|
|
// our caller's pc, sp.
|
|
|
|
sp = (byte*)&skip;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
pc = runtime·getcallerpc(&skip);
|
2009-01-09 16:52:43 -07:00
|
|
|
|
2010-03-23 18:01:17 -06:00
|
|
|
return gentraceback(pc, sp, g, skip, pcbuf, m);
|
2009-01-09 16:52:43 -07:00
|
|
|
}
|
2010-05-21 15:40:21 -06:00
|
|
|
|
|
|
|
static uintptr
|
|
|
|
isclosureentry(uintptr pc)
|
|
|
|
{
|
|
|
|
byte *p;
|
|
|
|
int32 i, siz;
|
|
|
|
|
|
|
|
p = (byte*)pc;
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
if(p < runtime·mheap.min || p+32 > runtime·mheap.max)
|
2010-05-21 15:40:21 -06:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// SUBQ $siz, SP
|
|
|
|
if((sizeof(uintptr) == 8 && *p++ != 0x48) || *p++ != 0x81 || *p++ != 0xec)
|
|
|
|
return 0;
|
|
|
|
siz = *(uint32*)p;
|
|
|
|
p += 4;
|
|
|
|
|
|
|
|
// MOVQ $q, SI
|
|
|
|
if((sizeof(uintptr) == 8 && *p++ != 0x48) || *p++ != 0xbe)
|
|
|
|
return 0;
|
|
|
|
p += sizeof(uintptr);
|
|
|
|
|
|
|
|
// MOVQ SP, DI
|
|
|
|
if((sizeof(uintptr) == 8 && *p++ != 0x48) || *p++ != 0x89 || *p++ != 0xe7)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// CLD on 32-bit
|
|
|
|
if(sizeof(uintptr) == 4 && *p++ != 0xfc)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(siz <= 4*sizeof(uintptr)) {
|
|
|
|
// MOVSQ...
|
|
|
|
for(i=0; i<siz; i+=sizeof(uintptr))
|
|
|
|
if((sizeof(uintptr) == 8 && *p++ != 0x48) || *p++ != 0xa5)
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
// MOVQ $(siz/8), CX [32-bit immediate siz/8]
|
|
|
|
if((sizeof(uintptr) == 8 && *p++ != 0x48) || *p++ != 0xc7 || *p++ != 0xc1)
|
|
|
|
return 0;
|
|
|
|
p += 4;
|
|
|
|
|
|
|
|
// REP MOVSQ
|
|
|
|
if(*p++ != 0xf3 || (sizeof(uintptr) == 8 && *p++ != 0x48) || *p++ != 0xa5)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CALL fn
|
|
|
|
if(*p == 0xe8) {
|
|
|
|
p++;
|
|
|
|
return (uintptr)p+4 + *(int32*)p;
|
|
|
|
}
|
|
|
|
|
|
|
|
// MOVQ $fn, CX; CALL *CX
|
|
|
|
if(sizeof(uintptr) != 8 || *p++ != 0x48 || *p++ != 0xb9)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pc = *(uintptr*)p;
|
|
|
|
p += 8;
|
|
|
|
|
|
|
|
if(*p++ != 0xff || *p != 0xd1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return pc;
|
|
|
|
}
|