[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r15206 - gnunet/src/monkey
From: |
gnunet |
Subject: |
[GNUnet-SVN] r15206 - gnunet/src/monkey |
Date: |
Thu, 12 May 2011 09:32:10 +0200 |
Author: safey
Date: 2011-05-12 09:32:10 +0200 (Thu, 12 May 2011)
New Revision: 15206
Added:
gnunet/src/monkey/bug_bad_memory_access
gnunet/src/monkey/bug_bad_memory_access.c
Modified:
gnunet/src/monkey/Makefile.am
gnunet/src/monkey/action_api.c
gnunet/src/monkey/gnunet-monkey.c
gnunet/src/monkey/gnunet_monkey_action.h
Log:
Monkey supports bad memory access using Valgrind
Modified: gnunet/src/monkey/Makefile.am
===================================================================
--- gnunet/src/monkey/Makefile.am 2011-05-11 15:38:25 UTC (rev 15205)
+++ gnunet/src/monkey/Makefile.am 2011-05-12 07:32:10 UTC (rev 15206)
@@ -40,7 +40,8 @@
gnunet-service-monkey
noinst_PROGRAMS = \
- bug_null_pointer_exception
+ bug_null_pointer_exception \
+ bug_bad_memory_access
gnunet_monkey_SOURCES = \
gdbmi.h \
@@ -80,6 +81,9 @@
bug_null_pointer_exception:
gcc -g -O0 -o bug_null_pointer_exception bug_null_pointer_exception.c
+bug_bad_memory_access:
+ gcc -g -O0 -o bug_bad_memory_access bug_bad_memory_access.c
+
check_PROGRAMS = \
test_monkey_edb
#test_gnunet_monkey
Modified: gnunet/src/monkey/action_api.c
===================================================================
--- gnunet/src/monkey/action_api.c 2011-05-11 15:38:25 UTC (rev 15205)
+++ gnunet/src/monkey/action_api.c 2011-05-12 07:32:10 UTC (rev 15206)
@@ -122,12 +122,6 @@
}
-
-int GNUNET_MONKEY_ACTION_rerun_with_valgrind()
-{
- return GNUNET_OK;
-}
-
static int iterateExpressions(void *cls, int numColumns, char **colValues,
char **colNames)
{
struct Expression *expression;
@@ -159,10 +153,10 @@
static int analyzeSegmentationFault(struct GNUNET_MONKEY_ACTION_Context *cntxt)
{
- struct Expression *faultyExpression;
+ struct Expression *faultyExpression = NULL;
struct Expression *tmp;
int expressionLength = 0;
- mi_wp *watchPoint;
+ //mi_wp *watchPoint;
tmp = expressionListHead;
while (NULL != tmp) {
@@ -174,23 +168,40 @@
tmp = tmp->next;
}
- /* Set watch points on the faulty-expression's subexpressions */
- tmp = expressionListHead;
- while (NULL != tmp) {
- if (tmp != faultyExpression) {
- /* Only subexpressions are interesting */
- watchPoint = gmi_break_watch(cntxt->gdb_handle,
wm_write, tmp->expressionSyntax);
- if (!watchPoint)
- {
- printf("Error in setting watchpoint\n");
- return 1;
- }
- printf("Watchpoint %d for expression: %s\n",
watchPoint->number, watchPoint->exp);
- mi_free_wp(watchPoint);
+ if (NULL != faultyExpression) {
+ tmp = expressionListHead;
+ while (NULL != tmp) {
+ const char* eval;
+ if (tmp != faultyExpression) {
+ eval =
gmi_data_evaluate_expression(cntxt->gdb_handle, tmp->expressionSyntax);
+ if (NULL != eval && strcmp(eval, "0x0") == 0) {
+ cntxt->gdb_null_variable =
tmp->expressionSyntax;
+ return GNUNET_OK;
+ }
+ }
+ tmp = tmp->next;
}
- tmp = tmp->next;
}
- return GNUNET_OK;
+ /* Set watch points on the faulty-expression's subexpressions */
+// if (NULL != faultyExpression) {
+// tmp = expressionListHead;
+// while (NULL != tmp) {
+// if (tmp != faultyExpression) {
+// /* Only subexpressions are interesting */
+// watchPoint =
gmi_break_watch(cntxt->gdb_handle, wm_write, tmp->expressionSyntax);
+// if (!watchPoint)
+// {
+// printf("Error in setting watchpoint\n");
+// return 1;
+// }
+// printf("Watchpoint %d for expression: %s\n",
watchPoint->number, watchPoint->exp);
+// mi_free_wp(watchPoint);
+// }
+// tmp = tmp->next;
+// }
+// return GNUNET_OK;
+// }
+ return GDB_STATE_ERROR;
}
@@ -219,13 +230,39 @@
NULL);
if (strcasecmp(cntxt->gdb_stop_reason->signal_meaning, "Segmentation
fault") == 0)
- analyzeSegmentationFault(cntxt);
+ ret = analyzeSegmentationFault(cntxt);
GNUNET_MONKEY_EDB_disconnect(edbCntxt);
+ mi_disconnect(cntxt->gdb_handle);
return ret;
}
+int GNUNET_MONKEY_ACTION_rerun_with_valgrind(struct
GNUNET_MONKEY_ACTION_Context* cntxt) {
+ FILE* valgrindPipe;
+ int size;
+ const char* valgrindCommand;
+ cntxt->debug_mode = DEBUG_MODE_VALGRIND;
+ asprintf(&valgrindCommand, "valgrind --leak-check=yes %s",
cntxt->binary_name);
+ valgrindPipe = popen(valgrindCommand, "r");
+ if (NULL == valgrindPipe) {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error in running
Valgrind!\n");
+ return GNUNET_NO;
+ }
+
+ fscanf(valgrindPipe, "%d", &size);
+
+ /* Read Valgrind stream */
+ cntxt->valgrind_output = GNUNET_malloc(size);
+ fscanf(valgrindPipe, "%s", cntxt->valgrind_output);
+ if (0 != pclose(valgrindPipe)) {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error while closing
Valgrind pipe!\n");
+ return GNUNET_NO;
+ }
+ return GNUNET_OK;
+}
+
+
int GNUNET_MONKEY_ACTION_rerun_with_gdb(struct GNUNET_MONKEY_ACTION_Context*
cntxt)
{
cntxt->debug_mode = DEBUG_MODE_GDB;
@@ -278,7 +315,7 @@
}
/* Here we should be stopped when the program crashes */
ret = wait_for_stop(cntxt->gdb_handle, cntxt);
- if (ret != GDB_STATE_ERROR)
+ if (ret == GDB_STATE_ERROR)
mi_disconnect(cntxt->gdb_handle);
return ret;
@@ -290,10 +327,15 @@
switch (cntxt->debug_mode) {
case DEBUG_MODE_GDB:
GNUNET_asprintf(&(cntxt->debug_report),
- "Bug detected in
file:%s\nfunction:%s\nline:%d\nreason:%s\nreceived signal:%s\n%s\n",
- cntxt->gdb_frames->file, cntxt->gdb_frames->func,
cntxt->gdb_frames->line, mi_reason_enum_to_str(cntxt->gdb_stop_reason->reason),
cntxt->gdb_stop_reason->signal_name, cntxt->gdb_stop_reason->signal_meaning);
+ "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),
+ cntxt->gdb_stop_reason->signal_name,
cntxt->gdb_stop_reason->signal_meaning, cntxt->gdb_null_variable);
break;
case DEBUG_MODE_VALGRIND:
+ GNUNET_asprintf(&(cntxt->debug_report),
+ "Bug detected in
file:%s\nfunction:%s\nline:%d\nreason:%s\nreceived signal:%s\n%s\n Details:\n
Memory Check from Valgrind:%s\n",
+ cntxt->gdb_frames->file, cntxt->gdb_frames->func,
cntxt->gdb_frames->line, mi_reason_enum_to_str(cntxt->gdb_stop_reason->reason),
+ cntxt->gdb_stop_reason->signal_name,
cntxt->gdb_stop_reason->signal_meaning, cntxt->valgrind_output);
break;
default:
break;
Added: gnunet/src/monkey/bug_bad_memory_access
===================================================================
(Binary files differ)
Property changes on: gnunet/src/monkey/bug_bad_memory_access
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: gnunet/src/monkey/bug_bad_memory_access.c
===================================================================
--- gnunet/src/monkey/bug_bad_memory_access.c (rev 0)
+++ gnunet/src/monkey/bug_bad_memory_access.c 2011-05-12 07:32:10 UTC (rev
15206)
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <string.h>
+
+
+void badMemoryAccess()
+{
+ int *p = (int*) 0x4252352;
+ printf("Bad memory access now!\n");
+ *p = 5;
+}
+
+int main(int argc, char *argv[])
+{
+ badMemoryAccess();
+ return 0;
+}
Modified: gnunet/src/monkey/gnunet-monkey.c
===================================================================
--- gnunet/src/monkey/gnunet-monkey.c 2011-05-11 15:38:25 UTC (rev 15205)
+++ gnunet/src/monkey/gnunet-monkey.c 2011-05-12 07:32:10 UTC (rev 15206)
@@ -77,6 +77,7 @@
result = GNUNET_MONKEY_ACTION_rerun_with_gdb(cntxt);
switch (result) {
+ int retVal;
case GDB_STATE_ERROR:
break;
case GDB_STATE_EXIT_NORMALLY:
@@ -85,10 +86,19 @@
break;
case GDB_STATE_STOPPED:
/*FIXME: Expression Database should be inspected here (before
writing the report) */
- if (GNUNET_OK !=
GNUNET_MONKEY_ACTION_inspect_expression_database(cntxt)) {
+ retVal =
GNUNET_MONKEY_ACTION_inspect_expression_database(cntxt);
+ if (GNUNET_NO == retVal) {
GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error using
Expression Database!\n");
ret = 1;
break;
+ } else if (GDB_STATE_ERROR == retVal) {
+ /* GDB could not locate a NULL value expression, launch
Valgrind */
+ retVal =
GNUNET_MONKEY_ACTION_rerun_with_valgrind(cntxt);
+ if (GNUNET_NO == retVal) {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error
using Valgrind!\n");
+ ret = 1;
+ break;
+ }
}
if(GNUNET_OK != GNUNET_MONKEY_ACTION_format_report(cntxt)){
GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error in
generating debug report!\n");
Modified: gnunet/src/monkey/gnunet_monkey_action.h
===================================================================
--- gnunet/src/monkey/gnunet_monkey_action.h 2011-05-11 15:38:25 UTC (rev
15205)
+++ gnunet/src/monkey/gnunet_monkey_action.h 2011-05-12 07:32:10 UTC (rev
15206)
@@ -63,14 +63,18 @@
const char* gdb_in_use;
mi_stop* gdb_stop_reason;
mi_frames* gdb_frames;
+ const char* gdb_null_variable;
+
+ /* Valgrind memcheck attributes */
+ char* valgrind_output;
};
int GNUNET_MONKEY_ACTION_report_file(struct GNUNET_MONKEY_ACTION_Context*
cntxt, const char* dumpFileName);
int GNUNET_MONKEY_ACTION_report_email(struct GNUNET_MONKEY_ACTION_Context*
cntxt);
-int GNUNET_MONKEY_ACTION_rerun_with_valgrind(void);
int GNUNET_MONKEY_ACTION_inspect_expression_database(struct
GNUNET_MONKEY_ACTION_Context* cntxt);
int GNUNET_MONKEY_ACTION_rerun_with_gdb(struct GNUNET_MONKEY_ACTION_Context*
cntxt);
+int GNUNET_MONKEY_ACTION_rerun_with_valgrind(struct
GNUNET_MONKEY_ACTION_Context* cntxt);
int GNUNET_MONKEY_ACTION_format_report(struct GNUNET_MONKEY_ACTION_Context*
cntxt);
int GNUNET_MONKEY_ACTION_check_bug_redundancy(void);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r15206 - gnunet/src/monkey,
gnunet <=