[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18263 - in monkey: . src/monkey
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18263 - in monkey: . src/monkey |
Date: |
Tue, 22 Nov 2011 23:44:39 +0100 |
Author: safey
Date: 2011-11-22 23:44:39 +0100 (Tue, 22 Nov 2011)
New Revision: 18263
Added:
monkey/bug_assertion_failure.db
monkey/src/monkey/bug_assertion_failure.db
monkey/src/monkey/bug_bad_memory_access.db
monkey/src/monkey/bug_division_by_zero_loop.c
monkey/src/monkey/bug_null_assertion_failure.db
monkey/src/monkey/bug_null_pointer_exception.db
monkey/src/monkey/test_monkey_assertion_failure.sh
Modified:
monkey/configure.ac
monkey/src/monkey/Makefile.am
monkey/src/monkey/action_api.c
monkey/src/monkey/edb_api.c
monkey/src/monkey/gnunet-monkey.c
monkey/src/monkey/gnunet_monkey_edb.h
monkey/src/monkey/test_gnunet_monkey.c
monkey/src/monkey/test_monkey_edb.c
monkey/src/monkey/test_monkey_npe.sh
Log:
GDB7 supported
NULL Pointer Exception, and Assertion Failure working with GDB7
Added: monkey/bug_assertion_failure.db
===================================================================
Modified: monkey/configure.ac
===================================================================
--- monkey/configure.ac 2011-11-22 19:37:07 UTC (rev 18262)
+++ monkey/configure.ac 2011-11-22 22:44:39 UTC (rev 18263)
@@ -176,6 +176,80 @@
AC_MSG_ERROR([monkey requires libgnunetcore]))
LIBS=$SAVELIBS
+# libgcrypt
+gcrypt=0
+AM_PATH_LIBGCRYPT(1.2.0, gcrypt=1)
+AC_CHECK_DECLS([gcry_mpi_lshift], [], [], [[#include <gcrypt.h>]])
+
+if test $gcrypt = 0
+then
+ AC_MSG_ERROR([GNUnet needs libgcrypt])
+fi
+
+extra_logging=GNUNET_NO
+AC_ARG_ENABLE([logging],
+ AS_HELP_STRING([--enable-logging@<:@=value@:>@],[Enable logging calls.
Possible values: yes,no,verbose,veryverbose ('yes' is the default)]),
+ [AS_IF([test "x$enableval" = "xyes"], [],
+ [test "x$enableval" = "xno"],
[AC_DEFINE([GNUNET_CULL_LOGGING],[],[Define to cull all logging calls])],
+ [test "x$enableval" = "xverbose"], [extra_logging=GNUNET_YES]
+ [test "x$enableval" = "xveryverbose"],
[extra_logging=\(GNUNET_YES+1\)])
+ ], [])
+AC_DEFINE_UNQUOTED([GNUNET_EXTRA_LOGGING],[$extra_logging],[1 if extra logging
is enabled, 2 for very verbose extra logging, 0 otherwise])
+
+if test $build = $target
+then
+AC_MSG_CHECKING([for working HMAC])
+AC_LANG_PUSH(C)
+LIBS="$LIBS $LIBGCRYPT_LIBS"
+CFLAGS="$CFLAGS $LIBGCRYPT_CFLAGS"
+AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM([#include <gcrypt.h>], [[
+ gcry_md_hd_t mac;
+
+ unsigned char data[] = { 0xbf, 0x16, 0x6e, 0x46, 0x3a, 0x6c, 0xf3,
0x93, 0xa7, 0x72,
+ 0x11, 0xa1, 0xdc, 0x0b, 0x07, 0xdb, 0x1a, 0x5e, 0xd9, 0xb9, 0x81,
0xbe,
+ 0xea, 0xe4, 0x31, 0x5f, 0x24, 0xff, 0xfe, 0x50, 0x8a, 0xde };
+ unsigned char key[] = { 0xfc, 0x62, 0x76, 0x35 };
+ unsigned char result[] = {0xa2, 0xb, 0x1, 0xd9, 0xc0, 0x8b, 0x5a,
0x12, 0x80,
+ 0xd5, 0x50, 0x12, 0x8e, 0xd0, 0x5b, 0xb6, 0x5c, 0x87, 0x24, 0xe2,
0xd0,
+ 0xd2, 0xaf, 0x63, 0xae, 0xd1, 0xd6, 0x64, 0x14, 0xe3, 0x6e, 0x61,
0x5b,
+ 0xd, 0xba, 0x17, 0x7d, 0xd3, 0x10, 0xb1, 0x37, 0x41, 0x91, 0x7d,
0xeb,
+ 0x1, 0x4d, 0x71, 0xe8, 0x59, 0x71, 0x42, 0x8e, 0xd6, 0xf3, 0x29,
0x3b,
+ 0x90, 0xf2, 0xd1, 0xaf, 0x65, 0x1e, 0xb3};
+
+ if (!gcry_check_version (GCRYPT_VERSION))
+ return 1;
+
+ gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
+ gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
+
+ if (gcry_md_open(&mac, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC) !=
GPG_ERR_NO_ERROR)
+ return 2;
+
+ gcry_md_setkey (mac, key, sizeof (key));
+ gcry_md_write (mac, data, sizeof (data));
+
+ if (memcmp(gcry_md_read (mac, 0), result, gcry_md_get_algo_dlen
(gcry_md_get_algo (mac))) != 0)
+ return 3;
+
+ gcry_md_close (mac);
+
+ return 0;
+ ]])],
+ [AC_MSG_RESULT([yes])],
+ [
+ if test $? = 3
+ then
+ AC_MSG_FAILURE([HMAC test vector does not match. This is a known problem
with libgcrypt 1.2.2 on Windows and fixed in 1.4.6.])
+ else
+ AC_MSG_FAILURE([HMAC test failed])
+ fi
+ ])
+AC_LANG_POP(C)
+fi # $build = $target
+
+
+
# openssl
openssl=0
AC_MSG_CHECKING([for openssl])
Modified: monkey/src/monkey/Makefile.am
===================================================================
--- monkey/src/monkey/Makefile.am 2011-11-22 19:37:07 UTC (rev 18262)
+++ monkey/src/monkey/Makefile.am 2011-11-22 22:44:39 UTC (rev 18263)
@@ -37,13 +37,19 @@
bin_PROGRAMS = \
gnunet-monkey \
- gnunet-service-monkey
+ gnunet-service-monkey \
+ bug_null_pointer_exception \
+ bug_bad_memory_access \
+ bug_assertion_failure \
+ bug_crypto_crc \
+ bug_division_by_zero_loop
-noinst_PROGRAMS = \
+#noinst_PROGRAMS = \
bug_null_pointer_exception \
bug_bad_memory_access \
bug_assertion_failure \
- bug_crypto_crc
+ bug_crypto_crc \
+ bug_division_by_zero_loop
gnunet_monkey_SOURCES = \
gdbmi.h \
@@ -90,7 +96,10 @@
gcc -g -O0 -o bug_assertion_failure bug_assertion_failure.c
bug_crypto_crc:
- gcc -g -O0 -o bug_crypto_crc bug_crypto_crc.c
+ gcc -g -O0 -o bug_crypto_crc bug_crypto_crc.c
+
+bug_division_by_zero_loop:
+ gcc -g -O0 -o bug_division_by_zero_loop bug_division_by_zero_loop.c
check_PROGRAMS = \
test_monkey_edb
@@ -120,7 +129,9 @@
EXTRA_DIST = \
test_gnunet_monkey_data.conf \
- test.db
+ test.db \
+ bug_null_pointer_exception.db
+
#$(check_SCRIPTS)
endif
Modified: monkey/src/monkey/action_api.c
===================================================================
--- monkey/src/monkey/action_api.c 2011-11-22 19:37:07 UTC (rev 18262)
+++ monkey/src/monkey/action_api.c 2011-11-22 22:44:39 UTC (rev 18263)
@@ -39,7 +39,19 @@
static struct WatchInfo *watchInfoListHead = NULL;
static struct WatchInfo *watchInfoListTail = NULL;
static struct Expression *faultyExpression = NULL;
+static struct FileName *fileNameListHead = NULL;
+static struct FileName *fileNameListTail = NULL;
+
+struct FileName
+{
+ struct FileNames *next;
+ struct FileNames *prev;
+
+ const char *name;
+};
+
+
struct Expression
{
struct Expression *next;
@@ -51,10 +63,10 @@
struct WatchInfo
{
- struct WatchInfo *next;
- struct WatchInfo *prev;
- int hitNumber;
- const char *value;
+ struct WatchInfo *next;
+ struct WatchInfo *prev;
+ int hitNumber;
+ const char *value;
};
@@ -101,7 +113,20 @@
async_c++;
}
+static int
+isInCodeBase (const char *name)
+{
+ struct FileName *fileName = fileNameListHead;
+ while (NULL != fileName)
+ {
+ if (strcmp (fileName->name, name) == 0)
+ return GNUNET_YES;
+ fileName = fileName->next;
+ }
+ return GNUNET_NO;
+}
+
static int
wait_for_stop (struct GNUNET_MONKEY_ACTION_Context *cntxt)
{
@@ -111,41 +136,73 @@
cntxt->gdb_stop_reason = mi_res_stop (cntxt->gdb_handle);
if (cntxt->gdb_stop_reason)
{
- if (cntxt->gdb_stop_reason->reason == sr_exited_normally)
- return GDB_STATE_EXIT_NORMALLY;
- else if (cntxt->gdb_stop_reason->reason == sr_bkpt_hit) {
- /* 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);
- /* continue execution */
- gmi_exec_continue(cntxt->gdb_handle);
- return wait_for_stop (cntxt);
- }
- else if (cntxt->gdb_stop_reason->reason == sr_wp_trigger) {
- static int watchPointHitNumber = 0;
- struct WatchInfo *watchInfo = GNUNET_malloc(sizeof(struct WatchInfo));
- watchInfo->hitNumber = ++watchPointHitNumber;
- watchInfo->value = cntxt->gdb_stop_reason->wp_val;
- GNUNET_CONTAINER_DLL_insert(watchInfoListHead, watchInfoListTail,
watchInfo);
- if (watchPointHitNumber == 1023)
- printf("HEY! 1023! WE ARE GETTING OUT OF THE LOOP!\n");
- gmi_exec_continue(cntxt->gdb_handle);
- return wait_for_stop (cntxt);
- }
- else if (cntxt->gdb_stop_reason->reason == sr_wp_scope) {
- gmi_exec_continue(cntxt->gdb_handle);
- return wait_for_stop (cntxt);
- }
+ switch (cntxt->gdb_stop_reason->reason)
+ {
+ case sr_exited_normally:
+ return GDB_STATE_EXIT_NORMALLY;
+ case sr_bkpt_hit:
+ {
+ /* 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);
+ /* continue execution */
+ gmi_exec_continue (cntxt->gdb_handle);
+ return wait_for_stop (cntxt);
+ }
+ case sr_wp_trigger:
+ {
+ static int watchPointHitNumber = 0;
+ struct WatchInfo *watchInfo =
+ GNUNET_malloc (sizeof (struct WatchInfo));
+ watchInfo->hitNumber = ++watchPointHitNumber;
+ watchInfo->value = cntxt->gdb_stop_reason->wp_val;
+ GNUNET_CONTAINER_DLL_insert (watchInfoListHead, watchInfoListTail,
+ watchInfo);
+ if (watchPointHitNumber == 1023)
+ printf ("HEY! 1023! WE ARE GETTING OUT OF THE LOOP!\n");
+ gmi_exec_continue (cntxt->gdb_handle);
+ return wait_for_stop (cntxt);
+ }
+ case sr_wp_scope:
+ gmi_exec_continue (cntxt->gdb_handle);
+ return wait_for_stop (cntxt);
+
+ default:
+ break;
+ }
+
+ /* Reaching this line means that the program has stopped abnormally */
+
cntxt->gdb_frames = gmi_stack_info_frame (cntxt->gdb_handle);
if (NULL == cntxt->gdb_frames)
- GNUNET_break (0);
+ {
+ cntxt->gdb_frames = gmi_stack_list_frames (cntxt->gdb_handle);
+ /*
+ * When working with GDB > 6.1, this is normal.
+ * libmigdb fails to load current frame from the handle.
+ * Instead, it's available in the reason struct
+ */
+ //cntxt->gdb_frames = cntxt->gdb_stop_reason->frame;
+ //EXPERIMENTAL CODE:
+ while (GNUNET_YES != isInCodeBase (cntxt->gdb_frames->file))
+ {
+ cntxt->gdb_frames = cntxt->gdb_frames->next;
+ }
+
+ if (NULL == cntxt->gdb_frames)
+ GNUNET_break (0);
+ }
+
if (0 == cntxt->gdb_frames->line)
{
/*
@@ -160,7 +217,7 @@
while (0 == cntxt->gdb_frames->line);
}
/* Change current GDB frame to the one containing source code */
- gmi_stack_select_frame(cntxt->gdb_handle, cntxt->gdb_frames->level);
+ gmi_stack_select_frame (cntxt->gdb_handle, cntxt->gdb_frames->level);
return GDB_STATE_STOPPED;
}
@@ -191,6 +248,44 @@
static int
+iterateFileNames (void *cls, int numColumns, char **colValues,
+ char **colNames)
+{
+ struct FileName *fileName;
+ char *token;
+ char *ext;
+ int tokenLength;
+
+ if (NULL == colValues[0] || NULL == colValues[1])
+ return 1; /* Error */
+
+ /* This is done to extract the only the file name from the full path coming
from the Database */
+ token = strtok (colValues[0], "/");
+ if (NULL == token)
+ return 1; /* Error */
+ do
+ {
+ tokenLength = strlen (token);
+ ext = &token[tokenLength - 2];
+ printf ("%s\n", ext);
+ if (strcmp (ext, ".c") == 0)
+ {
+ fileName = GNUNET_malloc (sizeof (struct FileName));
+ fileName->name = strdup (token);
+ GNUNET_CONTAINER_DLL_insert (fileNameListHead, fileNameListTail,
+ fileName);
+ return 0; /* OK */
+ }
+ token = strtok (NULL, "/");
+ }
+ while (NULL != token);
+
+
+ return 1; /* Error */
+}
+
+
+static int
iterateExpressions (void *cls, int numColumns, char **colValues,
char **colNames)
{
@@ -312,12 +407,13 @@
while (NULL != tmp)
{
const char *eval;
- eval =
- gmi_data_evaluate_expression (cntxt->gdb_handle,
- tmp->expressionSyntax);
- if (NULL != eval) {
- tmp->expressionValue = eval;
- }
+ eval =
+ gmi_data_evaluate_expression (cntxt->gdb_handle,
+ tmp->expressionSyntax);
+ if (NULL != eval)
+ {
+ tmp->expressionValue = eval;
+ }
tmp = tmp->next;
}
}
@@ -356,18 +452,19 @@
{
cntxt->bug_detected = BUG_NULL_POINTER;
GNUNET_MONKEY_EDB_get_expressions (edbCntxt,
- cntxt->gdb_frames->file,
- cntxt->gdb_frames->line, endScope,
- &iterateExpressions, NULL);
+ cntxt->gdb_frames->file,
+ cntxt->gdb_frames->line, endScope,
+ &iterateExpressions, NULL);
ret = analyzeSegmentationFault (cntxt);
}
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);
+ cntxt->gdb_frames->file,
+ cntxt->gdb_frames->line,
+ endScope, &iterateExpressions,
+ NULL);
ret = analyzeCustomFault (cntxt);
}
@@ -384,9 +481,10 @@
char *valgrindCommand;
FILE *valgrindPipe;
- GNUNET_asprintf(&cntxt->valgrind_output_tmp_file_name, "%d", rand());
+ GNUNET_asprintf (&cntxt->valgrind_output_tmp_file_name, "%d", rand ());
cntxt->debug_mode = DEBUG_MODE_VALGRIND;
- GNUNET_asprintf (&valgrindCommand, "valgrind --leak-check=yes --log-file=%s
%s",
+ GNUNET_asprintf (&valgrindCommand,
+ "valgrind --leak-check=yes --log-file=%s %s",
cntxt->valgrind_output_tmp_file_name, cntxt->binary_name);
valgrindPipe = popen (valgrindCommand, "r");
if (NULL == valgrindPipe)
@@ -396,8 +494,8 @@
return GNUNET_NO;
}
- pclose(valgrindPipe);
- GNUNET_free(valgrindCommand);
+ pclose (valgrindPipe);
+ GNUNET_free (valgrindCommand);
return GNUNET_OK;
}
@@ -406,6 +504,7 @@
GNUNET_MONKEY_ACTION_rerun_with_gdb (struct GNUNET_MONKEY_ACTION_Context
*cntxt)
{
+ struct GNUNET_MONKEY_EDB_Context *edbCntxt;
cntxt->debug_mode = DEBUG_MODE_GDB;
/* This is like a file-handle for fopen.
Here we have all the state of gdb "connection". */
@@ -446,19 +545,41 @@
return GNUNET_NO;
}
- if ((NULL != cntxt->inspect_expression) && (NULL != cntxt->inspect_function))
+ if ((NULL != cntxt->inspect_expression)
+ && (NULL != cntxt->inspect_function))
{
- /* Setting a breakpoint at the function containing the expression to
inspect */
- mi_bkpt *bp = gmi_break_insert_full(cntxt->gdb_handle, 0, 0, NULL,
-1, -1, cntxt->inspect_function);
- if (NULL == bp)
- {
- printf("Error setting breakpoint at function:%s\n",
cntxt->inspect_function);
- mi_disconnect(cntxt->gdb_handle);
- return GNUNET_NO;
- }
- mi_free_bkpt(bp);
+ /* Setting a breakpoint at the function containing the expression to
inspect */
+ mi_bkpt *bp =
+ gmi_break_insert_full (cntxt->gdb_handle, 0, 0, NULL, -1, -1,
+ cntxt->inspect_function);
+ if (NULL == bp)
+ {
+ printf ("Error setting breakpoint at function:%s\n",
+ cntxt->inspect_function);
+ mi_disconnect (cntxt->gdb_handle);
+ return GNUNET_NO;
+ }
+ mi_free_bkpt (bp);
}
+ /* Prepare a list of the file names for the source files we are analyzing */
+ edbCntxt = GNUNET_MONKEY_EDB_connect (cntxt->expression_database_path);
+ if (NULL == edbCntxt)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unable to connect to Expression Database file!\n");
+ return GNUNET_NO;
+ }
+
+ if (GNUNET_OK != GNUNET_MONKEY_EDB_get_file_names (edbCntxt,
+ &iterateFileNames, NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error in executing Database query!\n");
+ }
+ GNUNET_MONKEY_EDB_disconnect (edbCntxt);
+
+
/* Run the program. */
if (!gmi_exec_run (cntxt->gdb_handle))
{
@@ -476,36 +597,43 @@
static int
-getExpressionListSize(struct Expression *head)
+getExpressionListSize (struct Expression *head)
{
- int size, count = 0;
- struct Expression *tmp = head;
+ int size, count = 0;
+ struct Expression *tmp = head;
- while (NULL != tmp) {
- count++;
- tmp = tmp->next;
- }
- /* Since the faulty expression is the longest in the expression list */
- size = count * strlen(faultyExpression->expressionSyntax) *
sizeof(char);
- return size;
+ while (NULL != tmp)
+ {
+ count++;
+ tmp = tmp->next;
+ }
+ /* Since the faulty expression is the longest in the expression list */
+ size = count * strlen (faultyExpression->expressionSyntax) * sizeof (char);
+ return size;
}
static const char *
expressionListToString (struct Expression *head)
{
- char *string = GNUNET_malloc (getExpressionListSize(head));
+ char *string = GNUNET_malloc (getExpressionListSize (head));
char *strTmp;
struct Expression *tmp = head;
- GNUNET_asprintf (&strTmp, "%s = %s\n", tmp->expressionSyntax, NULL ==
tmp->expressionValue ? "Not evaluated" : tmp->expressionValue);
+ GNUNET_asprintf (&strTmp, "%s = %s\n", tmp->expressionSyntax,
+ NULL ==
+ tmp->expressionValue ? "Not evaluated" : tmp->
+ expressionValue);
strcpy (string, strTmp);
GNUNET_free (strTmp);
tmp = tmp->next;
while (NULL != tmp)
{
- GNUNET_asprintf (&strTmp, "%s = %s\n", tmp->expressionSyntax, NULL ==
tmp->expressionValue ? "Not evaluated" : tmp->expressionValue);
+ GNUNET_asprintf (&strTmp, "%s = %s\n", tmp->expressionSyntax,
+ NULL ==
+ tmp->expressionValue ? "Not evaluated" : tmp->
+ expressionValue);
strcat (string, strTmp);
GNUNET_free (strTmp);
tmp = tmp->next;
@@ -515,58 +643,61 @@
#if 0
static int
-getWatchInfoListSize(struct WatchInfo *head)
+getWatchInfoListSize (struct WatchInfo *head)
{
- int count = 0;
- int largestStr = 0;
- struct WatchInfo *tmp = head;
+ int count = 0;
+ int largestStr = 0;
+ struct WatchInfo *tmp = head;
- while (NULL != tmp) {
- if (largestStr < strlen(tmp->value))
- largestStr = strlen(tmp->value);
- tmp = tmp->next;
- count++;
- }
+ while (NULL != tmp)
+ {
+ if (largestStr < strlen (tmp->value))
+ largestStr = strlen (tmp->value);
+ tmp = tmp->next;
+ count++;
+ }
- return count * largestStr;
+ return count * largestStr;
}
-static const char*
-watchInfoListToString(struct WatchInfo *head)
+static const char *
+watchInfoListToString (struct WatchInfo *head)
{
- char *string = GNUNET_malloc(getWatchInfoListSize(head));
- char *strTmp;
- struct WatchInfo *tmp = head;
+ char *string = GNUNET_malloc (getWatchInfoListSize (head));
+ char *strTmp;
+ struct WatchInfo *tmp = head;
- GNUNET_asprintf (&strTmp, "%s\t \t%s\n", tmp->hitNumber, tmp->value);
- strcpy (string, strTmp);
- GNUNET_free (strTmp);
- tmp = tmp->next;
+ GNUNET_asprintf (&strTmp, "%s\t \t%s\n", tmp->hitNumber, tmp->value);
+ strcpy (string, strTmp);
+ GNUNET_free (strTmp);
+ tmp = tmp->next;
- while (NULL != tmp) {
- GNUNET_asprintf (&strTmp, "%s\t \t%s\n", tmp->hitNumber,
tmp->value);
- strcat (string, strTmp);
- GNUNET_free(strTmp);
- tmp = tmp->next;
- }
+ while (NULL != tmp)
+ {
+ GNUNET_asprintf (&strTmp, "%s\t \t%s\n", tmp->hitNumber, tmp->value);
+ strcat (string, strTmp);
+ GNUNET_free (strTmp);
+ tmp = tmp->next;
+ }
- return string;
+ return string;
}
#endif
-static const char* getValgrindOutput(struct GNUNET_MONKEY_ACTION_Context
*cntxt)
+static const char *
+getValgrindOutput (struct GNUNET_MONKEY_ACTION_Context *cntxt)
{
- char* valgrindOutput;
- int size;
- FILE *valgrindFile = fopen(cntxt->valgrind_output_tmp_file_name, "r");
- fseek(valgrindFile, 0L, SEEK_END);
- size = ftell(valgrindFile);
- fseek(valgrindFile, 0L, SEEK_SET);
+ char *valgrindOutput;
+ int size;
+ FILE *valgrindFile = fopen (cntxt->valgrind_output_tmp_file_name, "r");
+ fseek (valgrindFile, 0L, SEEK_END);
+ size = ftell (valgrindFile);
+ fseek (valgrindFile, 0L, SEEK_SET);
- valgrindOutput = GNUNET_malloc(size);
- fread(valgrindOutput, size - 1, 1, valgrindFile);
- fclose(valgrindFile);
- return valgrindOutput;
+ valgrindOutput = GNUNET_malloc (size);
+ fread (valgrindOutput, size - 1, 1, valgrindFile);
+ fclose (valgrindFile);
+ return valgrindOutput;
}
@@ -583,8 +714,8 @@
"Bug detected in
file:%s\nfunction:%s\nline:%d\nreason:%s\nreceived signal:%s\n%s\n Details:\n
Expression:%s is NULL\n",
cntxt->gdb_frames->file, cntxt->gdb_frames->func,
cntxt->gdb_frames->line,
- mi_reason_enum_to_str (cntxt->gdb_stop_reason->
- reason),
+ mi_reason_enum_to_str (cntxt->
+ gdb_stop_reason->reason),
cntxt->gdb_stop_reason->signal_name,
cntxt->gdb_stop_reason->signal_meaning,
cntxt->gdb_null_variable);
@@ -594,7 +725,8 @@
if (NULL == cntxt->inspect_expression)
{
/* Assertion Failure */
- const char *expToString =
expressionListToString(expressionListHead);
+ 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,
@@ -607,11 +739,11 @@
else
{
/* Inspection of user-defined expression */
- /*
- GNUNET_asprintf(&(cntxt->debug_report),
- "Inspection of expression: %s in function: %s,
file:%s\nHit Number: \t \tValue:\n%s",
- cntxt->inspect_expression, cntxt->inspect_function,
cntxt->binary_name, watchInfoListToString(watchInfoListHead));
- */
+ /*
+ GNUNET_asprintf(&(cntxt->debug_report),
+ "Inspection of expression: %s in function: %s, file:%s\nHit
Number: \t \tValue:\n%s",
+ cntxt->inspect_expression, cntxt->inspect_function,
cntxt->binary_name, watchInfoListToString(watchInfoListHead));
+ */
}
}
break;
@@ -622,7 +754,7 @@
cntxt->gdb_frames->line,
cntxt->gdb_stop_reason->signal_name,
cntxt->gdb_stop_reason->signal_meaning,
- getValgrindOutput(cntxt));
+ getValgrindOutput (cntxt));
break;
default:
break;
@@ -634,17 +766,19 @@
int
-GNUNET_MONKEY_ACTION_delete_context(struct GNUNET_MONKEY_ACTION_Context *cntxt)
+GNUNET_MONKEY_ACTION_delete_context (struct GNUNET_MONKEY_ACTION_Context
+ *cntxt)
{
- if (NULL != cntxt->debug_report)
- GNUNET_free(cntxt->debug_report);
- if (NULL != cntxt->valgrind_output_tmp_file_name) {
- remove(cntxt->valgrind_output_tmp_file_name);
- GNUNET_free(cntxt->valgrind_output_tmp_file_name);
- }
+ if (NULL != cntxt->debug_report)
+ GNUNET_free (cntxt->debug_report);
+ if (NULL != cntxt->valgrind_output_tmp_file_name)
+ {
+ remove (cntxt->valgrind_output_tmp_file_name);
+ GNUNET_free (cntxt->valgrind_output_tmp_file_name);
+ }
- GNUNET_free(cntxt);
- return GNUNET_OK;
+ GNUNET_free (cntxt);
+ return GNUNET_OK;
}
Added: monkey/src/monkey/bug_assertion_failure.db
===================================================================
(Binary files differ)
Property changes on: monkey/src/monkey/bug_assertion_failure.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: monkey/src/monkey/bug_bad_memory_access.db
===================================================================
(Binary files differ)
Property changes on: monkey/src/monkey/bug_bad_memory_access.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: monkey/src/monkey/bug_division_by_zero_loop.c
===================================================================
--- monkey/src/monkey/bug_division_by_zero_loop.c
(rev 0)
+++ monkey/src/monkey/bug_division_by_zero_loop.c 2011-11-22 22:44:39 UTC
(rev 18263)
@@ -0,0 +1,15 @@
+int
+main (const char *args[])
+{
+ int i;
+ int k = -1;
+ double result = 0.0;
+ int tmp;
+
+ for (i = 0; i < 5; i++)
+ {
+ k += i;
+ result = result / k; /* Division by zero in second iteration */
+ }
+ return 0;
+}
Property changes on: monkey/src/monkey/bug_division_by_zero_loop.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: monkey/src/monkey/bug_null_assertion_failure.db
===================================================================
Added: monkey/src/monkey/bug_null_pointer_exception.db
===================================================================
(Binary files differ)
Property changes on: monkey/src/monkey/bug_null_pointer_exception.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: monkey/src/monkey/edb_api.c
===================================================================
--- monkey/src/monkey/edb_api.c 2011-11-22 19:37:07 UTC (rev 18262)
+++ monkey/src/monkey/edb_api.c 2011-11-22 22:44:39 UTC (rev 18263)
@@ -81,6 +81,35 @@
}
+
+int
+GNUNET_MONKEY_EDB_get_file_names (struct GNUNET_MONKEY_EDB_Context *cntxt,
+ GNUNET_MONKEY_FileIterator iter,
+ void *iter_cls)
+{
+ int err;
+ char *errMsg;
+ char *query;
+
+ if (asprintf (&query, "select distinct file_name from Expression") == -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
*
@@ -92,28 +121,35 @@
* @return GNUNET_OK on success, GNUNET_NO on failure
*/
int
-GNUNET_MONKEY_EDB_get_expression_scope_end(struct GNUNET_MONKEY_EDB_Context
*cntxt,
- const char *file_name, int start_line_no,
- GNUNET_MONKEY_ExpressionIterator iter,
- void *iter_cls)
+GNUNET_MONKEY_EDB_get_expression_scope_end (struct GNUNET_MONKEY_EDB_Context
+ *cntxt, const char *file_name,
+ int start_line_no,
+ GNUNET_MONKEY_ExpressionIterator
+ iter, void *iter_cls)
{
- int err;
- char *errMsg;
- char *query;
+ int err;
+ char *errMsg;
+ char *query;
- if (asprintf(&query, "select end_lineno from Expression where file_name
LIKE \'%%/%s\' and start_lineno = %d", file_name, start_line_no) == -1) {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Memory allocation problem
occurred during creating database query!\n");
- return GNUNET_NO;
- }
+ if (asprintf
+ (&query,
+ "select end_lineno from Expression where file_name LIKE \'%%/%s\' and
start_lineno = %d",
+ file_name, start_line_no) == -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,
+ 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 GNUNET_NO;
+ }
+ return GNUNET_OK;
}
@@ -162,11 +198,11 @@
int
-GNUNET_MONKEY_EDB_get_sub_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_EDB_get_sub_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)
{
int err;
char *errMsg;
@@ -191,4 +227,3 @@
}
return GNUNET_OK;
}
-
Modified: monkey/src/monkey/gnunet-monkey.c
===================================================================
--- monkey/src/monkey/gnunet-monkey.c 2011-11-22 19:37:07 UTC (rev 18262)
+++ monkey/src/monkey/gnunet-monkey.c 2011-11-22 22:44:39 UTC (rev 18263)
@@ -24,6 +24,7 @@
*/
#include <stdio.h>
+#include <sys/stat.h>
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
#include "gnunet_monkey_action.h"
@@ -54,22 +55,35 @@
int result;
struct GNUNET_MONKEY_ACTION_Context *cntxt;
- if (strcasecmp (mode, "email") == 0)
+ if (NULL == edbFilePath)
{
- if (NULL == emailAddress)
+ /* lookup a file named test.db in the working directory */
+ struct stat buf;
+ if (0 != stat ("test.db", &buf))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Working in email mode requires an email address!\n");
+ "Expression Database file was not provided as and
argument, "
+ "and there is no file named test.db in monkey's working
directory!\n");
+ GNUNET_break (0);
ret = 1;
return;
}
+
}
- else if (strcasecmp (mode, "text") == 0)
+
+ if (NULL == dumpFileName)
{
- if (NULL == dumpFileName)
+ /* if no file name provided for the output report, use a default one in
the current working directory */
+ dumpFileName = "monkey_output";
+ }
+
+ if (strcasecmp (mode, "email") == 0)
+ {
+ if (NULL == emailAddress)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Working in text mode requires a path for the dump
file!\n");
+ "Working in email mode requires an email address!\n");
+ GNUNET_break (0);
ret = 1;
return;
}
@@ -144,7 +158,7 @@
default:
break;
}
- GNUNET_MONKEY_ACTION_delete_context(cntxt);
+ GNUNET_MONKEY_ACTION_delete_context (cntxt);
}
@@ -154,26 +168,31 @@
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'m', "mode", NULL,
gettext_noop
- ("monkey's mode of operation: options are \"text\" or \"email\""),
+ ("mandatory:monkey's mode of operation: options are \"text\" or
\"email\""),
GNUNET_YES, &GNUNET_GETOPT_set_string, &mode},
{'b', "binary", NULL,
- gettext_noop ("binary for program to debug with monkey"),
+ gettext_noop
+ ("mandatory:path to a binary file for a program to debug with monkey"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &binaryName},
{'o', "output", NULL,
gettext_noop
- ("path to file to dump monkey's output in case of text mode"),
+ ("path to the debug report generated by monkey. If not provided, monkey
will save the report in file named monkey_output"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &dumpFileName},
{'a', "address", NULL,
- gettext_noop ("address to send email to in case of email mode"),
+ gettext_noop ("email address to which monkey will send debug report"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &emailAddress},
- {'d', "database", NULL, gettext_noop ("path to Expression Database file"),
+ {'d', "database", NULL,
+ gettext_noop ("mandatory:path to Expression Database file"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &edbFilePath},
{'g', "gdb", NULL,
- gettext_noop ("path to gdb binary in use; default is /usr/bin/gdb"),
+ gettext_noop ("path to gdb binary to use. Default is /usr/bin/gdb"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &gdbBinaryPath},
- {'f', "function", NULL, gettext_noop ("Monkey will set a breakpoint on
this function"),
+ {'f', "function", NULL,
+ gettext_noop ("monkey will set a breakpoint on this function"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &inspectFunction},
- {'i', "inspect", NULL, gettext_noop ("An expression to inspect in the
function specified after the argument f"),
+ {'i', "inspect", NULL,
+ gettext_noop
+ ("expression to inspect in the function specified after the argument f"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &inspectExpression},
GNUNET_GETOPT_OPTION_END
};
Modified: monkey/src/monkey/gnunet_monkey_edb.h
===================================================================
--- monkey/src/monkey/gnunet_monkey_edb.h 2011-11-22 19:37:07 UTC (rev
18262)
+++ monkey/src/monkey/gnunet_monkey_edb.h 2011-11-22 22:44:39 UTC (rev
18263)
@@ -59,8 +59,10 @@
typedef int (*GNUNET_MONKEY_ExpressionIterator) (void *, int, char **,
char **);
+typedef int (*GNUNET_MONKEY_FileIterator) (void *, int, char **, char **);
+
/**
* Return the line number of the end-of-scope for the expression indicated by
start_line_no
*
@@ -72,13 +74,28 @@
* @return GNUNET_OK on success, GNUNET_NO on failure
*/
int
-GNUNET_MONKEY_EDB_get_expression_scope_end(struct GNUNET_MONKEY_EDB_Context
*cntxt,
- const char *file_name, int start_line_no,
- GNUNET_MONKEY_ExpressionIterator iter,
- void *iter_cls);
+GNUNET_MONKEY_EDB_get_expression_scope_end (struct GNUNET_MONKEY_EDB_Context
+ *cntxt, const char *file_name,
+ int start_line_no,
+ GNUNET_MONKEY_ExpressionIterator
+ iter, void *iter_cls);
+
/**
+ * Return all the source code file names available in the Expression Database
+ *
+ * @param cntxt context containing the Expression Database handle
+ * @param iter callback function, iterator for values returned from the
Database
+ * @param iter_cls closure for the file names iterator, will contain the file
names
+ * @return GNUNET_OK on success, GNUNET_NO on failure
+ */
+int
+GNUNET_MONKEY_EDB_get_file_names (struct GNUNET_MONKEY_EDB_Context *cntxt,
+ GNUNET_MONKEY_FileIterator 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
* For example, consider the following code snippet:
@@ -111,11 +128,11 @@
int
-GNUNET_MONKEY_EDB_get_sub_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_EDB_get_sub_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);
Modified: monkey/src/monkey/test_gnunet_monkey.c
===================================================================
--- monkey/src/monkey/test_gnunet_monkey.c 2011-11-22 19:37:07 UTC (rev
18262)
+++ monkey/src/monkey/test_gnunet_monkey.c 2011-11-22 22:44:39 UTC (rev
18263)
@@ -21,7 +21,7 @@
/**
* @file monkey/test_gnunet_monkey.c
* @brief Testcase for Monkey
- * @author Safey Abdel Halim
+ * @author Safey A.Halim
*/
/**
@@ -42,13 +42,13 @@
static int
check ()
{
- GNUNET_OS_process_close (GNUNET_OS_start_process (NULL, NULL,
- "gnunet-monkey",
- "gnunet-monkey",
- "./bug_null_pointer_exception",
- NULL));
-
- return 0;
+ GNUNET_OS_process_close (GNUNET_OS_start_process (NULL, NULL,
+ "gnunet-monkey",
+ "gnunet-monkey",
+
"./bug_null_pointer_exception",
+ NULL));
+
+ return 0;
}
@@ -59,14 +59,13 @@
GNUNET_log_setup ("test-gnunet-monkey",
#if VERBOSE
- "DEBUG",
+ "DEBUG",
#else
- "WARNING",
+ "WARNING",
#endif
- NULL);
+ NULL);
ret = check ();
return ret;
}
/* end of test_gnunet_monkey.c */
-
Added: monkey/src/monkey/test_monkey_assertion_failure.sh
===================================================================
--- monkey/src/monkey/test_monkey_assertion_failure.sh
(rev 0)
+++ monkey/src/monkey/test_monkey_assertion_failure.sh 2011-11-22 22:44:39 UTC
(rev 18263)
@@ -0,0 +1,13 @@
+#!/bin/sh
+echo -n "Test Monkey with Bug - Null Pointer Exception -"
+gnunet-monkey -m text -d bug_assertion_failure.db -b bug_assertion_failure -o
npe.out || (echo "Monkey Failed!" && exit 1)
+grep "Bug detected in file:bug_null_pointer_exception.c" npe.out > /dev/null
|| (echo "FAIL" && exit 1)
+grep "function:crashFunction" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep "line:14" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep "reason:(null)" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep "received signal:SIGSEGV" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep "Segmentation fault" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep " Details:" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep " Expression:crashStruct is NULL" npe.out > /dev/null || (echo "FAIL" &&
exit 1)
+rm -f npe.out
+echo "PASS"
Modified: monkey/src/monkey/test_monkey_edb.c
===================================================================
--- monkey/src/monkey/test_monkey_edb.c 2011-11-22 19:37:07 UTC (rev 18262)
+++ monkey/src/monkey/test_monkey_edb.c 2011-11-22 22:44:39 UTC (rev 18263)
@@ -22,14 +22,14 @@
* @brief testcase for edb_api.c
*/
#include "platform.h"
-#include "gnunet_common.h"
+#include "gnunet/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"
+ "whole.part=&part", "43"
};
static int refCount = 0;
@@ -53,6 +53,13 @@
int
main (int args, const char *argv[])
{
+ GNUNET_log_setup ("test-monkey-edb",
+#if VERBOSE
+ "DEBUG",
+#else
+ "WARNING",
+#endif
+ NULL);
struct GNUNET_MONKEY_EDB_Context *cntxt;
cntxt = GNUNET_MONKEY_EDB_connect ("test.db");
ret =
Modified: monkey/src/monkey/test_monkey_npe.sh
===================================================================
--- monkey/src/monkey/test_monkey_npe.sh 2011-11-22 19:37:07 UTC (rev
18262)
+++ monkey/src/monkey/test_monkey_npe.sh 2011-11-22 22:44:39 UTC (rev
18263)
@@ -1,11 +1,13 @@
#!/bin/sh
echo -n "Test Monkey with Bug - Null Pointer Exception -"
-gnunet-monkey --mode text --binary bug_null_pointer_exception --output npe.out
&& exit 0
-grep "Bug detected in file:bug_null_pointer_exception.c" npe.out > /dev/null
|| exit 1
-grep "function:crashFunction" npe.out > /dev/null || exit 1
-grep "line:8" npe.out > /dev/null || exit 1
-grep "reason:Signal received" npe.out > /dev/null || exit 1
-grep "received signal:EXC_BAD_ACCESS" npe.out > /dev/null || exit 1
-grep "Could not access memory" npe.out > /dev/null || exit 1
+gnunet-monkey -m text -d bug_null_pointer_exception.db -b
bug_null_pointer_exception -o npe.out || (echo "Monkey Failed!" && exit 1)
+grep "Bug detected in file:bug_null_pointer_exception.c" npe.out > /dev/null
|| (echo "FAIL" && exit 1)
+grep "function:crashFunction" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep "line:14" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep "reason:(null)" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep "received signal:SIGSEGV" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep "Segmentation fault" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep " Details:" npe.out > /dev/null || (echo "FAIL" && exit 1)
+grep " Expression:crashStruct is NULL" npe.out > /dev/null || (echo "FAIL" &&
exit 1)
rm -f npe.out
-echo "PASS"
\ No newline at end of file
+echo "PASS"
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18263 - in monkey: . src/monkey,
gnunet <=