gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r20348 - in monkey/branches/MonkeyBacktracking/monkey/src:


From: gnunet
Subject: [GNUnet-SVN] r20348 - in monkey/branches/MonkeyBacktracking/monkey/src: include monkey util
Date: Wed, 7 Mar 2012 17:58:31 +0100

Author: safey
Date: 2012-03-07 17:58:31 +0100 (Wed, 07 Mar 2012)
New Revision: 20348

Added:
   monkey/branches/MonkeyBacktracking/monkey/src/util/str_replace_all.c
Modified:
   monkey/branches/MonkeyBacktracking/monkey/src/include/monkey_common.h
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h
   monkey/branches/MonkeyBacktracking/monkey/src/monkey/xml_writer.c
   monkey/branches/MonkeyBacktracking/monkey/src/util/Makefile.am
Log:
XML reports generated for Assertion Failures.
XML reports generated for Division By Zero.
Supporting Multiple Scope Depth: Tested for division by zero.
XML Report Writer escapes special characters.

Modified: monkey/branches/MonkeyBacktracking/monkey/src/include/monkey_common.h
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/include/monkey_common.h       
2012-03-07 16:15:06 UTC (rev 20347)
+++ monkey/branches/MonkeyBacktracking/monkey/src/include/monkey_common.h       
2012-03-07 16:58:31 UTC (rev 20348)
@@ -309,6 +309,15 @@
 MONKEY_asprintf (char **buf, const char *format, ...);
 
 
+/**
+ * Replace all occurrences of a substring in a string
+ * @param string target string
+ * @param substr substring to replace
+ * @param replacement substitution of the substring
+ */
+char *
+MONKEY_str_replace_all ( const char *string, const char *substr, const char 
*replacement );
+
 /* ************** internal implementations, use macros above! ************** */
 
 /**

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c   
2012-03-07 16:15:06 UTC (rev 20347)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c   
2012-03-07 16:58:31 UTC (rev 20348)
@@ -356,7 +356,7 @@
   expression->lineNo = atoi (colValues[1]);
   expression->expressionValue = NULL; expression->next = NULL; 
expression->prev = NULL;
 
-  MONKEY_CONTAINER_DLL_insert (function->expressionListHead, 
function->expressionListTail,
+  MONKEY_CONTAINER_DLL_insert_tail (function->expressionListHead, 
function->expressionListTail,
                               expression);
 
   return 0;                    /* OK */
@@ -421,6 +421,7 @@
                      || strcmp (tmp->expressionValue, "NULL") == 0))
                {
                  cntxt->gdb_null_variable = tmp->expressionSyntax;
+                 cntxt->bug_detected = BUG_NULL_POINTER; // We are sure at 
this point that it's a NULL Pointer Exception and not a Bad Memory Access
                  return MONKEY_OK;
                }
            }
@@ -452,15 +453,15 @@
 
 
 static int
