debug.c 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Copyright (c) 2011 The Regents of the University of California
  2. * Barret Rhoden <brho@cs.berkeley.edu>
  3. * See LICENSE for details.
  4. *
  5. * Arch-independent kernel debugging */
  6. #include <u.h>
  7. #include <libc.h>
  8. #include "dat.h"
  9. #include "fns.h"
  10. static int tab_depth = 0;
  11. int printx_on = 0;
  12. int min(int a, int b)
  13. {
  14. return a < b ? a : b;
  15. }
  16. void __print_func_entry(const char *func, const char *file, int line)
  17. {
  18. char tentabs[] = "\t\t\t\t\t\t\t\t\t\t"; // ten tabs and a \0
  19. char *ourtabs = &tentabs[10 - min(tab_depth, 10)];
  20. if (!printx_on)
  21. return;
  22. fprint(2,"%s%s()@%d in %s\n", ourtabs, func, line, file);
  23. tab_depth++;
  24. }
  25. void __print_func_exit(const char *func, const char *file, int line)
  26. {
  27. char tentabs[] = "\t\t\t\t\t\t\t\t\t\t"; // ten tabs and a \0
  28. char *ourtabs;
  29. if (!printx_on)
  30. return;
  31. tab_depth--;
  32. ourtabs = &tentabs[10 - min(tab_depth, 10)];
  33. fprint(2,"%s---- %s()@%d\n", ourtabs, func, line);
  34. }
  35. void set_printx(int mode)
  36. {
  37. printx_on = mode;
  38. }