Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 18, 2012
@nbrown If at the end of the script file, close the script file 4011719
@nbrown Add logic to get a script filename from the commandline
Search argv for "-s" and if it's found load the next arg as the debugger
script filename.
6544c88
@nbrown Print the debugger command if it's from a script c03af38
@nbrown Add make target m0_c_debugger_tests
Add a make target to run the cm0 debugger tests and add 1 simple test.
f6adcdb
View
7 config/gen/makefiles/root.in
@@ -790,6 +790,7 @@ help :
@echo " m0_debug: Build only M0, with debugging
@echo " m0_tests: Run known-good M0 tests."
@echo " m0_c_tests: Run known-good M0 tests with C implementation."
+ @echo " m0_c_debugger_tests: Run known-good M0 debugger tests with C implementation."
@echo " m0_cover: Generate code coverage of m0 with Devel::Cover
@echo " moretests: Run standard suite, examples and most coding standards tests."
@echo ""
@@ -2102,6 +2103,8 @@ M0_TEST_FILES = \
t/m0/m0_assembler.t \
t/m0/m0_run_hello_m0b.t \
t/m0/m0_integration.t
+M0_DEBUGGER_TEST_FILES = \
+ t/m0/m0_debugger.t
INTEROP_TEST_FILES = \
t/pir/interop.t
HEADERIZER_TEST_FILES = $(TOOLS_TESTS_DIR)/dev/headerizer/*.t
@@ -2326,6 +2329,10 @@ m0_c_tests :
#IF(win32): set M0_INTERP=.\src\m0\c\m0$(EXE) && $(PERL) t/harness $(M0_TEST_FILES)
#UNLESS(win32): M0_INTERP=./src/m0/c/m0$(EXE) $(PERL) t/harness $(M0_TEST_FILES)
+m0_c_debugger_tests :
+#IF(win32): set M0_INTERP=.\src\m0\c\m0-debugger$(EXE) && $(PERL) t/harness $(M0_DEBUGGER_TEST_FILES)
+#UNLESS(win32): M0_INTERP=./src/m0/c/m0-debugger$(EXE) $(PERL) t/harness $(M0_DEBUGGER_TEST_FILES)
+
m0_cover :
PERL5OPT=-MDevel::Cover $(MAKE) m0_tests
cover
View
3  src/m0/c/include/m0_debugger.h
@@ -2,6 +2,7 @@
typedef enum {
+ INIT,
STEP,
RUN,
BREAK
@@ -30,7 +31,7 @@ typedef enum {
Help
} M0_Debugger_Command;
-void debugger(M0_CallFrame *cf, const unsigned char *ops, const unsigned long pc);
+void debugger(int argc, const char* argv[], M0_Interp *interp, M0_CallFrame *cf, const unsigned char *ops, const unsigned long pc);
# define M0_DEBUGGER_H 1
View
32 src/m0/c/m0_debugger.c
@@ -385,12 +385,18 @@ get_db_user_input(M0_Debugger_Info *db_info, M0_Debugger_Command *cmd, char *arg
p = get_line(input, 100, pFile);
if(db_info->input_source != NULL) {
- if(!feof(pFile))
+ if(feof(pFile)) {
fclose(pFile);
+ return NULL;
+ }
}
if (p) {
char *tok = NULL;
+
+ if(db_info->input_source != NULL)
+ printf("%s\n", input);
+
tok = strtok(input, " ");
if(tok)
*cmd = str_to_db_cmd(tok);
@@ -558,11 +564,33 @@ check_breakpoints(const unsigned long pc) {
return 0;
}
+static void
+parse_argv(M0_Debugger_Info *db_info, int argc, const char* argv[])
+{
+ if(argc > 2) {
+ int i = 2;
+ while(i < argc) {
+ if(strcmp("-s",argv[i]) == 0) {
+ size_t size = strlen(argv[++i]);
+ db_info->input_source = malloc((size+1)*sizeof(char));
+ strcpy(db_info->input_source, argv[i]);
+ }
+ i++;
+ }
+ }
+ db_info->state = STEP;
+}
+
void
-debugger(M0_CallFrame *cf, const unsigned char *ops, const unsigned long pc)
+debugger(int argc, const char* argv[], M0_Interp *interp, M0_CallFrame *cf, const unsigned char *ops, const unsigned long pc)
{
static M0_Debugger_Info db_info;
+ UNUSED(interp);
+
switch (db_info.state) {
+ case INIT:
+ parse_argv(&db_info, argc, argv);
+ break;
case STEP:
db_prompt(&db_info, cf, ops, pc);
break;
View
3  src/m0/c/m0_interp.c
@@ -41,6 +41,9 @@ main( int argc, const char *argv[]) {
if (!interp)
exit(1);
+#ifdef M0_DEBUGGER
+ debugger(argc, argv, interp, NULL, NULL, -1);
+#endif
(*interp)[ARGC] = argc - 1;
interp_argv = (uint64_t*) malloc((argc-1) * sizeof(uint64_t));
View
2  src/m0/c/m0_ops.c
@@ -333,7 +333,7 @@ run_ops( M0_Interp *interp, M0_CallFrame *cf ) {
const unsigned long op_count = bytecode->op_count;
#ifdef M0_DEBUGGER
- debugger(cf, ops, pc);
+ debugger(0, NULL, interp, cf, ops, pc);
#endif
/* XXX: access violation -- so produce an error? */
View
10 t/m0/debugger/01_simple.in
@@ -0,0 +1,10 @@
+l
+s
+l
+s
+ps S00
+l
+s
+l
+s
+s
View
17 t/m0/debugger/01_simple.out
@@ -0,0 +1,17 @@
+PC=0> l
+M0_SET_IMM I00,0,0
+PC=0> s
+PC=1> l
+M0_DEREF S00,CONSTS,I00
+PC=1> s
+PC=2> ps S00
+hello world
+
+PC=2> l
+M0_SET_IMM I00,0,0
+PC=2> s
+PC=3> l
+M0_PRINT_S I00,S00,CF
+PC=3> s
+hello world
+PC=4> s
View
65 t/m0/m0_debugger.t
@@ -0,0 +1,65 @@
+#! perl
+# Copyright (C) 2012, Parrot Foundation.
+
+=head1 NAME
+
+t/tools/m0_debugger.t - M0 debugger tests
+
+=head1 SYNOPSIS
+
+ % prove t/m0/m0_debugger.t
+
+=head1 DESCRIPTION
+
+Tests the M0 debugger and interpreter with the files in
+t/m0/debugger/ .
+
+=cut
+
+use strict;
+use warnings;
+use File::Slurp qw/slurp/;
+#use Carp::Always;
+
+use Test::More;
+use File::Spec::Functions;
+use TAP::Parser;
+use Data::Dumper;
+
+my $m0b_file = glob catfile( '.', qw/t m0 basic hello_canon.m0b/);
+
+plan tests => 1;
+
+output_like(
+ $m0b_file,
+ catfile( '.', qw/t m0 debugger 01_simple.in/),
+ catfile( '.', qw/t m0 debugger 01_simple.out/),
+ 'simple debugger test',
+);
+
+
+sub output_like {
+ my ($m0b_file, $script_file, $out_file, $desc) = @_;
+
+ my $interp = $ENV{M0_DEBUG_INTERP} || catfile( ".", qw/src m0 c m0-debugger.exe/ );
+ my $args = join(' ', ('-s', $script_file) );
+
+ diag "$interp ${m0b_file} $args 2>&1\n" if $ENV{DEBUG};
+ my $out = `$interp ${m0b_file} $args 2>&1`;
+ my $snippet = slurp $out_file;
+
+ is($out, $snippet, $desc);
+
+ return;
+}
+
+END {
+ unless ($ENV{POSTMORTEM}) {
+ }
+}
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

No commit comments for this range

Something went wrong with that request. Please try again.