forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduk_debug_macros.c
More file actions
88 lines (65 loc) · 2.01 KB
/
duk_debug_macros.c
File metadata and controls
88 lines (65 loc) · 2.01 KB
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
83
84
85
86
87
88
/*
* Debugging macro calls.
*/
#include "duk_internal.h"
#if defined(DUK_USE_DEBUG)
/*
* Debugging enabled
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#if !defined(DUK_USE_DEBUG_WRITE)
#error debugging enabled (DUK_USE_DEBUG) but DUK_USE_DEBUG_WRITE not defined
#endif
#define DUK__DEBUG_BUFSIZE DUK_USE_DEBUG_BUFSIZE
#if defined(DUK_USE_VARIADIC_MACROS)
DUK_INTERNAL void duk_debug_log(duk_int_t level, const char *file, duk_int_t line, const char *func, const char *fmt, ...) {
va_list ap;
long arg_level;
const char *arg_file;
long arg_line;
const char *arg_func;
const char *arg_msg;
char buf[DUK__DEBUG_BUFSIZE];
va_start(ap, fmt);
duk_memzero((void *) buf, (size_t) DUK__DEBUG_BUFSIZE);
duk_debug_vsnprintf(buf, DUK__DEBUG_BUFSIZE - 1, fmt, ap);
arg_level = (long) level;
arg_file = (const char *) file;
arg_line = (long) line;
arg_func = (const char *) func;
arg_msg = (const char *) buf;
DUK_USE_DEBUG_WRITE(arg_level, arg_file, arg_line, arg_func, arg_msg);
va_end(ap);
}
#else /* DUK_USE_VARIADIC_MACROS */
DUK_INTERNAL char duk_debug_file_stash[DUK_DEBUG_STASH_SIZE];
DUK_INTERNAL duk_int_t duk_debug_line_stash;
DUK_INTERNAL char duk_debug_func_stash[DUK_DEBUG_STASH_SIZE];
DUK_INTERNAL duk_int_t duk_debug_level_stash;
DUK_INTERNAL void duk_debug_log(const char *fmt, ...) {
va_list ap;
long arg_level;
const char *arg_file;
long arg_line;
const char *arg_func;
const char *arg_msg;
char buf[DUK__DEBUG_BUFSIZE];
va_start(ap, fmt);
duk_memzero((void *) buf, (size_t) DUK__DEBUG_BUFSIZE);
duk_debug_vsnprintf(buf, DUK__DEBUG_BUFSIZE - 1, fmt, ap);
arg_level = (long) duk_debug_level_stash;
arg_file = (const char *) duk_debug_file_stash;
arg_line = (long) duk_debug_line_stash;
arg_func = (const char *) duk_debug_func_stash;
arg_msg = (const char *) buf;
DUK_USE_DEBUG_WRITE(arg_level, arg_file, arg_line, arg_func, arg_msg);
va_end(ap);
}
#endif /* DUK_USE_VARIADIC_MACROS */
#else /* DUK_USE_DEBUG */
/*
* Debugging disabled
*/
#endif /* DUK_USE_DEBUG */