Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript bugs #326

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
more logging options better output
  • Loading branch information
john-peterson committed Sep 21, 2024
commit 657625db40108d0d40ff4ca9bc324a918296076f
2 changes: 1 addition & 1 deletion src/ecmascript/quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)); \
Expand Down
2 changes: 1 addition & 1 deletion src/elinks.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* config.h. */
#include "setup.h"

#ifdef CONFIG_DEBUG
#ifdef CONFIG_DEBUG_MEMLEAK
#define DEBUG_MEMLEAK
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/main/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern "C" {

struct elinks_object {
int refcount;
#ifdef CONFIG_DEBUG
#ifdef CONFIG_DEBUG_OBJ
char *name;
#endif
};
Expand All @@ -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)
Expand All @@ -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 { \
Expand Down
12 changes: 11 additions & 1 deletion src/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 13 additions & 11 deletions src/util/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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");
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down
35 changes: 22 additions & 13 deletions src/util/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, ...);


Expand All @@ -74,26 +78,31 @@ void usrerror(const char *fmt, ...);
* </dl>
*/
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


Expand All @@ -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) \
Expand All @@ -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...) \
Expand All @@ -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
Expand All @@ -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. */
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/util/memlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct memory_list {
};

#undef DEBUG_MEMLIST
#ifdef CONFIG_DEBUG
#ifdef CONFIG_DEBUG_MEMLIST
#define DEBUG_MEMLIST
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/util/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down