*** empty log message ***

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@1023 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2001-02-23 01:40:06 +00:00
commit d9da4e4777
13 changed files with 464 additions and 153 deletions

View file

@ -10,7 +10,7 @@
WADSRCS = vars.c io.c memory.c return.c default.c stack.c stab.c elf.c object.c init.c segment.c signal.c
WADOBJS = vars.o io.o memory.o return.o default.o stack.o stab.o elf.o object.o signal.o segment.o init.o
INCLUDE = -I../Include -I. $(SINCLUDE)
WADOPT = -DWAD_LINUX
WADOPT = -DWAD_SOLARIS
# Location of your Python installation
PYINCLUDE = -I/usr/local/include/python2.0
@ -23,24 +23,24 @@ TCLSRCS = wadtcl.cxx
TCLOBJS = wadtcl.o
# Location of your Perl installation
PERLINCLUDE = -I/usr/lib/perl5/5.00503/i386-linux/CORE
PERLINCLUDE = -I/usr/perl5/5.00503/sun4-solaris/CORE
PERLSRCS = wadpl.cxx
PERLOBJS = wadpl.o
# C Compiler
CC = gcc
CFLAGS = #-fpic
CC = cc
CFLAGS = #
# C++ Compiler
CXX = c++
CXXFLAGS = #-fpic
CXX = CC
CXXFLAGS = #-Kpic
# Linking options
CLINK =
CXXLINK = g++ -shared
CXXLINK = CC -G
# AR
CC = ar
AR = ar
# Rules for creation of a .o file from .cxx
.SUFFIXES: .cxx

View file

