]> git.donarmstrong.com Git - lilypond.git/blob - lily/debug.cc
release: 1.2.12
[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@cs.uu.nl>
7   
8  */
9 #include <fstream.h>
10 #include <signal.h>
11
12 // libg++ 2.8.0
13 // #include <std/new.h>
14 #include <stdlib.h>
15
16
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"
23
24 Dstream *my_monitor=0;
25
26 void
27 float_handler (int)
28 {
29   cerr << _ ("floating point exception") << endl;
30   assert (false);
31 }
32
33 void
34 debug_init()
35 {
36   my_monitor = new Dstream (&cout, ".dstreamrc");
37   signal (SIGFPE, float_handler);
38 }
39
40 bool check_malloc_b = false;
41
42 // #define MEMORY_PARANOID
43
44 #ifdef MEMORY_PARANOID
45
46 #include <malloc.h>
47
48 void
49 frobnify (void *p, size_t s)
50 {
51   char *cp = (char*)p;
52   char *e  = cp + s;
53   while (cp < e)
54     {
55       *cp++ ^=42;
56     }
57 }
58
59
60 void *
61 operator new (size_t size)
62 {
63   void *result;
64   result = malloc (size);
65   if (check_malloc_b)
66     frobnify (result, size);
67   return result;
68 }
69
70 void *to_frob; int frob_size;
71
72 void
73 set_frobnify (void * p, size_t sz)
74 {
75   to_frob = p;
76   frob_size = sz;
77 }
78
79 void 
80 operator delete (void *p)
81 {
82   if (!p)
83     return ;
84   if (p == to_frob)
85     {
86       frobnify (p, frob_size);
87       to_frob = 0;
88       frob_size=0;
89     }
90
91   free (p);
92 }
93 #endif // MEMORY_PARANOID
94
95 void
96 set_debug (bool b)
97 {
98   if (b)
99     flower_dstream = my_monitor;
100   else
101     flower_dstream = 0;
102   
103 #ifdef MEMORY_PARANOID
104   if (check_malloc_b)
105     if (mcheck (0))
106       warning (_ ("Can't set mem-checking!"));
107 #endif
108 }
109