]> git.donarmstrong.com Git - lilypond.git/blob - lily/debug.cc
c369f070ee96c5f93fc5e01ad73ba505a9972613
[lilypond.git] / lily / debug.cc
1 /*   
2   debug.cc --  implement debugging routines
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1996,98 Han-Wen Nienhuys <hanwen@stack.nl>
7   
8  */
9 #include <fstream.h>
10 #include <signal.h>
11 #include <std/new.h>
12 #include <stdlib.h>
13 #include "debug.hh"
14 #include "dstream.hh"
15 #include "flower-debug.hh"
16 #include "moment.hh"
17 #include "main.hh"
18 Dstream *monitor=0;
19 ostream * nulldev =0;
20
21
22 // ugh
23 struct _Dinit {
24   _Dinit()
25     {
26         nulldev = new ofstream ("/dev/null");
27         monitor = new Dstream (&cout,".dstreamrc");
28     }
29   ~_Dinit()
30     {
31         delete nulldev;
32         delete monitor;
33     }
34 } dinit;
35
36
37
38 /*
39   want to do a stacktrace .
40   */
41 void
42 mynewhandler()
43 {
44   assert (false);
45 }
46
47 void
48 float_handler (int)
49 {
50   cerr << _("Floating point exception .. \n")<< flush;
51   assert (false);
52 }
53
54 /// just to make sure print_rat is linked in
55 static void (*rat_printer)(Moment const&);
56
57 void
58 debug_init()
59 {
60   rat_printer = print_rat;
61 #ifndef NDEBUG
62   set_new_handler (&mynewhandler);
63 #endif
64   set_flower_debug (*monitor, check_debug);
65
66   signal (SIGFPE, float_handler);
67 }
68
69 bool check_debug=false;
70
71
72 bool check_malloc_b = false;
73
74 // #define MEMORY_PARANOID
75
76 #ifdef MEMORY_PARANOID
77 void *
78 operator new (size_t size)
79 {
80   void *result;
81   result = malloc (size);
82   if (check_malloc_b)
83     memfrob (result, size);
84   return result;
85 }
86
87
88 void 
89 operator delete (void *p)
90 {
91   if (!p)
92     return ;
93   if (check_malloc_b)
94     memfrob (p, 8);             // ugh.  Need the blocksize.   8 is sysdependant
95
96   free (p);
97 }
98 #endif // MEMORY_PARANOID
99
100 void
101 set_debug (bool b)
102 {
103   check_debug =b;
104   set_flower_debug (*monitor, check_debug);
105   check_malloc_b = experimental_features_global_b;
106 }
107