]> git.donarmstrong.com Git - lilypond.git/blob - lily/debug.cc
release: 0.0.77.jcn1
[lilypond.git] / lily / debug.cc
1 #include <fstream.h>
2 #include <signal.h>
3 #include <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 static void (*rat_printer)(Moment const&);
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 void
45 debug_init()
46 {
47     rat_printer = printm;       // make sure this is linked in
48 #ifndef NDEBUG
49     set_new_handler(&mynewhandler);
50 #endif
51     set_flower_debug(*monitor, check_debug);
52     
53     signal(SIGFPE, float_handler);
54 }   
55
56 bool check_debug=false;
57
58 void
59 set_debug(bool b)
60 {
61     check_debug =b;
62     set_flower_debug(*monitor, check_debug);
63 }
64
65