File: Debug.h

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (71 lines) | stat: -rw-r--r-- 1,706 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once

#include "Indent.h"
#include <iostream>

using std::wostream;
using std::endl;

#define DEBUG_OUT

#ifdef DEBUG_OUT

// print line to debug output, usage:
// PLN("Hello " << "world!");
// PLN("Hello " << n << " times!");
// PLN_IF("X is larger than 10", X > 10);
#define PNN(str) util::debugStream() << str
#define PLN(str) util::debugStream() << str << std::endl
#define PLN_IF(str, cond) if (cond) PLN(str)
#define PVAR(expr) PLN(#expr << "=" << (expr))

// Good way of making TODO: comments (only displays 5 times).
// #define TODO(str) PLN("TODO("__FUNCTION__"):" << str)
#define TODO(str) do { static nat _times = 0; if (++_times <= 5) PLN("TODO(" << __FUNCTION__ << "): " << str); } while (false)

// Good way of indicating something possibly interesting during debugging.
#if defined(VISUAL_STUDIO)
#define WARNING(str) PLN("WARNING " << __FUNCTION__ << ": " << str);
#elif defined(GCC)
#define WARNING(str) PLN("WARNING " << __PRETTY_FUNCTION__ << ": " << str);
#endif

#include "Timer.h"
#define TIME(str) util::Timer __timer__(str);

#else
#define PNN(str)
#define PLN(str)
#define PLN_IF(str, cond)
#define PVAR(expr)
#define TIME(str)
#define WARNING(str)
#define TODO(str)

#endif

namespace util {
	// Get the debug stream.
	std::wostream &debugStream();
}


/**
 * Insanely useful for debugging who made bad deallocations:
 * 		_CrtSetAllocHook(&myHook);
 * static void *watch = 0;
 *
 * int myHook(int type, void *data, size_t size, int blockuse, long request, const byte *filename, int line) {
 * 	if (data == watch && type == _HOOK_FREE)
 * 		DebugBreak();
 * 	return TRUE;
 * }
 *	_ASSERT(_CrtCheckMemory());
 *
 */


/**
 * Initialize debug runtime.
 */
void initDebug();