1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 "runtime/internal/sys"
15 // The code in this file implements stack trace walking for all architectures.
16 // The most important fact about a given architecture is whether it uses a link register.
17 // On systems with link registers, the prologue for a non-leaf function stores the
18 // incoming value of LR at the bottom of the newly allocated stack frame.
19 // On systems without link registers (x86), the architecture pushes a return PC during
20 // the call instruction, so the return PC ends up above the stack frame.
21 // In this file, the return PC is always called LR, no matter how it was found.
23 const usesLR = sys.MinFrameSize > 0
26 // tracebackInnerFrames is the number of innermost frames to print in a
27 // stack trace. The total maximum frames is tracebackInnerFrames +
28 // tracebackOuterFrames.
29 tracebackInnerFrames = 50
31 // tracebackOuterFrames is the number of outermost frames to print in a
33 tracebackOuterFrames = 50
36 // unwindFlags control the behavior of various unwinders.
37 type unwindFlags uint8
40 // unwindPrintErrors indicates that if unwinding encounters an error, it
41 // should print a message and stop without throwing. This is used for things
42 // like stack printing, where it's better to get incomplete information than
43 // to crash. This is also used in situations where everything may not be
44 // stopped nicely and the stack walk may not be able to complete, such as
45 // during profiling signals or during a crash.
47 // If neither unwindPrintErrors or unwindSilentErrors are set, unwinding
48 // performs extra consistency checks and throws on any error.
50 // Note that there are a small number of fatal situations that will throw
51 // regardless of unwindPrintErrors or unwindSilentErrors.
52 unwindPrintErrors unwindFlags = 1 << iota
54 // unwindSilentErrors silently ignores errors during unwinding.
57 // unwindTrap indicates that the initial PC and SP are from a trap, not a
58 // return PC from a call.
60 // The unwindTrap flag is updated during unwinding. If set, frame.pc is the
61 // address of a faulting instruction instead of the return address of a
62 // call. It also means the liveness at pc may not be known.
64 // TODO: Distinguish frame.continpc, which is really the stack map PC, from
65 // the actual continuation PC, which is computed differently depending on
66 // this flag and a few other things.
69 // unwindJumpStack indicates that, if the traceback is on a system stack, it
70 // should resume tracing at the user stack when the system stack is
75 // An unwinder iterates the physical stack frames of a Go sack.
77 // Typical use of an unwinder looks like:
80 // for u.init(gp, 0); u.valid(); u.next() {
81 // // ... use frame info in u ...
84 // Implementation note: This is carefully structured to be pointer-free because
85 // tracebacks happen in places that disallow write barriers (e.g., signals).
86 // Even if this is stack-allocated, its pointer-receiver methods don't know that
87 // their receiver is on the stack, so they still emit write barriers. Here we
88 // address that by carefully avoiding any pointers in this type. Another
89 // approach would be to split this into a mutable part that's passed by pointer
90 // but contains no pointers itself and an immutable part that's passed and
91 // returned by value and can contain pointers. We could potentially hide that
92 // we're doing that in trivial methods that are inlined into the caller that has
93 // the stack allocation, but that's fragile.
94 type unwinder struct {
95 // frame is the current physical stack frame, or all 0s if
99 // g is the G who's stack is being unwound. If the
100 // unwindJumpStack flag is set and the unwinder jumps stacks,
101 // this will be different from the initial G.
104 // cgoCtxt is the index into g.cgoCtxt of the next frame on the cgo stack.
105 // The cgo stack is unwound in tandem with the Go stack as we find marker frames.
108 // calleeFuncID is the function ID of the caller of the current
110 calleeFuncID abi.FuncID
112 // flags are the flags to this unwind. Some of these are updated as we
113 // unwind (see the flags documentation).
117 // init initializes u to start unwinding gp's stack and positions the
118 // iterator on gp's innermost frame. gp must not be the current G.
120 // A single unwinder can be reused for multiple unwinds.
121 func (u *unwinder) init(gp *g, flags unwindFlags) {
122 // Implementation note: This starts the iterator on the first frame and we
123 // provide a "valid" method. Alternatively, this could start in a "before
124 // the first frame" state and "next" could return whether it was able to
125 // move to the next frame, but that's both more awkward to use in a "for"
126 // loop and is harder to implement because we have to do things differently
127 // for the first frame.
128 u.initAt(^uintptr(0), ^uintptr(0), ^uintptr(0), gp, flags)
131 func (u *unwinder) initAt(pc0, sp0, lr0 uintptr, gp *g, flags unwindFlags) {
132 // Don't call this "g"; it's too easy get "g" and "gp" confused.
133 if ourg := getg(); ourg == gp && ourg == ourg.m.curg {
134 // The starting sp has been passed in as a uintptr, and the caller may
135 // have other uintptr-typed stack references as well.
136 // If during one of the calls that got us here or during one of the
137 // callbacks below the stack must be grown, all these uintptr references
138 // to the stack will not be updated, and traceback will continue
139 // to inspect the old stack memory, which may no longer be valid.
140 // Even if all the variables were updated correctly, it is not clear that
141 // we want to expose a traceback that begins on one stack and ends
142 // on another stack. That could confuse callers quite a bit.
143 // Instead, we require that initAt and any other function that
144 // accepts an sp for the current goroutine (typically obtained by
145 // calling getcallersp) must not run on that goroutine's stack but
146 // instead on the g0 stack.
147 throw("cannot trace user goroutine on its own stack")
150 if pc0 == ^uintptr(0) && sp0 == ^uintptr(0) { // Signal to fetch saved values from gp.
151 if gp.syscallsp != 0 {
173 // If the PC is zero, it's likely a nil function call.
174 // Start in the caller's frame.
177 frame.pc = *(*uintptr)(unsafe.Pointer(frame.sp))
180 frame.pc = *(*uintptr)(unsafe.Pointer(frame.sp))
181 frame.sp += goarch.PtrSize
185 // runtime/internal/atomic functions call into kernel helpers on
186 // arm < 7. See runtime/internal/atomic/sys_linux_arm.s.
188 // Start in the caller's frame.
189 if GOARCH == "arm" && goarm < 7 && GOOS == "linux" && frame.pc&0xffff0000 == 0xffff0000 {
190 // Note that the calls are simple BL without pushing the return
191 // address, so we use LR directly.
193 // The kernel helpers are frameless leaf functions, so SP and
194 // LR are not touched.
199 f := findfunc(frame.pc)
201 if flags&unwindSilentErrors == 0 {
202 print("runtime: g ", gp.goid, ": unknown pc ", hex(frame.pc), "\n")
203 tracebackHexdump(gp.stack, &frame, 0)
205 if flags&(unwindPrintErrors|unwindSilentErrors) == 0 {
213 // Populate the unwinder.
217 cgoCtxt: len(gp.cgoCtxt) - 1,
218 calleeFuncID: abi.FuncIDNormal,
222 isSyscall := frame.pc == pc0 && frame.sp == sp0 && pc0 == gp.syscallpc && sp0 == gp.syscallsp
223 u.resolveInternal(true, isSyscall)
226 func (u *unwinder) valid() bool {
227 return u.frame.pc != 0
230 // resolveInternal fills in u.frame based on u.frame.fn, pc, and sp.
232 // innermost indicates that this is the first resolve on this stack. If
233 // innermost is set, isSyscall indicates that the PC/SP was retrieved from
234 // gp.syscall*; this is otherwise ignored.
236 // On entry, u.frame contains:
237 // - fn is the running function.
238 // - pc is the PC in the running function.
239 // - sp is the stack pointer at that program counter.
240 // - For the innermost frame on LR machines, lr is the program counter that called fn.
242 // On return, u.frame contains:
243 // - fp is the stack pointer of the caller.
244 // - lr is the program counter that called fn.
245 // - varp, argp, and continpc are populated for the current frame.
247 // If fn is a stack-jumping function, resolveInternal can change the entire
248 // frame state to follow that stack jump.
250 // This is internal to unwinder.
251 func (u *unwinder) resolveInternal(innermost, isSyscall bool) {
257 // No frame information, must be external function, like race support.
258 // See golang.org/issue/13568.
263 // Compute function info flags.
265 if f.funcID == abi.FuncID_cgocallback {
266 // cgocallback does write SP to switch from the g0 to the curg stack,
267 // but it carefully arranges that during the transition BOTH stacks
268 // have cgocallback frame valid for unwinding through.
269 // So we don't need to exclude it with the other SP-writing functions.
270 flag &^= abi.FuncFlagSPWrite
273 // Some Syscall functions write to SP, but they do so only after
274 // saving the entry PC/SP using entersyscall.
275 // Since we are using the entry PC/SP, the later SP write doesn't matter.
276 flag &^= abi.FuncFlagSPWrite
279 // Found an actual function.
280 // Derive frame pointer.
282 // Jump over system stack transitions. If we're on g0 and there's a user
283 // goroutine, try to jump. Otherwise this is a regular call.
284 // We also defensively check that this won't switch M's on us,
285 // which could happen at critical points in the scheduler.
286 // This ensures gp.m doesn't change from a stack jump.
287 if u.flags&unwindJumpStack != 0 && gp == gp.m.g0 && gp.m.curg != nil && gp.m.curg.m == gp.m {
289 case abi.FuncID_morestack:
290 // morestack does not return normally -- newstack()
291 // gogo's to curg.sched. Match that.
292 // This keeps morestack() from showing up in the backtrace,
293 // but that makes some sense since it'll never be returned
297 frame.pc = gp.sched.pc
298 frame.fn = findfunc(frame.pc)
301 frame.lr = gp.sched.lr
302 frame.sp = gp.sched.sp
303 u.cgoCtxt = len(gp.cgoCtxt) - 1
304 case abi.FuncID_systemstack:
305 // systemstack returns normally, so just follow the
307 if usesLR && funcspdelta(f, frame.pc) == 0 {
308 // We're at the function prologue and the stack
309 // switch hasn't happened, or epilogue where we're
310 // about to return. Just unwind normally.
311 // Do this only on LR machines because on x86
312 // systemstack doesn't have an SP delta (the CALL
313 // instruction opens the frame), therefore no way
315 flag &^= abi.FuncFlagSPWrite
320 frame.sp = gp.sched.sp
321 u.cgoCtxt = len(gp.cgoCtxt) - 1
322 flag &^= abi.FuncFlagSPWrite
325 frame.fp = frame.sp + uintptr(funcspdelta(f, frame.pc))
327 // On x86, call instruction pushes return PC before entering new function.
328 frame.fp += goarch.PtrSize
332 // Derive link register.
333 if flag&abi.FuncFlagTopFrame != 0 {
334 // This function marks the top of the stack. Stop the traceback.
336 } else if flag&abi.FuncFlagSPWrite != 0 && (!innermost || u.flags&(unwindPrintErrors|unwindSilentErrors) != 0) {
337 // The function we are in does a write to SP that we don't know
338 // how to encode in the spdelta table. Examples include context
339 // switch routines like runtime.gogo but also any code that switches
340 // to the g0 stack to run host C code.
341 // We can't reliably unwind the SP (we might not even be on
342 // the stack we think we are), so stop the traceback here.
344 // The one exception (encoded in the complex condition above) is that
345 // we assume if we're doing a precise traceback, and this is the
346 // innermost frame, that the SPWRITE function voluntarily preempted itself on entry
347 // during the stack growth check. In that case, the function has
348 // not yet had a chance to do any writes to SP and is safe to unwind.
349 // isAsyncSafePoint does not allow assembly functions to be async preempted,
350 // and preemptPark double-checks that SPWRITE functions are not async preempted.
351 // So for GC stack traversal, we can safely ignore SPWRITE for the innermost frame,
352 // but farther up the stack we'd better not find any.
353 // This is somewhat imprecise because we're just guessing that we're in the stack
354 // growth check. It would be better if SPWRITE were encoded in the spdelta
355 // table so we would know for sure that we were still in safe code.
357 // uSE uPE inn | action
358 // T _ _ | frame.lr = 0
359 // F T _ | frame.lr = 0
360 // F F F | print; panic
361 // F F T | ignore SPWrite
362 if u.flags&(unwindPrintErrors|unwindSilentErrors) == 0 && !innermost {
363 println("traceback: unexpected SPWRITE function", funcname(f))
370 if innermost && frame.sp < frame.fp || frame.lr == 0 {
372 frame.lr = *(*uintptr)(unsafe.Pointer(lrPtr))
376 lrPtr = frame.fp - goarch.PtrSize
377 frame.lr = *(*uintptr)(unsafe.Pointer(lrPtr))
382 frame.varp = frame.fp
384 // On x86, call instruction pushes return PC before entering new function.
385 frame.varp -= goarch.PtrSize
388 // For architectures with frame pointers, if there's
389 // a frame, then there's a saved frame pointer here.
391 // NOTE: This code is not as general as it looks.
392 // On x86, the ABI is to save the frame pointer word at the
393 // top of the stack frame, so we have to back down over it.
394 // On arm64, the frame pointer should be at the bottom of
395 // the stack (with R29 (aka FP) = RSP), in which case we would
396 // not want to do the subtraction here. But we started out without
397 // any frame pointer, and when we wanted to add it, we didn't
398 // want to break all the assembly doing direct writes to 8(RSP)
399 // to set the first parameter to a called function.
400 // So we decided to write the FP link *below* the stack pointer
401 // (with R29 = RSP - 8 in Go functions).
402 // This is technically ABI-compatible but not standard.
403 // And it happens to end up mimicking the x86 layout.
404 // Other architectures may make different decisions.
405 if frame.varp > frame.sp && framepointer_enabled {
406 frame.varp -= goarch.PtrSize
409 frame.argp = frame.fp + sys.MinFrameSize
411 // Determine frame's 'continuation PC', where it can continue.
412 // Normally this is the return address on the stack, but if sigpanic
413 // is immediately below this function on the stack, then the frame
414 // stopped executing due to a trap, and frame.pc is probably not
415 // a safe point for looking up liveness information. In this panicking case,
416 // the function either doesn't return at all (if it has no defers or if the
417 // defers do not recover) or it returns from one of the calls to
418 // deferproc a second time (if the corresponding deferred func recovers).
419 // In the latter case, use a deferreturn call site as the continuation pc.
420 frame.continpc = frame.pc
421 if u.calleeFuncID == abi.FuncID_sigpanic {
422 if frame.fn.deferreturn != 0 {
423 frame.continpc = frame.fn.entry() + uintptr(frame.fn.deferreturn) + 1
424 // Note: this may perhaps keep return variables alive longer than
425 // strictly necessary, as we are using "function has a defer statement"
426 // as a proxy for "function actually deferred something". It seems
427 // to be a minor drawback. (We used to actually look through the
428 // gp._defer for a defer corresponding to this function, but that
429 // is hard to do with defer records on the stack during a stack copy.)
430 // Note: the +1 is to offset the -1 that
431 // stack.go:getStackMap does to back up a return
432 // address make sure the pc is in the CALL instruction.
439 func (u *unwinder) next() {
444 // Do not unwind past the bottom of the stack.
449 flr := findfunc(frame.lr)
451 // This happens if you get a profiling interrupt at just the wrong time.
452 // In that context it is okay to stop early.
453 // But if no error flags are set, we're doing a garbage collection and must
454 // get everything, so crash loudly.
455 fail := u.flags&(unwindPrintErrors|unwindSilentErrors) == 0
456 doPrint := u.flags&unwindSilentErrors == 0
457 if doPrint && gp.m.incgo && f.funcID == abi.FuncID_sigpanic {
458 // We can inject sigpanic
459 // calls directly into C code,
460 // in which case we'll see a C
461 // return PC. Don't complain.
465 print("runtime: g ", gp.goid, ": unexpected return pc for ", funcname(f), " called from ", hex(frame.lr), "\n")
466 tracebackHexdump(gp.stack, frame, 0)
469 throw("unknown caller pc")
476 if frame.pc == frame.lr && frame.sp == frame.fp {
477 // If the next frame is identical to the current frame, we cannot make progress.
478 print("runtime: traceback stuck. pc=", hex(frame.pc), " sp=", hex(frame.sp), "\n")
479 tracebackHexdump(gp.stack, frame, frame.sp)
480 throw("traceback stuck")
483 injectedCall := f.funcID == abi.FuncID_sigpanic || f.funcID == abi.FuncID_asyncPreempt || f.funcID == abi.FuncID_debugCallV2
485 u.flags |= unwindTrap
487 u.flags &^= unwindTrap
490 // Unwind to next frame.
491 u.calleeFuncID = f.funcID
498 // On link register architectures, sighandler saves the LR on stack
499 // before faking a call.
500 if usesLR && injectedCall {
501 x := *(*uintptr)(unsafe.Pointer(frame.sp))
502 frame.sp += alignUp(sys.MinFrameSize, sys.StackAlign)
503 f = findfunc(frame.pc)
507 } else if funcspdelta(f, frame.pc) == 0 {
512 u.resolveInternal(false, false)
515 // finishInternal is an unwinder-internal helper called after the stack has been
516 // exhausted. It sets the unwinder to an invalid state and checks that it
517 // successfully unwound the entire stack.
518 func (u *unwinder) finishInternal() {
521 // Note that panic != nil is okay here: there can be leftover panics,
522 // because the defers on the panic stack do not nest in frame order as
523 // they do on the defer stack. If you have:
529 // frame 4's panic starts running defers
530 // frame 5, running d3, defers d4
532 // frame 5's panic starts running defers
533 // frame 6, running d4, garbage collects
534 // frame 6, running d2, garbage collects
536 // During the execution of d4, the panic stack is d4 -> d3, which
537 // is nested properly, and we'll treat frame 3 as resumable, because we
538 // can find d3. (And in fact frame 3 is resumable. If d4 recovers
539 // and frame 5 continues running, d3, d3 can recover and we'll
540 // resume execution in (returning from) frame 3.)
542 // During the execution of d2, however, the panic stack is d2 -> d3,
543 // which is inverted. The scan will match d2 to frame 2 but having
544 // d2 on the stack until then means it will not match d3 to frame 3.
545 // This is okay: if we're running d2, then all the defers after d2 have
546 // completed and their corresponding frames are dead. Not finding d3
547 // for frame 3 means we'll set frame 3's continpc == 0, which is correct
548 // (frame 3 is dead). At the end of the walk the panic stack can thus
549 // contain defers (d3 in this case) for dead frames. The inversion here
550 // always indicates a dead frame, and the effect of the inversion on the
551 // scan is to hide those dead frames, so the scan is still okay:
552 // what's left on the panic stack are exactly (and only) the dead frames.
554 // We require callback != nil here because only when callback != nil
555 // do we know that gentraceback is being called in a "must be correct"
556 // context as opposed to a "best effort" context. The tracebacks with
557 // callbacks only happen when everything is stopped nicely.
558 // At other times, such as when gathering a stack for a profiling signal
559 // or when printing a traceback during a crash, everything may not be
560 // stopped nicely, and the stack walk may not be able to complete.
562 if u.flags&(unwindPrintErrors|unwindSilentErrors) == 0 && u.frame.sp != gp.stktopsp {
563 print("runtime: g", gp.goid, ": frame.sp=", hex(u.frame.sp), " top=", hex(gp.stktopsp), "\n")
564 print("\tstack=[", hex(gp.stack.lo), "-", hex(gp.stack.hi), "\n")
565 throw("traceback did not unwind completely")
569 // symPC returns the PC that should be used for symbolizing the current frame.
570 // Specifically, this is the PC of the last instruction executed in this frame.
572 // If this frame did a normal call, then frame.pc is a return PC, so this will
573 // return frame.pc-1, which points into the CALL instruction. If the frame was
574 // interrupted by a signal (e.g., profiler, segv, etc) then frame.pc is for the
575 // trapped instruction, so this returns frame.pc. See issue #34123. Finally,
576 // frame.pc can be at function entry when the frame is initialized without
577 // actually running code, like in runtime.mstart, in which case this returns
578 // frame.pc because that's the best we can do.
579 func (u *unwinder) symPC() uintptr {
580 if u.flags&unwindTrap == 0 && u.frame.pc > u.frame.fn.entry() {
582 return u.frame.pc - 1
584 // Trapping instruction or we're at the function entry point.
588 // cgoCallers populates pcBuf with the cgo callers of the current frame using
589 // the registered cgo unwinder. It returns the number of PCs written to pcBuf.
590 // If the current frame is not a cgo frame or if there's no registered cgo
591 // unwinder, it returns 0.
592 func (u *unwinder) cgoCallers(pcBuf []uintptr) int {
593 if cgoTraceback == nil || u.frame.fn.funcID != abi.FuncID_cgocallback || u.cgoCtxt < 0 {
594 // We don't have a cgo unwinder (typical case), or we do but we're not
595 // in a cgo frame or we're out of cgo context.
599 ctxt := u.g.ptr().cgoCtxt[u.cgoCtxt]
601 cgoContextPCs(ctxt, pcBuf)
602 for i, pc := range pcBuf {
610 // tracebackPCs populates pcBuf with the return addresses for each frame from u
611 // and returns the number of PCs written to pcBuf. The returned PCs correspond
612 // to "logical frames" rather than "physical frames"; that is if A is inlined
613 // into B, this will still return a PCs for both A and B. This also includes PCs
614 // generated by the cgo unwinder, if one is registered.
616 // If skip != 0, this skips this many logical frames.
618 // Callers should set the unwindSilentErrors flag on u.
619 func tracebackPCs(u *unwinder, skip int, pcBuf []uintptr) int {
620 var cgoBuf [32]uintptr
622 for ; n < len(pcBuf) && u.valid(); u.next() {
624 cgoN := u.cgoCallers(cgoBuf[:])
626 // TODO: Why does &u.cache cause u to escape? (Same in traceback2)
627 for iu, uf := newInlineUnwinder(f, u.symPC()); n < len(pcBuf) && uf.valid(); uf = iu.next(uf) {
629 if sf.funcID == abi.FuncIDWrapper && elideWrapperCalling(u.calleeFuncID) {
634 // Callers expect the pc buffer to contain return addresses
635 // and do the -1 themselves, so we add 1 to the call PC to
636 // create a return PC.
640 u.calleeFuncID = sf.funcID
642 // Add cgo frames (if we're done skipping over the requested number of
645 n += copy(pcBuf[n:], cgoBuf[:cgoN])
651 // printArgs prints function arguments in traceback.
652 func printArgs(f funcInfo, argp unsafe.Pointer, pc uintptr) {
653 // The "instruction" of argument printing is encoded in _FUNCDATA_ArgInfo.
654 // See cmd/compile/internal/ssagen.emitArgInfo for the description of the
656 // These constants need to be in sync with the compiler.
662 _offsetTooLarge = 0xfb
666 limit = 10 // print no more than 10 args/components
667 maxDepth = 5 // no more than 5 layers of nesting
668 maxLen = (maxDepth*3+2)*limit + 1 // max length of _FUNCDATA_ArgInfo (see the compiler side for reasoning)
671 p := (*[maxLen]uint8)(funcdata(f, abi.FUNCDATA_ArgInfo))
676 liveInfo := funcdata(f, abi.FUNCDATA_ArgLiveInfo)
677 liveIdx := pcdatavalue(f, abi.PCDATA_ArgLiveIndex, pc)
678 startOffset := uint8(0xff) // smallest offset that needs liveness info (slots with a lower offset is always live)
680 startOffset = *(*uint8)(liveInfo)
683 isLive := func(off, slotIdx uint8) bool {
684 if liveInfo == nil || liveIdx <= 0 {
685 return true // no liveness info, always live
687 if off < startOffset {
690 bits := *(*uint8)(add(liveInfo, uintptr(liveIdx)+uintptr(slotIdx/8)))
691 return bits&(1<<(slotIdx%8)) != 0
694 print1 := func(off, sz, slotIdx uint8) {
695 x := readUnaligned64(add(argp, uintptr(off)))
696 // mask out irrelevant bits
699 if goarch.BigEndian {
702 x = x << shift >> shift
706 if !isLive(off, slotIdx) {
712 printcomma := func() {
718 slotIdx := uint8(0) // register arg spill slot index
736 case _offsetTooLarge:
743 print1(o, sz, slotIdx)
744 if o >= startOffset {
752 // funcNamePiecesForPrint returns the function name for printing to the user.
753 // It returns three pieces so it doesn't need an allocation for string
755 func funcNamePiecesForPrint(name string) (string, string, string) {
756 // Replace the shape name in generic function with "...".
757 i := bytealg.IndexByteString(name, '[')
768 return name[:i], "[...]", name[j+1:]
771 // funcNameForPrint returns the function name for printing to the user.
772 func funcNameForPrint(name string) string {
773 a, b, c := funcNamePiecesForPrint(name)
777 // printFuncName prints a function name. name is the function name in
778 // the binary's func data table.
779 func printFuncName(name string) {
780 if name == "runtime.gopanic" {
784 a, b, c := funcNamePiecesForPrint(name)
788 func printcreatedby(gp *g) {
789 // Show what created goroutine, except main goroutine (goid 1).
792 if f.valid() && showframe(f.srcFunc(), gp, false, abi.FuncIDNormal) && gp.goid != 1 {
793 printcreatedby1(f, pc, gp.parentGoid)
797 func printcreatedby1(f funcInfo, pc uintptr, goid uint64) {
799 printFuncName(funcname(f))
801 print(" in goroutine ", goid)
804 tracepc := pc // back up to CALL instruction for funcline.
806 tracepc -= sys.PCQuantum
808 file, line := funcline(f, tracepc)
809 print("\t", file, ":", line)
811 print(" +", hex(pc-f.entry()))
816 func traceback(pc, sp, lr uintptr, gp *g) {
817 traceback1(pc, sp, lr, gp, 0)
820 // tracebacktrap is like traceback but expects that the PC and SP were obtained
821 // from a trap, not from gp->sched or gp->syscallpc/gp->syscallsp or getcallerpc/getcallersp.
822 // Because they are from a trap instead of from a saved pair,
823 // the initial PC must not be rewound to the previous instruction.
824 // (All the saved pairs record a PC that is a return address, so we
825 // rewind it into the CALL instruction.)
826 // If gp.m.libcall{g,pc,sp} information is available, it uses that information in preference to
827 // the pc/sp/lr passed in.
828 func tracebacktrap(pc, sp, lr uintptr, gp *g) {
829 if gp.m.libcallsp != 0 {
830 // We're in C code somewhere, traceback from the saved position.
831 traceback1(gp.m.libcallpc, gp.m.libcallsp, 0, gp.m.libcallg.ptr(), 0)
834 traceback1(pc, sp, lr, gp, unwindTrap)
837 func traceback1(pc, sp, lr uintptr, gp *g, flags unwindFlags) {
838 // If the goroutine is in cgo, and we have a cgo traceback, print that.
839 if iscgo && gp.m != nil && gp.m.ncgo > 0 && gp.syscallsp != 0 && gp.m.cgoCallers != nil && gp.m.cgoCallers[0] != 0 {
840 // Lock cgoCallers so that a signal handler won't
841 // change it, copy the array, reset it, unlock it.
842 // We are locked to the thread and are not running
843 // concurrently with a signal handler.
844 // We just have to stop a signal handler from interrupting
845 // in the middle of our copy.
846 gp.m.cgoCallersUse.Store(1)
847 cgoCallers := *gp.m.cgoCallers
848 gp.m.cgoCallers[0] = 0
849 gp.m.cgoCallersUse.Store(0)
851 printCgoTraceback(&cgoCallers)
854 if readgstatus(gp)&^_Gscan == _Gsyscall {
855 // Override registers if blocked in system call.
860 if gp.m != nil && gp.m.vdsoSP != 0 {
861 // Override registers if running in VDSO. This comes after the
862 // _Gsyscall check to cover VDSO calls after entersyscall.
870 // We print the first tracebackInnerFrames frames, and the last
871 // tracebackOuterFrames frames. There are many possible approaches to this.
872 // There are various complications to this:
874 // - We'd prefer to walk the stack once because in really bad situations
875 // traceback may crash (and we want as much output as possible) or the stack
878 // - Each physical frame can represent several logical frames, so we might
879 // have to pause in the middle of a physical frame and pick up in the middle
880 // of a physical frame.
882 // - The cgo symbolizer can expand a cgo PC to more than one logical frame,
883 // and involves juggling state on the C side that we don't manage. Since its
884 // expansion state is managed on the C side, we can't capture the expansion
885 // state part way through, and because the output strings are managed on the
886 // C side, we can't capture the output. Thus, our only choice is to replay a
887 // whole expansion, potentially discarding some of it.
889 // Rejected approaches:
891 // - Do two passes where the first pass just counts and the second pass does
892 // all the printing. This is undesirable if the stack is corrupted or changing
893 // because we won't see a partial stack if we panic.
895 // - Keep a ring buffer of the last N logical frames and use this to print
896 // the bottom frames once we reach the end of the stack. This works, but
897 // requires keeping a surprising amount of state on the stack, and we have
898 // to run the cgo symbolizer twice—once to count frames, and a second to
899 // print them—since we can't retain the strings it returns.
901 // Instead, we print the outer frames, and if we reach that limit, we clone
902 // the unwinder, count the remaining frames, and then skip forward and
903 // finish printing from the clone. This makes two passes over the outer part
904 // of the stack, but the single pass over the inner part ensures that's
905 // printed immediately and not revisited. It keeps minimal state on the
906 // stack. And through a combination of skip counts and limits, we can do all
907 // of the steps we need with a single traceback printer implementation.
909 // We could be more lax about exactly how many frames we print, for example
910 // always stopping and resuming on physical frame boundaries, or at least
911 // cgo expansion boundaries. It's not clear that's much simpler.
912 flags |= unwindPrintErrors
914 tracebackWithRuntime := func(showRuntime bool) int {
915 const maxInt int = 0x7fffffff
916 u.initAt(pc, sp, lr, gp, flags)
917 n, lastN := traceback2(&u, showRuntime, 0, tracebackInnerFrames)
918 if n < tracebackInnerFrames {
919 // We printed the whole stack.
922 // Clone the unwinder and figure out how many frames are left. This
923 // count will include any logical frames already printed for u's current
926 remaining, _ := traceback2(&u, showRuntime, maxInt, 0)
927 elide := remaining - lastN - tracebackOuterFrames
929 print("...", elide, " frames elided...\n")
930 traceback2(&u2, showRuntime, lastN+elide, tracebackOuterFrames)
931 } else if elide <= 0 {
932 // There are tracebackOuterFrames or fewer frames left to print.
933 // Just print the rest of the stack.
934 traceback2(&u2, showRuntime, lastN, tracebackOuterFrames)
938 // By default, omits runtime frames. If that means we print nothing at all,
939 // repeat forcing all frames printed.
940 if tracebackWithRuntime(false) == 0 {
941 tracebackWithRuntime(true)
945 if gp.ancestors == nil {
948 for _, ancestor := range *gp.ancestors {
949 printAncestorTraceback(ancestor)
953 // traceback2 prints a stack trace starting at u. It skips the first "skip"
954 // logical frames, after which it prints at most "max" logical frames. It
955 // returns n, which is the number of logical frames skipped and printed, and
956 // lastN, which is the number of logical frames skipped or printed just in the
957 // physical frame that u references.
958 func traceback2(u *unwinder, showRuntime bool, skip, max int) (n, lastN int) {
959 // commitFrame commits to a logical frame and returns whether this frame
960 // should be printed and whether iteration should stop.
961 commitFrame := func() (pr, stop bool) {
962 if skip == 0 && max == 0 {
979 level, _, _ := gotraceback()
980 var cgoBuf [32]uintptr
981 for ; u.valid(); u.next() {
984 for iu, uf := newInlineUnwinder(f, u.symPC()); uf.valid(); uf = iu.next(uf) {
986 callee := u.calleeFuncID
987 u.calleeFuncID = sf.funcID
988 if !(showRuntime || showframe(sf, gp, n == 0, callee)) {
992 if pr, stop := commitFrame(); stop {
999 file, line := iu.fileLine(uf)
1000 // Print during crash.
1001 // main(0x1, 0x2, 0x3)
1002 // /home/rsc/go/src/runtime/x.go:23 +0xf
1006 if iu.isInlined(uf) {
1009 argp := unsafe.Pointer(u.frame.argp)
1010 printArgs(f, argp, u.symPC())
1013 print("\t", file, ":", line)
1014 if !iu.isInlined(uf) {
1015 if u.frame.pc > f.entry() {
1016 print(" +", hex(u.frame.pc-f.entry()))
1018 if gp.m != nil && gp.m.throwing >= throwTypeRuntime && gp == gp.m.curg || level >= 2 {
1019 print(" fp=", hex(u.frame.fp), " sp=", hex(u.frame.sp), " pc=", hex(u.frame.pc))
1025 // Print cgo frames.
1026 if cgoN := u.cgoCallers(cgoBuf[:]); cgoN > 0 {
1027 var arg cgoSymbolizerArg
1028 anySymbolized := false
1030 for _, pc := range cgoBuf[:cgoN] {
1031 if cgoSymbolizer == nil {
1032 if pr, stop := commitFrame(); stop {
1035 print("non-Go function at pc=", hex(pc), "\n")
1038 stop = printOneCgoTraceback(pc, commitFrame, &arg)
1039 anySymbolized = true
1046 // Free symbolization state.
1048 callCgoSymbolizer(&arg)
1058 // printAncestorTraceback prints the traceback of the given ancestor.
1059 // TODO: Unify this with gentraceback and CallersFrames.
1060 func printAncestorTraceback(ancestor ancestorInfo) {
1061 print("[originating from goroutine ", ancestor.goid, "]:\n")
1062 for fidx, pc := range ancestor.pcs {
1063 f := findfunc(pc) // f previously validated
1064 if showfuncinfo(f.srcFunc(), fidx == 0, abi.FuncIDNormal) {
1065 printAncestorTracebackFuncInfo(f, pc)
1068 if len(ancestor.pcs) == tracebackInnerFrames {
1069 print("...additional frames elided...\n")
1071 // Show what created goroutine, except main goroutine (goid 1).
1072 f := findfunc(ancestor.gopc)
1073 if f.valid() && showfuncinfo(f.srcFunc(), false, abi.FuncIDNormal) && ancestor.goid != 1 {
1074 // In ancestor mode, we'll already print the goroutine ancestor.
1075 // Pass 0 for the goid parameter so we don't print it again.
1076 printcreatedby1(f, ancestor.gopc, 0)
1080 // printAncestorTracebackFuncInfo prints the given function info at a given pc
1081 // within an ancestor traceback. The precision of this info is reduced
1082 // due to only have access to the pcs at the time of the caller
1083 // goroutine being created.
1084 func printAncestorTracebackFuncInfo(f funcInfo, pc uintptr) {
1085 u, uf := newInlineUnwinder(f, pc)
1086 file, line := u.fileLine(uf)
1087 printFuncName(u.srcFunc(uf).name())
1089 print("\t", file, ":", line)
1091 print(" +", hex(pc-f.entry()))
1096 func callers(skip int, pcbuf []uintptr) int {
1101 systemstack(func() {
1103 u.initAt(pc, sp, 0, gp, unwindSilentErrors)
1104 n = tracebackPCs(&u, skip, pcbuf)
1109 func gcallers(gp *g, skip int, pcbuf []uintptr) int {
1111 u.init(gp, unwindSilentErrors)
1112 return tracebackPCs(&u, skip, pcbuf)
1115 // showframe reports whether the frame with the given characteristics should
1116 // be printed during a traceback.
1117 func showframe(sf srcFunc, gp *g, firstFrame bool, calleeID abi.FuncID) bool {
1119 if mp.throwing >= throwTypeRuntime && gp != nil && (gp == mp.curg || gp == mp.caughtsig.ptr()) {
1122 return showfuncinfo(sf, firstFrame, calleeID)
1125 // showfuncinfo reports whether a function with the given characteristics should
1126 // be printed during a traceback.
1127 func showfuncinfo(sf srcFunc, firstFrame bool, calleeID abi.FuncID) bool {
1128 level, _, _ := gotraceback()
1134 if sf.funcID == abi.FuncIDWrapper && elideWrapperCalling(calleeID) {
1140 // Special case: always show runtime.gopanic frame
1141 // in the middle of a stack trace, so that we can
1142 // see the boundary between ordinary code and
1143 // panic-induced deferred code.
1144 // See golang.org/issue/5832.
1145 if name == "runtime.gopanic" && !firstFrame {
1149 return bytealg.IndexByteString(name, '.') >= 0 && (!hasPrefix(name, "runtime.") || isExportedRuntime(name))
1152 // isExportedRuntime reports whether name is an exported runtime function.
1153 // It is only for runtime functions, so ASCII A-Z is fine.
1154 // TODO: this handles exported functions but not exported methods.
1155 func isExportedRuntime(name string) bool {
1156 const n = len("runtime.")
1157 return len(name) > n && name[:n] == "runtime." && 'A' <= name[n] && name[n] <= 'Z'
1160 // elideWrapperCalling reports whether a wrapper function that called
1161 // function id should be elided from stack traces.
1162 func elideWrapperCalling(id abi.FuncID) bool {
1163 // If the wrapper called a panic function instead of the
1164 // wrapped function, we want to include it in stacks.
1165 return !(id == abi.FuncID_gopanic || id == abi.FuncID_sigpanic || id == abi.FuncID_panicwrap)
1168 var gStatusStrings = [...]string{
1170 _Grunnable: "runnable",
1171 _Grunning: "running",
1172 _Gsyscall: "syscall",
1173 _Gwaiting: "waiting",
1175 _Gcopystack: "copystack",
1176 _Gpreempted: "preempted",
1179 func goroutineheader(gp *g) {
1180 gpstatus := readgstatus(gp)
1182 isScan := gpstatus&_Gscan != 0
1183 gpstatus &^= _Gscan // drop the scan bit
1185 // Basic string status
1187 if 0 <= gpstatus && gpstatus < uint32(len(gStatusStrings)) {
1188 status = gStatusStrings[gpstatus]
1194 if gpstatus == _Gwaiting && gp.waitreason != waitReasonZero {
1195 status = gp.waitreason.String()
1198 // approx time the G is blocked, in minutes
1200 if (gpstatus == _Gwaiting || gpstatus == _Gsyscall) && gp.waitsince != 0 {
1201 waitfor = (nanotime() - gp.waitsince) / 60e9
1203 print("goroutine ", gp.goid, " [", status)
1208 print(", ", waitfor, " minutes")
1210 if gp.lockedm != 0 {
1211 print(", locked to thread")
1216 func tracebackothers(me *g) {
1217 level, _, _ := gotraceback()
1219 // Show the current goroutine first, if we haven't already.
1220 curgp := getg().m.curg
1221 if curgp != nil && curgp != me {
1223 goroutineheader(curgp)
1224 traceback(^uintptr(0), ^uintptr(0), 0, curgp)
1227 // We can't call locking forEachG here because this may be during fatal
1228 // throw/panic, where locking could be out-of-order or a direct
1231 // Instead, use forEachGRace, which requires no locking. We don't lock
1232 // against concurrent creation of new Gs, but even with allglock we may
1233 // miss Gs created after this loop.
1234 forEachGRace(func(gp *g) {
1235 if gp == me || gp == curgp || readgstatus(gp) == _Gdead || isSystemGoroutine(gp, false) && level < 2 {
1240 // Note: gp.m == getg().m occurs when tracebackothers is called
1241 // from a signal handler initiated during a systemstack call.
1242 // The original G is still in the running state, and we want to
1244 if gp.m != getg().m && readgstatus(gp)&^_Gscan == _Grunning {
1245 print("\tgoroutine running on other thread; stack unavailable\n")
1248 traceback(^uintptr(0), ^uintptr(0), 0, gp)
1253 // tracebackHexdump hexdumps part of stk around frame.sp and frame.fp
1254 // for debugging purposes. If the address bad is included in the
1255 // hexdumped range, it will mark it as well.
1256 func tracebackHexdump(stk stack, frame *stkframe, bad uintptr) {
1257 const expand = 32 * goarch.PtrSize
1258 const maxExpand = 256 * goarch.PtrSize
1259 // Start around frame.sp.
1260 lo, hi := frame.sp, frame.sp
1261 // Expand to include frame.fp.
1262 if frame.fp != 0 && frame.fp < lo {
1265 if frame.fp != 0 && frame.fp > hi {
1268 // Expand a bit more.
1269 lo, hi = lo-expand, hi+expand
1270 // But don't go too far from frame.sp.
1271 if lo < frame.sp-maxExpand {
1272 lo = frame.sp - maxExpand
1274 if hi > frame.sp+maxExpand {
1275 hi = frame.sp + maxExpand
1277 // And don't go outside the stack bounds.
1285 // Print the hex dump.
1286 print("stack: frame={sp:", hex(frame.sp), ", fp:", hex(frame.fp), "} stack=[", hex(stk.lo), ",", hex(stk.hi), ")\n")
1287 hexdumpWords(lo, hi, func(p uintptr) byte {
1300 // isSystemGoroutine reports whether the goroutine g must be omitted
1301 // in stack dumps and deadlock detector. This is any goroutine that
1302 // starts at a runtime.* entry point, except for runtime.main,
1303 // runtime.handleAsyncEvent (wasm only) and sometimes runtime.runfinq.
1305 // If fixed is true, any goroutine that can vary between user and
1306 // system (that is, the finalizer goroutine) is considered a user
1308 func isSystemGoroutine(gp *g, fixed bool) bool {
1309 // Keep this in sync with internal/trace.IsSystemGoroutine.
1310 f := findfunc(gp.startpc)
1314 if f.funcID == abi.FuncID_runtime_main || f.funcID == abi.FuncID_handleAsyncEvent {
1317 if f.funcID == abi.FuncID_runfinq {
1318 // We include the finalizer goroutine if it's calling
1319 // back into user code.
1321 // This goroutine can vary. In fixed mode,
1322 // always consider it a user goroutine.
1325 return fingStatus.Load()&fingRunningFinalizer == 0
1327 return hasPrefix(funcname(f), "runtime.")
1330 // SetCgoTraceback records three C functions to use to gather
1331 // traceback information from C code and to convert that traceback
1332 // information into symbolic information. These are used when printing
1333 // stack traces for a program that uses cgo.
1335 // The traceback and context functions may be called from a signal
1336 // handler, and must therefore use only async-signal safe functions.
1337 // The symbolizer function may be called while the program is
1338 // crashing, and so must be cautious about using memory. None of the
1339 // functions may call back into Go.
1341 // The context function will be called with a single argument, a
1342 // pointer to a struct:
1348 // In C syntax, this struct will be
1351 // uintptr_t Context;
1354 // If the Context field is 0, the context function is being called to
1355 // record the current traceback context. It should record in the
1356 // Context field whatever information is needed about the current
1357 // point of execution to later produce a stack trace, probably the
1358 // stack pointer and PC. In this case the context function will be
1359 // called from C code.
1361 // If the Context field is not 0, then it is a value returned by a
1362 // previous call to the context function. This case is called when the
1363 // context is no longer needed; that is, when the Go code is returning
1364 // to its C code caller. This permits the context function to release
1365 // any associated resources.
1367 // While it would be correct for the context function to record a
1368 // complete a stack trace whenever it is called, and simply copy that
1369 // out in the traceback function, in a typical program the context
1370 // function will be called many times without ever recording a
1371 // traceback for that context. Recording a complete stack trace in a
1372 // call to the context function is likely to be inefficient.
1374 // The traceback function will be called with a single argument, a
1375 // pointer to a struct:
1379 // SigContext uintptr
1384 // In C syntax, this struct will be
1387 // uintptr_t Context;
1388 // uintptr_t SigContext;
1393 // The Context field will be zero to gather a traceback from the
1394 // current program execution point. In this case, the traceback
1395 // function will be called from C code.
1397 // Otherwise Context will be a value previously returned by a call to
1398 // the context function. The traceback function should gather a stack
1399 // trace from that saved point in the program execution. The traceback
1400 // function may be called from an execution thread other than the one
1401 // that recorded the context, but only when the context is known to be
1402 // valid and unchanging. The traceback function may also be called
1403 // deeper in the call stack on the same thread that recorded the
1404 // context. The traceback function may be called multiple times with
1405 // the same Context value; it will usually be appropriate to cache the
1406 // result, if possible, the first time this is called for a specific
1409 // If the traceback function is called from a signal handler on a Unix
1410 // system, SigContext will be the signal context argument passed to
1411 // the signal handler (a C ucontext_t* cast to uintptr_t). This may be
1412 // used to start tracing at the point where the signal occurred. If
1413 // the traceback function is not called from a signal handler,
1414 // SigContext will be zero.
1416 // Buf is where the traceback information should be stored. It should
1417 // be PC values, such that Buf[0] is the PC of the caller, Buf[1] is
1418 // the PC of that function's caller, and so on. Max is the maximum
1419 // number of entries to store. The function should store a zero to
1420 // indicate the top of the stack, or that the caller is on a different
1421 // stack, presumably a Go stack.
1423 // Unlike runtime.Callers, the PC values returned should, when passed
1424 // to the symbolizer function, return the file/line of the call
1425 // instruction. No additional subtraction is required or appropriate.
1427 // On all platforms, the traceback function is invoked when a call from
1428 // Go to C to Go requests a stack trace. On linux/amd64, linux/ppc64le,
1429 // linux/arm64, and freebsd/amd64, the traceback function is also invoked
1430 // when a signal is received by a thread that is executing a cgo call.
1431 // The traceback function should not make assumptions about when it is
1432 // called, as future versions of Go may make additional calls.
1434 // The symbolizer function will be called with a single argument, a
1435 // pointer to a struct:
1438 // PC uintptr // program counter to fetch information for
1439 // File *byte // file name (NUL terminated)
1440 // Lineno uintptr // line number
1441 // Func *byte // function name (NUL terminated)
1442 // Entry uintptr // function entry point
1443 // More uintptr // set non-zero if more info for this PC
1444 // Data uintptr // unused by runtime, available for function
1447 // In C syntax, this struct will be
1452 // uintptr_t Lineno;
1459 // The PC field will be a value returned by a call to the traceback
1462 // The first time the function is called for a particular traceback,
1463 // all the fields except PC will be 0. The function should fill in the
1464 // other fields if possible, setting them to 0/nil if the information
1465 // is not available. The Data field may be used to store any useful
1466 // information across calls. The More field should be set to non-zero
1467 // if there is more information for this PC, zero otherwise. If More
1468 // is set non-zero, the function will be called again with the same
1469 // PC, and may return different information (this is intended for use
1470 // with inlined functions). If More is zero, the function will be
1471 // called with the next PC value in the traceback. When the traceback
1472 // is complete, the function will be called once more with PC set to
1473 // zero; this may be used to free any information. Each call will
1474 // leave the fields of the struct set to the same values they had upon
1475 // return, except for the PC field when the More field is zero. The
1476 // function must not keep a copy of the struct pointer between calls.
1478 // When calling SetCgoTraceback, the version argument is the version
1479 // number of the structs that the functions expect to receive.
1480 // Currently this must be zero.
1482 // The symbolizer function may be nil, in which case the results of
1483 // the traceback function will be displayed as numbers. If the
1484 // traceback function is nil, the symbolizer function will never be
1485 // called. The context function may be nil, in which case the
1486 // traceback function will only be called with the context field set
1487 // to zero. If the context function is nil, then calls from Go to C
1488 // to Go will not show a traceback for the C portion of the call stack.
1490 // SetCgoTraceback should be called only once, ideally from an init function.
1491 func SetCgoTraceback(version int, traceback, context, symbolizer unsafe.Pointer) {
1493 panic("unsupported version")
1496 if cgoTraceback != nil && cgoTraceback != traceback ||
1497 cgoContext != nil && cgoContext != context ||
1498 cgoSymbolizer != nil && cgoSymbolizer != symbolizer {
1499 panic("call SetCgoTraceback only once")
1502 cgoTraceback = traceback
1503 cgoContext = context
1504 cgoSymbolizer = symbolizer
1506 // The context function is called when a C function calls a Go
1507 // function. As such it is only called by C code in runtime/cgo.
1508 if _cgo_set_context_function != nil {
1509 cgocall(_cgo_set_context_function, context)
1513 var cgoTraceback unsafe.Pointer
1514 var cgoContext unsafe.Pointer
1515 var cgoSymbolizer unsafe.Pointer
1517 // cgoTracebackArg is the type passed to cgoTraceback.
1518 type cgoTracebackArg struct {
1525 // cgoContextArg is the type passed to the context function.
1526 type cgoContextArg struct {
1530 // cgoSymbolizerArg is the type passed to cgoSymbolizer.
1531 type cgoSymbolizerArg struct {
1541 // printCgoTraceback prints a traceback of callers.
1542 func printCgoTraceback(callers *cgoCallers) {
1543 if cgoSymbolizer == nil {
1544 for _, c := range callers {
1548 print("non-Go function at pc=", hex(c), "\n")
1553 commitFrame := func() (pr, stop bool) { return true, false }
1554 var arg cgoSymbolizerArg
1555 for _, c := range callers {
1559 printOneCgoTraceback(c, commitFrame, &arg)
1562 callCgoSymbolizer(&arg)
1565 // printOneCgoTraceback prints the traceback of a single cgo caller.
1566 // This can print more than one line because of inlining.
1567 // It returns the "stop" result of commitFrame.
1568 func printOneCgoTraceback(pc uintptr, commitFrame func() (pr, stop bool), arg *cgoSymbolizerArg) bool {
1571 if pr, stop := commitFrame(); stop {
1577 callCgoSymbolizer(arg)
1578 if arg.funcName != nil {
1579 // Note that we don't print any argument
1580 // information here, not even parentheses.
1581 // The symbolizer must add that if appropriate.
1582 println(gostringnocopy(arg.funcName))
1584 println("non-Go function")
1587 if arg.file != nil {
1588 print(gostringnocopy(arg.file), ":", arg.lineno, " ")
1590 print("pc=", hex(pc), "\n")
1597 // callCgoSymbolizer calls the cgoSymbolizer function.
1598 func callCgoSymbolizer(arg *cgoSymbolizerArg) {
1600 if panicking.Load() > 0 || getg().m.curg != getg() {
1601 // We do not want to call into the scheduler when panicking
1602 // or when on the system stack.
1606 msanwrite(unsafe.Pointer(arg), unsafe.Sizeof(cgoSymbolizerArg{}))
1609 asanwrite(unsafe.Pointer(arg), unsafe.Sizeof(cgoSymbolizerArg{}))
1611 call(cgoSymbolizer, noescape(unsafe.Pointer(arg)))
1614 // cgoContextPCs gets the PC values from a cgo traceback.
1615 func cgoContextPCs(ctxt uintptr, buf []uintptr) {
1616 if cgoTraceback == nil {
1620 if panicking.Load() > 0 || getg().m.curg != getg() {
1621 // We do not want to call into the scheduler when panicking
1622 // or when on the system stack.
1625 arg := cgoTracebackArg{
1627 buf: (*uintptr)(noescape(unsafe.Pointer(&buf[0]))),
1628 max: uintptr(len(buf)),
1631 msanwrite(unsafe.Pointer(&arg), unsafe.Sizeof(arg))
1634 asanwrite(unsafe.Pointer(&arg), unsafe.Sizeof(arg))
1636 call(cgoTraceback, noescape(unsafe.Pointer(&arg)))