Text file src/runtime/testdata/testprogcgo/traceback_c.c

     1  // Copyright 2020 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  // The C definitions for traceback.go. That file uses //export so
     6  // it can't put function definitions in the "C" import comment.
     7  
     8  #include <stdint.h>
     9  
    10  char *p;
    11  
    12  int crashInGo;
    13  extern void h1(void);
    14  
    15  int tracebackF3(void) {
    16  	if (crashInGo)
    17  		h1();
    18  	else
    19  		*p = 0;
    20  	return 0;
    21  }
    22  
    23  int tracebackF2(void) {
    24  	return tracebackF3();
    25  }
    26  
    27  int tracebackF1(void) {
    28  	return tracebackF2();
    29  }
    30  
    31  struct cgoTracebackArg {
    32  	uintptr_t  context;
    33  	uintptr_t  sigContext;
    34  	uintptr_t* buf;
    35  	uintptr_t  max;
    36  };
    37  
    38  struct cgoSymbolizerArg {
    39  	uintptr_t   pc;
    40  	const char* file;
    41  	uintptr_t   lineno;
    42  	const char* func;
    43  	uintptr_t   entry;
    44  	uintptr_t   more;
    45  	uintptr_t   data;
    46  };
    47  
    48  void cgoTraceback(void* parg) {
    49  	struct cgoTracebackArg* arg = (struct cgoTracebackArg*)(parg);
    50  	arg->buf[0] = 1;
    51  	arg->buf[1] = 2;
    52  	arg->buf[2] = 3;
    53  	arg->buf[3] = 0;
    54  }
    55  
    56  void cgoSymbolizer(void* parg) {
    57  	struct cgoSymbolizerArg* arg = (struct cgoSymbolizerArg*)(parg);
    58  	if (arg->pc != arg->data + 1) {
    59  		arg->file = "unexpected data";
    60  	} else {
    61  		arg->file = "cgo symbolizer";
    62  	}
    63  	arg->lineno = arg->data + 1;
    64  	arg->data++;
    65  }
    66  

View as plain text