debug.c 832 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <thread.h>
  4. #include "threadimpl.h"
  5. int _threaddebuglevel;
  6. void
  7. _threaddebug(ulong flag, char *fmt, ...)
  8. {
  9. char buf[128];
  10. va_list arg;
  11. Fmt f;
  12. Proc *p;
  13. if((_threaddebuglevel&flag) == 0)
  14. return;
  15. fmtfdinit(&f, 2, buf, sizeof buf);
  16. p = _threadgetproc();
  17. if(p==nil)
  18. fmtprint(&f, "noproc ");
  19. else if(p->thread)
  20. fmtprint(&f, "%d.%d ", p->pid, p->thread->id);
  21. else
  22. fmtprint(&f, "%d._ ", p->pid);
  23. va_start(arg, fmt);
  24. fmtvprint(&f, fmt, arg);
  25. va_end(arg);
  26. fmtprint(&f, "\n");
  27. fmtfdflush(&f);
  28. }
  29. void
  30. _threadassert(char *s)
  31. {
  32. char buf[256];
  33. int n;
  34. Proc *p;
  35. p = _threadgetproc();
  36. if(p && p->thread)
  37. n = sprint(buf, "%d.%d ", p->pid, p->thread->id);
  38. else
  39. n = 0;
  40. snprint(buf+n, sizeof(buf)-n, "%s: assertion failed\n", s);
  41. write(2, buf, strlen(buf));
  42. abort();
  43. }