gnunet_transport_plugin.h \
gnunet_upnp_service.h \
gnunet_util_lib.h \
- gnunet_monkey_edb.h
+ gnunet_monkey_edb.h \
+ gnunet_monkey_action.h
--- /dev/null
+/*
+ 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
#ifdef __cplusplus
extern "C"
{
-#if 0 /* keep Emacsens' auto-indent happy */
+#if 0 /* keep Emacsens' auto-indent happy */
}
#endif
#endif
* @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
* 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
#endif
#endif
-
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
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)
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 = \
endif
endif
endif
-
--- /dev/null
+/*
+ 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;
+}
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;
}
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)";
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();
.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);
}
}
--- /dev/null
+/*
+ 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;
+}