debug.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <thread.h>
  12. #include "threadimpl.h"
  13. int _threaddebuglevel;
  14. void
  15. _threaddebug(uint32_t flag, char *fmt, ...)
  16. {
  17. char buf[128];
  18. va_list arg;
  19. Fmt f;
  20. Proc *p;
  21. if((_threaddebuglevel&flag) == 0)
  22. return;
  23. fmtfdinit(&f, 2, buf, sizeof buf);
  24. p = _threadgetproc();
  25. if(p==nil)
  26. fmtprint(&f, "noproc ");
  27. else if(p->thread)
  28. fmtprint(&f, "%d.%d ", p->pid, p->thread->id);
  29. else
  30. fmtprint(&f, "%d._ ", p->pid);
  31. va_start(arg, fmt);
  32. fmtvprint(&f, fmt, arg);
  33. va_end(arg);
  34. fmtprint(&f, "\n");
  35. fmtfdflush(&f);
  36. }
  37. void
  38. _threadassert(char *s)
  39. {
  40. char buf[256];
  41. int n;
  42. Proc *p;
  43. p = _threadgetproc();
  44. if(p && p->thread)
  45. n = sprint(buf, "%d.%d ", p->pid, p->thread->id);
  46. else
  47. n = 0;
  48. snprint(buf+n, sizeof(buf)-n, "%s: assertion failed\n", s);
  49. write(2, buf, strlen(buf));
  50. abort();
  51. }