summaryrefslogtreecommitdiffhomepage
path: root/mixutils
diff options
context:
space:
mode:
authorjaortega <jaortega>2000-12-19 00:12:25 +0000
committerjaortega <jaortega>2000-12-19 00:12:25 +0000
commit37bb3b675d3a9bcb492b9a1e1e19860228f8a8ca (patch)
tree43394d37b1cf2133ba508d5e24e0aa9d0a2fbd14 /mixutils
parentb9abc48ed04c21728d77933e69c6e6d007aa326f (diff)
downloadmdk-37bb3b675d3a9bcb492b9a1e1e19860228f8a8ca.tar.gz
mdk-37bb3b675d3a9bcb492b9a1e1e19860228f8a8ca.tar.bz2
added tracing instructions functionality
Diffstat (limited to 'mixutils')
-rw-r--r--mixutils/mixvm_command.c75
1 files changed, 68 insertions, 7 deletions
diff --git a/mixutils/mixvm_command.c b/mixutils/mixvm_command.c
index 53d98e0..3d783e1 100644
--- a/mixutils/mixvm_command.c
+++ b/mixutils/mixvm_command.c
@@ -31,7 +31,7 @@
#include <mixlib/mix_vm.h>
#include <mixlib/mix_vm_dump.h>
-#include "mixlib/mix_eval.h"
+#include <mixlib/mix_eval.h>
#include "mixvm_command.h"
/* The names of functions that actually do the manipulation. */
@@ -63,6 +63,8 @@ DEC_FUN (compile_);
DEC_FUN (edit_);
DEC_FUN (weval_);
DEC_FUN (w2d_);
+DEC_FUN (tron_);
+DEC_FUN (troff_);
DEC_FUN (quit_);
/* A structure which contains information on the commands this program
@@ -111,6 +113,8 @@ COMMAND commands[] = {
{ "weval", cmd_weval_, N_("Evaluate a given W-expres sion"), "weval WEXPR"},
{ "w2d", cmd_w2d_, N_("Convert a MIX word to its decimal value"),
"w2d WORD" },
+ { "tron", cmd_tron_, N_("Turn on instruction tracing."), "tron" },
+ { "troff", cmd_troff_, N_("Turn off instruction tracing."), "troff" },
{ "quit", cmd_quit_, N_("Quit the program"), "quit" },
{ (char *)NULL, (Function *)NULL, (char *)NULL }
};
@@ -187,14 +191,15 @@ find_command_ (const char *name)
return ((COMMAND *)NULL);
}
-
+
/* the virtual machine and dump context */
static mix_vm_t *vm_ = NULL;
static mix_dump_context_t *dc_ = NULL;
-
/* the w-expression evaluator */
static mix_eval_t *eval_ = NULL;
-
+/* trace status */
+static gboolean is_tracing_ = FALSE;
+
static int
cmd_help_ (char *arg)
@@ -258,20 +263,57 @@ cmd_load_ (char *arg)
}
mix_eval_set_symbols_from_table (eval_,
mix_vm_get_symbol_table (vm_));
-
+
fprintf (stderr, _("Program loaded. Start address: %d\n"),
mix_vm_get_prog_count (vm_));
return TRUE;
}
+/* trace current instruction */
+static void
+trace_ ()
+{
+ const mix_src_file_t *file = mix_vm_get_src_file (vm_);
+ const gchar *line = "";
+ gchar *strins;
+ mix_address_t loc = mix_vm_get_prog_count (vm_);
+ mix_word_t ins = mix_vm_get_addr_contents (vm_, loc);
+ mix_ins_t fins;
+ mix_word_to_ins_uncheck (ins, fins);
+ strins = mix_ins_to_string (&fins);
+
+ if (file != NULL)
+ {
+ gulong b = mix_vm_get_break_lineno (vm_);
+ if (b > 0) line = mix_src_file_get_line (file, b);
+ }
+
+ printf ("%d: [%s]\t%s", (gint)loc, strins, line);
+ if (strins != NULL) g_free (strins);
+}
+
+static int
+run_and_trace_ ()
+{
+ int k = MIX_VM_OK;
+ if (!is_tracing_)
+ return mix_vm_run (vm_);
+ else while (k == MIX_VM_OK)
+ {
+ trace_ ();
+ k = mix_vm_exec_next (vm_);
+ }
+ return k;
+}
+
static int
cmd_run_ (char *arg)
{
if (arg != NULL && *arg != '\0' && cmd_load_ (arg) != TRUE)
return TRUE;
puts (_("Running ..."));
- switch (mix_vm_run (vm_))
+ switch (run_and_trace_ ())
{
case MIX_VM_HALT:
puts (_("... done"));
@@ -301,6 +343,8 @@ static int
cmd_next_ (char *arg)
{
int ins_no = 1;
+ int k;
+
if ( strlen (arg) != 0 )
{
int k = 0;
@@ -316,7 +360,8 @@ cmd_next_ (char *arg)
while ( ins_no-- > 0 )
{
- int k = mix_vm_exec_next (vm_);
+ if (is_tracing_) trace_ ();
+ k = mix_vm_exec_next (vm_);
if (k == MIX_VM_HALT)
{
fprintf (stderr, _("End of program reached at address %d\n"),
@@ -928,6 +973,22 @@ cmd_w2d_ (char *arg)
return TRUE;
}
+static int
+cmd_tron_ (char *arg)
+{
+ is_tracing_ = TRUE;
+ printf (_("Instruction tracing has been turned ON.\n"));
+ return TRUE;
+}
+
+static int
+cmd_troff_ (char *arg)
+{
+ is_tracing_ = FALSE;
+ printf (_("Instruction tracing has been turned OFF.\n"));
+ return TRUE;
+}
+
/* external interface */
void