lilypond-1.3.12
[lilypond.git] / lily / debug.cc
blob35a32a7a288d1521d9ffb4616a9ff58d9f80140d
1 /*
2 debug.cc -- implement debugging routines
4 source file of the GNU LilyPond music typesetter
6 (c) 1996,98 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include <fstream.h>
10 #include <signal.h>
12 // libg++ 2.8.0
13 // #include <std/new.h>
14 #include <stdlib.h>
17 #include "debug.hh"
18 #include "dstream.hh"
19 #include "flower-debug.hh"
20 #include "moment.hh"
21 #include "misc.hh"
22 #include "main.hh"
24 Dstream *my_monitor=0;
26 void
27 float_handler (int)
29 cerr << _ ("floating point exception") << endl;
30 assert (false);
33 void
34 debug_init()
36 my_monitor = new Dstream (&cout, ".dstreamrc");
37 signal (SIGFPE, float_handler);
40 bool check_malloc_b = false;
42 // #define MEMORY_PARANOID
44 #ifdef MEMORY_PARANOID
46 #include <malloc.h>
48 void
49 frobnify (void *p, size_t s)
51 char *cp = (char*)p;
52 char *e = cp + s;
53 while (cp < e)
55 *cp++ ^=42;
60 void *
61 operator new (size_t size)
63 void *result;
64 result = malloc (size);
65 if (check_malloc_b)
66 frobnify (result, size);
67 return result;
70 void *to_frob; int frob_size;
72 void
73 set_frobnify (void * p, size_t sz)
75 to_frob = p;
76 frob_size = sz;
79 void
80 operator delete (void *p)
82 if (!p)
83 return ;
84 if (p == to_frob)
86 frobnify (p, frob_size);
87 to_frob = 0;
88 frob_size=0;
91 free (p);
93 #endif // MEMORY_PARANOID
95 void
96 set_debug (bool b)
98 if (b)
99 flower_dstream = my_monitor;
100 else
101 flower_dstream = 0;
103 #ifdef MEMORY_PARANOID
104 if (check_malloc_b)
105 if (mcheck (0))
106 warning (_ ("Can't set mem-checking!"));
107 #endif