/*
 * $RCSfile: trace.c,v $
 *
 * x-kernel v3.3
 *
 * Original Copyright (c) 1993,1991,1990,1996  Arizona Board of Regents
 * Modifications Copyright (c) 1993 Massachusetts Board of Regents
 *
 * $Log: trace.c,v $
 * Revision 1.2  1996/01/30 20:52:53  slm
 * Updated copyright and version.
 *
 * Revision 1.1  1995/07/29  02:42:45  slm
 * Initial revision
 *
 * Revision 1.2.1.1.1.2  1994/11/16  23:44:55  hkaram
 * Changed assert.h to xk_assert.h
 *
 * Revision 1.2.1.1.1.1  1994/11/12  19:13:48  hkaram
 * New branch
 *
 * Revision 1.2.1.1  1994/03/14  22:51:36  umass
 * process_kill_all_others calls added to Kabort and xAssertPrint
 *
 * Revision 1.2  1993/11/13  00:45:52  menze
 * Original version from UMass
 */

#include <x_stdio.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <ulocks.h>
#include <task.h>
#include <errno.h>

#include "platform.h"
#include "xk_debug.h"
#include "process.h"
#include "compose.h"

ulock_t *traceLock;
			 
void
xTraceInit()
{
    traceLock = usnewlock(xkernel_arena);
    initTraceLevels();
}

void
xTraceLock() 
{
    ussetlock(traceLock);
    printf("pid %d: ", getpid());
}

void
xTraceUnlock()
{
    fflush(stdout);
    usunsetlock(traceLock);
}

void
xAssertPrint(file, line)
char *file;
int  line;
{
    int pid = getpid();
    xTraceLock();
    fprintf(stderr, "Assertion failed: process %d, file %s, line %d\n",
            pid, file, line);
    process_kill_all_others();
    xTraceUnlock();
    abort();
}

void Kabort(s)
char *s;
{
    int pid = getpid();
    xTraceLock();
    fprintf(stderr, "xkernel abort: process %d, %s\n", pid, s);
    process_kill_all_others();
    xTraceUnlock();
    abort();
}
