gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r20487 - monkey/branches/MonkeyBacktracking/monkey/src/monk


From: gnunet
Subject: [GNUnet-SVN] r20487 - monkey/branches/MonkeyBacktracking/monkey/src/monkey
Date: Tue, 13 Mar 2012 23:52:13 +0100

Author: safey
Date: 2012-03-13 23:52:13 +0100 (Tue, 13 Mar 2012)
New Revision: 20487

Modified:
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi.h
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_prg_control.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h
Log:
Backtracking proof of concept: Monkey is able to run a program backwards.

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c   
2012-03-13 18:48:00 UTC (rev 20486)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c   
2012-03-13 22:52:13 UTC (rev 20487)
@@ -142,6 +142,7 @@
 static int
 wait_for_stop (struct MONKEY_ACTION_Context *cntxt)
 {
+       static int safetyCount = 0;
   while (!mi_get_response (cntxt->gdb_handle))
     usleep (1000);
   /* The end of the async. */
@@ -157,16 +158,16 @@
          {
            /* We want to inspect an expression */
            /* Set hardware watch at the expression to inspect */
-           mi_wp *wp =
-             gmi_break_watch (cntxt->gdb_handle, wm_write,
-                              cntxt->inspect_expression);
-           if (NULL == wp)
-             {
-               printf ("Error in setting a watchpoint at expression:%s\n",
-                       cntxt->inspect_expression);
-               return GDB_STATE_ERROR;
-             }
-           mi_free_wp (wp);
+//         mi_wp *wp =
+//           gmi_break_watch (cntxt->gdb_handle, wm_write,
+//                            cntxt->inspect_expression);
+//         if (NULL == wp)
+//           {
+//             printf ("Error in setting a watchpoint at expression:%s\n",
+//                     cntxt->inspect_expression);
+//             return GDB_STATE_ERROR;
+//           }
+//         mi_free_wp (wp);
            /* continue execution */
            gmi_exec_continue (cntxt->gdb_handle);
            return wait_for_stop (cntxt);
@@ -195,6 +196,12 @@
        }
 
       /* Reaching this line means that the program has stopped abnormally */
+      if (MONKEY_NO != gmi_exec_step_back(cntxt->gdb_handle)) {
+         printf("Hurray Reverse Execution!\n");
+      }
+      else {
+         printf("Bad Luck Reverse Execution!\n");
+      }
 
       cntxt->gdb_frames = gmi_stack_info_frame (cntxt->gdb_handle);
       if (NULL == cntxt->gdb_frames)
@@ -235,6 +242,16 @@
 
       return GDB_STATE_STOPPED;
     }
+  else if ((MONKEY_YES == cntxt->run_reverse) && (safetyCount < 
GDB_SAFETY_COUNT)) { // GDB_SAFETY_COUNT prevents infinite analysis
+         /* If the stop reason is NULL, don't bail out immediately, wait for 
stop again.
+          * It happens when a breakpoint is placed (for backtracking) that the 
program stops for an unknown reason,
+          * resulting in a NULL stop reason which causes Monkey to bail out 
before finishing its analysis. This else if
+          * clause prevents premature bail out
+          */
+         safetyCount++;
+         wait_for_stop(cntxt);
+  }
+
   return GDB_STATE_ERROR;
 }
 
@@ -785,6 +802,23 @@
       return MONKEY_NO;
     }
 
+
+  if (MONKEY_YES == cntxt->run_reverse) {
+         /* If Backtracking is enabled, we must set a breakpoint at the main 
function, starting the program, then starting recording */
+        mi_bkpt *bp =
+       gmi_break_insert_full (cntxt->gdb_handle, 0, 0, NULL, -1, -1,
+                                  "main");
+         if (NULL == bp)
+       {
+         printf ("Error setting breakpoint at function:%s\n",
+                 cntxt->inspect_function);
+         mi_disconnect (cntxt->gdb_handle);
+         return MONKEY_NO;
+       }
+         mi_free_bkpt (bp);
+  }
+
+
   if ((NULL != cntxt->inspect_expression)
       && (NULL != cntxt->inspect_function))
     {
@@ -827,6 +861,16 @@
       mi_disconnect (cntxt->gdb_handle);
       return MONKEY_NO;
     }
+
+  /* Backtracking is issued after running the program */
+       if (MONKEY_YES == cntxt->run_reverse) {
+         if (!gmi_exec_record_process(cntxt->gdb_handle)) {
+                 printf ("Error enabling Backtracking!\n");
+                 mi_disconnect(cntxt->gdb_handle);
+                 return MONKEY_NO;
+         }
+       }
+
   /* Here we should be stopped when the program crashes */
   ret = wait_for_stop (cntxt);
   if (ret == GDB_STATE_ERROR || ret == GDB_STATE_EXIT_NORMALLY)

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi.h
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi.h        
2012-03-13 18:48:00 UTC (rev 20486)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi.h        
2012-03-13 22:52:13 UTC (rev 20487)
@@ -565,6 +565,8 @@
 int gmi_exec_interrupt(mi_h *h);
 /* Next line of code. */
 int gmi_exec_next(mi_h *h);
+/* Start recording a process */
+int gmi_exec_record_process(mi_h *h);
 /* Next count lines of code. */
 int gmi_exec_next_cnt(mi_h *h, int count);
 /* Next line of assembler code. */

Modified: 
monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_prg_control.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_prg_control.c    
2012-03-13 18:48:00 UTC (rev 20486)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_prg_control.c    
2012-03-13 22:52:13 UTC (rev 20487)
@@ -110,6 +110,11 @@
  mi_send(h,"-exec-interrupt\n");
 }
 
+void mi_exec_record_process(h)
+{
+mi_send(h, "-interpreter-exec console record\n");
+}
+
 void mi_exec_next(mi_h *h, int count)
 {
  if (count>1)
@@ -316,6 +321,22 @@
 /**[txh]********************************************************************
 
   Description:
+  Start recording a process
+
+  Command: -interpreter-exec console record
+  Return: !=0 OK
+
+***************************************************************************/
+int gmi_exec_record_process(mi_h *h)
+{
+       mi_exec_record_process(h);
+       //return mi_res_simple_running(h);
+       return 1;
+}
+
+/**[txh]********************************************************************
+
+  Description:
   Skip count lines of code.
 
   Command: -exec-next count

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c       
2012-03-13 18:48:00 UTC (rev 20486)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c       
2012-03-13 22:52:13 UTC (rev 20487)
@@ -41,6 +41,7 @@
 static char *inspectExpression = NULL;
 static char *inspectFunction = NULL;
 static char *scopeDepth = NULL;
+static int reverseExecutionAllowed = MONKEY_NO;
 static int ret = 0;
 
 /**
@@ -96,6 +97,7 @@
   cntxt->scope_depth = (NULL == scopeDepth) ? 0 : atoi(scopeDepth);
   cntxt->function_start_line = 0;
   cntxt->xml_report_node = NULL;
+  cntxt->run_reverse = reverseExecutionAllowed;
 
   result = MONKEY_ACTION_rerun_with_gdb (cntxt);
   switch (result)
@@ -172,6 +174,7 @@
    printf ("\t-g: gdb: path to gdb binary to use. If not passed, monkey will 
set it to /usr/bin/gdb [optional]\n");
    printf ("\t-l: valgrind: path to valgrind binary. If not passed, monkey 
will set it to /usr/bin/valgrind [optional]\n");
    printf ("\t-p: depth: scope depth. How many scopes should monkey lookup 
expression values outer than the scope in which the problem occurs.\n\t Default 
is 0 which means, monkey is restricted to the scope of the expression in which 
the debugged program stopped [optional]\n");
+   printf ("\t-r: reverse: enables reverse execution. By default it's not 
allowed [optional]\n");
    printf ("\t-h: help: print this help [optional]\n");
    printf ("\t-i: inspect: expression to inspect in the function specified 
after argument f [optional]\n");
    printf ("\t-o: output: path to the debug report generated by monkey.\n\t If 
not provided monkey will save the report in a file named monkey_output in the 
current working directory [optional]\n");
@@ -260,6 +263,10 @@
                 else if (strcmp("-p", argv[i]) == 0) {
                         scopeDepth = MONKEY_strdup(argv[++i]);
                 }
+                else if (strcmp("-r", argv[i]) == 0) {
+                        reverseExecutionAllowed = MONKEY_YES;
+                        i++;
+                }
         }
         if (MONKEY_NO == binaryCheck)
                 printf("Error: missing argument: path to the binary file.\n");

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h        
2012-03-13 18:48:00 UTC (rev 20486)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h        
2012-03-13 22:52:13 UTC (rev 20487)
@@ -23,6 +23,7 @@
 #define GDB_STATE_STOPPED 1
 #define GDB_STATE_EXIT_NORMALLY 2
 #define GDB_STATE_ERROR 3
+#define GDB_SAFETY_COUNT 2
 #define DEBUG_MODE_VALGRIND 4
 #define DEBUG_MODE_REPORT_READY 5
 #define BUG_NULL_POINTER 6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]