*** empty log message ***

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@1028 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2001-02-25 19:30:41 +00:00
commit a41924d0ea
7 changed files with 339 additions and 67 deletions

View file

@ -47,15 +47,15 @@ wadobject_dealloc(wadobject *self) {
PyMem_DEL(self);
}
static char message[65536];
static PyObject *
wadobject_repr(wadobject *self) {
char message[65536];
char *srcstr = 0;
WadFrame *fp = 0;
int n;
WadFrame *f = self->frame;
strcpy(message,"[ C stack trace ]\n\n");
message[0] = 0;
/* Find the last exception frame */
n = self->count;
while (f && n) {
@ -84,7 +84,6 @@ wadobject_repr(wadobject *self) {
static PyObject *
wadobject_str(wadobject *self) {
char message[65536];
char *srcstr = 0;
int n;
@ -157,32 +156,34 @@ wadobject_getslice(wadobject *self, int start, int end) {
static PyObject *
wadobject_getattr(wadobject *self, char *name) {
if (strcmp(name,"name") == 0) {
if (strcmp(name,"__NAME__") == 0) {
return Py_BuildValue("z", self->frame->sym_name);
} else if (strcmp(name,"exe") == 0) {
} else if (strcmp(name,"__EXE__") == 0) {
return Py_BuildValue("z", self->frame->object->path);
} else if (strcmp(name,"source") == 0) {
} else if (strcmp(name,"__FILE__") == 0) {
return Py_BuildValue("z", self->frame->loc_srcfile);
} else if (strcmp(name,"object") == 0) {
} else if (strcmp(name,"__OBJECT__") == 0) {
return Py_BuildValue("z", self->frame->loc_objfile);
} else if (strcmp(name,"line") == 0) {
} else if (strcmp(name,"__LINE__") == 0) {
return Py_BuildValue("i", self->frame->loc_line);
} else if (strcmp(name,"pc") == 0) {
} else if (strcmp(name,"__SOURCE__") == 0) {
return Py_BuildValue("z",self->frame->debug_srcstr);
} else if (strcmp(name,"__PC__") == 0) {
return PyLong_FromUnsignedLong(self->frame->pc);
} else if (strcmp(name,"sp") == 0) {
} else if (strcmp(name,"__SP__") == 0) {
return PyLong_FromUnsignedLong(self->frame->sp);
} else if (strcmp(name,"fp") == 0) {
} else if (strcmp(name,"__FP__") == 0) {
return PyLong_FromUnsignedLong(self->frame->fp);
} else if (strcmp(name,"stack_size") == 0) {
return PyInt_FromLong(self->frame->stack_size);
} else if (strcmp(name,"stack") == 0) {
} else if (strcmp(name,"__STACK__") == 0) {
return PyString_FromStringAndSize(self->frame->stack, self->frame->stack_size);
} else if (strcmp(name,"nargs") == 0) {
} else if (strcmp(name,"__NARGS__") == 0) {
return PyInt_FromLong(self->frame->debug_nargs);
} else if (strcmp(name,"seg_base") == 0) {
return PyLong_FromUnsignedLong((long )self->frame->segment->base);
} else if (strcmp(name,"seg_size") == 0) {
return PyLong_FromUnsignedLong((long) self->frame->segment->size);
} else if (strcmp(name,"__LAST__") == 0) {
return PyInt_FromLong(self->frame->last);
} else if (strcmp(name,"__WHERE__") == 0) {
return Py_BuildValue("z",self->frame->debug_str);
} else if (strcmp(name,"__WAD__") == 0) {
return PyInt_FromLong(1);
}
PyErr_SetString(PyExc_NameError,"Unknown attribute.");

View file

@ -9,6 +9,9 @@
#include <string.h>
#include <assert.h>
typedef double Real;
typedef Real Float;
/* A simple segmentation fault on an uninitialized pointer */
int seg_crash() {
int *a = 0;

View file

@ -17,3 +17,15 @@ button = Button(text="Press me", command=spam)
button.pack()
#root.mainloop()

View file

@ -1,36 +1,179 @@
# -----------------------------------------------------------------------------
# Wad port-mortem debugger
# WAD Post-mortem debugger
#
# This program can be used to walk up and down the call stack of a mixed
# Python-C program. The following commands are supported:
#
# w - A stack traceback
# u - Go up the call stack
# d - Go down the call stack
# e - Edit a file
# c - Clear the debugger.
#
# David Beazley
# Copyright (C) 2001
# University of Chicago
# All Rights Reserved
# -----------------------------------------------------------------------------
import sys
import os
import traceback
import types
import linecache
_last_exc = None
print "**************************************************"
print "* WAD Post-Mortem Debugger *"
print "**************************************************"
# Save a local copy of the last exception and value objects from sys
_last_type = sys.last_type
_last_value = sys.last_value
_last_traceback = sys.last_traceback
_last_level = 0
frame = None
print "WAD port-mortem"
_cstack = None # Stack of C-only code
_pystack = None # Stack of Python only code
_combined_stack = None # Combined C-python stack
_allmode = 0 # Show entire C stack
# Generalized object for holding stack frames
class wad_frame:
def __init__(self,frame, n = 0):
if isinstance(frame,types.TupleType):
# A Python traceback object
self.file = frame[0]
self.line = frame[1]
self.name = frame[2]
self.argstr = frame[3]
self.frameno = n
# Make the debugging string
self.debugstr = "#%-3d [ Python ] in %s in %s, line %d" % (self.frameno, self.argstr, self.file, self.line)
# Try to get source data
self.source = "%s, Line %d\n\n" % (self.file, self.line)
for i in range(self.line-2,self.line+3):
l = linecache.getline(self.file,i)
if not l: l = '\n'
if (i == self.line):
self.source += " => "
else:
self.source += " "
self.source += l
elif hasattr(frame,"__WAD__"):
# A WAD traceback object
self.file = frame.__FILE__
self.line = frame.__LINE__
self.name = frame.__NAME__
self.debugstr = frame.__WHERE__
self.source = frame.__SOURCE__
def __str__(self):
return self.debugstr.strip()
def output(self):
print self
if self.source:
print "\n%s" % (self.source,)
def wad_build_info():
global _last_type,_last_value, _last_traceback, _cstack, _combined_stack,_pystack
_last_type = None
_last_value = None
_last_traceback = None
_cstack = None
_combined_stack = []
# Check to see if any exception is defined
if not sys.last_type:
print "No exception has occurred."
return
# Save a copy of previous exception
_last_type = sys.last_type
_last_value = sys.last_value
_last_traceback = sys.last_traceback
_last_level = 0
start_frame = 0
# Test to see what kind of object it is
if issubclass(_last_type,StandardError):
# Python exception
print "Python exception"
elif hasattr(_last_value[0],"__WAD__"):
# A wad exception frame object
w = sys.last_value[0]
i = 0
_cstack = []
while not w[i].__LAST__:
start_frame += 1
wf = wad_frame(w[i])
_cstack.append(wf)
i = i + 1
# wf = wad_frame(w[i])
# _cstack.append(wf)
# start_frame += 1
# Build the rest of the c stack
_combined_stack = _cstack[:]
while i < len(w):
wf = wad_frame(w[i])
_cstack.append(wf)
i = i + 1
else:
print "Unknown error"
# Build the Python call stack
_pystack = []
t = sys.last_traceback
tp = None
while hasattr(t,"tb_frame"):
tp = t
t = t.tb_next
fr = traceback.extract_stack(tp.tb_frame)
for i in range(len(fr),0,-1):
f = wad_frame(fr[i-1], start_frame)
start_frame += 1
_pystack.append(f)
_combined_stack.extend(_pystack)
wad_build_info()
class where_impl:
def __init__(self):
self.all = 0;
self.cstack = 0
def __repr__(self):
global _last_exc, _last_level, frame
if sys.last_value:
if not _last_exc:
_last_exc = sys.last_value[0]
_last_level = 0
global _combined_stack, _cstack, _last_level
if (self.cstack):
stack = _cstack
else:
stack = _combined_stack
else:
raise RuntimeError,"No pending error."
if (self.all):
print repr(_last_exc)
else:
print str(_last_exc)
frame = _last_exc
if not stack:
print "No current exception."
return ""
last_source = None
for i in range(len(stack),0,-1):
f = stack[i-1]
print f
if (f.source):
last_source = f.source
_last_level = i-1
if last_source: print "\n%s" % last_source
return ""
def __getattr__(self,name):
try:
@ -39,10 +182,14 @@ class where_impl:
raise AttributeError
def __getitem__(self,n):
global frame, _last_level
frame = _last_exc[n]
global _last_level, _cstack, _combined_stack
if (self.cstack):
stack = _cstack
else:
stack = _combined_stack
_last_level = n
return frame
stack[_last_level].output()
return None
def __len__(self):
return len(frame)
@ -53,12 +200,16 @@ w = where
class up_impl:
def __repr__(self):
global _last_exc, _last_level, frame
if not _last_exc:
global _last_level, _combined_stack, _cstack
if where.cstack:
stack = _cstack
else:
stack = _combined_stack
if not stack:
return ""
_last_level += 1
print repr(_last_exc[_last_level])
frame = _last_exc[_last_level]
stack[_last_level].output()
return ""
up = up_impl()
@ -66,12 +217,16 @@ u = up
class down_impl:
def __repr__(self):
global _last_exc, _last_level, frame
if not _last_exc:
global _last_level, _combined_stack, _cstack
if where.cstack:
stack = _cstack
else:
stack = _combined_stack
if not stack:
return ""
_last_level -= 1
print repr(_last_exc[_last_level])
frame = _last_exc[_last_level]
stack[_last_level].output()
return ""
down = down_impl()
@ -86,3 +241,26 @@ class clear_impl:
clear = clear_impl()
c = clear
class edit_impl:
def __repr__(self):
global _last_level, _combined_stack, _cstack
if where.cstack:
stack = _cstack
else:
stack = _combined_stack
if not stack:
return ""
f = stack[_last_level]
e = os.getenv("EDITOR","emacs")
if f.file:
os.system("%s +%d %s" % (e,f.line,f.file))
return ""
edit = edit_impl()
e = edit
repr(w)

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_SOLARIS
WADOPT = -DWAD_LINUX
# 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/perl5/5.00503/sun4-solaris/CORE
PERLINCLUDE = -I/usr/lib/perl5/5.00503/i386-linux/CORE
PERLSRCS = wadpl.cxx
PERLOBJS = wadpl.o
# C Compiler
CC = cc
CFLAGS = #
CC = gcc
CFLAGS = #-fpic
# C++ Compiler
CXX = CC
CXXFLAGS = #-Kpic
CXX = c++
CXXFLAGS = #-fpic
# Linking options
CLINK =
CXXLINK = CC -G
CXXLINK = g++ -shared
# AR
AR = ar

View file

@ -11,6 +11,8 @@
#include "wad.h"
extern void wad_stab_debug();
/* For some odd reason, certain linux distributions do not seem to define the
register constants in a way that is easily accessible to us. This is a hack */
@ -353,6 +355,8 @@ void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) {
/* Generate debugging strings */
wad_debug_make_strings(frame);
wad_stab_debug();
/* Walk the exception frames and try to find a return point */
origframe = frame;

View file

@ -77,30 +77,88 @@ static int thash(char *name) {
static void type_add(char *name, char *value) {
int h;
stabtype *s;
char sc =0;
char *v;
char *vr;
char *split;
if (!stab_type_init) {
init_hash();
stab_type_init = 1;
}
/* Split the "value" up into a type name and a value */
split = strchr(value,'=');
if (value[0] != '(') split = 0;
if (split) {
sc = *split;
v = value;
*split = 0;
vr = split+1;
} else {
v = value;
sc = 0;
vr = 0;
}
h = thash(name);
s = lnames[h];
while (s) {
if (strcmp(s->name,name) == 0) {
if (strcmp(s->value,value) == 0) {
if (strcmp(s->value,v) == 0) {
return;
}
s->value = (char *) wad_strdup(value);
return;
s->value = (char *) wad_strdup(v);
goto add_more;
}
s = s->next;
}
s = (stabtype *) wad_malloc(sizeof(stabtype));
s->name = wad_strdup(name);
s->value = wad_strdup(value);
s->value = wad_strdup(v);
s->next = lnames[h];
lnames[h] = s;
}
/* Now take a look at the value. If it is contains other types, we might be able to define more stuff */
add_more:
if (vr) {
/* There is a mapping to another type */
/* printf("adding '%s', '%s'\n", v, vr); */
type_add(v,vr);
}
}
static
char *type_resolve(char *name) {
int h;
stabtype *s;
h = thash(name);
s = lnames[h];
while(s) {
if (strcmp(s->name,name) == 0) {
return type_resolve(s->value);
}
s = s->next;
}
return name;
}
static void types_print() {
stabtype *s;
int i;
for (i = 0; i < HASH_SIZE; i++) {
s = lnames[i];
while (s) {
printf("%20s %s\n", s->name, s->value);
s = s->next;
}
}
}
void wad_stab_debug() {
/* types_print();*/
}
/* -----------------------------------------------------------------------------
* match_stab_symbol()
@ -135,6 +193,7 @@ stab_symbol(Stab *s, char *stabstr) {
char *str;
char *pstr;
char name[1024];
char value[65536];
int a;
str = stabstr+s->n_strx;
@ -143,12 +202,13 @@ stab_symbol(Stab *s, char *stabstr) {
strncpy(name,str, pstr-str);
name[(int)(pstr-str)] = 0;
if (pstr[1] == 't') {
if ((pstr[1] == 't') || (pstr[1] == 'p') || (pstr[1] == 'r')) {
/* A stabs type definition */
/* wad_printf("stab lsym: other=%d, desc=%d, value=%d, str='%s'\n", s->n_other,s->n_desc,s->n_value,
/* 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); */
/* wad_printf("name = '%s', pstr='%s'\n", name, pstr+2); */
type_add(name,pstr+2);
strcpy(value,pstr+2);
type_add(name,value);
}
}
@ -183,6 +243,9 @@ scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
if (s->n_type == N_LBRAC) {
get_parms = 0;
}
if (s->n_type == N_LSYM) {
stab_symbol(s,stabstr);
}
if (s->n_type == N_SLINE) {
get_parms = 0;
@ -203,7 +266,10 @@ scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
} else {
len = strlen(pname);
}
/* Get type information */
stab_symbol(s,stabstr);
/* 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 */
@ -249,6 +315,16 @@ scan_function(Stab *s, char *stabstr, int ns, WadFrame *f) {
}
arg->type = 0;
arg->next = 0;
{
char tname[128];
char *t = tname;
c+=2;
while ((*c) && (*c != '=')) {
*t++ = *c++;
}
*t = 0;
/* printf("type_resolve '%s' -> '%s'\n", tname, type_resolve(tname));*/
}
if (f->debug_args) {
f->debug_lastarg->next = arg;
f->debug_lastarg = arg;
@ -302,13 +378,11 @@ wad_search_stab(void *sp, int size, char *stabstr, WadFrame *f) {
objfile[0] = 0;
for (i = 0; i < ns; i++, s++) {
/*
if (wad_debug_mode & DEBUG_STABS) {
/* 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,
stabstr+s->n_strx);
}
*/
} */
if (s->n_type == N_LSYM) {
stab_symbol(s,stabstr);
continue;