Ejemplo n.º 1
0
Archivo: devcons.c Proyecto: 8l/inferno
void
panic(char *fmt, ...)
{
	int n;
	va_list arg;
	char buf[PRINTSIZE];

	setpanic();
	kprintq.q = nil;
	strcpy(buf, "panic: ");
	va_start(arg, fmt);
	n = vseprint(buf+strlen(buf), buf+sizeof(buf)-1, fmt, arg) - buf;
	va_end(arg);
	buf[n] = '\n';
	putstrn(buf, n+1);
	spllo();
	dumpstack();

	exit(1);
}
Ejemplo n.º 2
0
void
COND_DumpConditions(void)
{
#ifdef CTN_USE_THREADS
    if (THR_ObtainMutex(FAC_COND) != THR_NORMAL) {
    	fprintf(stderr, "COND_DumpConditions unable to obtain mutex\n");
    	return;
    }
#endif

    dumpstack(stderr);
    stackPtr = -1;

#ifdef CTN_USE_THREADS
    if (THR_ReleaseMutex(FAC_COND) != THR_NORMAL) {
    	fprintf(stderr, "COND_DumpConditions unable to release mutex\n");
    	return;
    }
#endif
}
Ejemplo n.º 3
0
void AGOSEngine_PN::popstack(int type) {
	int i = 0;

	while ((_stackbase != NULL) && (_stackbase->classnum != type)) {
		dumpstack();
		++i;
	}

	if (_stackbase == NULL)
		error("popstack: Stack underflow or unknown longjmp");

	_linct = _stackbase->ll;
	_linebase = _stackbase->lbase;
	_workptr = _stackbase->linpos;
	_procnum = _stackbase->process;
	_linembr = _stackbase->linenum;
	for (i = 0; i < 6; ++i)
		_variableArray[i] = _stackbase->flag[i];
	for (i = 0; i < 8; ++i)
		_variableArray[24 + i] = _stackbase->param[i];
}
Ejemplo n.º 4
0
void
panic(const char *fmt, ...)
{
  va_list ap;

  static void *frames[MAXFRAMES];
  int nframes = backtrace(frames, MAXFRAMES);

  signal(SIGSEGV, SIG_DFL);
  signal(SIGBUS,  SIG_DFL);
  signal(SIGILL,  SIG_DFL);
  signal(SIGABRT, SIG_DFL);
  signal(SIGFPE,  SIG_DFL);

  va_start(ap, fmt);
  tracev(0, TRACE_EMERG, "PANIC", fmt, ap);
  va_end(ap);

  dumpstack(frames, nframes);
  exit(1);
}
Ejemplo n.º 5
0
void signal_handler(int sig_num)
{
    switch(sig_num)
    {
#ifndef WIN32
    case SIGHUP:
        if (logfile!="")
        {
            _log.SetOutputFile(logfile.c_str());
        }
        break;
#endif
    case SIGINT:
    case SIGTERM:
#ifndef WIN32
        if ((g_bRunAsDaemon)||(g_bUseSyslog))
            syslog(LOG_INFO, "Domoticz is exiting...");
#endif
        g_bStopApplication = true;
        break;
    case SIGSEGV:
    case SIGILL:
    case SIGABRT:
    case SIGFPE:
        if (fatal_handling) {
            _log.Log(LOG_ERROR, "Domoticz received fatal signal %d while backtracing !...", sig_num);
            exit(EXIT_FAILURE);
        }
        fatal_handling = 1;
        _log.Log(LOG_ERROR, "Domoticz received fatal signal %d !...", sig_num);
        dumpstack();
        // re-raise signal to enforce core dump
        signal(sig_num, SIG_DFL);
        raise(sig_num);
        break;
    }
}
Ejemplo n.º 6
0
void execute(int x) {
	int op = disk[x];
	char *s;
	switch (op) {
	case DOCOL:
		w = ++IP;
		RPUSH ++IP;
		IP = disk[w];
		break;
	case KEY:
		PUSH getchar();
		NEXT;
		break;
	case WORD:
		w = *dict;
		enter(0);
		int slen = scant((char) TOS, (char *)(disk + (*dict)));
		DROP;
		disk[w] = slen;
		PUSH w;
		*dict += slen/PACK + 1;
		NEXT;
		break;
	case FIND:
		w = *link;
		while (!(streql(disk+TOS, (disk+w+1))) && w) {
			w = disk[w];
		}
		if (!w) {
			PUSH 1;
		} else {
			TOS = w + 2 + ((disk[w+1])/PACK + 2);
			w = disk[TOS-1];
			PUSH w;
		}
		NEXT;
		break;
	case EXIT:
		RDROP;
		NEXT;
		break;
	case PEEK:
		TOS = disk[TOS];
		NEXT;
		break;
	case POKE:
		disk[TOS] = NTOS;
		DROP;
		DROP;
		NEXT;
		break;
	case LIT:
		PUSH disk[TORS++];
		NEXT;
		break;
	case PUSNXT:
		PUSH disk[NTORS++];
		NEXT;
		break;
	case BRANCH:
		TORS += disk[TORS] + 1; //was off by one
		NEXT;
		break;
	case PDROP:
		DROP;
		NEXT;
		break;
	case TOR:
		w = TORS;
		TORS = TOS;
		RPUSH w;
		DROP;
		NEXT;
		break;
	case FROMR:
		PUSH NTORS;
		w = TORS;
		RDROP;
		TORS = w;
		NEXT;
		break;
	case DUP:
		w = TOS;
		PUSH w;
		NEXT;
		break;
	case SWAP:
		w = TOS;
		TOS = NTOS;
		NTOS = w;
		NEXT;
		break;
	case ROT:
		w = TOS;
		TOS = disk[(*tosp)+2];
		disk[(*tosp)+2] = NTOS;
		NTOS = w;
		NEXT;
		break;
	case PLUS:
		TWOLEVEL(TOS + NTOS);
		break;
	case MINUS:
		TWOLEVEL(NTOS - TOS);
		break;
	case MULT:
		TWOLEVEL(TOS * NTOS);
		break;
	case DIV:
		TWOLEVEL(NTOS / TOS);
		break;
	case RSHIFT:
		NTOS >>= TOS;
		DROP;
		NEXT;
		break;
	case LSHIFT:
		NTOS <<= TOS;
		DROP;
		NEXT;
		break;
	case LESS:
		TWOLEVEL(NTOS < TOS ? -1 : 0);
		break;
	case GREAT:
		TWOLEVEL(NTOS > TOS ? -1 : 0);
		break;
	case EQL:
		NTOS = NTOS == TOS ? -1 : 0;
		DROP;
		NEXT;
		break;
	case EMIT:
		mputchar(TOS);
		DROP;
		NEXT;
		break;
	case PUTS:
		putnumstr(disk+TOS);
		DROP;
		NEXT;
		break;
	case ATOI:
		w = TOS+1;
		TOS = (int) strtol((char *)(disk+w),&s, 10);
		if(s == (char *)(disk+w)){
			DROP;
			mputs("NO NUMBER FOUND: ");
			putnumstr(disk+w-1);
			puts("");
		}
		NEXT;
		break;
	case PNUM:
		puts(itoa(TOS));
		DROP;
		NEXT;
		break;
	case AND:
	       	NTOS &= TOS;
		DROP;
		NEXT;
		break;
	case OR:
		NTOS |= TOS;
		DROP;
		NEXT;
		break;
	case XOR:
		NTOS ^= TOS;
		DROP;
		NEXT;
		break;
	case NOT:
		TOS = ~TOS;
		NEXT;
		break;
	default: //this should be unreachable
		mputs("execute fallthrough: ");
		puts(itoa(op));
		dumpstack(3,tosp);
		dumpstack(5,rsp);
		dumpstack(15, disk+(*link));
		mputs("IP = ");
		puts(itoa(IP));
		stat();
		*rsp = DSIZE-(RSSIZE+STSIZE+1);
		IP = cs;
	}
}
Ejemplo n.º 7
0
void AGOSEngine_PN::opn_opcode26() {
	while ((_stackbase != NULL) && (_stackbase->classnum != kJmpClassNum))
		dumpstack();
	dumpstack();
	setScriptReturn(true);
}
Ejemplo n.º 8
0
/*
 *  sleep if a condition is not true.  Another process will
 *  awaken us after it sets the condition.  When we awaken
 *  the condition may no longer be true.
 *
 *  we lock both the process and the rendezvous to keep r->p
 *  and p->r synchronized.
 */
