Author: julianalbo
Date: Wed Aug 6 06:18:49 2008
New Revision: 30057
Modified:
trunk/include/parrot/debug.h
trunk/include/parrot/interpreter.h
trunk/src/debug.c
trunk/src/embed.c
trunk/src/interpreter.c
trunk/src/parrot_debugger.c
trunk/src/runops_cores.c
trunk/src/runops_cores.h
Log:
added runloop for debugger and some more debugger changes
Modified: trunk/include/parrot/debug.h
==============================================================================
--- trunk/include/parrot/debug.h (original)
+++ trunk/include/parrot/debug.h Wed Aug 6 06:18:49 2008
@@ -24,7 +24,8 @@
PDB_RUNNING = 1 << 2,
PDB_STOPPED = 1 << 3,
PDB_BREAK = 1 << 4, /* Set only from debug_break */
- PDB_EXIT = 1 << 5
+ PDB_EXIT = 1 << 5,
+ PDB_ENTER = 1 << 6
};
enum {
@@ -166,6 +167,7 @@
opcode_t *cur_opcode;
int state;
Interp *debugee;
+ unsigned long tracing;
} PDB_t;
@@ -182,9 +184,19 @@
__attribute__nonnull__(1);
PARROT_API
+void Parrot_debugger_start(PARROT_INTERP, ARGIN(opcode_t * cur_opcode))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_API
void Parrot_debugger_load(PARROT_INTERP, ARGIN_NULLOK(STRING *filename))
__attribute__nonnull__(1);
+PARROT_API
+void PDB_load_source(PARROT_INTERP, ARGIN(const char *command))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
long PDB_add_label(
ARGMOD(PDB_file_t *file),
ARGIN(const opcode_t *cur_opcode),
@@ -294,10 +306,6 @@
__attribute__nonnull__(1)
__attribute__nonnull__(2);
-void PDB_load_source(PARROT_INTERP, ARGIN(const char *command))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
void PDB_next(PARROT_INTERP, ARGIN_NULLOK(const char *command))
__attribute__nonnull__(1);
Modified: trunk/include/parrot/interpreter.h
==============================================================================
--- trunk/include/parrot/interpreter.h (original)
+++ trunk/include/parrot/interpreter.h Wed Aug 6 06:18:49 2008
@@ -71,7 +71,8 @@
PARROT_CGP_JIT_CORE = 0x16, /* JCP */
PARROT_SWITCH_JIT_CORE = 0x12, /* J P */
PARROT_EXEC_CORE = 0x20, /* TODO Parrot_exec_run variants */
- PARROT_GC_DEBUG_CORE = 0x40 /* run GC before each op */
+ PARROT_GC_DEBUG_CORE = 0x40, /* run GC before each op */
+ PARROT_DEBUGGER_CORE = 0x80 /* used by parrot debugger */
} Parrot_Run_core_t;
/* &end_gen */
Modified: trunk/src/debug.c
==============================================================================
--- trunk/src/debug.c (original)
+++ trunk/src/debug.c Wed Aug 6 06:18:49 2008
@@ -402,19 +402,18 @@
void
Parrot_debugger_init(PARROT_INTERP)
{
- PDB_t *pdb;
- Parrot_Interp debugger;
+ if (! interp->pdb) {
+ PDB_t *pdb = mem_allocate_zeroed_typed(PDB_t);
+ Parrot_Interp debugger = Parrot_new(interp);
+ interp->pdb = pdb;
+ debugger->pdb = pdb;
+ pdb->debugee = interp;
+ }
- if (interp->pdb)
- return;
+ /*PDB_disassemble(interp, NULL);*/
- pdb = mem_allocate_zeroed_typed(PDB_t);
- debugger = Parrot_new(interp);
- interp->pdb = pdb;
- debugger->pdb = pdb;
- pdb->debugee = interp;
- pdb->cur_opcode = interp->code->base.data;
- pdb->state |= PDB_RUNNING;
+ interp->pdb->cur_opcode = interp->code->base.data;
+ interp->pdb->state |= PDB_RUNNING;
}
PARROT_API
@@ -433,6 +432,37 @@
PARROT_API
void
+Parrot_debugger_start(PARROT_INTERP, ARGIN(opcode_t * cur_opcode))
+{
+ /*fprintf(stderr, "Parrot_debugger_start\n");*/
+
+ if (!interp->pdb)
+ Parrot_ex_throw_from_c_args(interp, NULL, 0, "No debugger");
+
+ if (interp->pdb->state & PDB_ENTER) {
+ if (!interp->pdb->file) {
+ /*PDB_disassemble(interp, NULL);*/
+ }
+ interp->pdb->state &= ~PDB_ENTER;
+ }
+
+ interp->pdb->cur_opcode = cur_opcode;
+
+ interp->pdb->state |= PDB_STOPPED;
+
+ while (interp->pdb->state & PDB_STOPPED) {
+ const char * command;
+ PDB_get_command(interp);
+ command = interp->pdb->cur_command;
+
+ PDB_run_command(interp, command);
+ }
+ if (interp->pdb->state & PDB_EXIT)
+ Parrot_exit(interp, 0);
+ }
+
+PARROT_API
+void
Parrot_debugger_break(PARROT_INTERP, ARGIN(opcode_t * cur_opcode))
{
if (!interp->pdb)
@@ -512,6 +542,7 @@
if (pdb->cur_command && *pdb->cur_command)
pdb->last_command = pdb->cur_command;
+ #if 0
/* if the program is stopped and running show the next line to run */
if ((pdb->state & PDB_STOPPED) && (pdb->state & PDB_RUNNING)) {
PDB_line_t *line = pdb->file->line;
@@ -528,6 +559,7 @@
PIO_eprintf(interp, "%c", *(c++));
}
}
+ #endif
i = 0;
@@ -708,6 +740,7 @@
case debug_cmd_q:
case debug_cmd_quit:
pdb->state |= PDB_EXIT;
+ pdb->state &= ~PDB_STOPPED;
break;
case (enum DebugCmd)0:
if (pdb->last_command)
@@ -813,6 +846,10 @@
debugee->pdb->cur_opcode);
DO_OP(pdb->cur_opcode, debugee);
}
+ pdb->tracing = n;
+ pdb->debugee->run_core = PARROT_DEBUGGER_CORE;
+
+ runops_int(pdb->debugee, pdb->debugee->code->base.data - pdb->cur_opcode);
/* we just stopped */
pdb->state |= PDB_STOPPED;
@@ -820,6 +857,8 @@
/* If program ended */
if (!pdb->cur_opcode)
(void)PDB_program_end(interp);
+ pdb->state |= PDB_RUNNING;
+ pdb->state &= ~PDB_STOPPED;
}
/*
@@ -1206,8 +1245,27 @@
}
/* Run while no break point is reached */
+ /*
while (!PDB_break(interp))
DO_OP(pdb->cur_opcode, pdb->debugee);
+ */
+
+ #if 0
+ pdb->tracing = 0;
+ pdb->debugee->run_core = PARROT_DEBUGGER_CORE;
+ new_internal_exception(pdb->debugee);
+ if (setjmp(pdb->debugee->exceptions->destination)) {
+ Parrot_eprintf(pdb->debugee, "Unhandled exception while debugging:
%Ss\n",
+ pdb->debugee->exceptions->msg);
+ pdb->state |= PDB_STOPPED;
+ return;
+ }
+ runops_int(pdb->debugee, pdb->debugee->code->base.data - pdb->cur_opcode);
+ if (!pdb->cur_opcode)
+ (void)PDB_program_end(interp);
+ #endif
+ pdb->state |= PDB_RUNNING;
+ pdb->state &= ~PDB_STOPPED;
}
/*
@@ -1707,8 +1765,10 @@
int size = 0;
/* Write the opcode name */
- const char * const p = full_name ? info->full_name : info->name;
- PARROT_ASSERT(p);
+ const char * p = full_name ? info->full_name : info->name;
+
+ if (! p)
+ p= "**UNKNOWN**";
strcpy(dest, p);
size += strlen(p);
@@ -2018,6 +2078,8 @@
pfile->label = NULL;
pfile->size = 0;
pfile->source = (char *)mem_sys_allocate(default_size);
+ pfile->sourcefilename = NULL;
+ pfile->next = NULL;
pline->source_offset = 0;
alloced = space = default_size;
@@ -2188,12 +2250,13 @@
*/
+PARROT_API
void
PDB_load_source(PARROT_INTERP, ARGIN(const char *command))
{
FILE *file;
char f[DEBUG_CMD_BUFFER_LENGTH + 1];
- int i, c;
+ int i, j, c;
PDB_file_t *pfile;
PDB_line_t *pline;
PDB_t * const pdb = interp->pdb;
@@ -2203,11 +2266,13 @@
/* If there was a file already loaded or the bytecode was
disassembled, free it */
if (pdb->file)
- PDB_free_file(interp);
+ PDB_free_file(interp->pdb->debugee);
/* Get the name of the file */
- for (i = 0; command[i]; i++)
- f[i] = command[i];
+ for (j = 0; command[j] == ' '; ++j)
+ continue;
+ for (i = 0; command[j]; i++, j++)
+ f[i] = command[j];
f[i] = '\0';
@@ -2216,7 +2281,7 @@
/* abort if fopen failed */
if (!file) {
- PIO_eprintf(interp, "Unable to load %s\n", f);
+ PIO_eprintf(interp, "Unable to load '%s'\n", f);
return;
}
Modified: trunk/src/embed.c
==============================================================================
--- trunk/src/embed.c (original)
+++ trunk/src/embed.c Wed Aug 6 06:18:49 2008
@@ -976,8 +976,10 @@
PDB_init(debugger, NULL);
/* disassemble needs this for now */
+ /*
interp = pdb->debugee;
interp->pdb = pdb;
+ */
debugger->lo_var_ptr = interp->lo_var_ptr;
PDB_disassemble(interp, NULL);
Modified: trunk/src/interpreter.c
==============================================================================
--- trunk/src/interpreter.c (original)
+++ trunk/src/interpreter.c Wed Aug 6 06:18:49 2008
@@ -398,6 +398,7 @@
case PARROT_SLOW_CORE:
case PARROT_FAST_CORE:
case PARROT_GC_DEBUG_CORE:
+ case PARROT_DEBUGGER_CORE:
init_func = PARROT_CORE_OPLIB_INIT;
break;
default:
@@ -918,6 +919,9 @@
case PARROT_GC_DEBUG_CORE:
core = runops_gc_debug_core;
break;
+ case PARROT_DEBUGGER_CORE:
+ core = runops_debugger_core;
+ break;
default:
Parrot_ex_throw_from_c_args(interp, NULL,
EXCEPTION_UNIMPLEMENTED,
"ambigious runcore switch used");
Modified: trunk/src/parrot_debugger.c
==============================================================================
--- trunk/src/parrot_debugger.c (original)
+++ trunk/src/parrot_debugger.c Wed Aug 6 06:18:49 2008
@@ -112,6 +112,7 @@
#include "../compilers/imcc/imc.h"
#include "../compilers/imcc/parser.h"
#include "parrot/embed.h"
+#include "parrot/debug.h"
static void PDB_printwelcome(void);
static void PDB_run_code(Parrot_Interp interp, int argc, char *argv[]);
@@ -144,6 +145,7 @@
interp->pdb = pdb;
interp->debugger = debugger;
pdb->debugee = interp;
+ pdb->state = PDB_ENTER;
Parrot_block_GC_mark(interp);
Parrot_block_GC_sweep(interp);
@@ -200,6 +202,7 @@
PDB_printwelcome();
+ interp->run_core = PARROT_DEBUGGER_CORE;
PDB_run_code(interp, argc - 1, argv + 1);
Modified: trunk/src/runops_cores.c
==============================================================================
--- trunk/src/runops_cores.c (original)
+++ trunk/src/runops_cores.c Wed Aug 6 06:18:49 2008
@@ -207,9 +207,10 @@
if (Interp_trace_TEST(interp, PARROT_TRACE_OPS_FLAG))
return runops_trace_core(interp, pc);
-
+#if 0
if (interp->debugger && interp->debugger->pdb)
return Parrot_debug(interp->debugger, pc);
+#endif
while (pc) {
if (pc < code_start || pc >= code_end)
@@ -310,6 +311,57 @@
/*
+=item C<opcode_t * runops_debugger_core>
+
+Used by the debugger, under construction
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+opcode_t *
+runops_debugger_core(PARROT_INTERP, ARGIN(opcode_t *pc))
+{
+ fprintf(stderr, "Enter runops_debugger_core\n");
+
+ PARROT_ASSERT(interp->pdb);
+
+ if (interp->pdb->state & PDB_ENTER) {
+ Parrot_debugger_start(interp, pc);
+ }
+
+ while (pc) {
+ if (pc < interp->code->base.data || pc >= interp->code->base.data +
interp->code->base.size)
+ Parrot_ex_throw_from_c_args(interp, NULL, 1,
+ "attempt to access code outside of current code segment");
+ Parrot_do_dod_run(interp, 0);
+
+ if (interp->pdb->tracing) {
+ trace_op(interp,
+ interp->code->base.data,
+ interp->code->base.data +
+ interp->code->base.size,
+ interp->pdb->cur_opcode);
+ }
+
+ CONTEXT(interp)->current_pc = pc;
+
+ DO_OP(pc, interp);
+ interp->pdb->cur_opcode = pc;
+ if (interp->pdb->tracing) {
+ if (--interp->pdb->tracing == 0) {
+ Parrot_debugger_start(interp, pc);
+ }
+ }
+ }
+
+ return pc;
+}
+
+/*
+
=back
*/
Modified: trunk/src/runops_cores.h
==============================================================================
--- trunk/src/runops_cores.h (original)
+++ trunk/src/runops_cores.h Wed Aug 6 06:18:49 2008
@@ -27,6 +27,12 @@
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
+opcode_t * runops_debugger_core(PARROT_INTERP, ARGIN(opcode_t *pc))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
opcode_t * runops_fast_core(PARROT_INTERP, ARGIN(opcode_t *pc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);