2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
debug.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-08-03 17:38:01 +02:00
|
|
|
(c) 2000-2013 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
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 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
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.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __DEBUG_C
|
|
|
|
|
|
|
|
// Do not include gbx_debug.h
|
|
|
|
#define __GBX_DEBUG_H
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gambas.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "gb_error.h"
|
|
|
|
#include "gbx_type.h"
|
|
|
|
#include "gb_limit.h"
|
|
|
|
#include "gbx_stack.h"
|
|
|
|
#include "gbx_class.h"
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
#include "gbx_local.h"
|
|
|
|
#include "gbx_object.h"
|
|
|
|
|
|
|
|
#include "gbx_eval.h"
|
|
|
|
|
|
|
|
#include "print.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
2009-08-18 00:36:54 +02:00
|
|
|
//#define DEBUG_ME
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
DEBUG_INFO DEBUG_info = { 0 };
|
|
|
|
GB_DEBUG_INTERFACE *DEBUG_interface;
|
|
|
|
char DEBUG_buffer[DEBUG_BUFFER_MAX + 1];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
static DEBUG_BREAK *Breakpoint;
|
|
|
|
static bool Error;
|
|
|
|
|
|
|
|
static EVAL_INTERFACE EVAL;
|
|
|
|
|
|
|
|
static int _fdr;
|
|
|
|
static int _fdw;
|
|
|
|
static FILE *_out;
|
|
|
|
static FILE *_in;
|
|
|
|
static bool _fifo;
|
|
|
|
|
|
|
|
#define EXEC_current (*(STACK_CONTEXT *)GB_DEBUG.GetExec())
|
|
|
|
|
2009-08-18 00:36:54 +02:00
|
|
|
#ifdef DEBUG_ME
|
|
|
|
#define WARNING(_msg, ...) fprintf(stderr, "W\t" _msg "\n", ##__VA_ARGS__)
|
|
|
|
#define INFO(_msg, ...) fprintf(stderr, "I\t" _msg "\n", ##__VA_ARGS__)
|
|
|
|
#else
|
2007-12-30 17:41:49 +01:00
|
|
|
#define WARNING(_msg, ...) fprintf(_out, "W\t" _msg "\n", ##__VA_ARGS__)
|
|
|
|
#define INFO(_msg, ...) fprintf(_out, "I\t" _msg "\n", ##__VA_ARGS__)
|
2009-08-18 00:36:54 +02:00
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-09-08 14:22:03 +02:00
|
|
|
static void init_eval_interface()
|
2009-08-24 16:19:32 +02:00
|
|
|
{
|
|
|
|
static bool init = FALSE;
|
|
|
|
|
|
|
|
if (!init)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
GB.GetInterface("gb.eval", EVAL_INTERFACE_VERSION, &EVAL);
|
|
|
|
init = TRUE;
|
2009-08-24 16:19:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
void DEBUG_break_on_next_line(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
DEBUG_info.stop = TRUE;
|
|
|
|
DEBUG_info.leave = FALSE;
|
|
|
|
DEBUG_info.fp = NULL;
|
|
|
|
DEBUG_info.bp = NULL;
|
2013-05-30 03:10:59 +02:00
|
|
|
DEBUG_info.pp = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void signal_user(int sig)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
signal(SIGUSR1, signal_user);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "Got SIGUSR1\n");
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
/*CAPP_got_signal();*/
|
|
|
|
DEBUG_break_on_next_line();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
bool DEBUG_calc_line_from_position(CLASS *class, FUNCTION *func, PCODE *addr, ushort *line)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2013-01-06 17:13:31 +01:00
|
|
|
int lo, hi;
|
2012-07-03 00:38:29 +02:00
|
|
|
int mid;
|
2012-05-19 04:55:05 +02:00
|
|
|
ushort pos = addr - func->code;
|
|
|
|
ushort *post;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (func->debug)
|
|
|
|
{
|
2013-01-06 17:13:31 +01:00
|
|
|
post = func->debug->pos;
|
|
|
|
|
|
|
|
lo = 0;
|
|
|
|
hi = func->debug->nline - 1;
|
|
|
|
|
2012-07-03 00:38:29 +02:00
|
|
|
while (lo < hi)
|
|
|
|
{
|
|
|
|
mid = (lo + hi) >> 1;
|
|
|
|
if (pos < post[mid])
|
|
|
|
{
|
|
|
|
hi = mid;
|
|
|
|
}
|
|
|
|
else if (pos >= post[mid + 1])
|
|
|
|
{
|
|
|
|
lo = mid + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*line = mid + func->debug->line;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-05-19 04:55:05 +02:00
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
static bool calc_position_from_line(CLASS *class, ushort line, FUNCTION **function, PCODE **addr)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
int i;
|
|
|
|
ushort pos, pos_after;
|
|
|
|
FUNCTION *func = NULL;
|
|
|
|
FUNC_DEBUG *debug = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
for (i = 0; i < class->load->n_func; i++)
|
|
|
|
{
|
|
|
|
func = &class->load->func[i];
|
|
|
|
debug = func->debug;
|
2012-12-22 01:23:51 +01:00
|
|
|
//fprintf(stderr, "calc_position_from_line: %s (%d -> %d) / %d\n", debug->name, debug->line, debug->line + debug->nline - 1, line);
|
2012-05-19 04:55:05 +02:00
|
|
|
if (debug && line >= debug->line && line < (debug->line + debug->nline))
|
|
|
|
break;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (i >= class->load->n_func)
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-12-22 01:23:51 +01:00
|
|
|
//fprintf(stderr, "calc_position_from_line: %s OK\n", debug->name);
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
line -= debug->line;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
pos = debug->pos[line];
|
|
|
|
pos_after = debug->pos[line + 1];
|
|
|
|
if (pos != pos_after)
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
line++;
|
|
|
|
if (line >= debug->nline)
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
*function = func;
|
|
|
|
*addr = &func->code[pos];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
/*printf("%s.%d -> %04X\n", class->name, line + debug->line, **addr);*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
DEBUG_INFO *DEBUG_init(GB_DEBUG_INTERFACE *debug, bool fifo, const char *fifo_name)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
char path[DEBUG_FIFO_PATH_MAX];
|
2009-05-22 16:52:36 +02:00
|
|
|
char name[16];
|
2009-05-25 23:51:48 +02:00
|
|
|
//int i;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
//if (!EXEC_debug)
|
|
|
|
// return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
DEBUG_interface = debug;
|
|
|
|
_fifo = fifo;
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (_fifo)
|
|
|
|
{
|
2009-05-22 16:52:36 +02:00
|
|
|
if (!fifo_name)
|
|
|
|
{
|
|
|
|
sprintf(name, "%d", getppid());
|
|
|
|
fifo_name = name;
|
|
|
|
}
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
snprintf(path, sizeof(path), "/tmp/gambas.%d/%s.out", getuid(), fifo_name);
|
2009-05-22 16:52:36 +02:00
|
|
|
|
|
|
|
/*for (i = 0; i < 20; i++)
|
|
|
|
{
|
|
|
|
_fdr = open(path, O_RDONLY | O_NONBLOCK);
|
|
|
|
if (_fdr >= 0)
|
|
|
|
break;
|
|
|
|
usleep(10000);
|
|
|
|
}
|
|
|
|
if (_fdr < 0)
|
|
|
|
return NULL;*/
|
|
|
|
|
2013-01-06 17:13:31 +01:00
|
|
|
_fdr = open(path, O_RDONLY | O_CLOEXEC);
|
2009-05-22 16:52:36 +02:00
|
|
|
if (_fdr < 0)
|
|
|
|
return NULL;
|
2012-05-19 04:55:05 +02:00
|
|
|
|
2009-05-22 16:52:36 +02:00
|
|
|
snprintf(path, sizeof(path), "/tmp/gambas.%d/%s.in", getuid(), fifo_name);
|
2012-05-19 04:55:05 +02:00
|
|
|
|
2013-01-06 17:13:31 +01:00
|
|
|
_fdw = open(path, O_WRONLY | O_CLOEXEC);
|
2009-05-22 16:52:36 +02:00
|
|
|
if (_fdw < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
_in = fdopen(_fdr, "r");
|
|
|
|
_out = fdopen(_fdw, "w");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (!_in || !_out)
|
|
|
|
return NULL;
|
|
|
|
//ERROR_panic("Cannot open fifos");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
setlinebuf(_in);
|
|
|
|
//setvbuf(_in, NULL, _IONBF, 0);
|
|
|
|
setlinebuf(_out);
|
|
|
|
//setvbuf(_out, NULL, _IONBF, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_in = stdin;
|
|
|
|
_out = stdout;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
//ARRAY_create(&Breakpoint);
|
|
|
|
GB.NewArray(&Breakpoint, sizeof(DEBUG_BREAK), 16);
|
|
|
|
signal(SIGUSR1, signal_user);
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
setlinebuf(_out);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
return &DEBUG_info;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
void DEBUG_exit(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
GB.FreeArray(&Breakpoint);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
/* Don't do it, it blocks!
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (EXEC_fifo)
|
|
|
|
{
|
|
|
|
fclose(_in);
|
|
|
|
fclose(_out);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
*/
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int find_free_breakpoint(void)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
int i;
|
|
|
|
char used[MAX_BREAKPOINT];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
memset(used, FALSE, MAX_BREAKPOINT);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
for (i = 0; i < ARRAY_count(Breakpoint); i++)
|
|
|
|
used[Breakpoint[i].id - 1] = TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
for (i = 0; i < MAX_BREAKPOINT; i++)
|
|
|
|
if (!used[i])
|
|
|
|
return (i + 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
return 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool init_breakpoint(DEBUG_BREAK *brk)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
PCODE *addr = NULL;
|
|
|
|
FUNCTION *func;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
//fprintf(stderr, "init_breakpoint: id = %d\n", brk->id);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2014-07-28 07:35:58 +02:00
|
|
|
if (brk->addr || !CLASS_is_loaded(brk->class))
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
WARNING("Breakpoint is pending");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (CLASS_is_native(brk->class) || !brk->class->debug)
|
|
|
|
{
|
|
|
|
WARNING("Cannot set breakpoint: no debugging information");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (calc_position_from_line(brk->class, brk->line, &func, &addr))
|
|
|
|
{
|
|
|
|
WARNING("Cannot set breakpoint: cannot calculate position");
|
|
|
|
//fprintf(_out, "Cannot calc position from line number\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PCODE_is_breakpoint(*addr))
|
|
|
|
{
|
|
|
|
//WARNING("Cannot set breakpoint: Not a line beginning: %04d: %04X", addr - func->code, *addr);
|
|
|
|
WARNING("Cannot set breakpoint: Not a line beginning");
|
|
|
|
//fprintf(_out, "Not a line beginning ?\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*addr & 0xFF)
|
|
|
|
{
|
|
|
|
WARNING("Breakpoint already set");
|
|
|
|
//fprintf(_out, "Breakpoint already set\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
brk->addr = addr;
|
2012-05-19 04:55:05 +02:00
|
|
|
*addr = PCODE_BREAKPOINT(brk->id);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
//fprintf(stderr, "init_breakpoint: OK\n");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "init_breakpoint: %s.%d\n", brk->class->name, brk->line);
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
INFO("Breakpoint set: %s.%d", brk->class->name, brk->line);
|
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
static bool set_breakpoint(CLASS *class, ushort line)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
DEBUG_BREAK *brk;
|
|
|
|
int id;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (GB.Count(Breakpoint) >= MAX_BREAKPOINT)
|
|
|
|
{
|
|
|
|
WARNING("Too many breakpoints");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
id = find_free_breakpoint();
|
|
|
|
if (id == 0)
|
|
|
|
{
|
|
|
|
WARNING("Cannot create breakpoint");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
brk = (DEBUG_BREAK *)GB.Add(&Breakpoint);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
brk->id = id;
|
|
|
|
brk->addr = NULL;
|
|
|
|
brk->class = class;
|
|
|
|
brk->line = line;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "set_breakpoint: %s.%d\n", class->name, line);
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
init_breakpoint(brk);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
return FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
static bool unset_breakpoint(CLASS *class, ushort line)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
int i;
|
|
|
|
DEBUG_BREAK *brk;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
for (i = 0; i < GB.Count(Breakpoint); i++)
|
|
|
|
{
|
|
|
|
brk = &Breakpoint[i];
|
|
|
|
if (brk->class == class && brk->line == line)
|
|
|
|
{
|
|
|
|
if (brk->addr)
|
|
|
|
*(brk->addr) = PCODE_BREAKPOINT(0);
|
|
|
|
GB.Remove(&Breakpoint, i, 1);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "unset_breakpoint: %s.%d\n", class->name, line);
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
INFO("Breakpoint removed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
WARNING("Unknown breakpoint");
|
|
|
|
return TRUE;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
void DEBUG_init_breakpoints(CLASS *class)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
int i;
|
|
|
|
DEBUG_BREAK *brk;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-08-18 00:36:54 +02:00
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "DEBUG_init_breakpoints: %p %s\n", class, class->name);
|
|
|
|
#endif
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
for (i = 0; i < GB.Count(Breakpoint); i++)
|
|
|
|
{
|
|
|
|
brk = &Breakpoint[i];
|
|
|
|
if (brk->class == class)
|
|
|
|
{
|
|
|
|
//fprintf(stderr, "DEBUG_init_breakpoints: %s\n", class->name);
|
|
|
|
init_breakpoint(brk);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
2012-05-19 04:55:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
static void print_local()
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
int i;
|
2009-05-25 23:51:48 +02:00
|
|
|
FUNCTION *fp;
|
2012-05-19 04:55:05 +02:00
|
|
|
LOCAL_SYMBOL *lp;
|
2009-05-25 23:51:48 +02:00
|
|
|
|
|
|
|
fp = DEBUG_info.fp;
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (!fp || !fp->debug)
|
|
|
|
return;
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
for (i = 0; i < fp->debug->n_local; i++)
|
|
|
|
{
|
|
|
|
lp = &fp->debug->local[i];
|
|
|
|
fprintf(_out, "%.*s ", lp->sym.len, lp->sym.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*else
|
|
|
|
{
|
|
|
|
cmd++;
|
|
|
|
|
|
|
|
for (i = 0; i < FP->debug->n_local; i++)
|
|
|
|
{
|
|
|
|
lp = &FP->debug->local[i];
|
|
|
|
if (lp->sym.len == strlen(cmd) && strncasecmp(lp->sym.name, cmd, lp->sym.len) == 0)
|
|
|
|
{
|
|
|
|
fprintf(_out, "=");
|
|
|
|
//fprintf(_out, "TUT\n");
|
|
|
|
PRINT_value(_out, &BP[lp->value], TRUE);
|
|
|
|
nl = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void print_symbol(GLOBAL_SYMBOL *gp, bool is_static, bool is_public)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
if (CTYPE_get_kind(gp->ctype) != TK_VARIABLE && CTYPE_get_kind(gp->ctype) != TK_CONST)
|
|
|
|
return;
|
2009-05-25 23:51:48 +02:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (CTYPE_is_static(gp->ctype) && !is_static)
|
|
|
|
return;
|
2009-05-25 23:51:48 +02:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (!CTYPE_is_static(gp->ctype) && is_static)
|
|
|
|
return;
|
2009-05-25 23:51:48 +02:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (CTYPE_is_public(gp->ctype) && !is_public)
|
|
|
|
return;
|
2009-05-25 23:51:48 +02:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (!CTYPE_is_public(gp->ctype) && is_public)
|
|
|
|
return;
|
2009-05-25 23:51:48 +02:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
fprintf(_out, "%.*s ", gp->sym.len, gp->sym.name);
|
2009-05-25 23:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void print_object()
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
int i;
|
|
|
|
GLOBAL_SYMBOL *gp;
|
2009-05-25 23:51:48 +02:00
|
|
|
CLASS *cp = DEBUG_info.cp;
|
|
|
|
void *op = DEBUG_info.op;
|
|
|
|
|
|
|
|
if (!cp || !cp->load)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(_out, "S: ");
|
|
|
|
|
|
|
|
for (i = 0; i < cp->load->n_global; i++)
|
|
|
|
{
|
|
|
|
gp = &cp->load->global[i];
|
|
|
|
print_symbol(gp, TRUE, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(_out, "s: ");
|
|
|
|
|
|
|
|
for (i = 0; i < cp->load->n_global; i++)
|
|
|
|
{
|
|
|
|
gp = &cp->load->global[i];
|
|
|
|
print_symbol(gp, TRUE, FALSE);
|
|
|
|
}
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (op)
|
|
|
|
{
|
|
|
|
fprintf(_out, "D: ");
|
2009-05-25 23:51:48 +02:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
for (i = 0; i < cp->load->n_global; i++)
|
|
|
|
{
|
|
|
|
gp = &cp->load->global[i];
|
|
|
|
print_symbol(gp, FALSE, TRUE);
|
|
|
|
}
|
2009-05-25 23:51:48 +02:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
fprintf(_out, "d: ");
|
2009-05-25 23:51:48 +02:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
for (i = 0; i < cp->load->n_global; i++)
|
|
|
|
{
|
|
|
|
gp = &cp->load->global[i];
|
|
|
|
print_symbol(gp, FALSE, FALSE);
|
|
|
|
}
|
|
|
|
}
|
2009-05-25 23:51:48 +02:00
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static void command_quit(const char *cmd)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
exit(1);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void command_go(const char *cmd)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
GB.Component.Signal(GB_SIGNAL_DEBUG_CONTINUE, 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
DEBUG_info.stop = FALSE;
|
|
|
|
DEBUG_info.leave = FALSE;
|
|
|
|
DEBUG_info.fp = NULL;
|
|
|
|
DEBUG_info.bp = NULL;
|
2013-05-30 03:10:59 +02:00
|
|
|
DEBUG_info.pp = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void command_step(const char *cmd)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
GB.Component.Signal(GB_SIGNAL_DEBUG_FORWARD, 0);
|
|
|
|
DEBUG_break_on_next_line();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void command_next(const char *cmd)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
GB.Component.Signal(GB_SIGNAL_DEBUG_FORWARD, 0);
|
|
|
|
DEBUG_info.stop = TRUE;
|
|
|
|
DEBUG_info.leave = FALSE;
|
|
|
|
DEBUG_info.fp = FP;
|
|
|
|
DEBUG_info.bp = BP;
|
2013-05-30 03:10:59 +02:00
|
|
|
DEBUG_info.pp = PP;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void command_from(const char *cmd)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
STACK_CONTEXT *sc = GB_DEBUG.GetStack(0); //STACK_get_current();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (sc && sc->pc)
|
|
|
|
{
|
|
|
|
GB.Component.Signal(GB_SIGNAL_DEBUG_FORWARD, 0);
|
|
|
|
DEBUG_info.stop = TRUE;
|
|
|
|
DEBUG_info.leave = FALSE;
|
|
|
|
DEBUG_info.fp = sc->fp;
|
|
|
|
DEBUG_info.bp = sc->bp;
|
2013-05-30 03:10:59 +02:00
|
|
|
DEBUG_info.pp = sc->pp;
|
2012-05-19 04:55:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GB.Component.Signal(GB_SIGNAL_DEBUG_FORWARD, 0);
|
|
|
|
DEBUG_info.stop = TRUE;
|
|
|
|
DEBUG_info.leave = TRUE;
|
|
|
|
DEBUG_info.fp = FP;
|
|
|
|
DEBUG_info.bp = BP;
|
2013-05-30 03:10:59 +02:00
|
|
|
DEBUG_info.pp = PP;
|
2012-05-19 04:55:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void command_set_breakpoint(const char *cmd)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
char class_name[64];
|
|
|
|
ushort line;
|
|
|
|
//CLASS *class;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (sscanf(cmd, "+%64[^.].%hu", class_name, &line) != 2)
|
|
|
|
WARNING("Cannot set breakpoint: syntax error");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//class = (CLASS *)GB.FindClassLocal(class_name);
|
|
|
|
//CLASS_load_without_init(class);
|
2007-12-30 17:41:49 +01:00
|
|
|
//fprintf(stderr, "command_set_breakpoint: %s %s\n", class->name, class->component ? class->component->name : "?");
|
2012-05-19 04:55:05 +02:00
|
|
|
set_breakpoint((CLASS *)GB_DEBUG.FindClass(class_name), line);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void command_unset_breakpoint(const char *cmd)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
char class_name[64];
|
|
|
|
ushort line;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (sscanf(cmd, "-%64[^.].%hu", class_name, &line) != 2)
|
|
|
|
WARNING("Cannot remove breakpoint: Syntax error");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//class = CLASS_find(class_name);
|
|
|
|
//CLASS_load_without_init(class);
|
|
|
|
unset_breakpoint((CLASS *)GB_DEBUG.FindClass(class_name), line);
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
void DEBUG_backtrace(FILE *out)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
int i, n;
|
|
|
|
STACK_CONTEXT *context;
|
|
|
|
ushort line;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (CP)
|
|
|
|
fprintf(out, "%s", DEBUG_get_current_position());
|
|
|
|
else
|
|
|
|
fprintf(out, "?");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
//for (i = 0; i < (STACK_frame_count - 1); i++)
|
2009-08-01 17:13:50 +02:00
|
|
|
n = 0;
|
2012-05-19 04:55:05 +02:00
|
|
|
for (i = 0;; i++)
|
|
|
|
{
|
|
|
|
context = GB_DEBUG.GetStack(i); //&STACK_frame[i];
|
|
|
|
if (!context)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (context->pc)
|
|
|
|
{
|
|
|
|
line = 0;
|
|
|
|
if (DEBUG_calc_line_from_position(context->cp, context->fp, context->pc, &line))
|
|
|
|
n += fprintf(out, " %s.?.?", context->cp->name);
|
|
|
|
else
|
|
|
|
n += fprintf(out, " %s.%s.%d", context->cp->name, context->fp->debug->name, line);
|
|
|
|
}
|
|
|
|
else if (context->cp)
|
|
|
|
n += fprintf(out, " ?");
|
2009-08-01 17:13:50 +02:00
|
|
|
|
|
|
|
if (n >= (DEBUG_OUTPUT_MAX_SIZE / 2))
|
|
|
|
{
|
|
|
|
fprintf(out, " ...");
|
|
|
|
break;
|
|
|
|
}
|
2012-05-19 04:55:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
static void debug_info()
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2013-07-27 19:23:04 +02:00
|
|
|
fprintf(_out, "*[%d]\t", getpid());
|
2012-05-19 04:55:05 +02:00
|
|
|
|
|
|
|
if (Error)
|
|
|
|
GB_DEBUG.PrintError(_out, TRUE, FALSE);
|
2009-05-25 23:51:48 +02:00
|
|
|
|
|
|
|
fprintf(_out, "\t");
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
DEBUG_backtrace(_out);
|
2009-05-25 23:51:48 +02:00
|
|
|
fprintf(_out, "\t");
|
|
|
|
|
|
|
|
print_local();
|
|
|
|
fprintf(_out, "\t");
|
|
|
|
|
|
|
|
print_object();
|
|
|
|
fprintf(_out, "\n");
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
static void command_frame(const char *cmd)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-05-25 23:51:48 +02:00
|
|
|
int i;
|
|
|
|
int frame;
|
|
|
|
STACK_CONTEXT *context = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
if (cmd)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-05-25 23:51:48 +02:00
|
|
|
frame = atoi(&cmd[1]);
|
|
|
|
//fprintf(_out, "switching to frame %d\n", frame);
|
|
|
|
|
|
|
|
if (frame > 0)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-05-25 23:51:48 +02:00
|
|
|
for (i = 0;; i++)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-05-25 23:51:48 +02:00
|
|
|
context = GB_DEBUG.GetStack(i);
|
|
|
|
if (!context)
|
|
|
|
break;
|
|
|
|
if (!context->pc && !context->cp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
frame--;
|
|
|
|
if (!frame)
|
|
|
|
{
|
|
|
|
DEBUG_info.bp = context->bp;
|
2013-05-30 03:10:59 +02:00
|
|
|
DEBUG_info.pp = context->pp;
|
2009-05-25 23:51:48 +02:00
|
|
|
DEBUG_info.fp = context->fp;
|
|
|
|
DEBUG_info.op = context->op;
|
|
|
|
DEBUG_info.cp = context->cp;
|
|
|
|
break;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
if (!context)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2009-05-25 23:51:48 +02:00
|
|
|
DEBUG_info.bp = BP;
|
2013-05-30 03:10:59 +02:00
|
|
|
DEBUG_info.pp = PP;
|
2009-05-25 23:51:48 +02:00
|
|
|
DEBUG_info.fp = FP;
|
|
|
|
DEBUG_info.op = OP;
|
|
|
|
DEBUG_info.cp = CP;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
debug_info();
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void command_eval(const char *cmd)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
EXPRESSION *expr;
|
|
|
|
ERROR_INFO save_error = { 0 };
|
|
|
|
ERROR_INFO save_last = { 0 };
|
|
|
|
DEBUG_INFO save_debug;
|
|
|
|
VALUE *val;
|
|
|
|
int start, len;
|
|
|
|
FILE *out;
|
2009-08-24 16:19:32 +02:00
|
|
|
const char *name;
|
|
|
|
int ret;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-08-24 16:19:32 +02:00
|
|
|
init_eval_interface();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
out = *cmd == '!' ? stdout : _out;
|
|
|
|
|
|
|
|
len = strlen(cmd);
|
|
|
|
for (start = 0; start < len; start++)
|
|
|
|
{
|
|
|
|
if (cmd[start] == '\t')
|
|
|
|
break;
|
|
|
|
if (*cmd != '!')
|
|
|
|
fputc(cmd[start], _out);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start >= len)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (*cmd != '!')
|
|
|
|
fprintf(_out, "\t");
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
GB_DEBUG.SaveError(&save_error, &save_last);
|
|
|
|
save_debug = DEBUG_info;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
start++;
|
|
|
|
EVAL.New(POINTER(&expr), &cmd[start], len - start);
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (EVAL.Compile(expr, *cmd == '='))
|
2011-02-07 02:58:19 +01:00
|
|
|
{
|
|
|
|
if (*cmd != '!')
|
|
|
|
fprintf(_out, "!");
|
|
|
|
fputs(expr->error, out);
|
2012-05-19 04:55:05 +02:00
|
|
|
goto __END;
|
2011-02-07 02:58:19 +01:00
|
|
|
}
|
2009-08-24 16:19:32 +02:00
|
|
|
|
2014-04-05 02:28:41 +02:00
|
|
|
GB_DEBUG.EnterEval();
|
2012-05-19 04:55:05 +02:00
|
|
|
val = (VALUE *)EVAL.Run(expr, GB_DEBUG.GetValue);
|
2014-04-05 02:28:41 +02:00
|
|
|
GB_DEBUG.LeaveEval();
|
2012-05-19 04:55:05 +02:00
|
|
|
if (!val)
|
|
|
|
goto __ERROR;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
switch(*cmd)
|
|
|
|
{
|
|
|
|
case '?':
|
2012-05-19 04:55:05 +02:00
|
|
|
PRINT_value(out, val, TRUE);
|
|
|
|
break;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
case '!':
|
2012-05-19 04:55:05 +02:00
|
|
|
PRINT_value(out, val, FALSE);
|
|
|
|
break;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
case '#':
|
2012-05-19 04:55:05 +02:00
|
|
|
PRINT_object(out, val);
|
|
|
|
break;
|
2009-08-24 16:19:32 +02:00
|
|
|
|
|
|
|
case '=':
|
|
|
|
if (!EVAL.GetAssignmentSymbol(expr, &name, &len))
|
|
|
|
{
|
|
|
|
ret = GB_DEBUG.SetValue(name, len, val);
|
|
|
|
if (ret == GB_DEBUG_SET_ERROR)
|
|
|
|
goto __ERROR;
|
|
|
|
else if (ret == GB_DEBUG_SET_READ_ONLY)
|
|
|
|
{
|
|
|
|
fprintf(out, "!%.*s is read-only", len, name);
|
|
|
|
goto __END;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(out, "OK");
|
|
|
|
break;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
goto __END;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
__ERROR:
|
2009-08-24 16:19:32 +02:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (*cmd != '!')
|
|
|
|
fprintf(out, "!");
|
|
|
|
GB_DEBUG.PrintError(out, TRUE, FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-01-29 17:11:30 +01:00
|
|
|
__END:
|
2009-08-24 16:19:32 +02:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
EVAL.Free(POINTER(&expr));
|
|
|
|
DEBUG_info = save_debug; //.cp = NULL;
|
|
|
|
GB_DEBUG.RestoreError(&save_error, &save_last);
|
|
|
|
|
2009-08-24 16:19:32 +02:00
|
|
|
fprintf(out, "\n");
|
|
|
|
fflush(out);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2009-08-24 16:19:32 +02:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
static void command_symbol(const char *cmd)
|
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
int start, len;
|
|
|
|
DEBUG_INFO save_debug = DEBUG_info;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
len = strlen(cmd);
|
|
|
|
for (start = 0; start < len; start++)
|
|
|
|
{
|
|
|
|
if (cmd[start] == '\t')
|
|
|
|
break;
|
2012-05-19 04:55:05 +02:00
|
|
|
fputc(cmd[start], _out);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (start >= len)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(_out, "\t");
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
/*DEBUG_info.bp = BP;
|
|
|
|
DEBUG_info.fp = FP;
|
|
|
|
DEBUG_info.op = OP;
|
|
|
|
DEBUG_info.cp = CP;*/
|
2012-05-19 04:55:05 +02:00
|
|
|
|
|
|
|
start++;
|
|
|
|
PRINT_symbol(_out, &cmd[start], len - start);
|
|
|
|
|
|
|
|
fprintf(_out, "\n");
|
|
|
|
fflush(_out);
|
|
|
|
|
|
|
|
DEBUG_info = save_debug;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-18 12:21:01 +01:00
|
|
|
static void command_break_on_error(const char *cmd)
|
|
|
|
{
|
|
|
|
GB_DEBUG.BreakOnError(cmd[1] == '+');
|
|
|
|
}
|
|
|
|
|
2011-05-16 04:16:22 +02:00
|
|
|
void DEBUG_main(bool error)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
static DEBUG_TYPE last_command = TC_NONE;
|
|
|
|
|
|
|
|
static DEBUG_COMMAND Command[] =
|
|
|
|
{
|
|
|
|
{ "q", TC_NONE, command_quit, FALSE },
|
|
|
|
{ "n", TC_NEXT, command_next, FALSE },
|
|
|
|
{ "s", TC_STEP, command_step, FALSE },
|
|
|
|
{ "f", TC_FROM, command_from, FALSE },
|
|
|
|
{ "g", TC_GO, command_go, FALSE },
|
|
|
|
{ "+", TC_NONE, command_set_breakpoint, TRUE },
|
|
|
|
{ "-", TC_NONE, command_unset_breakpoint, TRUE },
|
|
|
|
{ "&", TC_NONE, command_symbol, TRUE },
|
|
|
|
{ "?", TC_NONE, command_eval, TRUE },
|
|
|
|
{ "!", TC_NONE, command_eval, TRUE },
|
|
|
|
{ "#", TC_NONE, command_eval, TRUE },
|
|
|
|
{ "=", TC_NONE, command_eval, TRUE },
|
|
|
|
{ "@", TC_NONE, command_frame, TRUE },
|
2013-12-18 12:21:01 +01:00
|
|
|
{ "b", TC_NONE, command_break_on_error, TRUE },
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2013-07-27 19:23:04 +02:00
|
|
|
static bool first = TRUE;
|
2012-05-19 04:55:05 +02:00
|
|
|
char *cmd = NULL;
|
|
|
|
char cmdbuf[64];
|
|
|
|
int len;
|
|
|
|
DEBUG_COMMAND *tc = NULL;
|
|
|
|
/*static int cpt = 0;*/
|
|
|
|
|
|
|
|
Error = error;
|
|
|
|
|
2013-07-27 19:23:04 +02:00
|
|
|
fflush(_out);
|
2012-05-19 04:55:05 +02:00
|
|
|
|
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "DEBUG_main {\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (_fifo)
|
2013-07-27 19:23:04 +02:00
|
|
|
{
|
|
|
|
fprintf(_out, first ? "!!\n" : "!\n");
|
|
|
|
first = FALSE;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
command_frame(NULL);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
/*if (CP == NULL)
|
|
|
|
printf("[]:");
|
|
|
|
else
|
|
|
|
printf("[%s%s]:", DEBUG_get_current_position(), Error ? "*" : "");*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-08 17:32:33 +02:00
|
|
|
GB.Component.Signal(GB_SIGNAL_DEBUG_BREAK, 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (!_fifo)
|
|
|
|
{
|
|
|
|
fprintf(_out, "> ");
|
2013-07-27 19:23:04 +02:00
|
|
|
fflush(_out);
|
2012-05-19 04:55:05 +02:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
GB.FreeString(&cmd);
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
*cmdbuf = 0;
|
2011-02-24 16:41:38 +01:00
|
|
|
errno = 0;
|
2012-05-19 04:55:05 +02:00
|
|
|
if (fgets(cmdbuf, sizeof(cmdbuf), _in) == NULL && errno != EINTR)
|
|
|
|
break;
|
|
|
|
if (!*cmdbuf)
|
|
|
|
continue;
|
2011-09-07 21:43:11 +02:00
|
|
|
cmd = GB.AddString(cmd, cmdbuf, 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
if (cmd[GB.StringLength(cmd) - 1] == '\n')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
len = GB.StringLength(cmd);
|
|
|
|
|
|
|
|
// A null string command means an I/O error
|
|
|
|
if (len == 0)
|
2009-07-26 14:38:20 +02:00
|
|
|
{
|
2011-02-24 16:41:38 +01:00
|
|
|
fprintf(stderr, "warning: debugger I/O error: %s\n", strerror(errno));
|
2009-07-26 14:38:20 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2008-12-28 20:01:39 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (len > 0 && cmd[len - 1] == '\n')
|
|
|
|
{
|
|
|
|
len--;
|
|
|
|
cmd[len] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "--> %s\n", cmd);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
if (last_command == TC_NONE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (tc = Command; tc->pattern; tc++)
|
|
|
|
{
|
|
|
|
if (tc->type == last_command)
|
|
|
|
{
|
|
|
|
(*tc->func)(cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (tc = Command; tc->pattern; tc++)
|
|
|
|
{
|
|
|
|
if (strncasecmp(tc->pattern, cmd, strlen(tc->pattern)) == 0)
|
|
|
|
{
|
|
|
|
if (tc->type != TC_NONE)
|
|
|
|
last_command = tc->type;
|
|
|
|
(*tc->func)(cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tc->pattern == NULL)
|
|
|
|
WARNING("Unknown command: %s", cmd);
|
|
|
|
|
|
|
|
fflush(_out);
|
|
|
|
}
|
|
|
|
while (last_command == TC_NONE || tc->pattern == NULL || tc->loop);
|
|
|
|
|
|
|
|
GB.FreeString(&cmd);
|
|
|
|
|
|
|
|
#ifdef DEBUG_ME
|
|
|
|
fprintf(stderr, "} DEBUG_main\n");
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
void DEBUG_breakpoint(int id)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
DEBUG_main(FALSE);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
const char *DEBUG_get_position(CLASS *cp, FUNCTION *fp, PCODE *pc)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
if (pc)
|
|
|
|
{
|
|
|
|
ushort line = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
if (fp != NULL && fp->debug)
|
|
|
|
DEBUG_calc_line_from_position(cp, fp, pc, &line);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
snprintf(DEBUG_buffer, sizeof(DEBUG_buffer), "%.64s.%.64s.%d",
|
|
|
|
cp ? cp->name : "?",
|
|
|
|
(fp && fp->debug) ? fp->debug->name : "?",
|
|
|
|
line);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(DEBUG_buffer, sizeof(DEBUG_buffer), "%.64s.%.64s",
|
|
|
|
cp ? cp->name : "?",
|
|
|
|
(fp && fp->debug) ? fp->debug->name : "?");
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-05-19 04:55:05 +02:00
|
|
|
return DEBUG_buffer;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
2012-07-17 18:24:48 +02:00
|
|
|
const char *DEBUG_get_profile_position(CLASS *cp, FUNCTION *fp, PCODE *pc)
|
|
|
|
{
|
|
|
|
static uint prof_index = 0;
|
|
|
|
const char *name;
|
|
|
|
const char *func;
|
|
|
|
char buffer[16], buffer2[16];
|
|
|
|
|
2012-08-18 15:06:58 +02:00
|
|
|
func = "?";
|
|
|
|
|
2012-07-17 18:24:48 +02:00
|
|
|
if (cp)
|
|
|
|
{
|
2012-08-18 15:06:58 +02:00
|
|
|
if (cp->load && cp->load->prof)
|
2012-07-17 18:24:48 +02:00
|
|
|
{
|
|
|
|
if (cp->load->prof[0] == 0)
|
|
|
|
{
|
|
|
|
prof_index++;
|
|
|
|
cp->load->prof[0] = prof_index;
|
|
|
|
name = cp->name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(buffer, "%u", cp->load->prof[0]);
|
|
|
|
name = buffer;
|
|
|
|
}
|
2012-08-18 15:06:58 +02:00
|
|
|
|
|
|
|
if (fp && fp->debug)
|
|
|
|
{
|
|
|
|
int i = fp->debug->index + 1;
|
|
|
|
if (cp->load->prof[i] == 0)
|
|
|
|
{
|
|
|
|
prof_index++;
|
|
|
|
cp->load->prof[i] = prof_index;
|
|
|
|
func = fp->debug->name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(buffer2, "%u", cp->load->prof[i]);
|
|
|
|
func = buffer2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
func = "?";
|
2012-07-17 18:24:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
name = cp->name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
name = "?";
|
|
|
|
|
|
|
|
if (pc)
|
|
|
|
{
|
|
|
|
ushort line = 0;
|
|
|
|
|
|
|
|
if (fp != NULL && fp->debug)
|
|
|
|
DEBUG_calc_line_from_position(cp, fp, pc, &line);
|
|
|
|
|
|
|
|
snprintf(DEBUG_buffer, sizeof(DEBUG_buffer), "%.64s.%.64s.%d", name, func, line);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(DEBUG_buffer, sizeof(DEBUG_buffer), "%.64s.%.64s", name, func);
|
|
|
|
}
|
|
|
|
|
|
|
|
return DEBUG_buffer;
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
const char *DEBUG_get_current_position(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
return DEBUG_get_position(CP, FP, PC);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
void DEBUG_where(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
fprintf(_out ? _out : stderr, "%s: ", DEBUG_get_current_position());
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 23:51:48 +02:00
|
|
|
void DEBUG_welcome(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2012-05-19 04:55:05 +02:00
|
|
|
if (!_fifo)
|
|
|
|
fprintf(_out, DEBUG_WELCOME);
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|