Expression Database API, and Action API (without implementation).
authorSafey A.Halim <safey.allah@gmail.com>
Sun, 16 Jan 2011 21:51:12 +0000 (21:51 +0000)
committerSafey A.Halim <safey.allah@gmail.com>
Sun, 16 Jan 2011 21:51:12 +0000 (21:51 +0000)
src/include/Makefile.am
src/include/gnunet_monkey_action.h [new file with mode: 0644]
src/include/gnunet_monkey_edb.h
src/monkey/Makefile.am
src/monkey/action_api.c [new file with mode: 0644]
src/monkey/edb_api.c
src/monkey/seaspider/org/gnunet/seaspider/ExpressionDatabaseHandler.java
src/monkey/test.db [new file with mode: 0644]
src/monkey/test_monkey_edb.c [new file with mode: 0644]

index 2bdc4e1fa06fabcd10e8d8dd46839fa445759299..bdfa677c6f0b1fe0769dde5810d07bcce1003a89 100644 (file)
@@ -65,4 +65,5 @@ gnunetinclude_HEADERS = \
   gnunet_transport_plugin.h \
   gnunet_upnp_service.h \
   gnunet_util_lib.h \
-  gnunet_monkey_edb.h
+  gnunet_monkey_edb.h \
+  gnunet_monkey_action.h
diff --git a/src/include/gnunet_monkey_action.h b/src/include/gnunet_monkey_action.h
new file mode 100644 (file)
index 0000000..da8f853
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+      This file is part of GNUnet
+      (C) 2010, 2011 Christian Grothoff (and other contributing authors)
+
+      GNUnet 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 3, or (at your
+      option) any later version.
+
+      GNUnet 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 GNUnet; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file monkey/gnunet_monkey_action.h
+ * @brief Monkey API for actions taken by Monkey while debugging
+ */
+
+#ifndef GNUNET_MONKEY_ACTION_H
+#define GNUNET_MONKEY_ACTION_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#if 0                          /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
+int GNUNET_MONKEY_ACTION_report_file();
+int GNUNET_MONKEY_ACTION_report_email();
+int GNUNET_MONKEY_ACTION_rerun_with_valgrind();
+int GNUNET_MONKEY_ACTION_rerun_with_gdb();
+int GNUNET_MONKEY_ACTION_check_bug_redundancy();
+
+
+#if 0                          /* keep Emacsens' auto-indent happy */
+{
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
index 380ba4ade979b139fc3def56d1e99790b3a88dd9..af5142a82dfc99a126453b5d8e1fd2dec96791cf 100644 (file)
@@ -29,7 +29,7 @@
 #ifdef __cplusplus
 extern "C"
 {
-#if 0                           /* keep Emacsens' auto-indent happy */
+#if 0                          /* keep Emacsens' auto-indent happy */
 }
 #endif
 #endif
@@ -53,16 +53,16 @@ struct GNUNET_MONKEY_EDB_Context *GNUNET_MONKEY_EDB_connect (const char
  * @param context context
  * @return GNUNET_OK on success, GNUNET_NO on failure
  */
-int GNUNET_MONKEY_EDB_disconnect (struct GNUNET_MONKEY_EDB_Context *context);
+int GNUNET_MONKEY_EDB_disconnect (struct GNUNET_MONKEY_EDB_Context *cntxt);
 
 
-typedef int (*GNUNET_MONKEY_ExpressionIterator)(void *cls, const char *expression, int begin_line);
+typedef int (*GNUNET_MONKEY_ExpressionIterator) (void *, int, char **,
+                                                char **);
 
 
 /**
- * Update the context with a list of expressions. 
- * The list is the initializations of sub-expressions 
- * of the expression pointed to by start_line_no and end_line_no
+ * Run an SQLite query to retrieve those expressions that are previous to
+ * given expression and are in the same scope of the given expression
  * For example, consider the following code snippet:
  * {
  *   struct Something whole; // line no.1 
@@ -71,29 +71,27 @@ typedef int (*GNUNET_MONKEY_ExpressionIterator)(void *cls, const char *expressio
  *   whole.part->member = 1; // line no.4
  * }
  * If the expression supplied to the function is that of line no.4 "whole.part->member = 1;"
- * The returned list of expressions will be: whole.part = part (line no.3), 
- * struct SomethingElse part (line no.2), and struct Something whole (line no.1),
- * which are the initialization expressions of the building components of the expression in question
- * 
- * @param context the returned expessions will be available in it. 
- * expression_list_head, and expression_list_tail must be null, 
- * otherwise GNUNET_NO will be returned 
+ * The returned list of expressions will be: whole.part (line no.4), whole.part->member (line no.4),
+ * whole (line no.3), whole.part (line no.3), &part (line no.3), whole.part = &part (line no.3)
+ *
+ * @param cntxt context containing the Expression Database handle.
  * @param file_name path to the file in which the expression in question exists
  * @param start_line_no expression beginning line
- * @param end_line_no expression end line
+ * @param end_line_no line number for the expression's scope end
  * @param iter callback function, iterator for expressions returned from the Database
  * @param iter_cls closure for the expression iterator
  * @return GNUNET_OK success, GNUNET_NO failure
  */
 int
-GNUNET_MONKEY_EDB_get_expressions (struct GNUNET_MONKEY_EDB_Context *context,
+GNUNET_MONKEY_EDB_get_expressions (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);
+                                  GNUNET_MONKEY_ExpressionIterator iter,
+                                  void *iter_cls);
 
 
 
-#if 0                           /* keep Emacsens' auto-indent happy */
+#if 0                          /* keep Emacsens' auto-indent happy */
 {
 #endif
 #ifdef __cplusplus
@@ -101,4 +99,3 @@ GNUNET_MONKEY_EDB_get_expressions (struct GNUNET_MONKEY_EDB_Context *context,
 #endif
 
 #endif
-
index 39e5f8d5d4fbed0bd96b750a20a9c84d6dbce4dd..308a40866dada1db338986e0611797a15e558bb6 100644 (file)
@@ -14,6 +14,28 @@ if !MINGW
 if HAVE_ESMTP
 if HAVE_OPENSSL
 
+
+lib_LTLIBRARIES = libmonkeyedb.la \
+                                 libmonkeyaction.la
+
+libmonkeyedb_la_SOURCES = \
+  edb_api.c \
+  gnunet_monkey_edb.h
+  
+libmonkeyedb_la_LIBADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  -lsqlite3 \
+  $(GN_LIBINTL) $(XLIB)  
+  
+libmonkeyaction_la_SOURCES = \
+  action_api.c \
+  gnunet_monkey_action.h
+
+libmonkeyaction_la_LIBADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(GN_LIBINTL) $(XLIB)  
+
+  
 bin_PROGRAMS = \
  gnunet-monkey \
  gnunet-service-monkey 
@@ -39,11 +61,12 @@ gnunet_monkey_SOURCES = \
  gdbmi_thread.c \
  gdbmi_var_obj.c \
  gnunet-monkey.c \
- mail_sender.c \
- edb_api.c
+ mail_sender.c
 
 gnunet_monkey_LDADD = \
   $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/monkey/libmonkeyedb.la \
+  $(top_builddir)/src/monkey/libmonkeyaction.la \
   -lesmtp \
   $(GN_LIBINTL)
 
@@ -59,13 +82,21 @@ bug_null_pointer_exception:
        gcc -g -O0 -o bug_null_pointer_exception bug_null_pointer_exception.c
        
 check_PROGRAMS = \
-    bug_null_pointer_exception
+    bug_null_pointer_exception \
+    test_monkey_edb
     #test_gnunet_monkey        
 
 if !DISABLE_TEST_RUN
 # TESTS = $(check_SCRIPTS)
+TESTS = $(check_PROGRAMS)
 endif
 
+test_monkey_edb_SOURCES = \
+  test_monkey_edb.c
+test_monkey_edb_LDADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/monkey/libmonkeyedb.la
+  
 #test_gnunet_monkey_SOURCES = \
  #test_gnunet_monkey.c
 #test_gnunet_monkey_LDADD = \
@@ -84,4 +115,3 @@ check_SCRIPTS = \
 endif
 endif
 endif
-
diff --git a/src/monkey/action_api.c b/src/monkey/action_api.c
new file mode 100644 (file)
index 0000000..c1f39e7
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+     This file is part of GNUnet.
+     (C) 2010, 2011 Christian Grothoff (and other contributing authors)
+
+     GNUnet 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 3, or (at your
+     option) any later version.
+
+     GNUnet 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 GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file monkey/action_api.c
+ * @brief Monkey API for actions taken by Monkey while debugging
+ */
+
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_monkey_action.h"
+
+
+int GNUNET_MONKEY_ACTION_report_file()
+{
+       return GNUNET_OK;
+}
+
+
+int GNUNET_MONKEY_ACTION_report_email()
+{
+       return GNUNET_OK;
+}
+
+
+
+int GNUNET_MONKEY_ACTION_rerun_with_valgrind()
+{
+       return GNUNET_OK;
+}
+
+
+int GNUNET_MONKEY_ACTION_rerun_with_gdb()
+{
+       return GNUNET_OK;
+}
+
+
+int GNUNET_MONKEY_ACTION_check_bug_redundancy()
+{
+       return GNUNET_OK;
+}
index 3e7de2d09e89cdaf1e7d31b827823c8f00014592..78a340cd5e7b97a76775023ec425f96e248670c7 100644 (file)
@@ -50,46 +50,76 @@ struct GNUNET_MONKEY_EDB_Context
 struct GNUNET_MONKEY_EDB_Context *
 GNUNET_MONKEY_EDB_connect (const char *db_file_name)
 {
-       /* TODO: Implementation */
-       return NULL;
+  int err;
+  struct GNUNET_MONKEY_EDB_Context *ctxt =
+    GNUNET_malloc (sizeof (struct GNUNET_MONKEY_EDB_Context));
+
+  err = sqlite3_open (db_file_name, &ctxt->db_handle);
+  if (err)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                 "Cannot open Expression Database. `%s'\n",
+                 sqlite3_errmsg (ctxt->db_handle));
+      return NULL;
+    }
+  return ctxt;
 }
 
 
 /**
  * Disconnect from Database, and cleanup resources
  *
- * @param context context
+ * @param context context containing the Expression Database handle
  * @return GNUNET_OK on success, GNUNET_NO on failure
  */
 int
-GNUNET_MONKEY_EDB_disconnect (struct GNUNET_MONKEY_EDB_Context *context)
+GNUNET_MONKEY_EDB_disconnect (struct GNUNET_MONKEY_EDB_Context *cntxt)
 {
-       /* TODO: Implementation */
-       return GNUNET_OK;
+  sqlite3_close (cntxt->db_handle);
+  GNUNET_free (cntxt);
+  return GNUNET_OK;
 }
 
 
 /**
- * Update the context with a list of expressions. 
- * The list is the initializations of sub-expressions 
- * of the expression pointed to by start_line_no and end_line_no
+ * Run an SQLite query to retrieve those expressions that are previous to
+ * given expression and are in the same scope of the given expression
  * 
- * @param context the returned expessions will be available in it. 
- *        expression_list_head and expression_list_tail must be NULL, 
- *        otherwise GNUNET_NO will be returned 
+ * @param cntxt context containing the Expression Database handle.
  * @param file_name path to the file in which the expression in question exists
  * @param start_line_no expression beginning line
- * @param end_line_no expression end line
+ * @param end_line_no line number for the expression's scope end
  * @param iter callback function, iterator for expressions returned from the Database
  * @param iter_cls closure for the expression iterator
  * @return GNUNET_OK success, GNUNET_NO failure
  */
 int
-GNUNET_MONKEY_EDB_get_expressions (struct GNUNET_MONKEY_EDB_Context *context,
+GNUNET_MONKEY_EDB_get_expressions (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)
+                                  GNUNET_MONKEY_ExpressionIterator iter,
+                                  void *iter_cls)
 {
-       /* TODO: Implementation */
-       return GNUNET_OK;
+  int err;
+  char *errMsg;
+  char *query;
+  if (asprintf
+      (&query,
+       "select expr_syntax, start_lineno from Expression where file_name = \'%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.");
+      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;
 }
index 2c1df1b54f194036228ec8bd63e00d99b42046e3..b9a1e2cf8aaafd91358b50fb51e356a28fdd8fa5 100644 (file)
@@ -38,7 +38,7 @@ public class ExpressionDatabaseHandler {
        private static Stack<HashMap<String, Integer>> expressionStack = new Stack<HashMap<String, Integer>>();
 
        public static void createExpressionDatabase(String databasePath) {
-               String createTableQuery = "CREATE TABLE Expression ( expr_ID INT NOT NULL PRIMARY KEY , "
+               String createTableQuery = "CREATE TABLE Expression ( expr_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
                                + "file_name TEXT NOT NULL , expr_syntax TEXT NOT NULL ,"
                                + " start_lineno INT, end_lineno INT)";
 
@@ -79,7 +79,7 @@ public class ExpressionDatabaseHandler {
                        if (DEBUG)
                                System.out.println(fileName + ":[" + startLineNo + "-"
                                                + endLineNo + "]: " + expressionSyntax);
-                       table.insert(currentFileName, expressionSyntax, startLineNo,
+                       table.insert(null, currentFileName, expressionSyntax, startLineNo,
                                        endLineNo);
                } catch (SqlJetException e) {
                        e.printStackTrace();
@@ -195,7 +195,9 @@ public class ExpressionDatabaseHandler {
                                        .println("Error:Database handle is not initialized. Program will exit now!");
                        System.exit(1);
                }
-
+               
+               String[] fileNameArr = fileName.split("src/");
+               fileName = fileNameArr[1];
                insertExpression(fileName, expressionSyntax, startLineNo, endLineNo);
        }
 }
diff --git a/src/monkey/test.db b/src/monkey/test.db
new file mode 100644 (file)
index 0000000..6d15e70
Binary files /dev/null and b/src/monkey/test.db differ
diff --git a/src/monkey/test_monkey_edb.c b/src/monkey/test_monkey_edb.c
new file mode 100644 (file)
index 0000000..b418bee
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+     This file is part of GNUnet.
+     (C) 2010 Christian Grothoff (and other contributing authors)
+
+     GNUnet 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 3, or (at your
+     option) any later version.
+
+     GNUnet 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 GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file monkey/test_monkey_edb.c
+ * @brief testcase for edb_api.c
+ */
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_monkey_edb.h"
+
+
+static const char *ref[16] =
+  { "args", "32", "argv", "32", "whole", "42", "whole.member", "42",
+  "whole.member=1", "42", "whole.part", "43", "&part", "43",
+    "whole.part=&part", "43"
+};
+
+static int refCount = 0;
+static int ret = 1;
+
+int
+expressionIterator (void *cls, int colNum, char **colValues, char **colNames)
+{
+  int i;
+  for (i = 0; i < colNum; i++)
+    {
+      if (strcmp (colValues[i], ref[refCount]) != 0)
+       return 1;
+      refCount++;
+    }
+
+  return 0;
+}
+
+
+int
+main (int args, const char *argv[])
+{
+  struct GNUNET_MONKEY_EDB_Context *cntxt;
+  cntxt = GNUNET_MONKEY_EDB_connect ("test.db");
+  ret =
+    GNUNET_MONKEY_EDB_get_expressions (cntxt,
+                                      "monkey/seaspider/SeaspiderTest.c", 44,
+                                      83, &expressionIterator, NULL);
+  GNUNET_MONKEY_EDB_disconnect (cntxt);
+
+  if (ret == GNUNET_OK)
+    {
+      return 0;
+    }
+  return 1;
+}