1 /* -----------------------------------------------------------------------------
4 * Dynamically loadable module for Perl.
6 * Author(s) : David Beazley (beazley@cs.uchicago.edu)
8 * Copyright (C) 2000. The University of Chicago
9 * See the file LICENSE for information on usage and redistribution.
10 * ----------------------------------------------------------------------------- */
26 #include "wad_perl_handler.c"
28 /* Error message returned to perl */
30 static char message[65536];
31 static int global_signo = 0;
33 static void returnfunc(void) {
35 s = perl_eval_pv((char*)"libwadpl::wad_handler_traceback(0)", 0);
36 croak("%s\n%s",SvPV(s,PL_na),message);
40 /* Handler function */
41 static void handler(int signo, WadFrame *frame, char *ret) {
43 static char temp[1024];
53 wad_default_callback(signo, frame, ret);
60 type = (char*)"Segmentation fault.";
63 type = (char*)"Bus error.";
66 type = (char*)"Abort.";
69 type = (char*)"Math.";
74 strcat(message,"\n[ C stack trace ]\n\n");
78 /* Find the last exception frame */
83 /* Now work backwards */
84 fd = fd - f->lastsize;
87 sprintf(temp,"#%-3d 0x%08x in ", f->frameno, f->pc);
89 strcat(message,*(fd + f->sym_off) ? fd+f->sym_off : "?");
91 if (strlen(SRCFILE(f))) {
92 strcat(message," in '");
93 strcat(message, wad_strip_dir(SRCFILE(f)));
95 if (f->line_number > 0) {
96 sprintf(temp,", line %d", f->line_number);
101 if (strlen(fd+f->obj_off)) {
102 strcat(message," from '");
103 strcat(message, wad_strip_dir(OBJFILE(f)));
107 strcat(message,"\n");
108 if (!f->lastsize) break;
109 fd = fd - f->lastsize;
117 first = fline->line_number - 2;
118 last = fline->line_number + 2;
119 if (first < 1) first = 1;
121 line = wad_load_source(SRCFILE(fline),first);
123 strcat(message,"\n");
124 strcat(message, SRCFILE(fline));
125 sprintf(temp,", line %d\n\n", fline->line_number);
126 strcat(message, temp);
127 for (i = first; i <= last; i++) {
128 if (i == fline->line_number) strcat(message," => ");
129 else strcat(message," ");
130 c = strchr(line,'\n');
133 strcat(message,line);
134 strcat(message,"\n");
137 strcat(message,line);
138 strcat(message,"\n");
143 wad_release_source();
144 strcat(message,"\n");
147 wad_set_return_func(returnfunc);
151 static void perlwadinit() {
152 printf("WAD Enabled\n");
154 wad_set_callback(handler);
155 wad_set_return("Perl_pp_entersub", 0);
156 perl_eval_pv(wad_perl_handler, 0);
159 /* This hack is used to auto-initialize wad regardless of whether we are
160 used as an imported module or as a link-library for another module */
162 class wadinitializer {
169 static wadinitializer wi;