*** empty log message ***
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@1010 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
04440385b1
commit
cd2f18170d
12 changed files with 111 additions and 207 deletions
|
|
@ -40,6 +40,10 @@ extern void *wad_malloc(int nbytes);
|
||||||
extern void wad_release_memory();
|
extern void wad_release_memory();
|
||||||
extern char *wad_strdup(const char *c);
|
extern char *wad_strdup(const char *c);
|
||||||
|
|
||||||
|
/* I/O */
|
||||||
|
|
||||||
|
extern void wad_printf(const char *fmt, ...);
|
||||||
|
|
||||||
/* Memory segments */
|
/* Memory segments */
|
||||||
typedef struct WadSegment {
|
typedef struct WadSegment {
|
||||||
char *base; /* Base address for symbol lookup */
|
char *base; /* Base address for symbol lookup */
|
||||||
|
|
@ -57,17 +61,15 @@ extern WadSegment *wad_segment_find(void *vaddr);
|
||||||
/* Object file handling */
|
/* Object file handling */
|
||||||
typedef struct WadObjectFile {
|
typedef struct WadObjectFile {
|
||||||
struct WadFile *file; /* File data (private) */
|
struct WadFile *file; /* File data (private) */
|
||||||
int refcnt; /* Reference count */
|
|
||||||
void *ptr; /* Pointer to data */
|
void *ptr; /* Pointer to data */
|
||||||
int len; /* Length of data */
|
int len; /* Length of data */
|
||||||
int type; /* Type of the object file */
|
int type; /* Type of the object file */
|
||||||
char path[MAX_PATH]; /* Path name of this object */
|
char *path; /* Path name of this object */
|
||||||
|
struct WadObjectFile *next;
|
||||||
} WadObjectFile;
|
} WadObjectFile;
|
||||||
|
|
||||||
extern void wad_object_init();
|
extern void wad_object_reset();
|
||||||
extern WadObjectFile *wad_object_load(const char *path);
|
extern WadObjectFile *wad_object_load(const char *path);
|
||||||
extern void wad_object_release(WadObjectFile *);
|
|
||||||
extern void wad_object_cleanup();
|
|
||||||
|
|
||||||
/* Symbol table information */
|
/* Symbol table information */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
||||||
# These are the files that make up the WAD core
|
# These are the files that make up the WAD core
|
||||||
WADSRCS = memory.c return.c default.c stack.c stab.c elf.c object.c init.c segment.c signal.c
|
WADSRCS = io.c memory.c return.c default.c stack.c stab.c elf.c object.c init.c segment.c signal.c
|
||||||
WADOBJS = memory.o return.o default.o stack.o stab.o elf.o object.o signal.o segment.o init.o
|
WADOBJS = 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)
|
INCLUDE = -I../Include -I. $(SINCLUDE)
|
||||||
WADOPT = -DWAD_LINUX
|
WADOPT = -DWAD_LINUX
|
||||||
|
|
||||||
|
|
@ -76,7 +76,7 @@ wc::
|
||||||
wc $(SRCS)
|
wc $(SRCS)
|
||||||
|
|
||||||
semi::
|
semi::
|
||||||
egrep ";" $(SRCS) wadpy.cxx | wc
|
egrep ";" $(WADSRCS) | wc
|
||||||
|
|
||||||
|
|
||||||
clean::
|
clean::
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
||||||
# These are the files that make up the WAD core
|
# These are the files that make up the WAD core
|
||||||
WADSRCS = memory.c return.c default.c stack.c stab.c elf.c object.c init.c segment.c signal.c
|
WADSRCS = io.c memory.c return.c default.c stack.c stab.c elf.c object.c init.c segment.c signal.c
|
||||||
WADOBJS = memory.o return.o default.o stack.o stab.o elf.o object.o signal.o segment.o init.o
|
WADOBJS = 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)
|
INCLUDE = -I../Include -I. $(SINCLUDE)
|
||||||
WADOPT = @WADOPT@
|
WADOPT = @WADOPT@
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -240,7 +240,7 @@ wad_elf_find_symbol(WadObjectFile *wo, void *ptr, unsigned long base, WadSymbol
|
||||||
localfile = name;
|
localfile = name;
|
||||||
}
|
}
|
||||||
if (wad_debug_mode & DEBUG_SYMBOL_SEARCH) {
|
if (wad_debug_mode & DEBUG_SYMBOL_SEARCH) {
|
||||||
printf("%x(%x): %s %x + %x, %x, %x\n", base, vaddr, name, sym[i].st_value, sym[i].st_size, sym[i].st_info, sym[i].st_shndx);
|
wad_printf("%x(%x): %s %x + %x, %x, %x\n", base, vaddr, name, sym[i].st_value, sym[i].st_size, sym[i].st_info, sym[i].st_shndx);
|
||||||
}
|
}
|
||||||
|
|
||||||
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))) {
|
||||||
|
|
@ -281,7 +281,7 @@ wad_elf_find_symbol(WadObjectFile *wo, void *ptr, unsigned long base, WadSymbol
|
||||||
localfile = name;
|
localfile = name;
|
||||||
}
|
}
|
||||||
if (wad_debug_mode & DEBUG_SYMBOL_SEARCH) {
|
if (wad_debug_mode & DEBUG_SYMBOL_SEARCH) {
|
||||||
printf("%x(%x): %s %x + %x, %x, %x\n", base, vaddr, name, sym[i].st_value, sym[i].st_size, sym[i].st_info, sym[i].st_shndx);
|
wad_printf("%x(%x): %s %x + %x, %x, %x\n", base, vaddr, name, sym[i].st_value, sym[i].st_size, sym[i].st_info, sym[i].st_shndx);
|
||||||
}
|
}
|
||||||
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))) {
|
||||||
#ifdef WAD_LINUX
|
#ifdef WAD_LINUX
|
||||||
|
|
@ -324,12 +324,12 @@ wad_elf_debug_info(WadObjectFile *wo, WadSymbol *wsym, unsigned long offset, Wad
|
||||||
nstabexclstr = wad_elf_section_byname(wo,".stab.exclstr");
|
nstabexclstr = wad_elf_section_byname(wo,".stab.exclstr");
|
||||||
|
|
||||||
#ifdef DEBUG_DEBUG
|
#ifdef DEBUG_DEBUG
|
||||||
printf("nstab = %d\n", nstab);
|
wad_printf("nstab = %d\n", nstab);
|
||||||
printf("nstabstr = %d\n", nstabstr);
|
wad_printf("nstabstr = %d\n", nstabstr);
|
||||||
printf("nstabindex = %d\n", nstabindex);
|
wad_printf("nstabindex = %d\n", nstabindex);
|
||||||
printf("nstabindexstr = %d\n", nstabindexstr);
|
wad_printf("nstabindexstr = %d\n", nstabindexstr);
|
||||||
printf("nstabexcl = %d\n", nstabexcl);
|
wad_printf("nstabexcl = %d\n", nstabexcl);
|
||||||
printf("nstabexclstr = %d\n", nstabexclstr);
|
wad_printf("nstabexclstr = %d\n", nstabexclstr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Now start searching stabs */
|
/* Now start searching stabs */
|
||||||
|
|
@ -365,9 +365,8 @@ wad_elf_debug_info(WadObjectFile *wo, WadSymbol *wsym, unsigned long offset, Wad
|
||||||
wo1 = wad_object_load(objfile);
|
wo1 = wad_object_load(objfile);
|
||||||
if (wo1) {
|
if (wo1) {
|
||||||
ret = wad_debug_info(wo1,wsym,offset,wd);
|
ret = wad_debug_info(wo1,wsym,offset,wd);
|
||||||
wad_object_release(wo1);
|
|
||||||
} else {
|
} else {
|
||||||
/* printf("couldn't load %s\n", objfile); */
|
/* wad_printf("couldn't load %s\n", objfile); */
|
||||||
}
|
}
|
||||||
if (!ret) return wad_search_stab(stab,stabsize,stabstr,wsym, offset,wd);
|
if (!ret) return wad_search_stab(stab,stabsize,stabstr,wsym, offset,wd);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -385,13 +384,13 @@ wad_elf_debug_info(WadObjectFile *wo, WadSymbol *wsym, unsigned long offset, Wad
|
||||||
void
|
void
|
||||||
wad_elf_debug(WadObjectFile *wo) {
|
wad_elf_debug(WadObjectFile *wo) {
|
||||||
int i;
|
int i;
|
||||||
printf("ELF Debug : obj = %x (%s)\n", wo, wo->path);
|
wad_printf("ELF Debug : obj = %x (%s)\n", wo, wo->path);
|
||||||
printf(" phdrcnt = %d\n", wad_elf_phdrcnt(wo));
|
wad_printf(" phdrcnt = %d\n", wad_elf_phdrcnt(wo));
|
||||||
printf(" phdrpos = %x\n", wad_elf_phdrpos(wo));
|
wad_printf(" phdrpos = %x\n", wad_elf_phdrpos(wo));
|
||||||
printf(" shdrcnt = %d\n", wad_elf_shdrcnt(wo));
|
wad_printf(" shdrcnt = %d\n", wad_elf_shdrcnt(wo));
|
||||||
printf(" shdrpos = %x\n", wad_elf_shdrpos(wo));
|
wad_printf(" shdrpos = %x\n", wad_elf_shdrpos(wo));
|
||||||
for (i = 0; i < wad_elf_shdrcnt(wo); i++) {
|
for (i = 0; i < wad_elf_shdrcnt(wo); i++) {
|
||||||
printf(" section '%s': data = 0x%x, size = %d\n",
|
wad_printf(" section '%s': data = 0x%x, size = %d\n",
|
||||||
wad_elf_section_name(wo,i),
|
wad_elf_section_name(wo,i),
|
||||||
wad_elf_section_data(wo,i),
|
wad_elf_section_data(wo,i),
|
||||||
wad_elf_section_size(wo,i));
|
wad_elf_section_size(wo,i));
|
||||||
|
|
@ -413,20 +412,20 @@ wad_find_symbol(WadObjectFile *wo, void *ptr, unsigned base, WadSymbol *ws) {
|
||||||
ws->bind = 0;
|
ws->bind = 0;
|
||||||
ws->value = 0;
|
ws->value = 0;
|
||||||
if (wad_debug_mode & DEBUG_SYMBOL) {
|
if (wad_debug_mode & DEBUG_SYMBOL) {
|
||||||
printf("wad: Searching for 0x%08x --> ", ptr);
|
wad_printf("wad: Searching for 0x%08x --> ", ptr);
|
||||||
}
|
}
|
||||||
r = wad_elf_find_symbol(wo,ptr,base,ws);
|
r = wad_elf_find_symbol(wo,ptr,base,ws);
|
||||||
if (r) {
|
if (r) {
|
||||||
if (wad_debug_mode & DEBUG_SYMBOL) {
|
if (wad_debug_mode & DEBUG_SYMBOL) {
|
||||||
printf("%s", ws->name);
|
wad_printf("%s", ws->name);
|
||||||
if (ws->file)
|
if (ws->file)
|
||||||
printf(" in '%s'\n", ws->file);
|
wad_printf(" in '%s'\n", ws->file);
|
||||||
else
|
else
|
||||||
printf("\n");
|
wad_printf("\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (wad_debug_mode & DEBUG_SYMBOL) {
|
if (wad_debug_mode & DEBUG_SYMBOL) {
|
||||||
printf("?\n");
|
wad_printf("?\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
|
|
||||||
|
|
@ -76,12 +76,12 @@ void wad_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wad_debug_mode & DEBUG_INIT) {
|
if (wad_debug_mode & DEBUG_INIT) {
|
||||||
printf("WAD: initializing\n");
|
wad_printf("WAD: initializing\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!init) {
|
if (!init) {
|
||||||
wad_signal_init();
|
wad_signal_init();
|
||||||
wad_object_init();
|
wad_object_reset();
|
||||||
}
|
}
|
||||||
init = 1;
|
init = 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
Tools/WAD/Wad/io.c
Normal file
21
Tools/WAD/Wad/io.c
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* io.c
|
||||||
|
*
|
||||||
|
* This file provides some I/O routines so that WAD can produce
|
||||||
|
* debugging output without using buffered I/O.
|
||||||
|
*
|
||||||
|
* 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"
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
void wad_printf(const char *fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vfprintf(stderr,fmt,ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
@ -36,7 +36,7 @@ int wad_memory_init() {
|
||||||
pagesize = getpagesize();
|
pagesize = getpagesize();
|
||||||
devzero = open("/dev/zero", O_RDWR);
|
devzero = open("/dev/zero", O_RDWR);
|
||||||
if (devzero < 0) {
|
if (devzero < 0) {
|
||||||
printf("WAD: couldn't open /dev/zero.\n");
|
wad_printf("WAD: couldn't open /dev/zero.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -70,7 +70,7 @@ void *wad_malloc(int nbytes) {
|
||||||
WadMemory *wm;
|
WadMemory *wm;
|
||||||
char *c;
|
char *c;
|
||||||
int npages;
|
int npages;
|
||||||
printf("wad_malloc: %d\n", nbytes);
|
/* wad_printf("wad_malloc: %d\n", nbytes); */
|
||||||
if (nbytes >= (pagesize >> 2)) {
|
if (nbytes >= (pagesize >> 2)) {
|
||||||
/* Large allocation. */
|
/* Large allocation. */
|
||||||
npages = ((nbytes + sizeof(WadMemory))/pagesize) + 1;
|
npages = ((nbytes + sizeof(WadMemory))/pagesize) + 1;
|
||||||
|
|
@ -94,6 +94,7 @@ void *wad_malloc(int nbytes) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!wm) {
|
if (!wm) {
|
||||||
|
wad_printf("wad_malloc: new page\n", nbytes);
|
||||||
wm = (WadMemory *) wad_page_alloc(1);
|
wm = (WadMemory *) wad_page_alloc(1);
|
||||||
if (!wm) return 0;
|
if (!wm) return 0;
|
||||||
wm->npages = 1;
|
wm->npages = 1;
|
||||||
|
|
|
||||||
|
|
@ -14,173 +14,84 @@
|
||||||
#include "wad.h"
|
#include "wad.h"
|
||||||
#include <ar.h>
|
#include <ar.h>
|
||||||
|
|
||||||
/* Maximum number of files that can be loaded at once */
|
|
||||||
|
|
||||||
#define WAD_MAX_FILE 32
|
|
||||||
|
|
||||||
typedef struct WadFile {
|
typedef struct WadFile {
|
||||||
int refcnt;
|
void *addr; /* Base address of the file */
|
||||||
void *addr;
|
int size; /* Size in bytes */
|
||||||
int size;
|
char *path; /* Path name */
|
||||||
char path[MAX_PATH];
|
struct WadFile *next; /* Next file */
|
||||||
} WadFile;
|
} WadFile;
|
||||||
|
|
||||||
static WadFile wad_files[WAD_MAX_FILE]; /* Array of file objects */
|
static WadFile *wad_files = 0; /* Linked list of loaded files */
|
||||||
|
|
||||||
/* private function to manage the loading of raw files into memory */
|
/* private function to manage the loading of raw files into memory */
|
||||||
static WadFile *
|
static WadFile *
|
||||||
load_file(const char *path) {
|
load_file(const char *path) {
|
||||||
int i;
|
int i;
|
||||||
int fd;
|
int fd;
|
||||||
WadFile *firstfree = 0;
|
|
||||||
WadFile *firstreplace = 0;
|
|
||||||
WadFile *wf = wad_files;
|
WadFile *wf = wad_files;
|
||||||
|
|
||||||
if (wad_debug_mode & DEBUG_FILE) {
|
if (wad_debug_mode & DEBUG_FILE) {
|
||||||
printf("wad: Loading file '%s' ... ", path);
|
wad_printf("wad: Loading file '%s' ... ", path);
|
||||||
}
|
}
|
||||||
/* Walk through the file list to see if we already know about the file */
|
while (wf) {
|
||||||
for (i = 0; i < WAD_MAX_FILE; i++, wf++) {
|
if (strcmp(wf->path,path) == 0) {
|
||||||
if (strcmp(wf->path, path) == 0) {
|
if (wad_debug_mode & DEBUG_FILE) wad_printf("cached.\n");
|
||||||
wf->refcnt++;
|
|
||||||
if (wad_debug_mode & DEBUG_FILE) {
|
|
||||||
printf("cached.\n");
|
|
||||||
}
|
|
||||||
return wf;
|
return wf;
|
||||||
}
|
}
|
||||||
if (wf->refcnt <= 0) {
|
wf = wf->next;
|
||||||
if (wf->path[0] == 0) firstfree = wf;
|
|
||||||
else firstreplace = wf;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!firstfree && !firstreplace) {
|
|
||||||
if (wad_debug_mode & DEBUG_FILE) printf("out of memory!\n");
|
|
||||||
return 0; /* Out of space */
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!firstfree) firstfree = firstreplace;
|
|
||||||
|
|
||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (wad_debug_mode & DEBUG_FILE) printf("not found!\n");
|
if (wad_debug_mode & DEBUG_FILE) wad_printf("not found!\n");
|
||||||
return 0; /* Doesn't exist. Oh well */
|
return 0; /* Doesn't exist. Oh well */
|
||||||
}
|
}
|
||||||
if (wad_debug_mode & DEBUG_FILE) printf("loaded.\n");
|
if (wad_debug_mode & DEBUG_FILE) wad_printf("loaded.\n");
|
||||||
/* If already mapped, unmap the file */
|
wf = (WadFile *) wad_malloc(sizeof(WadFile));
|
||||||
if (firstfree->addr) {
|
wf->path = wad_strdup(path);
|
||||||
if (wad_debug_mode & DEBUG_FILE)
|
|
||||||
printf("wad: Unloading file '%s'\n", firstfree->path);
|
|
||||||
munmap(firstfree->addr,firstfree->size);
|
|
||||||
}
|
|
||||||
|
|
||||||
firstfree->refcnt = 1;
|
|
||||||
strncpy(firstfree->path,path,MAX_PATH);
|
|
||||||
|
|
||||||
/* Get file length */
|
/* Get file length */
|
||||||
firstfree->size = lseek(fd,0,SEEK_END);
|
wf->size = lseek(fd,0,SEEK_END);
|
||||||
lseek(fd,0,SEEK_SET);
|
lseek(fd,0,SEEK_SET);
|
||||||
|
|
||||||
/* Try to mmap the file */
|
/* Try to mmap the file */
|
||||||
firstfree->addr = mmap(NULL,firstfree->size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0);
|
wf->addr = mmap(NULL,wf->size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0);
|
||||||
close(fd);
|
close(fd);
|
||||||
if (firstfree->addr == MAP_FAILED) {
|
if (wf->addr == MAP_FAILED) {
|
||||||
if (wad_debug_mode & DEBUG_FILE) printf("wad: Couldn't mmap '%s'\n", path);
|
if (wad_debug_mode & DEBUG_FILE) wad_printf("wad: Couldn't mmap '%s'\n", path);
|
||||||
firstfree->refcnt = 0;
|
|
||||||
firstfree->path[0] = 0;
|
|
||||||
firstfree->addr = 0;
|
|
||||||
firstfree->size = 0;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return firstfree;
|
wf->next = wad_files;
|
||||||
|
wad_files = wf;
|
||||||
|
return wf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
release_file(WadFile *f) {
|
|
||||||
if (wad_debug_mode & DEBUG_FILE) printf("wad: Releasing file '%s'\n", f->path);
|
|
||||||
f->refcnt--;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define WAD_MAX_OBJECT 32
|
|
||||||
|
|
||||||
static WadObjectFile wad_objects[WAD_MAX_OBJECT]; /* Object file descriptor table */
|
|
||||||
static int wad_obj_free[WAD_MAX_OBJECT]; /* Free object stack */
|
|
||||||
static int wad_obj_nfree = 0; /* Num free object descriptors */
|
|
||||||
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
static WadObjectFile *wad_objects = 0; /* Linked list of object files */
|
||||||
* wad_object_init()
|
|
||||||
*
|
|
||||||
* Initialize the object file system
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void wad_object_init() {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < WAD_MAX_FILE; i++) {
|
|
||||||
wad_files[i].refcnt = 0;
|
|
||||||
wad_files[i].addr = 0;
|
|
||||||
wad_files[i].size = 0;
|
|
||||||
wad_files[i].path[0] = 0;
|
|
||||||
}
|
|
||||||
wad_obj_nfree = 0;
|
|
||||||
for (i = 0; i < WAD_MAX_OBJECT; i++) {
|
|
||||||
wad_objects[i].ptr = 0;
|
|
||||||
wad_objects[i].len = 0;
|
|
||||||
wad_objects[i].refcnt = 0;
|
|
||||||
wad_objects[i].path[0] = 0;
|
|
||||||
wad_obj_free[i] = i;
|
|
||||||
wad_obj_nfree++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* wad_object_cleanup()
|
* wad_object_cleanup()
|
||||||
*
|
*
|
||||||
* Release all files loaded during the debugging
|
* Reset the object file loader
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
wad_object_cleanup() {
|
wad_object_reset() {
|
||||||
int i;
|
int i;
|
||||||
WadFile *f = wad_files;
|
WadFile *f = wad_files;
|
||||||
if (wad_debug_mode & DEBUG_OBJECT) {
|
if (wad_debug_mode & DEBUG_OBJECT) {
|
||||||
printf("wad: Releasing all files.\n");
|
wad_printf("wad: Releasing all files.\n");
|
||||||
}
|
}
|
||||||
for (i = 0; i < WAD_MAX_FILE; i++, f++) {
|
/* Unmap all of the loaded files */
|
||||||
|
while (f) {
|
||||||
if (f->addr) {
|
if (f->addr) {
|
||||||
munmap(f->addr, f->size);
|
munmap(f->addr, f->size);
|
||||||
}
|
}
|
||||||
f->addr = 0;
|
f = f->next;
|
||||||
f->size = 0;
|
|
||||||
f->path[0] = 0;
|
|
||||||
f->refcnt = 0;
|
|
||||||
}
|
}
|
||||||
}
|
/* Reset the linked lists */
|
||||||
|
wad_files = 0;
|
||||||
/* -----------------------------------------------------------------------------
|
wad_objects = 0;
|
||||||
* wad_object_release()
|
|
||||||
*
|
|
||||||
* Done with the object.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void
|
|
||||||
wad_object_release(WadObjectFile *wo) {
|
|
||||||
int n;
|
|
||||||
if (!wo) return;
|
|
||||||
|
|
||||||
wo->refcnt--;
|
|
||||||
if (wo->refcnt > 0) return;
|
|
||||||
if (wad_debug_mode & DEBUG_OBJECT) {
|
|
||||||
printf("wad: Releasing object '%s'\n", wo->path);
|
|
||||||
}
|
|
||||||
release_file(wo->file);
|
|
||||||
wo->file = 0;
|
|
||||||
wo->ptr = 0;
|
|
||||||
wo->len = 0;
|
|
||||||
wo->path[0] = 0;
|
|
||||||
n = wo - wad_objects;
|
|
||||||
wad_obj_free[wad_obj_nfree++] = n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -198,21 +109,12 @@ wad_object_load(const char *path) {
|
||||||
WadObjectFile *wad_arobject_load(const char *path, const char *name);
|
WadObjectFile *wad_arobject_load(const char *path, const char *name);
|
||||||
|
|
||||||
if (wad_debug_mode & DEBUG_OBJECT) {
|
if (wad_debug_mode & DEBUG_OBJECT) {
|
||||||
printf("wad: Loading object '%s'\n", path);
|
wad_printf("wad: Loading object '%s'\n", path);
|
||||||
}
|
}
|
||||||
/* See if the path has already been loaded */
|
for (wo = wad_objects; wo; wo=wo->next) {
|
||||||
for (i = 0; i < WAD_MAX_OBJECT; i++) {
|
if (strcmp(wo->path,path) == 0) return wo;
|
||||||
if (strcmp(wad_objects[i].path,path) == 0) {
|
|
||||||
wo = &wad_objects[i];
|
|
||||||
wo->refcnt++;
|
|
||||||
return wo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (wad_obj_nfree == 0) {
|
|
||||||
if (wad_debug_mode & DEBUG_OBJECT)
|
|
||||||
printf("wad: No more space in wad_object_load()\n");
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
/* Didn't find it. Now we need to go load some files */
|
||||||
|
|
||||||
/* If this is an archive reference like /path/libfoo.a(blah.o), we need to
|
/* If this is an archive reference like /path/libfoo.a(blah.o), we need to
|
||||||
split up the name a little bit */
|
split up the name a little bit */
|
||||||
|
|
@ -232,7 +134,8 @@ wad_object_load(const char *path) {
|
||||||
/* Okay, I'm going to attempt to map this as a library file */
|
/* Okay, I'm going to attempt to map this as a library file */
|
||||||
wo = wad_arobject_load(realfile,objfile);
|
wo = wad_arobject_load(realfile,objfile);
|
||||||
if (wo) {
|
if (wo) {
|
||||||
strncpy(wo->path, path, MAX_PATH);
|
/* Reset the path */
|
||||||
|
wo->path = wad_strdup(path);
|
||||||
return wo;
|
return wo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -240,12 +143,9 @@ wad_object_load(const char *path) {
|
||||||
wf = load_file(path);
|
wf = load_file(path);
|
||||||
if (!wf) return 0;
|
if (!wf) return 0;
|
||||||
|
|
||||||
wo = wad_objects + wad_obj_free[wad_obj_nfree-1];
|
wo = (WadObjectFile *) wad_malloc(sizeof(WadObjectFile));
|
||||||
wad_obj_nfree--;
|
|
||||||
|
|
||||||
wo->file = wf;
|
wo->file = wf;
|
||||||
wo->refcnt = 1;
|
wo->path = wad_strdup(path);
|
||||||
strncpy(wo->path,path, MAX_PATH);
|
|
||||||
wo->ptr = wf->addr;
|
wo->ptr = wf->addr;
|
||||||
wo->len = wf->size;
|
wo->len = wf->size;
|
||||||
return wo;
|
return wo;
|
||||||
|
|
@ -283,18 +183,10 @@ wad_arobject_load(const char *arpath, const char *robjname) {
|
||||||
arptr = (char *) wf->addr;
|
arptr = (char *) wf->addr;
|
||||||
arlen = wf->size;
|
arlen = wf->size;
|
||||||
|
|
||||||
nf = wad_obj_free[wad_obj_nfree-1];
|
|
||||||
wo = wad_objects + nf;
|
|
||||||
wad_obj_nfree--;
|
|
||||||
wo->refcnt = 1;
|
|
||||||
wo->ptr = 0;
|
|
||||||
|
|
||||||
/* Now take a look at the archive */
|
/* Now take a look at the archive */
|
||||||
if (strncmp(arptr,ARMAG,SARMAG) == 0) {
|
if (strncmp(arptr,ARMAG,SARMAG) == 0) {
|
||||||
/* printf("Got an archive\n"); */
|
/* printf("Got an archive\n"); */
|
||||||
} else {
|
} else {
|
||||||
/* Not an archive file */
|
|
||||||
release_file(wf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -318,7 +210,6 @@ wad_arobject_load(const char *arpath, const char *robjname) {
|
||||||
soff = atoi(ah->ar_name+1);
|
soff = atoi(ah->ar_name+1);
|
||||||
if (!strtab) {
|
if (!strtab) {
|
||||||
/* No offset table */
|
/* No offset table */
|
||||||
release_file(wf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
e = strchr(strtab+soff,'\n');
|
e = strchr(strtab+soff,'\n');
|
||||||
|
|
@ -336,18 +227,15 @@ wad_arobject_load(const char *arpath, const char *robjname) {
|
||||||
/* Compare the names */
|
/* Compare the names */
|
||||||
if (strncmp(mname,objname,sobjname) == 0) {
|
if (strncmp(mname,objname,sobjname) == 0) {
|
||||||
/* Found the archive */
|
/* Found the archive */
|
||||||
|
wo = (WadObjectFile *) wad_malloc(sizeof(WadObjectFile));
|
||||||
wo = wad_objects + wad_obj_free[wad_obj_nfree-1];
|
|
||||||
wad_obj_nfree--;
|
|
||||||
wo->file = wf;
|
wo->file = wf;
|
||||||
wo->refcnt = 1;
|
|
||||||
wo->ptr = (void *) (arptr + offset);
|
wo->ptr = (void *) (arptr + offset);
|
||||||
wo->len = msize;
|
wo->len = msize;
|
||||||
|
wo->path = 0;
|
||||||
return wo;
|
return wo;
|
||||||
}
|
}
|
||||||
offset += msize;
|
offset += msize;
|
||||||
}
|
}
|
||||||
release_file(wf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ wad_segment_read() {
|
||||||
lasts = s;
|
lasts = s;
|
||||||
}
|
}
|
||||||
if (wad_debug_mode & DEBUG_SEGMENT) {
|
if (wad_debug_mode & DEBUG_SEGMENT) {
|
||||||
printf("wad_segment: read : %08x-%08x, base=%x in %s\n", s->vaddr, ((char *) s->vaddr) + s->size, s->base, s->mappath);
|
wad_printf("wad_segment: read : %08x-%08x, base=%x in %s\n", s->vaddr, ((char *) s->vaddr) + s->size, s->base, s->mappath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(fs);
|
close(fs);
|
||||||
|
|
@ -90,7 +90,7 @@ wad_segment_find(void *vaddr) {
|
||||||
}
|
}
|
||||||
if ((addr >= s->vaddr) && (addr < (s->vaddr + s->size))) {
|
if ((addr >= s->vaddr) && (addr < (s->vaddr + s->size))) {
|
||||||
if (wad_debug_mode & DEBUG_SEGMENT) {
|
if (wad_debug_mode & DEBUG_SEGMENT) {
|
||||||
printf("wad_segment: %08x --> %08x-%08x in %s\n", vaddr, s->vaddr, ((char *) s->vaddr) + s->size, s->mappath);
|
wad_printf("wad_segment: %08x --> %08x-%08x in %s\n", vaddr, s->vaddr, ((char *) s->vaddr) + s->size, s->mappath);
|
||||||
}
|
}
|
||||||
return ls;
|
return ls;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -259,9 +259,6 @@ void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) {
|
||||||
|
|
||||||
wad_nlr_func = 0;
|
wad_nlr_func = 0;
|
||||||
|
|
||||||
if (!wad_stacked_signal)
|
|
||||||
wad_object_init();
|
|
||||||
|
|
||||||
context = (ucontext_t *) vcontext;
|
context = (ucontext_t *) vcontext;
|
||||||
|
|
||||||
if (wad_debug_mode & DEBUG_SIGNAL) {
|
if (wad_debug_mode & DEBUG_SIGNAL) {
|
||||||
|
|
@ -399,8 +396,6 @@ void wad_signalhandler(int sig, siginfo_t *si, void *vcontext) {
|
||||||
|
|
||||||
if (wad_debug_mode & DEBUG_HOLD) while(1);
|
if (wad_debug_mode & DEBUG_HOLD) while(1);
|
||||||
|
|
||||||
wad_object_cleanup();
|
|
||||||
|
|
||||||
/* If we found a function to which we should return, we jump to
|
/* If we found a function to which we should return, we jump to
|
||||||
an alternative piece of code that unwinds the stack and
|
an alternative piece of code that unwinds the stack and
|
||||||
initiates a non-local return. */
|
initiates a non-local return. */
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ typedef struct Stab {
|
||||||
extra information delimetered by a colon */
|
extra information delimetered by a colon */
|
||||||
|
|
||||||
int match_stab_symbol(char *symbol, char *stabtext, int slen) {
|
int match_stab_symbol(char *symbol, char *stabtext, int slen) {
|
||||||
/* printf("matching: %s -> %s\n", symbol, stabtext); */
|
/* wad_printf("matching: %s -> %s\n", symbol, stabtext); */
|
||||||
if (strcmp(symbol,stabtext) == 0) {
|
if (strcmp(symbol,stabtext) == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -74,9 +74,9 @@ wad_search_stab(void *sp, int size, char *stabstr, WadSymbol *wsym, unsigned lon
|
||||||
for (i = 0; i < ns; i++, s++) {
|
for (i = 0; i < ns; i++, s++) {
|
||||||
/*#define DEBUG_DEBUG */
|
/*#define DEBUG_DEBUG */
|
||||||
if (wad_debug_mode & DEBUG_STABS) {
|
if (wad_debug_mode & DEBUG_STABS) {
|
||||||
/* printf(" %10d %10x %10d %10d %10d: '%x'\n", s->n_strx, s->n_type, s->n_other, s->n_desc, s->n_value,
|
/* wad_printf(" %10d %10x %10d %10d %10d: '%x'\n", s->n_strx, s->n_type, s->n_other, s->n_desc, s->n_value,
|
||||||
stabstr+s->n_strx); */
|
stabstr+s->n_strx); */
|
||||||
printf(" %10d %10x %10d %10d %10d: '%s'\n", s->n_strx, s->n_type, s->n_other, s->n_desc, s->n_value,
|
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);
|
stabstr+s->n_strx);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ static void
|
||||||
stack_unwind(unsigned long *sp, unsigned long *pc, unsigned long *fp) {
|
stack_unwind(unsigned long *sp, unsigned long *pc, unsigned long *fp) {
|
||||||
|
|
||||||
if (wad_debug_mode & DEBUG_UNWIND) {
|
if (wad_debug_mode & DEBUG_UNWIND) {
|
||||||
printf("::: stack unwind : pc = %x, sp = %x, fp = %x\n", *pc, *sp, *fp);
|
wad_printf("::: stack unwind : pc = %x, sp = %x, fp = %x\n", *pc, *sp, *fp);
|
||||||
}
|
}
|
||||||
#ifdef WAD_SOLARIS
|
#ifdef WAD_SOLARIS
|
||||||
*pc = *((unsigned long *) *sp+15); /* %i7 - Return address */
|
*pc = *((unsigned long *) *sp+15); /* %i7 - Return address */
|
||||||
|
|
@ -80,7 +80,7 @@ wad_stack_trace(unsigned long pc, unsigned long sp, unsigned long fp) {
|
||||||
/* Read the segments */
|
/* Read the segments */
|
||||||
|
|
||||||
if (wad_segment_read() < 0) {
|
if (wad_segment_read() < 0) {
|
||||||
printf("WAD: Unable to read segment map\n");
|
wad_printf("WAD: Unable to read segment map\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ wad_stack_trace(unsigned long pc, unsigned long sp, unsigned long fp) {
|
||||||
tmpnam(framefile);
|
tmpnam(framefile);
|
||||||
ffile = open(framefile, O_CREAT | O_TRUNC | O_WRONLY, 0644);
|
ffile = open(framefile, O_CREAT | O_TRUNC | O_WRONLY, 0644);
|
||||||
if (ffile < 0) {
|
if (ffile < 0) {
|
||||||
printf("can't open %s\n", framefile);
|
wad_printf("can't open %s\n", framefile);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,7 +156,7 @@ 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));*/
|
/* wad_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)) {
|
||||||
|
|
@ -171,9 +171,9 @@ wad_stack_trace(unsigned long pc, unsigned long sp, unsigned long fp) {
|
||||||
/*
|
/*
|
||||||
if (wd.nargs >=0) {
|
if (wd.nargs >=0) {
|
||||||
int i;
|
int i;
|
||||||
printf("%s\n",symname);
|
wad_printf("%s\n",symname);
|
||||||
for (i = 0; i < wd.nargs; i++) {
|
for (i = 0; i < wd.nargs; i++) {
|
||||||
printf(" [%d] = '%s', %d, %d\n", i, wd.parms[i].name, wd.parms[i].type, wd.parms[i].value);
|
wad_printf(" [%d] = '%s', %d, %d\n", i, wd.parms[i].name, wd.parms[i].type, wd.parms[i].value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
@ -188,7 +188,7 @@ wad_stack_trace(unsigned long pc, unsigned long sp, unsigned long fp) {
|
||||||
int i;
|
int i;
|
||||||
long *lsp = (long *) p_lastsp;
|
long *lsp = (long *) p_lastsp;
|
||||||
for (i = 0; i < 16; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
/* printf("regs[%d] = 0x%x\n", lsp[i]); */
|
/* wad_printf("regs[%d] = 0x%x\n", lsp[i]); */
|
||||||
frame.regs[i] = lsp[i];
|
frame.regs[i] = lsp[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -255,8 +255,6 @@ wad_stack_trace(unsigned long pc, unsigned long sp, unsigned long fp) {
|
||||||
}
|
}
|
||||||
write(ffile,frame.data, pad);
|
write(ffile,frame.data, pad);
|
||||||
lastsize = frame.size;
|
lastsize = frame.size;
|
||||||
if (wo)
|
|
||||||
wad_object_release(wo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue