]> www.ginac.de Git - cln.git/blob - src/base/cl_debug.cc
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / base / cl_debug.cc
1 // Debugging support for dynamic typing.
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/object.h"
8
9
10 // Implementation.
11
12 #include "cln/io.h"
13 #include "cln/abort.h"
14
15 namespace cln {
16
17 // The default printer function.
18 void cl_dprint_unknown (cl_heap* pointer)
19 {
20         fprint(cl_debugout, "<unknown @0x");
21         fprinthexadecimal(cl_debugout, (unsigned long) pointer);
22         fprint(cl_debugout, " refcount=");
23         fprintdecimal(cl_debugout, pointer->refcount);
24         fprint(cl_debugout, " type=");
25         fprinthexadecimal(cl_debugout, (unsigned long) pointer->type);
26         fprint(cl_debugout, ">");
27 }
28
29 static void cl_dprint_unknown_immediate (cl_heap* pointer)
30 {
31         fprint(cl_debugout, "<unknown @0x");
32         fprinthexadecimal(cl_debugout, (unsigned long) pointer);
33         fprint(cl_debugout, ">");
34 }
35
36 // Print an object. This function is callable from the debugger.
37 extern "C" void* cl_print (cl_uint word);
38 void* cl_print (cl_uint word)
39 {
40         var cl_heap* pointer = (cl_heap*)word;
41         if (cl_pointer_p(word)) {
42                 var const cl_class* type = pointer->type;
43                 if (type->dprint)
44                         type->dprint(pointer);
45                 else
46                         cl_dprint_unknown(pointer);
47         } else {
48                 var const cl_class* type = cl_immediate_classes[cl_tag(word)];
49                 if (type && type->dprint)
50                         type->dprint(pointer);
51                 else
52                         cl_dprint_unknown_immediate(pointer);
53         }
54         cl_debugout << std::endl; // newline and flush output
55         return pointer;
56 }
57
58 void cl_gcobject::debug_print () const
59 {
60         cl_print(word);
61 }
62
63 void cl_gcpointer::debug_print () const
64 {
65         cl_print(word);
66 }
67
68 void cl_rcobject::debug_print () const
69 {
70         cl_print(word);
71 }
72
73 void cl_rcpointer::debug_print () const
74 {
75         cl_print(word);
76 }
77
78 }  // namespace cln