...

Source file src/runtime/testdata/testprogcgo/traceback.go

Documentation: runtime/testdata/testprogcgo

     1  // Copyright 2016 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.
     4  
     5  package main
     6  
     7  // This program will crash.
     8  // We want the stack trace to include the C functions.
     9  // We use a fake traceback, and a symbolizer that dumps a string we recognize.
    10  
    11  /*
    12  #cgo CFLAGS: -g -O0
    13  
    14  // Defined in traceback_c.c.
    15  extern int crashInGo;
    16  int tracebackF1(void);
    17  void cgoTraceback(void* parg);
    18  void cgoSymbolizer(void* parg);
    19  */
    20  import "C"
    21  
    22  import (
    23  	"runtime"
    24  	"unsafe"
    25  )
    26  
    27  func init() {
    28  	register("CrashTraceback", CrashTraceback)
    29  	register("CrashTracebackGo", CrashTracebackGo)
    30  }
    31  
    32  func CrashTraceback() {
    33  	runtime.SetCgoTraceback(0, unsafe.Pointer(C.cgoTraceback), nil, unsafe.Pointer(C.cgoSymbolizer))
    34  	C.tracebackF1()
    35  }
    36  
    37  func CrashTracebackGo() {
    38  	C.crashInGo = 1
    39  	CrashTraceback()
    40  }
    41  
    42  //export h1
    43  func h1() {
    44  	h2()
    45  }
    46  
    47  func h2() {
    48  	h3()
    49  }
    50  
    51  func h3() {
    52  	var x *int
    53  	*x = 0
    54  }
    55  

View as plain text