void *SafeRecurseCpp( func_sr rtn, void *arg ) /********************************************/ /* This code assumes NO parameters on the stack! */ { #define SAVE_SIZE 512 /* this must be smaller than the stack */ void *savearea; void *retval; if( stackavail() < 0x2000 ) { /* stack getting low! */ savearea = CMemAlloc( SAVE_SIZE ); if( savearea != NULL ) { memcpy( bp(), savearea, SAVE_SIZE ); memcpy( sp(), sp() + SAVE_SIZE, bp() - sp() ); setbp( bp() + SAVE_SIZE ); setsp( sp() + SAVE_SIZE ); retval = rtn( arg ); setsp( sp() - SAVE_SIZE ); memcpy( sp() + SAVE_SIZE, sp(), bp() - sp() - SAVE_SIZE ); setbp( bp() - SAVE_SIZE ); memcpy( savearea, bp(), SAVE_SIZE ); CMemFree( savearea ); return( retval ); } } return( rtn( arg ) ); }
void *SafeRecurseCG( func_sr rtn, void *arg ) /**********************************************/ /* This code assumes NO parameters on the stack! */ { #define SAVE_SIZE 512 /* this must be smaller than the stack */ void *savearea; void *retval; mem_out_action old_action; if( stackavail() < 0x2000 ) { /* stack getting low! */ old_action = SetMemOut( MO_OK ); savearea = CGAlloc( SAVE_SIZE ); if( savearea == NULL ) { FatalError( "No memory to save stack" ); } SetMemOut( old_action ); CypCopy( bp(), savearea, SAVE_SIZE ); CypCopy( sp(), sp() + SAVE_SIZE, bp() - sp() ); setbp( bp() + SAVE_SIZE ); setsp( sp() + SAVE_SIZE ); retval = rtn( arg ); setsp( sp() - SAVE_SIZE ); CypCopy( sp() + SAVE_SIZE, sp(), bp() - sp() - SAVE_SIZE ); setbp( bp() - SAVE_SIZE ); CypCopy( savearea, bp(), SAVE_SIZE ); CGFree( savearea ); return( retval ); } else { return( rtn( arg ) ); } }
setallbps() { register BPINFO *p; for (p = bphead; p != NIL; p = p->bpnext) { setbp(p->bpaddr); } }
runpcs(runmode,execsig) { INT rc; REG BKPTR bkpt; IF adrflg THEN userpc=dot; FI printf("%s: running\n", symfil); WHILE --loopcnt>=0 DO #ifdef DEBUG printf("\ncontinue %x %d\n",userpc,execsig); #endif IF runmode==SINGLE THEN delbp(); /* hardware handles single-stepping */ ELSE /* continuing from a breakpoint is hard */ IF bkpt=scanbkpt(userpc) THEN execbkpt(bkpt,execsig); execsig=0; FI setbp(); FI ptrace(runmode,pid,userpc,execsig); bpwait(); chkerr(); execsig=0; delbp(); readregs(); IF signo==0 ANDF runmode != SINGLE #ifdef mc68000 ANDF (bkpt=scanbkpt(userpc - 2)) /* argh */ #else ANDF (bkpt=scanbkpt(userpc)) #endif THEN /* stopped by BPT instruction */ #ifdef DEBUG printf("\n BPT code; '%s'%o'%o'%d", bkpt->comm,bkpt->comm[0],EOR,bkpt->flag); #endif dot=bkpt->loc; userpc = dot; *(ADDR *)(((ADDR)&u)+PC-getradj(1)) = userpc; IF bkpt->flag==BKPTEXEC ORF ((bkpt->flag=BKPTEXEC) ANDF bkpt->comm[0]!=EOR ANDF command(bkpt->comm,':') ANDF --bkpt->count) THEN execbkpt(bkpt,execsig); execsig=0; loopcnt++; ELSE bkpt->count=bkpt->initcnt; rc=1; FI ELSE execsig=signo; rc=0; FI OD return(rc); }
runpcs(int runmode, int keepnote) { int rc; BKPT *bkpt; rc = 0; if (adrflg) rput(cormap, mach->pc, dot); dot = rget(cormap, mach->pc); flush(); while (loopcnt-- > 0) { if(loopcnt != 0) printpc(); if (runmode == SINGLE) { bkpt = scanbkpt(dot); if (bkpt) { switch(bkpt->flag){ case BKPTTMP: bkpt->flag = BKPTCLR; break; case BKPTSKIP: bkpt->flag = BKPTSET; break; } } runstep(dot, keepnote); } else { if ((bkpt = scanbkpt(rget(cormap, mach->pc))) != 0) { execbkpt(bkpt, keepnote); keepnote = 0; } setbp(); runrun(keepnote); } keepnote = 0; delbp(); dot = rget(cormap, mach->pc); /* real note? */ if (nnote > 0) { keepnote = 1; rc = 0; continue; } bkpt = scanbkpt(dot); if(bkpt == 0){ keepnote = 0; rc = 0; continue; } /* breakpoint */ if (bkpt->flag == BKPTTMP) bkpt->flag = BKPTCLR; else if (bkpt->flag == BKPTSKIP) { execbkpt(bkpt, keepnote); keepnote = 0; loopcnt++; /* we didn't really stop */ continue; } else { bkpt->flag = BKPTSKIP; --bkpt->count; if ((bkpt->comm[0] == EOR || command(bkpt->comm, ':') != 0) && bkpt->count != 0) { execbkpt(bkpt, keepnote); keepnote = 0; loopcnt++; continue; } bkpt->count = bkpt->initcnt; } rc = 1; } return(rc); }