void
sleep(Rendez *r, int (*f)(void*), void *arg)
{
	int s;
	void (*pt)(Proc*, int, vlong);

	s = splhi();

	if(up->nlocks)
		print("process %lud sleeps with %d locks held, last lock %#p locked at pc %#p, sleep called from %#p\n",
			up->pid, up->nlocks, up->lastlock, up->lastlock->pc, getcallerpc(&r));
	lock(r);
	lock(&up->rlock);
	if(r->p != nil){
		print("double sleep called from %#p, %lud %lud\n", getcallerpc(&r), r->p->pid, up->pid);
		dumpstack();
	}

	/*
	 *  Wakeup only knows there may be something to do by testing
	 *  r->p in order to get something to lock on.
	 *  Flush that information out to memory in case the sleep is
	 *  committed.
	 */
	r->p = up;

	if((*f)(arg) || up->notepending){
		/*
		 *  if condition happened or a note is pending
		 *  never mind
		 */
		r->p = nil;
		unlock(&up->rlock);
		unlock(r);
	} else {
		/*
		 *  now we are committed to
		 *  change state and call scheduler
		 */
		pt = proctrace;
		if(pt != nil)
			pt(up, SSleep, 0);
		up->state = Wakeme;
		up->r = r;

		/* statistics */
		m->cs++;

		procsave(up);
		if(setlabel(&up->sched)) {
			/*
			 *  here when the process is awakened
			 */
			procrestore(up);
			spllo();
		} else {
			/*
			 *  here to go to sleep (i.e. stop Running)
			 */
			unlock(&up->rlock);
			unlock(r);
			gotolabel(&m->sched);
		}
	}

	if(up->notepending) {
		up->notepending = 0;
		splx(s);
		interrupted();
	}

	splx(s);
}
Ejemplo n.º 9
0
Archivo: proc.c Proyecto: npe9/harvey
/*
 *  sleep if a condition is not true.  Another process will
 *  awaken us after it sets the condition.  When we awaken
 *  the condition may no longer be true.
 *
 *  we lock both the process and the rendezvous to keep r->p
 *  and p->r synchronized.
 */
