Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about this approach? #1

Open
ghost opened this issue Feb 18, 2016 · 0 comments
Open

How about this approach? #1

ghost opened this issue Feb 18, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 18, 2016

# include <unistd.h>
# include <signal.h>
# include <string.h>
# include <stdlib.h>

static int fds[2];

static void sgsgvhndlr (int signr)
{
    write (fds[1], &signr, 1);
    _Exit (EXIT_FAILURE);
}

static int err (int exit_code, char *msg)
{
    write (STDERR_FILENO, msg, strlen (msg));
    write (STDERR_FILENO, "\n", 1);
    _Exit (EXIT_FAILURE);
}

int main (void)
{
    int rc;
    pid_t pid;

    rc = pipe (fds);
    if (rc != 0) err (EXIT_FAILURE, "pipe");
    pid = fork ();
    if (pid == -1) err (EXIT_FAILURE, "fork");
    if (pid) {
        rc = read (fds[0], &pid, 1);
        if (rc - 1) err (EXIT_FAILURE, "read");
        write (STDOUT_FILENO, "gdb\n", 4);
        /* execute gdb */
        return EXIT_SUCCESS;
    }
    else {
        struct sigaction sa = {0,};
        sa.sa_handler = sgsgvhndlr;
        rc = sigaction (SIGSEGV, &sa, NULL);
        if (rc) err (EXIT_SUCCESS, "sigaction");
        return *(char*)0;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants