| 1 |
// Copyright 2025 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 tracebackctxt.go. That file uses //export so |
| 6 |
// it can't put function definitions in the "C" import comment. |
| 7 |
|
| 8 |
#include <stdint.h> |
| 9 |
#include <stdio.h> |
| 10 |
|
| 11 |
// Functions exported from Go. |
| 12 |
extern void G1(void); |
| 13 |
extern void G2(void); |
| 14 |
|
| 15 |
void C1() { |
| 16 |
G1(); |
| 17 |
} |
| 18 |
|
| 19 |
void C2() { |
| 20 |
G2(); |
| 21 |
} |
| 22 |
|
| 23 |
struct cgoContextArg { |
| 24 |
uintptr_t context; |
| 25 |
}; |
| 26 |
|
| 27 |
struct cgoTracebackArg { |
| 28 |
uintptr_t context; |
| 29 |
uintptr_t sigContext; |
| 30 |
uintptr_t* buf; |
| 31 |
uintptr_t max; |
| 32 |
}; |
| 33 |
|
| 34 |
struct cgoSymbolizerArg { |
| 35 |
uintptr_t pc; |
| 36 |
const char* file; |
| 37 |
uintptr_t lineno; |
| 38 |
const char* func; |
| 39 |
uintptr_t entry; |
| 40 |
uintptr_t more; |
| 41 |
uintptr_t data; |
| 42 |
}; |
| 43 |
|
| 44 |
void tcContext(void* parg) { |
| 45 |
struct cgoContextArg* arg = (struct cgoContextArg*)(parg); |
| 46 |
if (arg->context == 0) { |
| 47 |
arg->context = 1; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
void tcTraceback(void* parg) { |
| 52 |
int base, i; |
| 53 |
struct cgoTracebackArg* arg = (struct cgoTracebackArg*)(parg); |
| 54 |
if (arg->max < 1) { |
| 55 |
return; |
| 56 |
} |
| 57 |
arg->buf[0] = 6; // Chosen by fair dice roll. |
| 58 |
} |
| 59 |
|
| 60 |
void tcSymbolizer(void *parg) { |
| 61 |
struct cgoSymbolizerArg* arg = (struct cgoSymbolizerArg*)(parg); |
| 62 |
if (arg->pc == 0) { |
| 63 |
return; |
| 64 |
} |
| 65 |
// Report two lines per PC returned by traceback, to test more handling. |
| 66 |
arg->more = arg->file == NULL; |
| 67 |
arg->file = "tracebackctxt.go"; |
| 68 |
arg->func = "cFunction"; |
| 69 |
arg->lineno = arg->pc + (arg->more << 16); |
| 70 |
} |