mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.0 KiB
89 lines
2.0 KiB
12 years ago
|
/*
|
||
|
* Debugging macro calls.
|
||
|
*/
|
||
|
|
||
|
#include "duk_internal.h"
|
||
|
|
||
9 years ago
|
#if defined(DUK_USE_DEBUG)
|
||
12 years ago
|
|
||
|
/*
|
||
|
* Debugging enabled
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <stdarg.h>
|
||
|
|
||
9 years ago
|
#if !defined(DUK_USE_DEBUG_WRITE)
|
||
|
#error debugging enabled (DUK_USE_DEBUG) but DUK_USE_DEBUG_WRITE not defined
|
||
|
#endif
|
||
12 years ago
|
|
||
9 years ago
|
#define DUK__DEBUG_BUFSIZE DUK_USE_DEBUG_BUFSIZE
|
||
12 years ago
|
|
||
9 years ago
|
#if defined(DUK_USE_VARIADIC_MACROS)
|
||
12 years ago
|
|
||
9 years ago
|
DUK_INTERNAL void duk_debug_log(duk_int_t level, const char *file, duk_int_t line, const char *func, const char *fmt, ...) {
|
||
12 years ago
|
va_list ap;
|
||
9 years ago
|
long arg_level;
|
||
|
const char *arg_file;
|
||
|
long arg_line;
|
||
|
const char *arg_func;
|
||
|
const char *arg_msg;
|
||
|
char buf[DUK__DEBUG_BUFSIZE];
|
||
12 years ago
|
|
||
|
va_start(ap, fmt);
|
||
|
|
||
9 years ago
|
DUK_MEMZERO((void *) buf, (size_t) DUK__DEBUG_BUFSIZE);
|
||
|
duk_debug_vsnprintf(buf, DUK__DEBUG_BUFSIZE - 1, fmt, ap);
|
||
12 years ago
|
|
||
9 years ago
|
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);
|
||
12 years ago
|
|
||
|
va_end(ap);
|
||
|
}
|
||
|
|
||
|
#else /* DUK_USE_VARIADIC_MACROS */
|
||
|
|
||
10 years ago
|
DUK_INTERNAL char duk_debug_file_stash[DUK_DEBUG_STASH_SIZE];
|
||
9 years ago
|
DUK_INTERNAL duk_int_t duk_debug_line_stash;
|
||
10 years ago
|
DUK_INTERNAL char duk_debug_func_stash[DUK_DEBUG_STASH_SIZE];
|
||
9 years ago
|
DUK_INTERNAL duk_int_t duk_debug_level_stash;
|
||
12 years ago
|
|
||
10 years ago
|
DUK_INTERNAL void duk_debug_log(const char *fmt, ...) {
|
||
12 years ago
|
va_list ap;
|
||
9 years ago
|
long arg_level;
|
||
|
const char *arg_file;
|
||
|
long arg_line;
|
||
|
const char *arg_func;
|
||
|
const char *arg_msg;
|
||
|
char buf[DUK__DEBUG_BUFSIZE];
|
||
12 years ago
|
|
||
|
va_start(ap, fmt);
|
||
|
|
||
9 years ago
|
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);
|
||
12 years ago
|
|
||
|
va_end(ap);
|
||
|
}
|
||
|
|
||
|
#endif /* DUK_USE_VARIADIC_MACROS */
|
||
|
|
||
|
#else /* DUK_USE_DEBUG */
|
||
|
|
||
|
/*
|
||
|
* Debugging disabled
|
||
|
*/
|
||
|
|
||
|
#endif /* DUK_USE_DEBUG */
|