]> git.donarmstrong.com Git - lilypond.git/blob - lily/debug.cc
release: 0.1.1
[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         nulldev = new ofstream("/dev/null");
18         monitor = new Dstream(&cout,".dstreamrc");
19     }
20     ~_Dinit() {
21         delete nulldev;
22         delete monitor;
23     }
24 } dinit;
25
26
27
28 /*
29   want to do a stacktrace .
30   */
31 void
32 mynewhandler()
33 {
34     assert(false);
35 }
36
37 void
38 float_handler(int)
39 {
40     cerr << "Floating point exception .. \n"<< flush;
41     assert(false);
42 }
43
44 /// just to make sure print_rat is linked in
45 static void (*rat_printer)(Moment const&);
46
47 void
48 debug_init()
49 {
50     rat_printer = print_rat;    
51 #ifndef NDEBUG
52     set_new_handler(&mynewhandler);
53 #endif
54     set_flower_debug(*monitor, check_debug);
55     
56     signal(SIGFPE, float_handler);
57 }   
58
59 bool check_debug=false;
60
61 void
62 set_debug(bool b)
63 {
64     check_debug =b;
65     set_flower_debug(*monitor, check_debug);
66 }
67
68