From 657625db40108d0d40ff4ca9bc324a918296076f Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Mon, 9 Sep 2024 12:50:21 +0300 Subject: [PATCH] more logging options better output --- src/ecmascript/quickjs.h | 2 +- src/elinks.h | 2 +- src/main/object.h | 6 +++--- src/setup.h | 12 +++++++++++- src/util/error.c | 24 +++++++++++++----------- src/util/error.h | 35 ++++++++++++++++++++++------------- src/util/memlist.h | 2 +- src/util/string.h | 2 +- 8 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/ecmascript/quickjs.h b/src/ecmascript/quickjs.h index 87cbedf19..e855e5ae0 100644 --- a/src/ecmascript/quickjs.h +++ b/src/ecmascript/quickjs.h @@ -14,7 +14,7 @@ inline int operator<(JSValueConst a, JSValueConst b) extern "C" { #endif -#ifdef ECMASCRIPT_DEBUG +#ifdef ECMASCRIPT_DEBUG_OBJ #define RETURN_JS(obj) \ fprintf(stderr, "%s:%d obj=%p\n", __FILE__, __LINE__, JS_VALUE_GET_PTR(obj)); \ diff --git a/src/elinks.h b/src/elinks.h index 46acc06ca..03718bec3 100644 --- a/src/elinks.h +++ b/src/elinks.h @@ -25,7 +25,7 @@ * config.h. */ #include "setup.h" -#ifdef CONFIG_DEBUG +#ifdef CONFIG_DEBUG_MEMLEAK #define DEBUG_MEMLEAK #endif diff --git a/src/main/object.h b/src/main/object.h index be932be99..eb0a2936d 100644 --- a/src/main/object.h +++ b/src/main/object.h @@ -13,7 +13,7 @@ extern "C" { struct elinks_object { int refcount; -#ifdef CONFIG_DEBUG +#ifdef CONFIG_DEBUG_OBJ char *name; #endif }; @@ -28,7 +28,7 @@ struct object_head { #ifdef DEBUG_REFCOUNT #include "util/error.h" -#ifdef CONFIG_DEBUG +#ifdef CONFIG_DEBUG_OBJ #define object_lock_debug(obj, info) \ DBG("object %s[%p] lock %s to %d", (obj)->object.name, obj, \ info, (obj)->object.refcount) @@ -40,7 +40,7 @@ struct object_head { #define object_lock_debug(obj, info) #endif /* DEBUG_REFCOUNT */ -#ifdef CONFIG_DEBUG +#ifdef CONFIG_DEBUG_OBJ #include "util/error.h" #define object_sanity_check(obj) \ do { \ diff --git a/src/setup.h b/src/setup.h index 965db6e40..70a76cd96 100644 --- a/src/setup.h +++ b/src/setup.h @@ -125,6 +125,16 @@ #define FG_POLL_TIME 500 #define TERMINAL_POLL_TIMEOUT 1000 -//#define ECMASCRIPT_DEBUG 1 +#ifdef CONFIG_DEBUG +//#define CONFIG_ASSERT +//#define CONFIG_DEBUG_DUMP +//#define CONFIG_DEBUG_LIST +//#define CONFIG_DEBUG_MEMLEAK +//#define CONFIG_DEBUG_MEMLIST +//#define CONFIG_DEBUG_OBJ +//#define CONFIG_DEBUG_STRING +// #define ECMASCRIPT_DEBUG +//#define ECMASCRIPT_DEBUG_OBJ +#endif #endif diff --git a/src/util/error.c b/src/util/error.c index 9f099fc8a..f9f354bbc 100644 --- a/src/util/error.c +++ b/src/util/error.c @@ -52,6 +52,7 @@ er(int bell, int shall_sleep, const char *fmt, va_list params) int errline; const char *errfile; +const char *errfun; void elinks_debug(const char *fmt, ...) @@ -110,13 +111,13 @@ elinks_internal(const char *fmt, ...) va_start(params, fmt); snprintf(errbuf, sizeof(errbuf), - "\033[1mINTERNAL ERROR\033[0m at %s:%d: %s", - errfile, errline, fmt); + "\033[1mINTERNAL ERROR\033[0m at %s %d %s: %s", + errfile, errline, errfun, fmt); er(1, 1, errbuf, params); va_end(params); -#ifdef CONFIG_DEBUG +#ifdef CONFIG_DEBUG_DUMP force_dump(); #endif } @@ -191,25 +192,26 @@ done_log(void) loctime); errbuf[len] = '\0'; - fprintf(log_file, "[%-5s %-15s %4s]: Log stopped at %s\n\n\n", + fprintf(log_file, "[%-5s %-15s %4s]: Log stopped at %s\n", "", "", "", errbuf); fclose(log_file); } void -elinks_log(char *msg, char *file, int line, +elinks_log(char *msg, char *file, int line,char*fun, const char *fmt, ...) { static char *log_files = NULL; static char *log_msg = NULL; char errbuf[4096]; + char tbuf[32]; va_list params; + time_t curtime = time(NULL); + struct tm *loctime = localtime(&curtime); if (!log_file) { char *log_name; - time_t curtime = time(NULL); - struct tm *loctime = localtime(&curtime); int len; log_files = getenv("ELINKS_FILES"); @@ -223,8 +225,7 @@ elinks_log(char *msg, char *file, int line, loctime); errbuf[len] = '\0'; - fprintf(log_file, "\n\n[%-5s %-15s %4s]: Log started at %s\n", - "type", "file", "line", errbuf); + fprintf(log_file, "Log started at %s\n",errbuf); atexit(done_log); } @@ -237,8 +238,9 @@ elinks_log(char *msg, char *file, int line, va_start(params, fmt); - snprintf(errbuf, sizeof(errbuf), "[%-5s %-15s %4d]: %s", - msg, file, line, fmt); + strftime(tbuf, sizeof(tbuf), "%T", loctime); + snprintf(errbuf, sizeof(errbuf), "[%s %s %s %d %s]: %s", + tbuf, msg, file, line, fun, fmt); vfprintf(log_file, errbuf, params); fputc('\n', log_file); diff --git a/src/util/error.h b/src/util/error.h index 790cee006..1e2b89321 100644 --- a/src/util/error.h +++ b/src/util/error.h @@ -13,10 +13,14 @@ extern "C" { #endif +#include "main/main.h" + /* This errfile thing is needed, as we don't have var-arg macros in standart, * only as gcc extension :(. */ extern int errline; extern const char *errfile; +extern const char *errfun; + /** @c DBG(format_string) is used for printing of debugging information. It * should not be used anywhere in the official codebase (although it is often @@ -48,7 +52,7 @@ void elinks_error(const char *fmt, ...); * run. It tries to draw user's attention to the error and dumps core if ELinks * is running in the CONFIG_DEBUG mode. */ #undef INTERNAL -#define INTERNAL errfile = __FILE__, errline = __LINE__, elinks_internal +#define INTERNAL errfile = __FILE__, errline = __LINE__, errfun = __FUNCTION__, elinks_internal void elinks_internal(const char *fmt, ...); @@ -74,26 +78,31 @@ void usrerror(const char *fmt, ...); * */ void -elinks_log(char *msg, char *file, int line, +elinks_log(char *msg, char *file, int line,char*, const char *fmt, ...); +#undef LOG_JS +#define LOG_JS(args...) \ +if (program.testjs)\ + elinks_log("js", __FILE__, __LINE__,__FUNCTION__, args) + #undef LOG_ERR #define LOG_ERR(args...) \ - elinks_log("error", __FILE__, __LINE__, args) + elinks_log("error", __FILE__, __LINE__,__FUNCTION__, args) #undef LOG_WARN #define LOG_WARN(args...) \ - elinks_log("warn", __FILE__, __LINE__, args) + elinks_log("warn", __FILE__, __LINE__,__FUBCTION__, args) #undef LOG_INFO #define LOG_INFO(args...) \ - elinks_log("info", __FILE__, __LINE__, args) + elinks_log("info", __FILE__, __LINE__,__FUNCTION__, args) #undef LOG_DBG #define LOG_DBG(args...) \ - elinks_log("debug", __FILE__, __LINE__, args) + elinks_log("debug", __FILE__, __LINE__,__FUNCTION__, args) -#endif +#endif // CONFIG_DEBUG #endif @@ -104,7 +113,7 @@ elinks_log(char *msg, char *file, int line, * recovery path, see below ::if_assert_failed. */ #undef assert -#ifdef CONFIG_FASTMEM +#ifndef CONFIG_ASSERT #define assert(x) /* We don't do anything in CONFIG_FASTMEM mode. */ #else #define assert(x) \ @@ -123,7 +132,7 @@ do { if (!assert_failed && (assert_failed = !(x))) { \ #undef assertm #ifdef HAVE_VARIADIC_MACROS -#ifdef CONFIG_FASTMEM +#ifndef CONFIG_ASSERT #define assertm(x,m...) /* We don't do anything in CONFIG_FASTMEM mode. */ #else #define assertm(x,m...) \ @@ -132,7 +141,7 @@ do { if (!assert_failed && (assert_failed = !(x))) { \ } } while (0) #endif #else /* HAVE_VARIADIC_MACROS */ -#ifdef CONFIG_FASTMEM +#ifndef CONFIG_ASSERT #define assertm elinks_assertm #else #define assertm errfile = __FILE__, errline = __LINE__, elinks_assertm @@ -144,11 +153,11 @@ do { if (!assert_failed && (assert_failed = !(x))) { \ * expression is int (and that's completely fine, I do *NOT* want to see any * stinking assert((int) pointer) ! ;-)), so CONFIG_DEBUG (-Werror) and * !HAVE_VARIADIC_MACROS won't play well together. Hrm. --pasky */ -#ifdef CONFIG_FASTMEM +#ifndef CONFIG_ASSERT static inline #endif void elinks_assertm(int x, const char *fmt, ...) -#ifdef CONFIG_FASTMEM +#ifndef CONFIG_ASSERT { /* We don't do anything in CONFIG_FASTMEM mode. Let's hope that the compiler * will at least optimize out the @x computation. */ @@ -187,7 +196,7 @@ void elinks_assertm(int x, const char *fmt, ...) extern int assert_failed; #undef if_assert_failed -#ifdef CONFIG_FASTMEM +#ifndef CONFIG_ASSERT #define if_assert_failed if (0) /* This should be optimalized away. */ #else #define if_assert_failed if (assert_failed && !(assert_failed = 0)) diff --git a/src/util/memlist.h b/src/util/memlist.h index 145340efa..91f8ded39 100644 --- a/src/util/memlist.h +++ b/src/util/memlist.h @@ -11,7 +11,7 @@ struct memory_list { }; #undef DEBUG_MEMLIST -#ifdef CONFIG_DEBUG +#ifdef CONFIG_DEBUG_MEMLIST #define DEBUG_MEMLIST #endif diff --git a/src/util/string.h b/src/util/string.h index da57d9efc..602f10881 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -152,7 +152,7 @@ int elinks_isspace(int c); /** String debugging using magic number, it may catch some errors. */ -#ifdef CONFIG_DEBUG +#ifdef CONFIG_DEBUG_STRING #define DEBUG_STRING #endif