-analyzeCustomFault (struct MONKEY_ACTION_Context *cntxt)
+analyzeCustomFault (struct Function *function, struct MONKEY_ACTION_Context 
*cntxt)
 {
   struct Expression *tmp;
-  faultyExpression = getFaultyExpression (cntxt);
+  faultyExpression = getFaultyExpression (function);
 
 
   if (NULL != faultyExpression)
     {
-      tmp = expressionListHead;
+      tmp = function->expressionListHead;
       while (NULL != tmp)
        {
          const char *eval;
@@ -574,6 +575,26 @@
                &outerScopesCallback, NULL);
   if (ret == MONKEY_NO)
          return MONKEY_NO;
+  /**
+   * 1 void fun()
+   * 2 {
+   * 3 int i;
+   * 4 int j;
+   * 5 for (i = 0; i < 5; i++)
+   * 6 {
+   * 7         //Stuff
+   * 8         .
+   * 9         .
+   * 10                for (j = 0; j < 7; j++)
+   * 11                {
+   * 12                        //Other Stuff
+   * 13                        .
+   * 14                        .
+   * 15                        stop->because = crash->happens->here; 
<----------Crash happens here (Depth 0)
+   * 16                }
+   * 17         }<------- Scope End List: first element <---------------Outer 
scope depth 1
+   * 18}<--------- Scope End List: second element<---------------Outer scope 
depth 2
+   */
   if (NULL != scopeEndListHead) {
          scopeEndPtr = scopeEndListHead;
          while (index < cntxt->scope_depth && NULL != scopeEndPtr)
@@ -594,16 +615,15 @@
 
   if (strcasecmp (signalMeaning, "Segmentation fault") == 0)
     {
-      cntxt->bug_detected = BUG_NULL_POINTER;
       MONKEY_EDB_get_expressions (edbCntxt,
                                         cntxt->gdb_frames->file,
                                         cntxt->gdb_frames->line, endScope,
                                         &iterateExpressions, function);
-      ret = analyzeSegmentationFault (function, cntxt);
+      ret = analyzeSegmentationFault (function, cntxt); // will decide whether 
the problem is a NULL Pointer Exception or a Bad Memory Access
     }
   else if (strcasecmp (signalMeaning, "Aborted") == 0)
     {
-      cntxt->bug_detected = BUG_CUSTOM;
+      cntxt->bug_detected = BUG_ABORT;
       /*
       MONKEY_EDB_get_sub_expressions (edbCntxt,
                                             cntxt->gdb_frames->file,
@@ -614,11 +634,11 @@
       MONKEY_EDB_get_expressions (edbCntxt,
                                         cntxt->gdb_frames->file,
                                         cntxt->gdb_frames->line, endScope,
-                                        &iterateExpressions, NULL);
-      ret = analyzeCustomFault (cntxt);
+                                        &iterateExpressions, function);
+      ret = analyzeCustomFault (function, cntxt);
     }
   else if (strcasecmp(signalMeaning, "Arithmetic exception") == 0) {
-         cntxt->bug_detected = BUG_CUSTOM;
+         cntxt->bug_detected = BUG_ARITHMETIC;
          /*
          MONKEY_EDB_get_sub_expressions (edbCntxt,
                                                     cntxt->gdb_frames->file,
@@ -630,13 +650,13 @@
                  MONKEY_EDB_get_expressions_outer_scopes (edbCntxt,
                                                                         
cntxt->gdb_frames->file,
                                                                         
cntxt->gdb_frames->line, endScope,
-                                                                        
&iterateExpressions, NULL);
+                                                                        
&iterateExpressions, function);
          else
                  MONKEY_EDB_get_expressions (edbCntxt,
                                                                         
cntxt->gdb_frames->file,
                                                                         
cntxt->gdb_frames->line, endScope,
-                                                                        
&iterateExpressions, NULL);
-         ret = analyzeCustomFault (cntxt);
+                                                                        
&iterateExpressions, function);
+         ret = analyzeCustomFault (function, cntxt);
   }
 
   printTrace();
@@ -945,7 +965,12 @@
                        cntxt->xmlReportRootNode = createXmlCrashNode("Bad 
memory access", functionPtr->name, functionPtr->line, functionPtr->file);
                        node = 
MONKEY_XML_WRITER_add_child(cntxt->xmlReportRootNode, 
createXmlSimpleNode("valgrind", getValgrindOutput(cntxt)));
                        break;
-               case BUG_CUSTOM:
+               case BUG_ABORT:
+                       cntxt->xmlReportRootNode = 
createXmlCrashNode("Assertion Failure", functionPtr->name, functionPtr->line, 
functionPtr->file);
+                       break;
+               case BUG_ARITHMETIC:
+                       cntxt->xmlReportRootNode = createXmlCrashNode("Division 
By Zero", functionPtr->name, functionPtr->line, functionPtr->file);
+                       break;
                default:
                        return MONKEY_NO; //problem!
                }
@@ -990,15 +1015,12 @@
                           cntxt->gdb_stop_reason->signal_meaning,
                           cntxt->gdb_null_variable);
        }
-      else if (cntxt->bug_detected == BUG_CUSTOM)
+      else if (NULL == cntxt->inspect_expression)
        {
-         if (NULL == cntxt->inspect_expression)
-           {
-             /* Assertion Failure or Arithmetic Exception (Division by Zero, 
etc...) */
            const char *expToString =
                expressionListToString (expressionListHead);
 
-           if (strcasecmp(cntxt->gdb_stop_reason->signal_meaning, "Arithmetic 
exception") == 0) {
+           if (cntxt->bug_detected == BUG_ARITHMETIC) {
                MONKEY_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,
@@ -1008,7 +1030,7 @@
                                                           
cntxt->gdb_stop_reason->signal_meaning,
                                                           expToString);
            }
-           else {
+           else if (cntxt->bug_detected == BUG_ABORT) {
                /* Assertion Failure */
                        MONKEY_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",
@@ -1019,8 +1041,8 @@
                                           
cntxt->gdb_stop_reason->signal_meaning,
                                           expToString);
            }
-           }
-         else
+       }
+       else
            {
              /* Inspection of user-defined expression */
              /*
@@ -1029,7 +1051,6 @@
                 cntxt->inspect_expression, cntxt->inspect_function, 
cntxt->binary_name, watchInfoListToString(watchInfoListHead));
               */
            }
-       }
       break;
     case DEBUG_MODE_VALGRIND:
       MONKEY_asprintf (&(cntxt->debug_report),

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h        
2012-03-07 16:15:06 UTC (rev 20347)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h        
2012-03-07 16:58:31 UTC (rev 20348)
@@ -26,9 +26,10 @@
 #define DEBUG_MODE_VALGRIND 4
 #define DEBUG_MODE_REPORT_READY 5
 #define BUG_NULL_POINTER 6
-#define BUG_CUSTOM 7
-#define BUG_BAD_MEM_ACCESS 8
-#define EXPRESSION_EVALUATION_DEPTH 0
+#define BUG_ABORT 7
+#define BUG_ARITHMETIC 8
+#define BUG_BAD_MEM_ACCESS 9
+#define EXPRESSION_EVALUATION_DEPTH 1
 
 
 /**

Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/xml_writer.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/xml_writer.c   
2012-03-07 16:15:06 UTC (rev 20347)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/xml_writer.c   
2012-03-07 16:58:31 UTC (rev 20348)
@@ -93,10 +93,14 @@
        else {
                fprintf(file, "<%s ", root->name);
                while (NULL != tmpAttribute) {
-                       if (NULL != strchr(tmpAttribute->value, '"')) // if the 
Attribute value has double quotes, it should be displayed between single quotes 
instead of double quotes
-                               fprintf(file, "%s='%s' ", tmpAttribute->name, 
tmpAttribute->value);
-                       else
-                               fprintf(file, "%s=\"%s\" ", tmpAttribute->name, 
tmpAttribute->value);
+                       /* Escaping special characters in attribute values */
+                       tmpAttribute->value = MONKEY_str_replace_all 
(tmpAttribute->value, "&", "&amp;"); // & (escaping amp character MUST be the 
first, otherwise, it will spoil the other escaped characters
+                       tmpAttribute->value = MONKEY_str_replace_all 
(tmpAttribute->value, "\"", "&quot;"); // single quote
+                       tmpAttribute->value = MONKEY_str_replace_all 
(tmpAttribute->value, "'", "&apos;"); // double quotes
+                       tmpAttribute->value = MONKEY_str_replace_all 
(tmpAttribute->value, "<", "&lt;"); // less than
+                       tmpAttribute->value = MONKEY_str_replace_all 
(tmpAttribute->value, ">", "&gt;");// greater than
+
+                       fprintf(file, "%s=\"%s\" ", tmpAttribute->name, 
tmpAttribute->value);
                        tmpAttribute = tmpAttribute->next;
                }
                fprintf(file, ">\n");

Modified: monkey/branches/MonkeyBacktracking/monkey/src/util/Makefile.am
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/util/Makefile.am      
2012-03-07 16:15:06 UTC (rev 20347)
+++ monkey/branches/MonkeyBacktracking/monkey/src/util/Makefile.am      
2012-03-07 16:58:31 UTC (rev 20348)
@@ -8,4 +8,5 @@
 lib_LTLIBRARIES = libmonkeyutil.la
 
 libmonkeyutil_la_SOURCES = \
-  common_allocation.c
\ No newline at end of file
+  common_allocation.c \
+  str_replace_all.c
\ No newline at end of file

Added: monkey/branches/MonkeyBacktracking/monkey/src/util/str_replace_all.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/util/str_replace_all.c        
                        (rev 0)
+++ monkey/branches/MonkeyBacktracking/monkey/src/util/str_replace_all.c        
2012-03-07 16:58:31 UTC (rev 20348)
@@ -0,0 +1,55 @@
+/**
+ * vim: tabstop=2:shiftwidth=2:softtabstop=2:expandtab
+ *
+ * str_replace.c implements a str_replace PHP like function
+ * Copyright (C) 2010  chantra <chantra__A__debuntu__D__org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA.
+ *
+ * gcc -o str_replace_all str_replace_all.c
+ */
+
+#include "monkey_common.h"
+
+char *
+MONKEY_str_replace_all ( const char *string, const char *substr, const char 
*replacement ){
+  char *tok = NULL;
+  char *newstr = NULL;
+  char *oldstr = NULL;
+  char *head = NULL;
+
+  /* if either substr or replacement is NULL, duplicate string a let caller 
handle it */
+  if ( substr == NULL || replacement == NULL ) return MONKEY_strdup (string);
+  newstr = MONKEY_strdup (string);
+  head = newstr;
+  while ( (tok = strstr ( head, substr ))){
+    oldstr = newstr;
+    newstr = MONKEY_malloc ( strlen ( oldstr ) - strlen ( substr ) + strlen ( 
replacement ) + 1 );
+    /*failed to alloc mem, free old string and return NULL */
+    if ( newstr == NULL ){
+      MONKEY_free (oldstr);
+      return NULL;
+    }
+    memcpy ( newstr, oldstr, tok - oldstr );
+    memcpy ( newstr + (tok - oldstr), replacement, strlen ( replacement ) );
+    memcpy ( newstr + (tok - oldstr) + strlen( replacement ), tok + strlen ( 
substr ), strlen ( oldstr ) - strlen ( substr ) - ( tok - oldstr ) );
+    memset ( newstr + strlen ( oldstr ) - strlen ( substr ) + strlen ( 
replacement ) , 0, 1 );
+    /* move back head right after the last replacement */
+    head = newstr + (tok - oldstr) + strlen( replacement );
+    MONKEY_free (oldstr);
+  }
+  return newstr;
+}
+


Property changes on: 
monkey/branches/MonkeyBacktracking/monkey/src/util/str_replace_all.c
___________________________________________________________________
Added: svn:mime-type
   + text/plain




reply via email to

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