@ -83,8 +83,11 @@ char *wad_strip_dir(char *name) {
return name;
}
static char *src_file = 0;
static int src_len = 0;
static char src_path[1024] = "";
/* Opens up a source file and tries to locate a specific line number */
@ -94,16 +97,22 @@ char *wad_load_source(char *path, int line) {
char *start;
int n;
fd = open(path, O_RDONLY);
if (fd < 0) return 0;
src_len = lseek(fd, 0, SEEK_END);
lseek(fd,0,SEEK_SET);
src_file = (char *)mmap(NULL,src_len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
if (src_file == MAP_FAILED) {
if (strcmp(src_path,path)) {
if (src_file) {
munmap(src_file, src_len);
}
fd = open(path, O_RDONLY);
if (fd < 0) return 0;
src_len = lseek(fd, 0, SEEK_END);
lseek(fd,0,SEEK_SET);
src_file = (char *)mmap(NULL,src_len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
if (src_file == MAP_FAILED) {
close(fd);
return 0;
}
close(fd);
return 0;
}
close(fd);
strcpy(src_path,path);
}
n = 0;
start = src_file;
c = src_file;
@ -118,14 +127,102 @@ char *wad_load_source(char *path, int line) {
c++;
n++;
}
munmap(src_file,src_len);
src_file = 0;
return 0;
}
void wad_release_source() {
if (src_file)
if (src_file) {
munmap(src_file,src_len);
src_file = 0;
src_len = 0;
src_path[0] = 0;
}
}
/* -----------------------------------------------------------------------------
* wad_debug_src_code(WadFrame *f)
*
* Get source code for a frame
* ----------------------------------------------------------------------------- */
char *wad_debug_src_string(WadFrame *f, int window) {
static char temp[16384];
char ntemp[64];
if (f->loc_srcfile && strlen(f->loc_srcfile) && (f->loc_line > 0)) {
char *line, *c;
int i;
int first, last;
first = f->loc_line - window;
last = f->loc_line + window;
if (first < 1) first = 1;
line = wad_load_source(f->loc_srcfile,first);
if (line) {
strcpy(temp,f->loc_srcfile);
strcat(temp,", line ");
sprintf(ntemp,"%d\n\n", f->loc_line);
strcat(temp,ntemp);
for (i = first; i <= last; i++) {
if (i == f->loc_line) strcat(temp," => ");
else strcat(temp," ");
c = strchr(line,'\n');
if (c) {
*c = 0;
strcat(temp,line);
strcat(temp,"\n");
*c = '\n';
} else {
strcat(temp,line);
strcat(temp,"\n");
break;
}
line = c+1;
}
f->debug_srcstr = wad_strdup(temp);
return f->debug_srcstr;
}
}
f->debug_srcstr = 0;
return 0;
}
/* -----------------------------------------------------------------------------
* wad_debug_make_strings(WadFrame *f)
*
* This function walks the stack trace and tries to generate a debugging string
* ----------------------------------------------------------------------------- */
void
wad_debug_make_strings(WadFrame *f) {
static char msg[16384];
char temp[1024];
while (f) {
sprintf(msg,"#%-3d 0x%08x in ", f->frameno, f->pc);
strcat(msg, f->sym_name ? f->sym_name : "?");
strcat(msg,"(");
strcat(msg,wad_arg_string(f));
strcat(msg,")");
if (f->loc_srcfile && strlen(f->loc_srcfile)) {
strcat(msg," in '");
strcat(msg, wad_strip_dir(f->loc_srcfile));
strcat(msg,"'");
if (f->loc_line > 0) {
sprintf(temp,", line %d", f->loc_line);
strcat(msg,temp);
/* Try to locate the source file */
wad_debug_src_string(f, WAD_SRC_WINDOW);
}
} else {
if (f->loc_objfile && strlen(f->loc_objfile)) {
strcat(msg," from '");
strcat(msg, wad_strip_dir(f->loc_objfile));
strcat(msg,"'");
}
}
strcat(msg,"\n");
f->debug_str = wad_strdup(msg);
f = f->next;
}
}
/* -----------------------------------------------------------------------------
@ -135,6 +232,7 @@ void wad_release_source() {
void wad_default_callback(int signo, WadFrame *f, char *ret) {
char *fd;
WadFrame *fline = 0;
char *srcstr = 0;
switch(signo) {
case SIGSEGV:
@ -161,60 +259,18 @@ void wad_default_callback(int signo, WadFrame *f, char *ret) {
while (f && !(f->last)) {
f = f->next;
}
while (f) {
fprintf(stderr,"#%-3d 0x%08x in %s(%s)", f->frameno, f->pc, f->sym_name ? f->sym_name : "?",
wad_arg_string(f));
if (f->loc_srcfile && strlen(f->loc_srcfile)) {
fprintf(stderr," in '%s'", wad_strip_dir(f->loc_srcfile));
if (f->loc_line > 0) {
fprintf(stderr,", line %d", f->loc_line);
{
int fd;
fd = open(f->loc_srcfile, O_RDONLY);
if (fd > 0) {
fline = f;
}
close(fd);
}
}
} else {
if (f->loc_objfile && strlen(f->loc_objfile)) {
fprintf(stderr," from '%s'", f->loc_objfile);
}
fputs(f->debug_str, stderr);
if (f->debug_srcstr) {
srcstr = f->debug_srcstr;
}
fprintf(stderr,"\n");
f = f->prev;
}
if (fline) {
int first;
int last;
char *line, *c;
int i;
first = fline->loc_line - 2;
last = fline->loc_line + 2;
if (first < 1) first = 1;
line = wad_load_source(fline->loc_srcfile,first);
if (line) {
fprintf(stderr,"\n%s, line %d\n\n", fline->loc_srcfile,fline->loc_line);
for (i = first; i <= last; i++) {
if (i == fline->loc_line) fprintf(stderr," => ");
else fprintf(stderr," ");
c = strchr(line,'\n');
if (c) {
*c = 0;
fprintf(stderr,"%s\n",line);
*c = '\n';
} else {
fprintf(stderr,"%s\n",line);
break;
}
line = c+1;
}
wad_release_source();
fprintf(stderr,"\n");
}
if (srcstr) {
fputs("\n", stderr);
fputs(srcstr,stderr);
fputs("\n", stderr);
}
}

View file

@ -351,8 +351,12 @@ void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) {
if (sig == SIGSEGV) {
if (addr >= current_brk) wad_heap_overflow = 1;
}
wad_stack_debug(frame);
/* Generate debugging strings */
wad_debug_make_strings(frame);
/* Walk the exception frames and try to find a return point */
origframe = frame;
while (frame) {

View file

@ -44,6 +44,8 @@ new_frame() {
f->debug_nargs = -1;
f->debug_args = 0;
f->debug_lastarg = 0;
f->debug_str = 0;
f->debug_srcstr = 0;
f->last = 0;
f->next = 0;

View file

@ -91,7 +91,8 @@ char *wad_format_var(WadLocal *l) {
#endif
strcat(buffer,"0x");
c = buffer+2;
for (i = 0; i < l->size; i++) {
/* for (i = 0; i < l->size; i++) { */
for (i = 0; i < 4; i++) {
b = (int) *ptr;
if (!leading || (b)) {
if (!leading || (b & 0xf0))