2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
gb_error.c
|
|
|
|
|
|
|
|
Errors management routines
|
|
|
|
|
|
|
|
(c) 2000-2007 Benoit Minisini <gambas@users.sourceforge.net>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 1, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __GB_ERROR_C
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "gb_buffer.h"
|
|
|
|
#include "gb_error.h"
|
|
|
|
#include "gbx_debug.h"
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
#include "gbx_api.h"
|
|
|
|
|
2008-02-02 11:54:13 +01:00
|
|
|
//#define DEBUG_ERROR 1
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-25 16:01:02 +01:00
|
|
|
ERROR_CONTEXT *ERROR_current = NULL;
|
2008-01-27 15:00:04 +01:00
|
|
|
ERROR_INFO ERROR_last = { 0 };
|
2008-03-11 14:29:47 +01:00
|
|
|
bool ERROR_backtrace = FALSE;
|
2008-01-25 16:01:02 +01:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static int _lock = 0;
|
|
|
|
|
|
|
|
static const char *_message[64] =
|
|
|
|
{
|
|
|
|
/* 0 E_UNKNOWN */ "Unknown error",
|
|
|
|
/* 1 E_MEMORY */ "Out of memory",
|
2008-01-27 15:00:04 +01:00
|
|
|
/* 2 E_CLASS */ ".Cannot load class '&1': &2&3",
|
2007-12-30 17:41:49 +01:00
|
|
|
/* 3 E_STACK */ "Stack overflow",
|
|
|
|
/* 4 E_NEPARAM */ "Not enough arguments",
|
|
|
|
/* 5 E_TMPARAM */ "Too many arguments",
|
2008-01-27 15:00:04 +01:00
|
|
|
/* 6 E_TYPE */ ".Type mismatch: wanted &1, got &2 instead",
|
2007-12-30 17:41:49 +01:00
|
|
|
/* 7 E_OVERFLOW */ "Overflow",
|
|
|
|
/* 8 E_ILLEGAL */ "Illegal instruction",
|
|
|
|
/* 9 E_NFUNC */ "Not a function",
|
2008-01-27 15:00:04 +01:00
|
|
|
/* 10 E_CSTATIC */ ".Class '&1' is not creatable",
|
|
|
|
/* 11 E_NSYMBOL */ ".Unknown symbol '&1' in class '&2'",
|
2007-12-30 17:41:49 +01:00
|
|
|
/* 12 E_NOBJECT */ "Not an object",
|
|
|
|
/* 13 E_NULL */ "Null object",
|
2008-01-27 15:00:04 +01:00
|
|
|
/* 14 E_STATIC */ ".'&1.&2' is static",
|
|
|
|
/* 15 E_NREAD */ ".'&1.&2' is write only",
|
|
|
|
/* 16 E_NWRITE */ ".'&1.&2' is read only",
|
|
|
|
/* 17 E_NPROPERTY */ ".'&1.&2' is not a property",
|
2007-12-30 17:41:49 +01:00
|
|
|
/* 18 E_NRETURN */ "No return value",
|
|
|
|
/* 19 E_MATH*/ "Mathematic error",
|
|
|
|
/* 20 E_ARG */ "Bad argument",
|
|
|
|
/* 21 E_BOUND */ "Out of bounds",
|
|
|
|
/* 22 E_NDIM */ "Bad number of dimensions",
|
|
|
|
/* 23 E_NARRAY */ "Not an array",
|
|
|
|
/* 24 E_MAIN */ "No startup method",
|
|
|
|
/* 25 E_NNEW */ "No instanciation method",
|
|
|
|
/* 26 E_ZERO */ "Division by zero",
|
2008-01-27 15:00:04 +01:00
|
|
|
/* 27 E_LIBRARY */ ".Cannot load component '&1': &2",
|
|
|
|
/* 28 E_EVENT */ ".Bad event handler in &1.&2(): &3",
|
2007-12-30 17:41:49 +01:00
|
|
|
/* 29 E_IOBJECT */ "Invalid object",
|
|
|
|
/* 30 E_ENUM */ "Not an enumeration",
|
|
|
|
/* 31 E_UCONV */ "Unsupported string conversion",
|
|
|
|
/* 32 E_CONV */ "Bad string conversion",
|
|
|
|
/* 33 E_DATE */ "Invalid date",
|
|
|
|
/* 34 E_BADPATH */ "Invalid path",
|
2008-01-27 15:00:04 +01:00
|
|
|
/* 35 E_OPEN */ ".Cannot open file '&1': &2",
|
|
|
|
/* 36 E_PROJECT */ ".Bad project file: line &1: &2",
|
2007-12-30 17:41:49 +01:00
|
|
|
/* 37 E_FULL */ "Device is full",
|
|
|
|
/* 38 E_EXIST */ "File already exists", /* &1 */
|
|
|
|
/* 39 E_EOF */ "End of file",
|
|
|
|
/* 40 E_FORMAT */ "Bad format string",
|
2008-01-27 15:00:04 +01:00
|
|
|
/* 41 E_DYNAMIC */ ".'&1.&2' is not static",
|
|
|
|
/* 42 E_SYSTEM */ ".System error. &1",
|
2007-12-30 17:41:49 +01:00
|
|
|
/* 43 E_ACCESS */ "Access forbidden",
|
|
|
|
/* 44 E_TOOLONG */ "File name is too long",
|
|
|
|
/* 45 E_NEXIST */ "File or directory does not exist", /* &1 */
|
|
|
|
/* 46 E_DIR */ "File is a directory", /* &1 */
|
|
|
|
/* 47 E_READ */ "Read error",
|
|
|
|
/* 48 E_WRITE */ "Write error",
|
2008-01-27 15:00:04 +01:00
|
|
|
/* 49 E_NDIR */ ".Not a directory: &1",
|
|
|
|
/* 50 E_REGEXP */ ".Bad regular expression: &1",
|
|
|
|
/* 51 E_ARCH */ ".Bad archive: &1: &2",
|
|
|
|
/* 52 E_REGISTER */ ".Cannot register class '&1'",
|
2007-12-30 17:41:49 +01:00
|
|
|
/* 53 E_CLOSED */ "Stream is closed",
|
|
|
|
/* 54 E_VIRTUAL */ "Bad use of virtual class",
|
|
|
|
/* 55 E_STOP */ "STOP instruction encountered",
|
|
|
|
/* 56 E_STRING */ "Too many simultaneous new strings",
|
2008-01-27 15:00:04 +01:00
|
|
|
/* 57 E_EVAL */ ".Bad expression: &1",
|
2007-12-30 17:41:49 +01:00
|
|
|
/* 58 E_LOCK */ "File is locked",
|
|
|
|
/* 59 E_PARENT */ "No parent class",
|
2008-01-27 15:00:04 +01:00
|
|
|
/* 60 E_EXTLIB */ ".Cannot find dynamic library '&1': &2",
|
|
|
|
/* 61 E_EXTSYM */ ".Cannot find symbol '&2' in dynamic library '&1'",
|
2008-02-24 17:29:02 +01:00
|
|
|
/* 62 E_BYREF */ "Argument cannot be passed by reference",
|
2007-12-30 17:41:49 +01:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void ERROR_lock()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
_lock++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void ERROR_unlock()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
_lock--;
|
|
|
|
}
|
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
void ERROR_reset(ERROR_INFO *info)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-01-27 15:00:04 +01:00
|
|
|
info->code = 0;
|
|
|
|
if (info->free)
|
2008-01-25 16:01:02 +01:00
|
|
|
{
|
2008-02-02 11:54:13 +01:00
|
|
|
STRING_unref(&info->msg);
|
2008-01-27 15:00:04 +01:00
|
|
|
info->free = FALSE;
|
2008-01-25 16:01:02 +01:00
|
|
|
}
|
2008-02-02 11:54:13 +01:00
|
|
|
info->msg = NULL;
|
2008-01-27 15:00:04 +01:00
|
|
|
DEBUG_free_backtrace(&info->backtrace);
|
2008-03-11 14:29:47 +01:00
|
|
|
info->backtrace = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void ERROR_clear()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
if (_lock)
|
|
|
|
return;
|
2008-01-27 15:00:04 +01:00
|
|
|
ERROR_reset(&ERROR_current->info);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void ERROR_enter(ERROR_CONTEXT *err)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-01-25 16:01:02 +01:00
|
|
|
err->prev = ERROR_current;
|
2008-03-19 15:32:30 +01:00
|
|
|
err->info.code = 0;
|
|
|
|
err->info.free = FALSE;
|
|
|
|
err->info.msg = NULL;
|
|
|
|
err->info.backtrace = NULL;
|
|
|
|
|
2008-01-25 16:01:02 +01:00
|
|
|
ERROR_current = err;
|
|
|
|
|
|
|
|
#if DEBUG_ERROR
|
|
|
|
fprintf(stderr, ">> ERROR_enter");
|
|
|
|
{
|
|
|
|
ERROR_CONTEXT *e = err;
|
|
|
|
while (e)
|
|
|
|
{
|
|
|
|
fprintf(stderr, " -> %p", e);
|
|
|
|
e = e->prev;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void ERROR_leave(ERROR_CONTEXT *err)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-01-25 16:01:02 +01:00
|
|
|
if (err->prev == ERROR_LEAVE_DONE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if DEBUG_ERROR
|
|
|
|
fprintf(stderr, "<< ERROR_leave");
|
|
|
|
{
|
|
|
|
ERROR_CONTEXT *e = err;
|
|
|
|
while (e)
|
|
|
|
{
|
|
|
|
fprintf(stderr, " -> %p", e);
|
|
|
|
e = e->prev;
|
|
|
|
}
|
2008-02-02 11:54:13 +01:00
|
|
|
fprintf(stderr, " : %d %s\n", err->info.code, err->info.msg);
|
2008-01-25 16:01:02 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//if (!err->prev)
|
|
|
|
// BREAKPOINT();
|
|
|
|
|
|
|
|
ERROR_current = err->prev;
|
|
|
|
|
|
|
|
if (ERROR_current)
|
|
|
|
{
|
2008-01-27 15:00:04 +01:00
|
|
|
ERROR_reset(&ERROR_current->info);
|
2008-01-25 16:01:02 +01:00
|
|
|
ERROR_current->info = err->info;
|
|
|
|
}
|
|
|
|
|
|
|
|
err->prev = ERROR_LEAVE_DONE;
|
|
|
|
//ERROR_reset(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ERROR_propagate()
|
|
|
|
{
|
2008-02-02 11:54:13 +01:00
|
|
|
#if DEBUG_ERROR
|
|
|
|
fprintf(stderr, "ERROR_propagate: %d %s\n", ERROR_current->info.code, ERROR_current->info.msg);
|
|
|
|
#endif
|
2008-01-25 16:01:02 +01:00
|
|
|
if (ERROR_current->ret)
|
|
|
|
ERROR_leave(ERROR_current);
|
|
|
|
longjmp(ERROR_current->env, 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-25 16:01:02 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
const char *ERROR_get(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
if (code > 0 && code < 256)
|
|
|
|
return strerror(code);
|
|
|
|
else
|
|
|
|
return ERROR_Message[code - 256];
|
|
|
|
*/
|
|
|
|
return strerror(errno);
|
|
|
|
}
|
|
|
|
|
2008-03-11 14:29:47 +01:00
|
|
|
static int get_message_length(const char *pattern, char *arg[])
|
|
|
|
{
|
|
|
|
uchar c;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
c = *pattern++;
|
|
|
|
if (!c)
|
|
|
|
break;
|
|
|
|
if (c == '&')
|
|
|
|
{
|
|
|
|
c = *pattern++;
|
|
|
|
if (c >= '1' && c <= '4')
|
|
|
|
len += strlen(arg[c - '1']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void ERROR_define(const char *pattern, char *arg[])
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
uchar c;
|
|
|
|
boolean subst;
|
2008-03-11 14:29:47 +01:00
|
|
|
char *msg;
|
|
|
|
int len;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
ERROR_clear();
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
if ((intptr_t)pattern >= 0 && (intptr_t)pattern < 256)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-01-25 16:01:02 +01:00
|
|
|
ERROR_current->info.code = (int)(intptr_t)pattern;
|
2008-01-17 22:39:26 +01:00
|
|
|
pattern = _message[(int)(intptr_t)pattern];
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2008-01-17 22:39:26 +01:00
|
|
|
else if ((intptr_t)pattern == E_ABORT)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-01-25 16:01:02 +01:00
|
|
|
ERROR_current->info.code = E_ABORT;
|
2007-12-30 17:41:49 +01:00
|
|
|
pattern = "";
|
|
|
|
}
|
|
|
|
else
|
2008-01-25 16:01:02 +01:00
|
|
|
ERROR_current->info.code = E_CUSTOM;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
if (*pattern == '.' || ERROR_current->info.code == E_CUSTOM) //(arg) //(index(pattern, '&'))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-01-27 15:00:04 +01:00
|
|
|
if (*pattern == '.')
|
|
|
|
pattern++;
|
2007-12-30 17:41:49 +01:00
|
|
|
subst = FALSE;
|
|
|
|
|
2008-03-11 14:29:47 +01:00
|
|
|
STRING_new(&msg, NULL, get_message_length(pattern, arg));
|
|
|
|
ERROR_current->info.msg = msg;
|
2008-01-25 16:01:02 +01:00
|
|
|
ERROR_current->info.free = TRUE;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
c = *pattern++;
|
|
|
|
if (c == 0)
|
|
|
|
break;
|
2008-03-11 14:29:47 +01:00
|
|
|
|
|
|
|
if (c == '&')
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-03-11 14:29:47 +01:00
|
|
|
c = *pattern++;
|
|
|
|
if (c >= '1' && c <= '4')
|
|
|
|
{
|
|
|
|
c -= '1';
|
|
|
|
len = strlen(arg[c]);
|
|
|
|
memcpy(msg, arg[c], len);
|
|
|
|
msg += len;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
else
|
2008-03-11 14:29:47 +01:00
|
|
|
*msg++ = c;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2008-03-11 14:29:47 +01:00
|
|
|
|
|
|
|
*msg = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-25 16:01:02 +01:00
|
|
|
ERROR_current->info.msg = (char *)pattern;
|
|
|
|
ERROR_current->info.free = FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
//fprintf(stderr, "ERROR_define: %p %d %p '%s'\n", ERROR_current, ERROR_current->info.code, ERROR_current->info.msg, ERROR_current->info.msg);
|
|
|
|
|
|
|
|
//STRING_add_char(&ERROR_current->info.msg, 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-25 16:01:02 +01:00
|
|
|
ERROR_current->info.cp = CP;
|
|
|
|
ERROR_current->info.fp = FP;
|
|
|
|
ERROR_current->info.pc = PC;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-11 14:29:47 +01:00
|
|
|
if (EXEC_debug || (ERROR_backtrace && (CP && CP->debug)))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-01-25 16:01:02 +01:00
|
|
|
//DEBUG_free_backtrace(&ERROR_current->info.backtrace);
|
|
|
|
ERROR_current->info.backtrace = DEBUG_backtrace();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2008-02-02 11:54:13 +01:00
|
|
|
|
|
|
|
#if DEBUG_ERROR
|
|
|
|
fprintf(stderr, "ERROR_define: %s\n", ERROR_current->info.msg);
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void THROW(int code, ...)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int i;
|
|
|
|
char *arg[4];
|
|
|
|
|
|
|
|
va_start(args, code);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
arg[i] = va_arg(args, char *);
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
ERROR_define((char *)(intptr_t)code, arg);
|
2007-12-30 17:41:49 +01:00
|
|
|
PROPAGATE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void THROW_SYSTEM(int err, const char *path)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
switch(err)
|
|
|
|
{
|
|
|
|
case ENOENT:
|
|
|
|
THROW(E_NEXIST, path);
|
|
|
|
|
|
|
|
case EISDIR:
|
|
|
|
THROW(E_DIR, path);
|
|
|
|
|
|
|
|
case ENOTDIR:
|
|
|
|
THROW(E_NDIR, path);
|
|
|
|
|
|
|
|
case ENOMEM:
|
|
|
|
THROW(E_MEMORY);
|
|
|
|
|
|
|
|
case EACCES:
|
|
|
|
THROW(E_ACCESS);
|
|
|
|
|
|
|
|
case ENAMETOOLONG:
|
|
|
|
THROW(E_TOOLONG);
|
|
|
|
|
|
|
|
case ENOSPC:
|
|
|
|
THROW(E_FULL);
|
|
|
|
|
|
|
|
case EEXIST:
|
|
|
|
THROW(E_EXIST, path);
|
|
|
|
|
|
|
|
default:
|
|
|
|
THROW(E_SYSTEM, strerror(err));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void ERROR_panic(const char *error, ...)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, error);
|
|
|
|
|
|
|
|
fflush(NULL);
|
|
|
|
|
2008-02-02 11:54:13 +01:00
|
|
|
fprintf(stderr, "\n** INTERNAL ERROR **\n** ");
|
2007-12-30 17:41:49 +01:00
|
|
|
vfprintf(stderr, error, args);
|
2008-01-27 15:00:04 +01:00
|
|
|
putc('\n', stderr);
|
2008-01-25 16:01:02 +01:00
|
|
|
if (ERROR_current->info.code)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
ERROR_print();
|
|
|
|
}
|
2008-01-27 15:00:04 +01:00
|
|
|
fprintf(stderr, "** Program aborting. Sorry! :-(\n");
|
2007-12-30 17:41:49 +01:00
|
|
|
/*abort();*/
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void ERROR_print_at(FILE *where, bool msgonly, bool newline)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-01-25 16:01:02 +01:00
|
|
|
if (!ERROR_current->info.code)
|
2007-12-30 17:41:49 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!msgonly)
|
|
|
|
{
|
2008-01-25 16:01:02 +01:00
|
|
|
if (ERROR_current->info.cp && ERROR_current->info.fp && ERROR_current->info.pc)
|
|
|
|
fprintf(where, "%s: ", DEBUG_get_position(ERROR_current->info.cp, ERROR_current->info.fp, ERROR_current->info.pc));
|
2007-12-30 17:41:49 +01:00
|
|
|
else
|
|
|
|
fprintf(where, "ERROR: ");
|
2008-01-25 16:01:02 +01:00
|
|
|
/*if (ERROR_current->info.code > 0 && ERROR_current->info.code < 256)
|
|
|
|
fprintf(where, "%ld:", ERROR_current->info.code);*/
|
|
|
|
if (ERROR_current->info.code > 0)
|
|
|
|
fprintf(where, "#%d: ", ERROR_current->info.code);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-25 16:01:02 +01:00
|
|
|
fprintf(where, "%s", ERROR_current->info.msg);
|
2007-12-30 17:41:49 +01:00
|
|
|
if (newline)
|
|
|
|
fputc('\n', where);
|
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void ERROR_print(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
static bool lock = FALSE;
|
|
|
|
|
2008-01-25 16:01:02 +01:00
|
|
|
DEBUG_BACKTRACE *bt = ERROR_current->info.backtrace;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
ERROR_print_at(stderr, FALSE, TRUE);
|
|
|
|
|
|
|
|
if (bt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < ARRAY_count(bt); i++)
|
|
|
|
fprintf(stderr, "%d: %s\n", i, DEBUG_get_position(bt[i].cp, bt[i].fp, bt[i].pc));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EXEC_main_hook_done && !EXEC_debug && EXEC_Hook.error && !lock)
|
|
|
|
{
|
|
|
|
lock = TRUE;
|
|
|
|
GAMBAS_DoNotRaiseEvent = TRUE;
|
2008-01-25 16:01:02 +01:00
|
|
|
HOOK(error)(ERROR_current->info.code, ERROR_current->info.msg, DEBUG_get_position(ERROR_current->info.cp, ERROR_current->info.fp, ERROR_current->info.pc));
|
2007-12-30 17:41:49 +01:00
|
|
|
lock = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void ERROR_save(ERROR_INFO *save)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-01-27 15:00:04 +01:00
|
|
|
ERROR_reset(save);
|
2008-01-25 16:01:02 +01:00
|
|
|
*save = ERROR_current->info;
|
2008-01-27 15:00:04 +01:00
|
|
|
CLEAR(&ERROR_current->info);
|
|
|
|
//ERROR_reset(&ERROR_current->info);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void ERROR_restore(ERROR_INFO *save)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2008-01-27 15:00:04 +01:00
|
|
|
ERROR_reset(&ERROR_current->info);
|
2008-01-25 16:01:02 +01:00
|
|
|
ERROR_current->info = *save;
|
2008-01-27 15:00:04 +01:00
|
|
|
CLEAR(save);
|
|
|
|
//ERROR_reset(save);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2008-02-02 11:54:13 +01:00
|
|
|
|
|
|
|
void ERROR_set_last(void)
|
|
|
|
{
|
|
|
|
ERROR_reset(&ERROR_last);
|
|
|
|
ERROR_last = ERROR_current->info;
|
|
|
|
if (ERROR_last.free)
|
|
|
|
STRING_ref(ERROR_last.msg);
|
|
|
|
ERROR_last.backtrace = DEBUG_copy_backtrace(ERROR_last.backtrace);
|
2008-03-11 14:29:47 +01:00
|
|
|
}
|