-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug.cc
82 lines (74 loc) · 1.73 KB
/
debug.cc
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
81
82
#define ICI_CORE
#include "array.h"
#include "buf.h"
#include "cfunc.h"
#include "exec.h"
#include "file.h"
#include "func.h"
#include "fwd.h"
#include "int.h"
#include "map.h"
#include "op.h"
#include "src.h"
#include "str.h"
namespace ici
{
/*
* Flag indicating if debugging is enabled. If this is non-zero and
* there is a current debugger instance it's functions are called.
* This value is the result of the ICI debug() function.
*/
int debug_enabled = 0;
/*
* Flag indicating if error catching should be ignored.
*/
int debug_ignore_err = 0;
/*
* Ignore errors within exec loop. Used by internal calls to
* exec that handle errors themselves, e.g., f_include().
*/
void debug_ignore_errors()
{
++debug_ignore_err;
}
/*
* Restore error processing.
*/
void debug_respect_errors()
{
--debug_ignore_err;
}
/*
* int = debug([int])
*
* With no argument debug() returns the current debug status, an integer
* which is zero if not debugging or non-zero if debugging is enabled. If
* non-zero the value of the debug status variable may affect debugging
* functionality.
*
* With an argument - only one, an integer - the debug status is set and
* the old value returned. This may be used to get the current debug state
* and set a new one in one operation which may be useful for functions that
* don't want to be debugged or need to avoid the performance impact of
* debugging.
*/
static int f_debug(...)
{
auto result = debug_enabled;
if (NARGS() != 0)
{
int64_t v;
if (typecheck("i", &v))
{
return 1;
}
debug_enabled = v;
}
return int_ret(result);
}
ICI_DEFINE_CFUNCS(debug)
{
ICI_DEFINE_CFUNC(debug, f_debug),
ICI_CFUNCS_END()
};
} // namespace ici