]> git.donarmstrong.com Git - lilypond.git/blob - lily/debug.cc
2141be63a461435f1550ee6c9ec392e5142523fb
[lilypond.git] / lily / debug.cc
1 #include <fstream.h>
2 #include <signal.h>
3 #include <std/new.h>
4 #include <stdlib.h>
5 #include "debug.hh"
6 #include "dstream.hh"
7 #include "flower-debug.hh"
8 #include "moment.hh"
9
10 Dstream *monitor=0;
11 ostream * nulldev =0;
12
13
14 // ugh
15 struct _Dinit {
16   _Dinit() 
17     {
18         nulldev = new ofstream ("/dev/null");
19         monitor = new Dstream (&cout,".dstreamrc");
20     }
21   ~_Dinit() 
22     {
23         delete nulldev;
24         delete monitor;
25     }
26 } dinit;
27
28
29
30 /*
31   want to do a stacktrace .
32   */
33 void
34 mynewhandler()
35 {
36   assert (false);
37 }
38
39 void
40 float_handler (int)
41 {
42   cerr << "Floating point exception .. \n"<< flush;
43   assert (false);
44 }
45
46 /// just to make sure print_rat is linked in
47 static void (*rat_printer)(Moment const&);
48
49 void
50 debug_init()
51 {
52   rat_printer = print_rat;      
53 #ifndef NDEBUG
54   set_new_handler (&mynewhandler);
55 #endif
56   set_flower_debug (*monitor, check_debug);
57   
58   signal (SIGFPE, float_handler);
59 }   
60
61 bool check_debug=false;
62
63 void
64 set_debug (bool b)
65 {
66   check_debug =b;
67   set_flower_debug (*monitor, check_debug);
68 }
69
70