Cleanup
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@944 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
1276667e18
commit
e4444a5c78
10 changed files with 123 additions and 129 deletions
|
|
@ -156,11 +156,12 @@ extern long wad_steal_outarg(WadFrame *f, char *symbol, int argno, int *error);
|
||||||
extern char *wad_arg_string(WadFrame *f);
|
extern char *wad_arg_string(WadFrame *f);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
char name[128];
|
||||||
long value;
|
long value;
|
||||||
} WadReturnFunc;
|
} WadReturnFunc;
|
||||||
|
|
||||||
extern void wad_set_returns(WadReturnFunc *rf);
|
extern void wad_set_returns(WadReturnFunc *rf);
|
||||||
|
extern WadReturnFunc *wad_check_return(const char *name);
|
||||||
|
|
||||||
/* --- Debugging Interface --- */
|
/* --- Debugging Interface --- */
|
||||||
|
|
||||||
|
|
@ -170,10 +171,10 @@ extern void wad_set_returns(WadReturnFunc *rf);
|
||||||
#define DEBUG_OBJECT 0x8
|
#define DEBUG_OBJECT 0x8
|
||||||
#define DEBUG_FILE 0x10
|
#define DEBUG_FILE 0x10
|
||||||
#define DEBUG_HOLD 0x20
|
#define DEBUG_HOLD 0x20
|
||||||
|
#define DEBUG_RETURN 0x40
|
||||||
|
|
||||||
extern int wad_debug_mode;
|
extern int wad_debug_mode;
|
||||||
|
extern char *wad_cplus_demangle(WadSymbol *wsym);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
|
|
||||||
SRCS = default.c stack.c stab.c elf.c object.c init.c segment.c signal.c
|
SRCS = demangle.c return.c default.c stack.c stab.c elf.c object.c init.c segment.c signal.c
|
||||||
OBJS = default.o stack.o stab.o elf.o object.o signal.o segment.o init.o main.o
|
OBJS = demangle.o return.o default.o stack.o stab.o elf.o object.o signal.o segment.o init.o main.o
|
||||||
INCLUDE = -I../Include -I.
|
INCLUDE = -I../Include -I.
|
||||||
OPT = -DWAD_SOLARIS
|
OPT = -DWAD_SOLARIS
|
||||||
|
LIBS =
|
||||||
|
|
||||||
PYINCLUDE = -I/usr/local/include/python2.0
|
PYINCLUDE = -I/usr/local/include/python2.0
|
||||||
TCLINCLUDE = -I/usr/local/include
|
TCLINCLUDE = -I/usr/local/include
|
||||||
|
|
@ -10,19 +11,19 @@ TCLINCLUDE = -I/usr/local/include
|
||||||
all::
|
all::
|
||||||
CC -Kpic -c $(OPT) $(INCLUDE) main.cxx
|
CC -Kpic -c $(OPT) $(INCLUDE) main.cxx
|
||||||
cc -c $(OPT) $(INCLUDE) $(SRCS)
|
cc -c $(OPT) $(INCLUDE) $(SRCS)
|
||||||
CC -G $(OBJS) -o libwad.so
|
CC -G $(OBJS) -o libwad.so $(LIBS)
|
||||||
cp libwad.so ..
|
cp libwad.so ..
|
||||||
|
|
||||||
python::
|
python::
|
||||||
cc -c $(INCLUDE) $(SRCS)
|
cc -c $(OPT) $(INCLUDE) $(SRCS)
|
||||||
CC -Kpic -c $(INCLUDE) $(PYINCLUDE) wadpy.cxx
|
CC -Kpic -c $(INCLUDE) $(PYINCLUDE) wadpy.cxx
|
||||||
CC -G $(OBJS) wadpy.o -o libwadpy.so
|
CC -G $(OBJS) wadpy.o -o libwadpy.so $(LIBS)
|
||||||
cp libwadpy.so ..
|
cp libwadpy.so ..
|
||||||
|
|
||||||
tcl::
|
tcl::
|
||||||
cc -c $(INCLUDE) $(SRCS)
|
cc -c $(OPT) $(INCLUDE) $(SRCS)
|
||||||
CC -Kpic -c $(INCLUDE) $(TCLINCLUDE) wadtcl.cxx
|
CC -Kpic -c $(INCLUDE) $(TCLINCLUDE) wadtcl.cxx
|
||||||
CC -G $(OBJS) wadtcl.o -o wad.so
|
CC -G $(OBJS) wadtcl.o -o wad.so $(LIBS)
|
||||||
cp wad.so libwadtcl.so
|
cp wad.so libwadtcl.so
|
||||||
cp libwadtcl.so ..
|
cp libwadtcl.so ..
|
||||||
|
|
||||||
|
|
|
||||||
19
SWIG/Tools/WAD/Wad/demangle.c
Normal file
19
SWIG/Tools/WAD/Wad/demangle.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* demangle.c
|
||||||
|
*
|
||||||
|
* This file performs C++ partial name demangling to the extent that it
|
||||||
|
* seems reasonable.
|
||||||
|
*
|
||||||
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000. The University of Chicago
|
||||||
|
* See the file LICENSE for information on usage and redistribution.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include "wad.h"
|
||||||
|
|
||||||
|
char *wad_cplus_demangle(WadSymbol *ws) {
|
||||||
|
static char buffer[4096];
|
||||||
|
strcpy(buffer,ws->name);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
@ -233,7 +233,6 @@ wad_elf_find_symbol(WadObjectFile *wo, void *ptr, unsigned long base, WadSymbol
|
||||||
if (ELF32_ST_TYPE(sym[i].st_info) == STT_FILE) {
|
if (ELF32_ST_TYPE(sym[i].st_info) == STT_FILE) {
|
||||||
localfile = name;
|
localfile = name;
|
||||||
}
|
}
|
||||||
/* printf("%s %x\n", name, sym[i].st_value); */
|
|
||||||
if (((base + sym[i].st_value) <= vaddr) && (vaddr < (base+sym[i].st_value + sym[i].st_size))) {
|
if (((base + sym[i].st_value) <= vaddr) && (vaddr < (base+sym[i].st_value + sym[i].st_size))) {
|
||||||
ws->value = sym[i].st_value;
|
ws->value = sym[i].st_value;
|
||||||
if (ELF32_ST_BIND(sym[i].st_info) == STB_LOCAL) {
|
if (ELF32_ST_BIND(sym[i].st_info) == STB_LOCAL) {
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,12 @@ void wad_init() {
|
||||||
if (getenv("WAD_DEBUG_STABS")) {
|
if (getenv("WAD_DEBUG_STABS")) {
|
||||||
wad_debug_mode |= DEBUG_STABS;
|
wad_debug_mode |= DEBUG_STABS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getenv("WAD_DEBUG_RETURN")) {
|
||||||
|
wad_debug_mode |= DEBUG_RETURN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef WAD_LINUX
|
#ifndef WAD_LINUX
|
||||||
if (!init) {
|
if (!init) {
|
||||||
wad_signal_init();
|
wad_signal_init();
|
||||||
|
|
|
||||||
|
|
@ -11,89 +11,34 @@
|
||||||
* See the file LICENSE for information on usage and redistribution.
|
* See the file LICENSE for information on usage and redistribution.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
WadSegment *
|
|
||||||
wad_segment_read() {
|
static FILE *
|
||||||
int fd;
|
segment_open() {
|
||||||
|
FILE *f;
|
||||||
|
f = fopen("/proc/self/map", "r");
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
segment_read(FILE *fs, WadSegment *s) {
|
||||||
int dz;
|
int dz;
|
||||||
int offset = 0;
|
int n;
|
||||||
int i;
|
|
||||||
int n = 0;
|
|
||||||
int nsegments;
|
|
||||||
WadSegment *segments;
|
|
||||||
WadSegment *s;
|
|
||||||
prmap_t pmap;
|
prmap_t pmap;
|
||||||
|
|
||||||
/* Try to load the virtual address map */
|
n = fread(&pmap, sizeof(prmap_t), 1, fs);
|
||||||
fd = open("/proc/self/map", O_RDONLY);
|
if (n <= 0) return 0;
|
||||||
if (fd < 0) {
|
strncpy(s->mapname, pmap.pr_mapname, MAX_PATH);
|
||||||
return 0;
|
strcpy(s->mappath,"/proc/self/object/");
|
||||||
}
|
strcat(s->mappath,pmap.pr_mapname);
|
||||||
nsegments = 0;
|
s->vaddr = (char *) pmap.pr_vaddr;
|
||||||
while (1) {
|
|
||||||
n = read(fd,&pmap,sizeof(prmap_t));
|
|
||||||
if (n <= 0) break;
|
|
||||||
nsegments++;
|
|
||||||
}
|
|
||||||
nsegments+=3;
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
dz = open("/dev/zero", O_RDWR, 0644);
|
/* This is a solaris oddity. a.out section starts 1 page up, but
|
||||||
if (dz < 0) {
|
symbols are relative to a base of 0 */
|
||||||
puts("Couldn't open /dev/zero\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
segments = (WadSegment *) mmap(NULL, nsegments*sizeof(WadSegment), PROT_READ | PROT_WRITE, MAP_PRIVATE, dz, 0);
|
|
||||||
close(dz);
|
|
||||||
|
|
||||||
fd = open("/proc/self/map", O_RDONLY);
|
|
||||||
if (fd < 0) return;
|
|
||||||
i = 0;
|
|
||||||
s = segments;
|
|
||||||
|
|
||||||
/* First segment is a map to the segment list */
|
if (strcmp(s->mapname,"a.out") == 0) s->base = 0;
|
||||||
s->base = (char *) segments;
|
else s->base = s->vaddr;
|
||||||
s->vaddr = (char *) segments;
|
|
||||||
s->size = nsegments*sizeof(WadSegment);
|
|
||||||
s->mapname[0] = 0;
|
|
||||||
s->mappath[0] = 0;
|
|
||||||
s++;
|
|
||||||
|
|
||||||
while (1) {
|
s->size = pmap.pr_size;
|
||||||
n = read(fd,&pmap,sizeof(prmap_t));
|
s->offset = pmap.pr_offset;
|
||||||
if (n <= 0) break;
|
return 1;
|
||||||
strncpy(s->mapname, pmap.pr_mapname, MAX_PATH);
|
|
||||||
strcpy(s->mappath,"/proc/self/object/");
|
|
||||||
strcat(s->mappath,pmap.pr_mapname);
|
|
||||||
s->vaddr = (char *) pmap.pr_vaddr;
|
|
||||||
|
|
||||||
/* This is a solaris oddity. a.out section starts 1 page up, but
|
|
||||||
symbols are relative to a base of 0 */
|
|
||||||
|
|
||||||
if (strcmp(s->mapname,"a.out") == 0) s->base = 0;
|
|
||||||
else s->base = s->vaddr;
|
|
||||||
|
|
||||||
s->size = pmap.pr_size;
|
|
||||||
s->offset = pmap.pr_offset;
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
/* Create sentinel */
|
|
||||||
s->base = 0;
|
|
||||||
s->vaddr = 0;
|
|
||||||
s->size = 0;
|
|
||||||
s->offset = 0;
|
|
||||||
s->mapname[0] =0;
|
|
||||||
s->mappath[0] = 0;
|
|
||||||
close(fd);
|
|
||||||
return segments;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* wad_segment_release()
|
|
||||||
*
|
|
||||||
* This function releases all of the segments.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void
|
|
||||||
wad_segment_release(WadSegment *s) {
|
|
||||||
munmap((void *)s, s->size);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
50
SWIG/Tools/WAD/Wad/return.c
Normal file
50
SWIG/Tools/WAD/Wad/return.c
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* return.c
|
||||||
|
*
|
||||||
|
* This file manages the set of return-points for the WAD signal handler.
|
||||||
|
*
|
||||||
|
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||||
|
*
|
||||||
|
* Copyright (C) 2000. The University of Chicago
|
||||||
|
* See the file LICENSE for information on usage and redistribution.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include "wad.h"
|
||||||
|
|
||||||
|
/* Maximum number of return points */
|
||||||
|
#define WAD_NUMBER_RETURN 128
|
||||||
|
|
||||||
|
static WadReturnFunc return_points[WAD_NUMBER_RETURN];
|
||||||
|
static int num_return = 0;
|
||||||
|
|
||||||
|
void wad_set_return(const char *name, long value) {
|
||||||
|
WadReturnFunc *rp;
|
||||||
|
rp = &return_points[num_return];
|
||||||
|
strcpy(rp->name,name);
|
||||||
|
rp->value = value;
|
||||||
|
num_return++;
|
||||||
|
if (wad_debug_mode & DEBUG_RETURN) {
|
||||||
|
printf("wad: Setting return ('%s', %d)\n", name,value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wad_set_returns(WadReturnFunc *rf) {
|
||||||
|
int i;
|
||||||
|
while (strlen(rf[i].name)) {
|
||||||
|
wad_set_return(rf[i].name, rf[i].value);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WadReturnFunc *wad_check_return(const char *name) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < num_return; i++) {
|
||||||
|
if (strcmp(name,return_points[i].name) == 0) {
|
||||||
|
if (wad_debug_mode & DEBUG_RETURN) {
|
||||||
|
printf("wad: Found return ('%s', %d)\n", return_points[i].name, return_points[i].value);
|
||||||
|
}
|
||||||
|
return &return_points[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -15,33 +15,6 @@
|
||||||
#define STACK_SIZE 4*SIGSTKSZ
|
#define STACK_SIZE 4*SIGSTKSZ
|
||||||
char wad_sig_stack[STACK_SIZE];
|
char wad_sig_stack[STACK_SIZE];
|
||||||
|
|
||||||
/* Data structures for containing information about non-local returns */
|
|
||||||
|
|
||||||
typedef struct nonlocal {
|
|
||||||
char symname[256];
|
|
||||||
long value;
|
|
||||||
struct nonlocal *next;
|
|
||||||
} nonlocal;
|
|
||||||
|
|
||||||
static nonlocal *return_points = 0;
|
|
||||||
|
|
||||||
void wad_set_return(const char *name, long value) {
|
|
||||||
nonlocal *nl;
|
|
||||||
nl = (nonlocal *) malloc(sizeof(nonlocal));
|
|
||||||
strcpy(nl->symname,name);
|
|
||||||
nl->value = value;
|
|
||||||
nl->next = return_points;
|
|
||||||
return_points = nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wad_set_returns(WadReturnFunc *rf) {
|
|
||||||
int i;
|
|
||||||
while (rf[i].name) {
|
|
||||||
wad_set_return(rf[i].name, rf[i].value);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void (*sig_callback)(int signo, WadFrame *data, char *ret) = 0;
|
static void (*sig_callback)(int signo, WadFrame *data, char *ret) = 0;
|
||||||
|
|
||||||
void wad_set_callback(void (*s)(int,WadFrame *,char *ret)) {
|
void wad_set_callback(void (*s)(int,WadFrame *,char *ret)) {
|
||||||
|
|
@ -132,16 +105,11 @@ void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) {
|
||||||
framedata = (char *) frame;
|
framedata = (char *) frame;
|
||||||
|
|
||||||
while (frame->size) {
|
while (frame->size) {
|
||||||
nonlocal *nl = return_points;
|
WadReturnFunc *wr = wad_check_return(framedata+frame->sym_off);
|
||||||
nl = return_points;
|
if (wr) {
|
||||||
while (nl) {
|
found = 1;
|
||||||
if (strcmp(framedata + frame->sym_off,nl->symname) == 0) {
|
nlr_value = wr->value;
|
||||||
found = 1;
|
retname = wr->name;
|
||||||
nlr_value = nl->value;
|
|
||||||
retname = nl->symname;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
nl = nl->next;
|
|
||||||
}
|
}
|
||||||
framedata = framedata + frame->size;
|
framedata = framedata + frame->size;
|
||||||
frame = (WadFrame *) framedata;
|
frame = (WadFrame *) framedata;
|
||||||
|
|
@ -186,7 +154,7 @@ void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) {
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* wad_signal_init()
|
* wad_signal_init()
|
||||||
*
|
*
|
||||||
* Reset the signal handler.
|
* Resets the signal handler.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void wad_signal_init() {
|
void wad_signal_init() {
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,9 @@ wad_stack_trace(unsigned long pc, unsigned long sp, unsigned long fp) {
|
||||||
} else {
|
} else {
|
||||||
symname = 0;
|
symname = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (symname) symname = wad_cplus_demangle(&wsym);
|
||||||
|
|
||||||
value = wsym.value;
|
value = wsym.value;
|
||||||
|
|
||||||
/* Build up some information about the exception frame */
|
/* Build up some information about the exception frame */
|
||||||
|
|
@ -114,6 +117,8 @@ wad_stack_trace(unsigned long pc, unsigned long sp, unsigned long fp) {
|
||||||
if (symname) {
|
if (symname) {
|
||||||
symsize = strlen(symname)+1;
|
symsize = strlen(symname)+1;
|
||||||
|
|
||||||
|
/* printf("C++: '%s' ---> '%s'\n", symname, wad_cplus_demangle(&wsym));*/
|
||||||
|
|
||||||
/* Try to gather some debugging information about this symbol */
|
/* Try to gather some debugging information about this symbol */
|
||||||
if (wad_debug_info(wo,&wsym, p_pc - (unsigned long) ws->base - value, &wd)) {
|
if (wad_debug_info(wo,&wsym, p_pc - (unsigned long) ws->base - value, &wd)) {
|
||||||
srcname = wd.srcfile;
|
srcname = wd.srcfile;
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ static WadReturnFunc retpts[] = {
|
||||||
{"PyMapping_Length", -1},
|
{"PyMapping_Length", -1},
|
||||||
{"PyMapping_SetItemString", -1},
|
{"PyMapping_SetItemString", -1},
|
||||||
{"PyMapping_Values", 0},
|
{"PyMapping_Values", 0},
|
||||||
{0,0}};
|
{"",0}};
|
||||||
|
|
||||||
/* Handler function */
|
/* Handler function */
|
||||||
static void handler(int signo, WadFrame *frame, char *ret) {
|
static void handler(int signo, WadFrame *frame, char *ret) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue