gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r18581 - monkey/src/monkey


From: gnunet
Subject: [GNUnet-SVN] r18581 - monkey/src/monkey
Date: Tue, 13 Dec 2011 18:02:57 +0100

Author: safey
Date: 2011-12-13 18:02:57 +0100 (Tue, 13 Dec 2011)
New Revision: 18581

Added:
   monkey/src/monkey/bug_bug_assertion_failure.db
Modified:
   monkey/src/monkey/action_api.c
   monkey/src/monkey/bug_division_by_zero_loop.c
   monkey/src/monkey/bug_division_by_zero_loop.db
   monkey/src/monkey/edb_api.c
   monkey/src/monkey/gnunet-monkey.c
   monkey/src/monkey/gnunet_monkey_action.h
   monkey/src/monkey/gnunet_monkey_edb.h
Log:
Monkey now is supports analyzing expressions in nested scopes. Levels of nested 
scopes (How many scopes should Monkey look outside the expression's scope) are 
currently specified by a preprocessing directive

Modified: monkey/src/monkey/action_api.c
===================================================================
--- monkey/src/monkey/action_api.c      2011-12-13 17:01:09 UTC (rev 18580)
+++ monkey/src/monkey/action_api.c      2011-12-13 17:02:57 UTC (rev 18581)
@@ -41,8 +41,19 @@
 static struct Expression *faultyExpression = NULL;
 static struct FileName *fileNameListHead = NULL;
 static struct FileName *fileNameListTail = NULL;
+static struct ScopeEnd *scopeEndListHead = NULL;
+static struct ScopeEnd *scopeEndListTail = NULL;
 
 
+struct ScopeEnd
+{
+       struct ScopeEnd *next;
+       struct ScopeEnd *prev;
+
+       int lineNo;
+};
+
+
 struct FileName
 {
   struct FileNames *next;
@@ -286,7 +297,39 @@
 }
 
 
+
+
 static int
+outerScopesCallback (void *cls, int numColumns, char **colValues,
+               char **colNames)
+{
+       if (NULL == colValues[0])
+               return 1; /* Error */
+
+       struct ScopeEnd *scopeEnd = GNUNET_malloc(sizeof(struct ScopeEnd));
+       scopeEnd->lineNo = atoi(colValues[0]);
+       GNUNET_CONTAINER_DLL_insert (scopeEndListHead, scopeEndListTail,
+                                                scopeEnd);
+       return 0; /* OK */
+}
+
+
+static int
+functionStartCallback (void *cls, int numColumns, char **colValues,
+               char **colNames)
+{
+       struct GNUNET_MONKEY_ACTION_Context *cntxt =
+                       (struct GNUNET_MONKEY_ACTION_Context *) cls;
+
+       if (NULL == colValues[0])
+               return 1; /* Error */
+
+       cntxt->function_start_line = atoi(colValues[0]);
+       return 0; /* OK */
+}
+
+
+static int
 iterateExpressions (void *cls, int numColumns, char **colValues,
                    char **colNames)
 {
@@ -445,10 +488,35 @@
                                                    cntxt->gdb_frames->line,
                                                    &scopeEndCallback,
                                                    &endScope);
-  if (endScope < 0)
+  if (endScope <= 0)
     return GNUNET_NO;
 
+#if EXPRESSION_EVALUATION_DEPTH
+  struct ScopeEnd *scopeEndPtr;
+  int index = 1;
 
+  cntxt->scope_depth = EXPRESSION_EVALUATION_DEPTH;
+  ret = GNUNET_MONKEY_EDB_function_start_line_for_scope(edbCntxt, 
cntxt->gdb_frames->file,
+               endScope,
+               &functionStartCallback, cntxt);
+  if (ret == GNUNET_NO || cntxt->function_start_line <= 0)
+         return GNUNET_NO;
+
+  ret = GNUNET_MONKEY_EDB_get_all_outer_scopes(edbCntxt, 
cntxt->gdb_frames->file,
+               cntxt->function_start_line,
+               cntxt->gdb_frames->line,
+               endScope,
+               &outerScopesCallback, NULL);
+  if (ret == GNUNET_NO)
+         return GNUNET_NO;
+  if (NULL != scopeEndListHead) {
+         scopeEndPtr = scopeEndListHead;
+         while (index < cntxt->scope_depth && NULL != scopeEndPtr)
+                 scopeEndPtr = scopeEndPtr->next;
+         endScope = scopeEndPtr->lineNo;
+  }
+#endif
+
   if (strcasecmp (signalMeaning, "Segmentation fault") == 0)
     {
       cntxt->bug_detected = BUG_NULL_POINTER;
@@ -461,20 +529,38 @@
   else if (strcasecmp (signalMeaning, "Aborted") == 0)
     {
       cntxt->bug_detected = BUG_CUSTOM;
+      /*
       GNUNET_MONKEY_EDB_get_sub_expressions (edbCntxt,
                                             cntxt->gdb_frames->file,
                                             cntxt->gdb_frames->line,
                                             endScope, &iterateExpressions,
                                             NULL);
+                                            */
+      GNUNET_MONKEY_EDB_get_expressions (edbCntxt,
+                                        cntxt->gdb_frames->file,
+                                        cntxt->gdb_frames->line, endScope,
+                                        &iterateExpressions, NULL);
       ret = analyzeCustomFault (cntxt);
     }
   else if (strcasecmp(signalMeaning, "Arithmetic exception") == 0) {
          cntxt->bug_detected = BUG_CUSTOM;
+         /*
          GNUNET_MONKEY_EDB_get_sub_expressions (edbCntxt,
                                                     cntxt->gdb_frames->file,
                                                     cntxt->gdb_frames->line,
                                                     endScope, 
&iterateExpressions,
                                                     NULL);
+                                                    */
+         if (cntxt->scope_depth > 0)
+                 GNUNET_MONKEY_EDB_get_expressions_outer_scopes (edbCntxt,
+                                                                        
cntxt->gdb_frames->file,
+                                                                        
cntxt->gdb_frames->line, endScope,
+                                                                        
&iterateExpressions, NULL);
+         else
+                 GNUNET_MONKEY_EDB_get_expressions (edbCntxt,
+                                                                        
cntxt->gdb_frames->file,
+                                                                        
cntxt->gdb_frames->line, endScope,
+                                                                        
&iterateExpressions, NULL);
          ret = analyzeCustomFault (cntxt);
   }
 
@@ -616,7 +702,7 @@
   for (tmp = head; NULL != tmp;  tmp = tmp->next)
     {
       GNUNET_asprintf (&strTmp,
-                      "%s%s = %s\n", 
+                      "%s%s => %s\n",
                       string,
                       tmp->expressionSyntax,
                       NULL ==
@@ -711,19 +797,32 @@
        {
          if (NULL == cntxt->inspect_expression)
            {
-             /* Assertion Failure */
-             //const char *expToString =
-               //expressionListToString (expressionListHead);
+             /* Assertion Failure or Arithmetic Exception (Division by Zero, 
etc...) */
+           const char *expToString =
+               expressionListToString (expressionListHead);
 
-           GNUNET_asprintf (&(cntxt->debug_report),
-                              "Bug detected in 
file:%s\nfunction:%s\nline:%d\nreceived signal:%s\n%s\nDetails:\nAssertion 
Failure\nExpression evaluation:\n%s\n",
-                              cntxt->gdb_frames->file,
-                              cntxt->gdb_frames->func,
-                              cntxt->gdb_frames->line,
-                              cntxt->gdb_stop_reason->signal_name,
-                              cntxt->gdb_stop_reason->signal_meaning,
-                              "hello/world\n");
+           if (strcasecmp(cntxt->gdb_stop_reason->signal_meaning, "Arithmetic 
exception") == 0) {
+               GNUNET_asprintf (&(cntxt->debug_report),
+                                                          "Bug detected in 
file:%s\nfunction:%s\nline:%d\nreceived signal:%s\n%s\nDetails:\nArithmetic 
Exception: Division by Zero suspected\nExpression evaluation:\n%s\n",
+                                                          
cntxt->gdb_frames->file,
+                                                          
cntxt->gdb_frames->func,
+                                                          
cntxt->gdb_frames->line,
+                                                          
cntxt->gdb_stop_reason->signal_name,
+                                                          
cntxt->gdb_stop_reason->signal_meaning,
+                                                          expToString);
            }
+           else {
+               /* Assertion Failure */
+                       GNUNET_asprintf (&(cntxt->debug_report),
+                                          "Bug detected in 
file:%s\nfunction:%s\nline:%d\nreceived signal:%s\n%s\nDetails:\nAssertion 
Failure\nExpression evaluation:\n%s\n",
+                                          cntxt->gdb_frames->file,
+                                          cntxt->gdb_frames->func,
+                                          cntxt->gdb_frames->line,
+                                          cntxt->gdb_stop_reason->signal_name,
+                                          
cntxt->gdb_stop_reason->signal_meaning,
+                                          expToString);
+           }
+           }
          else
            {
              /* Inspection of user-defined expression */

Added: monkey/src/monkey/bug_bug_assertion_failure.db
===================================================================
Modified: monkey/src/monkey/bug_division_by_zero_loop.c
===================================================================
--- monkey/src/monkey/bug_division_by_zero_loop.c       2011-12-13 17:01:09 UTC 
(rev 18580)
+++ monkey/src/monkey/bug_division_by_zero_loop.c       2011-12-13 17:02:57 UTC 
(rev 18581)
@@ -3,10 +3,9 @@
 int
 main (int argc, char *argv[])
 {
-  int i;
-  int k = -1;
-  int result = 10;
-  int tmp;
+  int i, k, result, tmp;
+  k = -1;
+  result = 10;
 
   printf("I am alive!\n");
   for (i = 0; i < 5; i++)

Modified: monkey/src/monkey/bug_division_by_zero_loop.db
===================================================================
(Binary files differ)

Modified: monkey/src/monkey/edb_api.c
===================================================================
--- monkey/src/monkey/edb_api.c 2011-12-13 17:01:09 UTC (rev 18580)
+++ monkey/src/monkey/edb_api.c 2011-12-13 17:02:57 UTC (rev 18581)
@@ -110,6 +110,75 @@
 }
 
 
+
+int
+GNUNET_MONKEY_EDB_get_all_outer_scopes(struct GNUNET_MONKEY_EDB_Context
+               *cntxt, const char *file_name,
+               int function_beginning,
+               int scope_in_question_start,
+               int scope_in_question_end,
+               GNUNET_MONKEY_ExpressionIterator
+               iter, void *iter_cls)
+{
+         int err;
+         char *errMsg;
+         char *query;
+
+         if (asprintf
+                 (&query,
+                  "select distinct end_lineno from Expression where file_name 
LIKE \'%%/%s\' and start_lineno >= %d and start_lineno < %d and end_lineno > %d 
order by end_lineno",
+                  file_name, function_beginning, scope_in_question_start, 
scope_in_question_end) == -1)
+               {
+                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                         "Memory allocation problem occurred during creating 
database query!\n");
+                 return GNUNET_NO;
+               }
+
+         err = sqlite3_exec (cntxt->db_handle, query, iter, iter_cls, &errMsg);
+         if (err)
+               {
+                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                         "Error occurred while executing Database query. `%s'",
+                         errMsg);
+                 return GNUNET_NO;
+               }
+         return GNUNET_OK;
+}
+
+
+int
+GNUNET_MONKEY_EDB_function_start_line_for_scope(struct 
GNUNET_MONKEY_EDB_Context
+               *cntxt, const char *file_name,
+               int scope_end,
+               GNUNET_MONKEY_ExpressionIterator
+               iter, void *iter_cls)
+{
+         int err;
+         char *errMsg;
+         char *query;
+
+         if (asprintf
+             (&query,
+              "select MIN(start_lineno) from Expression where file_name LIKE 
\'%%/%s\' and end_lineno >= %d",
+              file_name, scope_end) == -1)
+           {
+             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                         "Memory allocation problem occurred during creating 
database query!\n");
+             return GNUNET_NO;
+           }
+
+         err = sqlite3_exec (cntxt->db_handle, query, iter, iter_cls, &errMsg);
+         if (err)
+           {
+             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                         "Error occurred while executing Database query. `%s'",
+                         errMsg);
+             return GNUNET_NO;
+           }
+         return GNUNET_OK;
+}
+
+
 /**
  * Return the line number of the end-of-scope for the expression indicated by 
start_line_no
  *
@@ -153,6 +222,37 @@
 }
 
 
+
+int
+GNUNET_MONKEY_EDB_get_expressions_outer_scopes (struct 
GNUNET_MONKEY_EDB_Context *cntxt,
+                                  const char *file_name, int start_line_no,
+                                  int end_line_no,
+                                  GNUNET_MONKEY_ExpressionIterator iter,
+                                  void *iter_cls) {
+  int err;
+  char *errMsg;
+  char *query;
+  if (asprintf
+         (&query,
+          "select expr_syntax, start_lineno from Expression where file_name 
LIKE \'%%/%s\' and start_lineno <= %d and end_lineno <= %d",
+          file_name, start_line_no, end_line_no) == -1)
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "Memory allocation problem occurred!\n");
+         return GNUNET_NO;
+       }
+
+  err = sqlite3_exec (cntxt->db_handle, query, iter, iter_cls, &errMsg);
+  if (err)
+       {
+         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "Error occurred while executing Database query. `%s'",
+                 errMsg);
+         return GNUNET_NO;
+       }
+  return GNUNET_OK;
+}
+
 /**
  * Run an SQLite query to retrieve those expressions that are previous to
  * given expression and are in the same scope of the given expression

Modified: monkey/src/monkey/gnunet-monkey.c
===================================================================
--- monkey/src/monkey/gnunet-monkey.c   2011-12-13 17:01:09 UTC (rev 18580)
+++ monkey/src/monkey/gnunet-monkey.c   2011-12-13 17:02:57 UTC (rev 18581)
@@ -96,6 +96,8 @@
   cntxt->gdb_binary_path = gdbBinaryPath;
   cntxt->inspect_expression = inspectExpression;
   cntxt->inspect_function = inspectFunction;
+  cntxt->function_start_line = 0;
+  cntxt->scope_depth = 0;
 
   result = GNUNET_MONKEY_ACTION_rerun_with_gdb (cntxt);
   switch (result)

Modified: monkey/src/monkey/gnunet_monkey_action.h
===================================================================
--- monkey/src/monkey/gnunet_monkey_action.h    2011-12-13 17:01:09 UTC (rev 
18580)
+++ monkey/src/monkey/gnunet_monkey_action.h    2011-12-13 17:02:57 UTC (rev 
18581)
@@ -46,6 +46,7 @@
 #define DEBUG_MODE_REPORT_READY 5
 #define BUG_NULL_POINTER 6
 #define BUG_CUSTOM 7
+#define EXPRESSION_EVALUATION_DEPTH 0
 
 
 /**
@@ -65,6 +66,8 @@
 
   /* gdb debugging attributes */
   int run_reverse;
+  int function_start_line;
+  int scope_depth;
   mi_h *gdb_handle;
   const char *gdb_in_use;
   mi_stop *gdb_stop_reason;

Modified: monkey/src/monkey/gnunet_monkey_edb.h
===================================================================
--- monkey/src/monkey/gnunet_monkey_edb.h       2011-12-13 17:01:09 UTC (rev 
18580)
+++ monkey/src/monkey/gnunet_monkey_edb.h       2011-12-13 17:02:57 UTC (rev 
18581)
@@ -63,6 +63,21 @@
 
 
 
+int
+GNUNET_MONKEY_EDB_get_all_outer_scopes(struct GNUNET_MONKEY_EDB_Context
+               *cntxt, const char *file_name,
+               int function_beginning,
+               int scope_in_question_start,
+               int scope_in_question_end,
+               GNUNET_MONKEY_ExpressionIterator
+               iter, void *iter_cls);
+
+int
+GNUNET_MONKEY_EDB_function_start_line_for_scope(struct 
GNUNET_MONKEY_EDB_Context
+               *cntxt, const char *file_name,
+               int scope_end,
+               GNUNET_MONKEY_ExpressionIterator
+               iter, void *iter_cls);
 /**
  * Return the line number of the end-of-scope for the expression indicated by 
start_line_no
  *
@@ -95,6 +110,14 @@
                                  GNUNET_MONKEY_FileIterator iter,
                                  void *iter_cls);
 
+
+int
+GNUNET_MONKEY_EDB_get_expressions_outer_scopes (struct 
GNUNET_MONKEY_EDB_Context *cntxt,
+                                  const char *file_name, int start_line_no,
+                                  int end_line_no,
+                                  GNUNET_MONKEY_ExpressionIterator iter,
+                                  void *iter_cls);
+
 /**
  * Run an SQLite query to retrieve those expressions that are previous to
  * given expression and are in the same scope of the given expression




reply via email to

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