*** empty log message ***

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@1013 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2001-02-02 17:17:04 +00:00
commit e21ec340d8
8 changed files with 168 additions and 104 deletions

View file

@ -87,9 +87,12 @@ extern void wad_set_return_func(void (*f)(void));
typedef struct WadLocal {
char *name; /* Name of the local */
void *ptr; /* Pointer to data */
void *ptr; /* Pointer to the actual data (if known) */
int size; /* Size of the data */
int type; /* Data type */
/* Debugging information */
int loc; /* Location: register or stack */
int stack; /* location on the stack */
int reg; /* Register number */

View file

@ -7,10 +7,10 @@
#######################################################################
# These are the files that make up the WAD core
WADSRCS = vars.c default.c io.c memory.c return.c stack.c stab.c elf.c object.c init.c segment.c signal.c
WADOBJS = vars.o default.o io.o memory.o return.o stack.o stab.o elf.o object.o signal.o segment.o init.o
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,21 +23,21 @@ 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
# Rules for creation of a .o file from .cxx
.SUFFIXES: .cxx
@ -67,7 +67,8 @@ wad_perl_handler.c:
python makehandler.py
debug::
cc -g debug.c $(INCLUDE) -L. -Xlinker -rpath . -lwad
gcc -g debug.c $(INCLUDE) -L. -Xlinker -rpath . -lwad
# cc -g debug.c $(INCLUDE) -L. -R. -lwad
plus::
CC -g debug.cxx $(INCLUDE) -L. -R. -lwad
@ -76,7 +77,7 @@ wc::
wc $(SRCS)
semi::
egrep ";" $(WADSRCS) wadpy.cxx | wc
egrep ";" $(SRCS) wadpy.cxx | wc
clean::

View file

@ -96,7 +96,7 @@ void *wad_malloc(int nbytes) {
wm = wm->next;
}
if (!wm) {
wad_printf("wad_malloc: new page\n", nbytes);
/* wad_printf("wad_malloc: new page\n", nbytes);*/
wm = (WadMemory *) wad_page_alloc(1);
if (!wm) return 0;
wm->npages = 1;

View file

@ -107,7 +107,7 @@ wad_segment_find(void *vaddr) {
* ----------------------------------------------------------------------------- */
int wad_segment_valid(void *vaddr) {
return wad_segment_find ? 1 : 0;
return wad_segment_find(vaddr) ? 1 : 0;
}

View file

@ -255,6 +255,9 @@ void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) {
char *retname = 0;
unsigned long current_brk;
wad_release_memory();
wad_nlr_func = 0;
context = (ucontext_t *) vcontext;

View file

@ -29,7 +29,9 @@ typedef struct Stab {
#define N_RSYM 0x40 /* Register symbol */
#define N_SLINE 0x44 /* Source line */
#define N_SO 0x64 /* Source file name */
#define N_LSYM 0x80 /* Local symbol */
#define N_PSYM 0xa0 /* Parameter */
#define N_LBRAC 0xc0 /* Left brace */
/* -----------------------------------------------------------------------------
* match_stab_symbol()
@ -48,6 +50,32 @@ match_stab_symbol(char *symbol, char *stabtext, int slen) {
return 0;
}
static char *
stab_string_parm(char *str) {
return strchr(str,':');
}
/* -----------------------------------------------------------------------------
* stab_symbol(Stab *s, char *stabstr)
*
* Process stab symbol specifier N_LSYM
* ----------------------------------------------------------------------------- */
static void
stab_symbol(Stab *s, char *stabstr) {
char *pstr;
int a;
pstr = stab_string_parm(stabstr+s->n_strx);
if (!pstr) return;
if (pstr[1] == 't') {
/* wad_printf("stab lsym: other=%d, desc=%d, value=%d, str='%s'\n", s->n_other,s->n_desc,s->n_value,
stabstr+s->n_strx); */
}
}
/* -----------------------------------------------------------------------------
* scan_function()
*
@ -58,8 +86,13 @@ static void
scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
int i;
unsigned long offset;
offset = f->pc - f->sym_base;
int get_parms = 1;
offset = f->pc - f->sym_base;
if (wad_debug_mode & DEBUG_STABS) {
wad_printf("---[ %s ] --------------\n", f->sym_name);
}
for (i = 0; i < ns; i++,s++) {
if (wad_debug_mode & DEBUG_STABS) {
wad_printf(" %10d %10x %10d %10d %10d: '%s'\n", s->n_strx, s->n_type, s->n_other, s->n_desc, s->n_value,
@ -70,78 +103,85 @@ scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
if ((s->n_type == N_UNDF) || (s->n_type == N_SO) || (s->n_type == N_FUN) ||
(s->n_type == N_OBJ)) return;
if (s->n_type == N_LBRAC) {
get_parms = 0;
}
if (s->n_type == N_SLINE) {
get_parms = 0;
if (s->n_value < offset) {
f->loc_line = s->n_desc;
}
} else if ((s->n_type == N_PSYM) || (s->n_type == N_RSYM)) {
/* Parameter counting */
char *pname;
char *c;
int len;
WadLocal *arg;
pname = stabstr+s->n_strx;
c = strchr(pname,':');
if (c) {
len = (c-pname);
} else {
len = strlen(pname);
}
/* Check if the argument was already used */
/* In this case, the first stab simply identifies an argument. The second
one identifies its location for the debugger */
if (f->debug_args) {
/* Need to do some fix up for linux here */
WadLocal *a = f->debug_args;
while (a) {
if ((strncmp(a->name,pname,len) == 0) && (strlen(a->name) == len)) {
/* We already saw this argument. Given a choice between a register and a stack
argument. We will choose the stack version */
if (a->loc == PARM_STACK) {
if (get_parms) {
/* Parameter counting */
char *pname;
char *c;
int len;
WadLocal *arg;
pname = stabstr+s->n_strx;
c = strchr(pname,':');
if (c) {
len = (c-pname);
} else {
len = strlen(pname);
}
/* Check if the argument was already used */
/* In this case, the first stab simply identifies an argument. The second
one identifies its location for the debugger */
if (f->debug_args) {
/* Need to do some fix up for linux here */
WadLocal *a = f->debug_args;
while (a) {
if ((strncmp(a->name,pname,len) == 0) && (strlen(a->name) == len)) {
/* We already saw this argument. Given a choice between a register and a stack
argument. We will choose the stack version */
if (a->loc == PARM_STACK) {
break;
}
/* Go ahead and use the new argument */
if (s->n_type == N_RSYM) {
a->loc = PARM_REGISTER;
a->reg = s->n_value;
} else {
a->loc = PARM_STACK;
a->stack = s->n_value;
}
break;
}
/* Go ahead and use the new argument */
if (s->n_type == N_RSYM) {
a->loc = PARM_REGISTER;
a->reg = s->n_value;
} else {
a->loc = PARM_STACK;
a->stack = s->n_value;
}
break;
a = a->next;
}
a = a->next;
if (a) continue; /* We got an argument match. Just skip to the next stab */
}
if (a) continue; /* We got an argument match. Just skip to the next stab */
arg = (WadLocal *) wad_malloc(sizeof(WadLocal));
arg->name = (char *) wad_malloc(len+1);
strncpy(arg->name, pname, len);
arg->name[len] = 0;
if (s->n_type == N_RSYM) {
arg->loc = PARM_REGISTER;
arg->reg = s->n_value;
arg->stack = 0;
} else {
arg->loc = PARM_STACK;
arg->line = s->n_desc;
arg->stack = s->n_value;
}
arg->type = 0;
arg->next = 0;
if (f->debug_args) {
f->debug_lastarg->next = arg;
f->debug_lastarg = arg;
} else {
f->debug_args = arg;
f->debug_lastarg = arg;
f->debug_nargs= 0;
}
f->debug_nargs++;
}
arg = (WadLocal *) wad_malloc(sizeof(WadLocal));
arg->name = (char *) wad_malloc(len+1);
strncpy(arg->name, pname, len);
arg->name[len] = 0;
if (s->n_type == N_RSYM) {
arg->loc = PARM_REGISTER;
arg->reg = s->n_value;
arg->stack = 0;
} else {
arg->loc = PARM_STACK;
arg->line = s->n_desc;
arg->stack = s->n_value;
}
arg->type = 0;
arg->next = 0;
if (f->debug_args) {
f->debug_lastarg->next = arg;
f->debug_lastarg = arg;
} else {
f->debug_args = arg;
f->debug_lastarg = arg;
f->debug_nargs= 0;
}
f->debug_nargs++;
}
}
}
@ -192,6 +232,10 @@ wad_search_stab(void *sp, int size, char *stabstr, WadFrame *f) {
}
*/
if (s->n_type == N_LSYM) {
stab_symbol(s,stabstr);
continue;
}
if ((s->n_type == N_UNDF)) { /* && (s->n_desc >= 0)) { */
/* New stabs section. We need to be a little careful here. Do a recursive
search of the subsection. */

View file

@ -65,6 +65,8 @@ static WadFrame *
stack_unwind(unsigned long *pc, unsigned long *sp, unsigned long *fp) {
WadSegment *sp_seg, *fp_seg;
WadFrame *f;
unsigned long fake_fp;
if (wad_debug_mode & DEBUG_UNWIND) {
wad_printf("::: stack unwind : pc = %x, sp = %x, fp = %x\n", *pc, *sp, *fp);
}
@ -72,10 +74,22 @@ stack_unwind(unsigned long *pc, unsigned long *sp, unsigned long *fp) {
/* Verify that the sp and fp are in mapped memory */
sp_seg = wad_segment_find((void *) *sp);
fp_seg = wad_segment_find((void *) *fp);
if (!(sp_seg && fp_seg && (sp_seg == fp_seg))) {
/* Either the stack pointer or frame pointer is invalid. Or, the stack pointer
and frame pointer are in different memory regions. */
/* Make sure the stack pointer is in memory */
if (!sp_seg) {
return 0;
}
if (!fp_seg) {
/* Hmmm. If no frame pointer, we must be off the top of the call stack */
fake_fp = (unsigned long) (sp_seg->vaddr + sp_seg->size);
fp_seg = sp_seg;
} else {
fake_fp = *fp;
}
if (sp_seg != fp_seg) {
/* Whoa. Stack pointer and frame pointer are in different memory segments. */
wad_printf("WAD: Warning. Stack pointer and frame pointer are in different regions.\n");
return 0;
}
@ -87,9 +101,9 @@ stack_unwind(unsigned long *pc, unsigned long *sp, unsigned long *fp) {
f = new_frame();
f->pc = *pc;
f->sp = *sp;
f->fp = *fp;
f->fp = fake_fp;
f->segment = wad_segment_find((void *) *pc);
f->stack_size = *fp - *sp;
f->stack_size = fake_fp - *sp;
/* Make a copy of the call stack */
f->stack = (char *) wad_malloc(f->stack_size);
@ -173,44 +187,44 @@ void wad_stack_debug(WadFrame *frame) {
/* Walk the exception frames and try to find a return point */
while (frame) {
/* Print out detailed stack trace information */
printf("::: Stack frame - 0x%08x :::\n", frame);
printf(" pc = %x\n", frame->pc);
printf(" sp = %x\n", frame->sp);
printf(" fp = %x\n", frame->fp);
printf(" stack = %x\n", frame->stack);
printf(" size = %x\n", frame->stack_size);
printf(" segment = %x (%s)\n", frame->segment, frame->segment ? frame->segment->mappath : "?");
printf(" object = %x (%s)\n", frame->object, frame->object ? frame->object->path : "?");
wad_printf("::: Stack frame - 0x%08x :::\n", frame);
wad_printf(" pc = %x\n", frame->pc);
wad_printf(" sp = %x\n", frame->sp);
wad_printf(" fp = %x\n", frame->fp);
wad_printf(" stack = %x\n", frame->stack);
wad_printf(" size = %x\n", frame->stack_size);
wad_printf(" segment = %x (%s)\n", frame->segment, frame->segment ? frame->segment->mappath : "?");
wad_printf(" object = %x (%s)\n", frame->object, frame->object ? frame->object->path : "?");
if (frame->sym_name) {
printf(" sym_name = %s\n", frame->sym_name);
printf(" sym_base = %x\n", frame->sym_base);
printf(" sym_size = %x\n", frame->sym_size);
printf(" sym_bind = %x\n", frame->sym_bind);
printf(" sym_file = %s\n", frame->sym_file ? frame->sym_file : "");
wad_printf(" sym_name = %s\n", frame->sym_name);
wad_printf(" sym_base = %x\n", frame->sym_base);
wad_printf(" sym_size = %x\n", frame->sym_size);
wad_printf(" sym_bind = %x\n", frame->sym_bind);
wad_printf(" sym_file = %s\n", frame->sym_file ? frame->sym_file : "");
}
if (frame->loc_srcfile) {
printf(" loc_srcfile = %s\n", frame->loc_srcfile);
wad_printf(" loc_srcfile = %s\n", frame->loc_srcfile);
}
if (frame->loc_objfile) {
printf(" loc_objfile = %s\n", frame->loc_objfile);
wad_printf(" loc_objfile = %s\n", frame->loc_objfile);
}
printf(" loc_line = %d\n", frame->loc_line);
wad_printf(" loc_line = %d\n", frame->loc_line);
printf(" debug_nargs = %d\n", frame->debug_nargs);
wad_printf(" debug_nargs = %d\n", frame->debug_nargs);
if (frame->debug_args) {
int i = 0;
WadLocal *p = frame->debug_args;
printf(" debug_args = [ \n");
wad_printf(" debug_args = [ \n");
while (p) {
printf(" arg[%d] : name = '%s', loc = %d, type = %d, stack = %d, reg = %d, line=%d, ptr=%x(%d)\n", i, p->name, p->loc, p->type, p->stack,p->reg,p->line,p->ptr,p->size);
wad_printf(" arg[%d] : name = '%s', loc = %d, type = %d, stack = %d, reg = %d, line=%d, ptr=%x(%d)\n", i, p->name, p->loc, p->type, p->stack,p->reg,p->line,p->ptr,p->size);
p = p->next;
}
}
printf(" ]\n");
wad_printf(" ]\n");
frame = frame->next;
}

View file

@ -137,7 +137,6 @@ static void handler(int signo, WadFrame *frame, char *ret) {
while (!f->last) {
f= f->next;
}
printf("f = %x\n", f);
/* Now work backwards */
f = f->prev;
while (f) {