PageRenderTime 40ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/cln-1.3.2/src/base/cl_debug.cc

#
C++ | 77 lines | 57 code | 14 blank | 6 comment | 5 complexity | 11acd9493f72079c3a166666a934aed7 MD5 | raw file
Possible License(s): GPL-2.0
  1. // Debugging support for dynamic typing.
  2. // General includes.
  3. #include "base/cl_sysdep.h"
  4. // Specification.
  5. #include "cln/object.h"
  6. // Implementation.
  7. #include "cln/io.h"
  8. namespace cln {
  9. // The default printer function.
  10. void cl_dprint_unknown (cl_heap* pointer)
  11. {
  12. fprint(cl_debugout, "<unknown @0x");
  13. fprinthexadecimal(cl_debugout, (unsigned long) pointer);
  14. fprint(cl_debugout, " refcount=");
  15. fprintdecimal(cl_debugout, pointer->refcount);
  16. fprint(cl_debugout, " type=");
  17. fprinthexadecimal(cl_debugout, (unsigned long) pointer->type);
  18. fprint(cl_debugout, ">");
  19. }
  20. static void cl_dprint_unknown_immediate (cl_heap* pointer)
  21. {
  22. fprint(cl_debugout, "<unknown @0x");
  23. fprinthexadecimal(cl_debugout, (unsigned long) pointer);
  24. fprint(cl_debugout, ">");
  25. }
  26. // Print an object. This function is callable from the debugger.
  27. extern "C" void* cl_print (cl_uint word);
  28. void* cl_print (cl_uint word)
  29. {
  30. var cl_heap* pointer = (cl_heap*)word;
  31. if (cl_pointer_p(word)) {
  32. var const cl_class* type = pointer->type;
  33. if (type->dprint)
  34. type->dprint(pointer);
  35. else
  36. cl_dprint_unknown(pointer);
  37. } else {
  38. var const cl_class* type = cl_immediate_classes[cl_tag(word)];
  39. if (type && type->dprint)
  40. type->dprint(pointer);
  41. else
  42. cl_dprint_unknown_immediate(pointer);
  43. }
  44. cl_debugout << std::endl; // newline and flush output
  45. return pointer;
  46. }
  47. void cl_gcobject::debug_print () const
  48. {
  49. cl_print(word);
  50. }
  51. void cl_gcpointer::debug_print () const
  52. {
  53. cl_print(word);
  54. }
  55. void cl_rcobject::debug_print () const
  56. {
  57. cl_print(word);
  58. }
  59. void cl_rcpointer::debug_print () const
  60. {
  61. cl_print(word);
  62. }
  63. } // namespace cln