-
Notifications
You must be signed in to change notification settings - Fork 6
/
debugger.d
80 lines (61 loc) · 1.5 KB
/
debugger.d
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
72
73
74
75
76
77
78
79
80
/*
* debugger.d
*
* This file contains the exception sink and other helpful debugging routines.
*
* Author: Dave Wilkinson
*
*/
module analyzing.debugger;
import io.console;
import djehuty;
import synch.thread;
import binding.c;
// Description: This class provides a set of functions to facilitate common
// debugging functions and capabilities to profile code.
// Feature: Provides a method of logging all debug information to a file.
// (Functionality)
// Feature: The log file can be easily parsed and the information easily
// extracted. (Usability)
class Debugger {
static:
protected:
void delegate(Exception) _delegate;
public:
void raiseException(Exception e) {
printf("exception %s\n", e.msg.ptr);
if (_delegate !is null) {
// Wouldn't it be ridiculous if the handler threw an exception?
try {
_delegate(e);
return;
}
catch(Exception exp) {
// no chance for the handler to be reentered in this case
e = exp;
}
}
Console.putln("");
Console.forecolor = Color.Red;
string cause = e.toString();
if (cause == "null this") {
cause = "Null Pointer Exception";
}
Console.putln(" cause: ", cause);
version(LDC) {
// Tango provides a traceback for us
Console.putln(" file: ", e.file, " : ", e.line);
}
else {
}
Console.forecolor = Color.White;
}
void receiver(void delegate(Exception) newDelegate) {
_delegate = newDelegate;
}
void delegate(Exception) receiver() {
return _delegate;
}
void raiseSignal(uint signal) {
}
}