1 // $Header$
2 //
3 // Copyright (C) 2000 - 2003, by
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
8 //
9 // This file may be distributed under the terms of the Q Public License
10 // version 1.0 as appearing in the file LICENSE.QPL included in the
11 // packaging of this file.
12 //
13 
14 #include "sys.h"
15 #include "alloctag_debug.h"
16 #include <iostream>
17 
18 // A dummy class
19 class Am {
20   int i;
21   int j;
22   char k;
23 };
24 
25 MAIN_FUNCTION
26 { PREFIX_CODE
27 #if !CWDEBUG_ALLOC || !CWDEBUG_LOCATION || !CWDEBUG_MARKER
28   DoutFatal(dc::fatal, "Expected Failure.");
29 #endif
30 
31   Debug( check_configuration() );
32 #if CWDEBUG_ALLOC && !defined(THREADTEST)
33   int* dummy = new int;					// Make sure initialization of libcwd is done.
34   libcwd::make_all_allocations_invisible_except(NULL);	// Don't show allocations that are done as part of initialization.
35 #endif
36 #if CWDEBUG_LOCATION
37   // Make sure we initialized the bfd stuff before we turn on WARNING.
38   Debug( (void)pc_mangled_function_name((void*)exit) );
39 #endif
40 
41   // Select channels
42   ForAllDebugChannels( if (debugChannel.is_on()) debugChannel.off() );
43   Debug( dc::notice.on() );
44   Debug( dc::malloc.on() );
45   Debug( dc::warning.on() );
46 #ifndef THREADTEST
47   // Write debug output to cout
48   Debug( libcw_do.set_ostream(&std::cout) );
49 #endif
50   // Turn debug object on
51   Debug( libcw_do.on() );
52 
53   // Allocate new object
54   Am* a1 = new Am;
55   AllocTag(a1, "First created");
56 
57 #if CWDEBUG_MARKER
58   // Create marker
59   libcwd::marker_ct* marker = new libcwd::marker_ct("A test marker");
60 #endif
61 
62   // Allocate more objects
63   Am* a2 = new Am[10];
64   AllocTag(a2, "Created after the marker");
65   int* p = new int[30];
66   AllocTag(p, "Created after the marker");
67 
68   // Show Memory Allocation Overview
69   Debug( list_allocations_on(libcw_do) );
70 
71 #if CWDEBUG_MARKER
72   Dout(dc::notice, "Moving the int array outside of the marker...");
73   Debug( move_outside(marker, p) );
74 #endif
75 
76   // Show Memory Allocation Overview
77   Debug( list_allocations_on(libcw_do) );
78 
79 #if CWDEBUG_MARKER
80   // Delete the marker
81   delete marker;
82 #endif
83 
84   delete [] p;
85   delete [] a2;
86   delete a1;
87 
88   Dout(dc::notice, "Finished successfully.");
89 
90   Debug( libcw_do.off() );
91 
92 #if CWDEBUG_ALLOC && !defined(THREADTEST)
93   delete dummy;
94 #endif
95 
96   EXIT(0);
97 }
98