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