Permalink
Browse files

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.
  • Loading branch information...
1 parent 4011719 commit 6544c8828172dca4f04b1cdc168ea956b7a94e3e @nbrown nbrown committed May 18, 2012
Showing with 29 additions and 3 deletions.
  1. +2 −1 src/m0/c/include/m0_debugger.h
  2. +23 −1 src/m0/c/m0_debugger.c
  3. +3 −0 src/m0/c/m0_interp.c
  4. +1 −1 src/m0/c/m0_ops.c
@@ -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
@@ -560,11 +560,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
@@ -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
@@ -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? */

0 comments on commit 6544c88

Please sign in to comment.