Добавил:
ivanov666
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Проектирование экзоскелета. Монография
.pdf
171
return;
}
fatal("too many child processes (table overflow)",0);
}
/********************************
* Describe function parameters *
********************************/
static inline void display_value(const unsigned int q,const char*
where) {
if ((q >> 24) == CODESEG) debug("g/%x",q); // global
else if ((q >> 24) == STACKSEG) debug("l/%x",q); // local
else if (INLIBC(q)) debug("s/%x",q); // shared
else debug("%d",q);
add_pdescr(q);
print_string(q,where);
}
/*********************************************
* Modify last input parameter for SOMETHING *
*********************************************/

172
static inline void modify_lasti(unsigned int sth,char* where,int
fd,unsigned int map,char* what) {
char buf[MAXDESCR*2];
struct fenris_map* ma=0;
struct fenris_mem* me=0;
if (!sth || (sth>0xffffff00)) return;
strncpy(buf,where,MAXDESCR);
if (map) sprintf(&buf[strlen(buf)]," on map %x",map);
else if (fd) sprintf(&buf[strlen(buf)]," on file \"%s\"",get_fname(fd));
else if (what && what[0]) snprintf(&buf[strlen(buf)],MAXDESCR," on
%s",what);
me=lookup_mem(sth);
if (me) {
if (me->lasti) free(me->lasti);
me->lasti=strdup(buf);
if (current->nest>=0 && !be_silent) {
indent(0);
debug("\\ buffer %x modified.\n",me->addr);
}
return;
}
ma=lookup_map(sth);
if (ma) {
if (ma->lasti) free(ma->lasti);
ma->lasti=strdup(buf);

173
if (current->nest>=0 && !be_silent) {
indent(0);
debug("\\ buffer %x modified.\n",ma->addr);
}
return;
}
// Doh. Nothing.
}
/**************************************
* Some fast-action debug() functions *
**************************************/
static inline unsigned int Xv(const unsigned int q) {
if (q) add_pdescr(q);
return q;
}
static inline int Xf(int q) {
if (q>=0) add_fd_pdescr(q);
return q;
}
static inline unsigned int Wv(const unsigned int q) {
if (q) add_wdescr(q,1);
return q;
}

174
/*******************************
* Add something to pdescr log *
*******************************/
static inline void add_pdescr(const unsigned int q) {
int miau=0;
char tmp[MAXDESCR];
struct fenris_map* ma=0;
struct fenris_mem* me=0;
if (T_dostep) {
if ((q >> 24) == CODESEG) break_memread(q); else
if ((q >> 24) == STACKSEG) break_memread(q); else
if (INLIBC(q)) break_memread(q);
}
if (T_nodesc) return;
if ((q >> 24) == CODESEG) miau=1; // global
else if ((q >> 24) == STACKSEG) miau=2; // local
else if (INLIBC(q)) miau=3; // shared
else return;
tmp[0]=0;
// First of all, it might be a local function. Look for extact
// match.
if (miau==1) {
if (lookup_fnct(q,0,1)) {
sprintf(tmp,"+ g/%x = local %s\n",q,lookup_fnct(q,0,1));

175
nappend(pdescr,tmp,MAXPDESC);
}
}
// Then, it can be a library function. Check for extact match, again.
else if (miau==3) {
char* x;
current->lentry=q;
x=find_name_ex(q,1,1);
if (x) {
snprintf(tmp,MAXDESCR,"+ s/%x = %s\n",q,x);
nappend(pdescr,tmp,MAXPDESC);
}
}
// Hmm, look for unspecific stuff - is this a buffer? Or a map?
if (miau) {
me=lookup_mem(q);
if (me) {
if (!tmp[0]) {
snprintf(tmp,MAXDESCR,"+ %x = %x:%d <off %d> (%s)\n",q,
me->addr,me->len,q-me->addr,me->descr);
nappend(pdescr,tmp,MAXPDESC);
} else {
sprintf(tmp,":%d\n",me->len);
pdescr[strlen(pdescr)-1]=0;
nappend(pdescr,tmp,MAXPDESC);
}
if (me->lasti) {
snprintf(tmp,MAXDESCR," last input: %s\n",me->lasti);
nappend(pdescr,tmp,MAXPDESC);

176
}
return;
}
if (!me) ma=lookup_map(q);
if (ma) {
if (!tmp[0]) {
snprintf(tmp,MAXDESCR,"+ %x = map %x:%d <off %d> (%s)\n",q,
ma->addr,ma->len,q-ma->addr,ma->descr);
nappend(pdescr,tmp,MAXPDESC);
}
if (ma->lasti) {
snprintf(tmp,MAXDESCR," last input: %s\n",ma->lasti);
nappend(pdescr,tmp,MAXPDESC);
}
return;
}
}
if (tmp[0]) return;
// Last resort: try do determine where does it point on stack, if
// it does point there.
if (miau==2) {
int i;
for (i=1;i<=current->fntop;i++) {
if (q >= current->frstart[i])
if (q < current->frend[i]) {
// Wow, something local.
sprintf(tmp,"+ l/%x (maxsize %d) = stack of fcnt_%d (%d down)\n",
q,current->frend[i]-q,current->fnid[i],current->fntop-i);

177
nappend(pdescr,tmp,MAXPDESC);
return;
}
}
}
// Giving up.
return;
}
inline char* get_addrdescr(const unsigned int q) {
int miau=1;
char tmp[MAXDESCR];
static char ret[MAXDESCR];
struct fenris_map* ma=0;
struct fenris_mem* me=0;
ret[0]=0;
if (miau) {
me=lookup_mem(q);
if (me) {
if (!tmp[0]) {
snprintf(tmp,MAXDESCR,"+ %x = %x:%d <off %d> (%s)\n",q,
me->addr,me->len,q-me->addr,me->descr);
nappend(ret,tmp,MAXPDESC);

178
} else {
sprintf(tmp,":%d\n",me->len);
pdescr[strlen(pdescr)-1]=0;
nappend(ret,tmp,MAXPDESC);
}
if (me->lasti) {
snprintf(tmp,MAXDESCR," last input: %s\n",me->lasti);
nappend(ret,tmp,MAXPDESC);
}
}
if (!me) ma=lookup_map(q);
if (ma) {
if (!tmp[0]) {
snprintf(tmp,MAXDESCR,"+ %x = map %x:%d <off %d> (%s)\n",q,
ma->addr,ma->len,q-ma->addr,ma->descr);
nappend(ret,tmp,MAXPDESC);
}
if (ma->lasti) {
snprintf(tmp,MAXDESCR," last input: %s\n",ma->lasti);
nappend(ret,tmp,MAXPDESC);
}
}
}
// Last resort: try do determine where does it point on stack, if
// it does point there.
if ((q >> 24) == STACKSEG) {
int i;
for (i=1;i<=current->fntop;i++) {
if (q >= current->frstart[i])
if (q < current->frend[i]) {
sprintf(tmp,"+ l/%x (maxsize %d) = stack of fcnt_%d (%d down)\n",

179
q,current->frend[i]-q,current->fnid[i],current->fntop-i);
nappend(ret,tmp,MAXPDESC);
}
}
}
return ret;
}
/********************************************
* Add description of given addr to the log *
********************************************/
static inline void add_wdescr(unsigned int q,char wri) {
int miau=0;
char tmp[MAXDESCR];
struct fenris_map* ma=0;
struct fenris_mem* me=0;
char b2[64];
if (T_nodesc) return;
if ((q >> 24) == CODESEG) miau=1; // global
else if ((q >> 24) == STACKSEG) miau=2; // local
else if (INLIBC(q)) miau=3; // shared
else return;
if (current->idtop) sprintf(b2,"%s",lookup_fnct((*current-
>fnaddr)[current->idtop-1],0,1));

180
else strcpy(b2,"main");
be_silent=1;
add_mem(q,4,0,b2,0);
be_silent=0;
tmp[0]=0;
// First of all, it might be a local function. Look for extact
// match.
if (miau==1) {
if (lookup_fnct(q,0,0)) {
sprintf(tmp,"* %s local object %s
~%x)\n",wri?"WRITE":"READ",lookup_fnct(q,0,0),find_id(q,0)?(*current>fnaddr)[find_id(q,0)-1]:q);
append_wlog(tmp);
}
}
// Then, it can be a library function. Check for extact match, again.
else if (miau==3) {
char* x;
current->lentry=q;
x=find_name_ex(q,2,1);
if (x) {
sprintf(tmp,"* %s shared object %s
~%x)\n",wri?"WRITE":"READ",x,appr_addr(q));
append_wlog(tmp);
}
}
Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]
