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