Fix line numbers on sigsegv
When hitting a signal, the stacktrace doesn't show the line number where the actual signal occurred. It's possible to patch this by looking into the right registers. See #1081.
As per https://github.com/c3lang/c3c/issues/1390#issuecomment-2316301521 here is the source code:
import std::io;
import libc;
const String[] PICKS = {
"migico",
"buqaku",
"isax",
"papopoy",
"medaxor",
"dux",
"roor",
"ibpupu",
"younop",
"tojto",
};
const String VOW = "aeiou";
const String CON = "bcdfghjklmnpqrstvwxyz";
macro char rand_vow() => VOW[libc::rand()%VOW.len];
macro char rand_con() => CON[libc::rand()%CON.len];
macro bool is_vow(char x) => @ok(VOW.index_of_char(x));
fn void print_rand_syl() {
switch (libc::rand()%3) {
case 0: io::printf("%c%c", rand_con(), rand_vow());
case 1: io::printf("%c%c%c", rand_con(), rand_vow(), rand_con());
case 2: io::printf("%c%c", rand_vow(), rand_con());
}
}
fn void print_rand_words() {
const int N = 10;
const int SYL = 5;
for (int j = 0; j < N; ++j) {
for (int i = 0; i < 1 + libc::rand()%(SYL-1); ++i) {
print_rand_syl();
}
io::printf("\n");
}
}
fn void print_mutated_word(String word) {
if (word.len > 0) {
int index = libc::rand()%word.len;
if (is_vow(word[index])) {
word[index] = rand_vow();
} else {
word[index] = rand_con();
}
}
}
fn void main()
{
libc::srand((uint)libc::time(null));
foreach (word: PICKS) print_mutated_word(word);
}
The problem is only reproducible for me on the Linux compiler downloaded from https://github.com/c3lang/c3c/releases/tag/v0.6.1 On the latest commit dfe80eb05003a69fde3476dec4346a01f6ef8716 it just segfaults for me without printing any stack for some reason.
Argh... that was a bad regression (the lack of backtrace) it's back in now @rexim.
Line numbers of sigsegv for Darwin Arm64 is added