c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Fix line numbers on sigsegv

Open lerno opened this issue 1 year ago • 3 comments

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.

lerno avatar Feb 01 '24 23:02 lerno

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.

rexim avatar Aug 29 '24 13:08 rexim

Argh... that was a bad regression (the lack of backtrace) it's back in now @rexim.

lerno avatar Aug 29 '24 17:08 lerno

Line numbers of sigsegv for Darwin Arm64 is added

lerno avatar Nov 20 '25 19:11 lerno