Skip to content

Commit

Permalink
Split into 2 packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Leont committed Sep 19, 2012
1 parent 306dd15 commit b5ebc81
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,7 +1,7 @@
Build
Build.bat
.build/*
Devel-Backtrace-*
Devel-cst-*
*.swp
*.tdy
*.c
Expand Down
2 changes: 1 addition & 1 deletion dist.ini
@@ -1,4 +1,4 @@
name = Devel-CStacktrace
name = Devel-cst
author = Leon Timmermans <leont@cpan.org>
license = Perl_5
copyright_holder = Leon Timmermans
Expand Down
8 changes: 2 additions & 6 deletions lib/Devel/CStacktrace.pm
Expand Up @@ -2,24 +2,20 @@ package Devel::CStacktrace;

use strict;
use warnings;
use XSLoader;
use Devel::cst ();
use Sub::Exporter::Progressive -setup => { exports => [qw/stacktrace/] };

XSLoader::load(__PACKAGE__, __PACKAGE__->VERSION);

1;

# ABSTRACT: C stacktraces for GNU systems

__END__
=head1 SYNOPSIS
say for stacktrace(128);
=head1 DESCRIPTION
This module exports one function, stacktrace, that returns a list. It also sets signal handlers for C<SIGSEGV>, C<SIGBUS>, C<SIGILL> and C<SIGFPE> that prints a stacktrace and some more information about the fault to stderr before dying.
This module exports one function, stacktrace, that returns a list.
=func stacktrace($max_depth)
Expand Down
19 changes: 19 additions & 0 deletions lib/Devel/cst.pm
@@ -0,0 +1,19 @@
package Devel::cst;

use strict;
use warnings;
use XSLoader;
XSLoader::load(__PACKAGE__, __PACKAGE__->VERSION);

sub DB::DB {}

# ABSTRACT: C stacktraces for GNU systems

=head1 SYNOPSIS
perl -d:cst -e ...
=head1 DESCRIPTION
This module sets signal handlers for C<SIGSEGV>, C<SIGBUS>, C<SIGILL> and C<SIGFPE> that prints a stacktrace and some more information about the fault to stderr before dying. This enables debugging even without gdb being present.
33 changes: 22 additions & 11 deletions lib/Devel/CStacktrace.xs → lib/Devel/cst.xs
Expand Up @@ -105,28 +105,39 @@ void handler(int signo, siginfo_t* info, void* context) {

#pragma GCC diagnostic pop

int signals[] = { SIGSEGV, SIGBUS, SIGILL, SIGFPE };
static const int signals[] = { SIGSEGV, SIGBUS, SIGILL, SIGFPE };
static int inited = 0;

#define STACKSIZE 8096
char altstack_buffer[STACKSIZE];

MODULE = Devel::CStacktrace PACKAGE = Devel::CStacktrace
MODULE = Devel::cst PACKAGE = Devel::cst

BOOT:
struct sigaction action;
int i;
stack_t altstack = { altstack_buffer, 0, STACKSIZE };
sigaltstack(&altstack, NULL);
action.sa_sigaction = handler;
action.sa_flags = SA_RESETHAND | SA_SIGINFO | SA_ONSTACK;
sigemptyset(&action.sa_mask);
for (i = 0; i < sizeof signals / sizeof *signals; i++)
sigaction(signals[i], &action, NULL);
name[SIGSEGV] = (struct iovec){ STR_WITH_LEN("SIGSEGV") };
name[SIGBUS] = (struct iovec){ STR_WITH_LEN("SIGBUS") };
name[SIGILL] = (struct iovec){ STR_WITH_LEN("SIGILL") };
name[SIGFPE] = (struct iovec){ STR_WITH_LEN("SIGFPE") };

void
import(package)
SV* package;
CODE:
if (!inited) {
struct sigaction action;
int i;
stack_t altstack = { altstack_buffer, 0, STACKSIZE };
sigaltstack(&altstack, NULL);
action.sa_sigaction = handler;
action.sa_flags = SA_RESETHAND | SA_SIGINFO | SA_ONSTACK;
sigemptyset(&action.sa_mask);
for (i = 0; i < sizeof signals / sizeof *signals; i++)
sigaction(signals[i], &action, NULL);
inited = 1;
}

MODULE = Devel::cst PACKAGE = Devel::CStacktrace

void
stacktrace(depth)
size_t depth;
Expand Down

0 comments on commit b5ebc81

Please sign in to comment.