void
sleep(Rendez *r, int (*f)(void*), void *arg)
{
	Mach *m = machp();
	Mpl pl;

	pl = splhi();

	if(m->externup->nlocks)
		print("process %d sleeps with %d locks held, last lock %#p locked at pc %#p, sleep called from %#p\n",
			m->externup->pid, m->externup->nlocks, m->externup->lastlock, m->externup->lastlock->_pc, getcallerpc(&r));
	lock(r);
	lock(&m->externup->rlock);
	if(r->_p){
		print("double sleep called from %#p, %d %d\n",
			getcallerpc(&r), r->_p->pid, m->externup->pid);
		dumpstack();
	}

	/*
	 *  Wakeup only knows there may be something to do by testing
	 *  r->p in order to get something to lock on.
	 *  Flush that information out to memory in case the sleep is
	 *  committed.
	 */
	r->_p = m->externup;

	if((*f)(arg) || m->externup->notepending){
		/*
		 *  if condition happened or a note is pending
		 *  never mind
		 */
		r->_p = nil;
		unlock(&m->externup->rlock);
		unlock(r);
	} else {
		/*
		 *  now we are committed to
		 *  change state and call scheduler
		 */
		if(m->externup->trace)
			proctrace(m->externup, SSleep, 0);
		m->externup->state = Wakeme;
		m->externup->r = r;

		/* statistics */
		m->cs++;

		procsave(m->externup);
		mmuflushtlb(m->pml4->pa);
		if(setlabel(&m->externup->sched)) {
			/*
			 *  here when the process is awakened
			 */
			procrestore(m->externup);
			spllo();
		} else {
			/*
			 *  here to go to sleep (i.e. stop Running)
			 */
			unlock(&m->externup->rlock);
			unlock(r);
			/*debug*/gotolabel(&m->sched);
		}
	}

	if(m->externup->notepending) {
		m->externup->notepending = 0;
		splx(pl);
		if(m->externup->procctl == Proc_exitme && m->externup->closingfgrp)
			forceclosefgrp();
		error(Eintr);
	}

	splx(pl);
}
Ejemplo n.º 10
0
static void 
traphandler(int sig, siginfo_t *si, void *UC)
{
  ucontext_t *uc = UC;

  if(extra_traphandler != NULL && !extra_traphandler(sig, si, UC))
    return;
    
  static void *frames[MAXFRAMES];
  char buf[256];
  int nframes = backtrace(frames, MAXFRAMES);
  const char *reason = NULL;

  TRAPMSG("Signal: %d in %s ", sig, line1);

  switch(sig) {
  case SIGSEGV:
    switch(si->si_code) {
    case SEGV_MAPERR:  reason = "Address not mapped"; break;
    case SEGV_ACCERR:  reason = "Access error"; break;
    }
    break;

  case SIGFPE:
    switch(si->si_code) {
    case FPE_INTDIV:  reason = "Integer division by zero"; break;
    }
    break;
  }

  addr2text(buf, sizeof(buf), si->si_addr);

  TRAPMSG("Fault address %s (%s)", buf, reason ?: "N/A");

  TRAPMSG("Loaded libraries: %s ", libs);

#if defined(__arm__) 
  TRAPMSG("   trap_no = %08lx", uc->uc_mcontext.trap_no);
  TRAPMSG("error_code = %08lx", uc->uc_mcontext.error_code);
  TRAPMSG("   oldmask = %08lx", uc->uc_mcontext.oldmask);
  TRAPMSG("        R0 = %08lx", uc->uc_mcontext.arm_r0);
  TRAPMSG("        R1 = %08lx", uc->uc_mcontext.arm_r1);
  TRAPMSG("        R2 = %08lx", uc->uc_mcontext.arm_r2);
  TRAPMSG("        R3 = %08lx", uc->uc_mcontext.arm_r3);
  TRAPMSG("        R4 = %08lx", uc->uc_mcontext.arm_r4);
  TRAPMSG("        R5 = %08lx", uc->uc_mcontext.arm_r5);
  TRAPMSG("        R6 = %08lx", uc->uc_mcontext.arm_r6);
  TRAPMSG("        R7 = %08lx", uc->uc_mcontext.arm_r7);
  TRAPMSG("        R8 = %08lx", uc->uc_mcontext.arm_r8);
  TRAPMSG("        R9 = %08lx", uc->uc_mcontext.arm_r9);
  TRAPMSG("       R10 = %08lx", uc->uc_mcontext.arm_r10);
  TRAPMSG("        FP = %08lx", uc->uc_mcontext.arm_fp);
  TRAPMSG("        IP = %08lx", uc->uc_mcontext.arm_ip);
  TRAPMSG("        SP = %08lx", uc->uc_mcontext.arm_sp);
  TRAPMSG("        LR = %08lx", uc->uc_mcontext.arm_lr);
  TRAPMSG("        PC = %08lx", uc->uc_mcontext.arm_pc);
  TRAPMSG("      CPSR = %08lx", uc->uc_mcontext.arm_cpsr);
  TRAPMSG("fault_addr = %08lx", uc->uc_mcontext.fault_address);

#else
  char tmpbuf[1024];
  snprintf(tmpbuf, sizeof(tmpbuf), "Register dump [%d]: ", NGREG);
  int i;
  for(i = 0; i < NGREG; i++) {
#if __WORDSIZE == 64
    sappend(tmpbuf, sizeof(tmpbuf), "%016llx ", uc->uc_mcontext.gregs[i]);
#else
    sappend(tmpbuf, sizeof(tmpbuf), "%08x ", uc->uc_mcontext.gregs[i]);
#endif
  }
  TRAPMSG("%s", tmpbuf);
#endif

  dumpstack(frames, nframes);
  _exit(8);
}
Ejemplo n.º 11
0
int main(void)
{
	char buf[BUFSIZ];
	lua_State *L = luaL_newstate();

	lua_pushstring(L, "hello");
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "hello ") == 0);

	lua_pushstring(L, "world");
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "hello world ") == 0);

	lua_pushnumber(L, 42);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "hello world 42 ") == 0);

	lua_pushnumber(L, 1327);
	lua_pushnumber(L, 42);

	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "hello world 42 1327 42 ") == 0);

	lua_insert(L, 1);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "42 hello world 42 1327 ") == 0);

	lua_insert(L, 2);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "42 1327 hello world 42 ") == 0);

	lua_remove(L, 1);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "1327 hello world 42 ") == 0);

	lua_replace(L, 1);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "42 hello world ") == 0);

	lua_copy(L, 1, 3);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "42 hello 42 ") == 0);

	lua_settop(L, -1);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "42 hello 42 ") == 0);

	lua_settop(L, -2);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "42 hello ") == 0);

	lua_insert(L, -1);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "42 hello ") == 0);

	lua_pushvalue(L, 1);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "42 hello 42 ") == 0);

	lua_pushvalue(L, -1);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "42 hello 42 42 ") == 0);

	lua_pushvalue(L, 2);
	memset(buf, 0, BUFSIZ);
	assert(strcmp(dumpstack(L, buf), "42 hello 42 42 hello ") == 0);

	return 0;
}
Ejemplo n.º 12
0
static void echo(char *buf, int n)
{
    static int ctrlt, pid;
    char *e, *p;

    if (n == 0)
        return;

    e = buf + n;
    for (p = buf; p < e; p++) {
        switch (*p) {
#if 0
        case 0x10:	/* ^P */
            if (cpuserver && !kbd.ctlpoff) {
                active.exiting = 1;
                return;
            }
            break;
#endif
        case 0x14:	/* ^T */
            ctrlt++;
            if (ctrlt > 2)
                ctrlt = 2;
            continue;
        }

        if (ctrlt != 2)
            continue;

        /* ^T escapes */
        ctrlt = 0;
        switch (*p) {
#if 0
        case 'S': {
            int8_t x = 0;
            disable_irqsave(&x);
            dumpstack();
            procdump();
            enable_irqsave(&x);
            return;
        }
#endif
        case 's':
            dumpstack();
            return;
#if 0
        case 'x':
            xsummary();
            ixsummary();
            mallocsummary();
            memorysummary();
            pagersummary();
            return;
        case 'd':
            if (consdebug == NULL)
                consdebug = rdb;
            else
                consdebug = NULL;
            printd("consdebug now %#p\n", consdebug);
            return;
        case 'D':
            if (consdebug == NULL)
                consdebug = rdb;
            consdebug();
            return;
        case 'p':
            x = spllo();
            procdump();
            splx(x);
            return;
        case 'q':
            scheddump();
            return;
        case 'k':
            killbig("^t ^t k");
            return;
#endif
        case 'r':
            exit(0);
            return;
        }
    }

    qproduce(kbdq, buf, n);
    if (kbd.raw)
        return;
    kmesgputs(buf, n);
    if (screenputs != NULL)
        echoscreen(buf, n);
    if (serialoq)
        echoserialoq(buf, n);
}
Ejemplo n.º 13
0
void
echo(char *buf, int n)
{
	static int ctrlt;
	int x;
	char *e, *p;

	if(n == 0)
		return;

	e = buf+n;
	for(p = buf; p < e; p++){
		switch(*p){
		case 0x10:	/* ^P */
			if(cpuserver && !kbd.ctlpoff){
				active.exiting = 1;
				return;
			}
			break;
		case 0x14:	/* ^T */
			ctrlt++;
			if(ctrlt > 2)
				ctrlt = 2;
			continue;
		}

		if(ctrlt != 2)
			continue;

		/* ^T escapes */
		ctrlt = 0;
		switch(*p){
		case 'S':
			x = splhi();
			dumpstack();
			procdump();
			splx(x);
			return;
		case 's':
			dumpstack();
			return;
		case 'x':
			xsummary();
			ixsummary();
			mallocsummary();
		//	memorysummary();
			pagersummary();
			return;
		case 'd':
			if(consdebug == nil)
				consdebug = rdb;
			else
				consdebug = nil;
			print("consdebug now 0x%p\n", consdebug);
			return;
		case 'D':
			if(consdebug == nil)
				consdebug = rdb;
			consdebug();
			return;
		case 'p':
			x = spllo();
			procdump();
			splx(x);
			return;
		case 'q':
			scheddump();
			return;
		case 'k':
			killbig("^t ^t k");
			return;
		case 'r':
			exit(0);
			return;
		}
	}

	qproduce(kbdq, buf, n);
	if(kbd.raw)
		return;
	kmesgputs(buf, n);
	if(screenputs != nil)
		echoscreen(buf, n);
	uartecho(buf, n);	// Plan 9 VX
}