[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r20665 - in monkey/branches/MonkeyBacktracking/monkey: . sr
From: |
gnunet |
Subject: |
[GNUnet-SVN] r20665 - in monkey/branches/MonkeyBacktracking/monkey: . src/monkey |
Date: |
Wed, 21 Mar 2012 19:36:12 +0100 |
Author: safey
Date: 2012-03-21 19:36:12 +0100 (Wed, 21 Mar 2012)
New Revision: 20665
Removed:
monkey/branches/MonkeyBacktracking/monkey/bug_assertion_failure.db
Modified:
monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
monkey/branches/MonkeyBacktracking/monkey/src/monkey/bug_assertion_failure.c
monkey/branches/MonkeyBacktracking/monkey/src/monkey/bug_assertion_failure.db
monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi.h
monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_prg_control.c
monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c
Log:
Backtracking supporting Division By Zero, and loops.
Assertion failures still not working
Deleted: monkey/branches/MonkeyBacktracking/monkey/bug_assertion_failure.db
===================================================================
Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
2012-03-21 17:22:30 UTC (rev 20664)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
2012-03-21 18:36:12 UTC (rev 20665)
@@ -11,13 +11,14 @@
#include <string.h>
#include <stdio.h>
-extern void sendMail (const char *messageContents, const char *emailAddress);
+extern void sendMail(const char *messageContents,
+ const char *emailAddress);
static int async_c = 0;
static int stepBackCount = 0;
static char *signalMeaning = NULL;
-static int failureFunctionStartLine = 0; // start line number of the function
in which the failure occurs
+static int failureFunctionStartLine = 0; // start line number of the
function in which the failure occurs
static struct Expression *expressionListHead = NULL;
static struct Expression *expressionListTail = NULL;
static struct WatchInfo *watchInfoListHead = NULL;
@@ -29,455 +30,403 @@
static struct ScopeEnd *scopeEndListTail = NULL;
-struct ScopeEnd
-{
- struct ScopeEnd *next;
- struct ScopeEnd *prev;
+struct ScopeEnd {
+ struct ScopeEnd *next;
+ struct ScopeEnd *prev;
- int lineNo;
+ int lineNo;
};
-struct FileName
-{
- struct FileName *next;
- struct FileName *prev;
+struct FileName {
+ struct FileName *next;
+ struct FileName *prev;
- const char *name;
+ const char *name;
};
-struct Expression
-{
- struct Expression *next;
- struct Expression *prev;
- const char *expressionSyntax;
- const char *expressionValue;
- int lineNo;
+struct Expression {
+ struct Expression *next;
+ struct Expression *prev;
+ const char *expressionSyntax;
+ const char *expressionValue;
+ int lineNo;
};
-struct Function
-{
- struct Function *next;
- struct Function *prev;
- const char *name;
- const char *file;
- int line;
- int depth;
- struct Expression *expressionListHead;
- struct Expression *expressionListTail;
+struct Function {
+ struct Function *next;
+ struct Function *prev;
+ const char *name;
+ const char *file;
+ int line;
+ int depth;
+ struct Expression *expressionListHead;
+ struct Expression *expressionListTail;
};
-struct Trace
-{
- struct Trace *next;
- struct Trace *prev;
- struct Function *functionListHead;
- struct Function *functionListTail;
+struct Trace {
+ struct Trace *next;
+ struct Trace *prev;
+ struct Function *functionListHead;
+ struct Function *functionListTail;
};
-struct Epoch
-{
- struct Trace *traceListHead;
- struct Trace *traceListTail;
+struct Epoch {
+ struct Trace *traceListHead;
+ struct Trace *traceListTail;
} *epoch;
-struct WatchInfo
-{
- struct WatchInfo *next;
- struct WatchInfo *prev;
- int hitNumber;
- const char *value;
+struct WatchInfo {
+ struct WatchInfo *next;
+ struct WatchInfo *prev;
+ int hitNumber;
+ const char *value;
};
-static void
-cb_console (const char *str, void *data)
+static void cb_console(const char *str, void *data)
{
- printf ("CONSOLE> %s\n", str);
+ printf("CONSOLE> %s\n", str);
}
/* Note that unlike what's documented in gdb docs it isn't usable. */
-static void
-cb_target (const char *str, void *data)
+static void cb_target(const char *str, void *data)
{
- printf ("TARGET> %s\n", str);
+ printf("TARGET> %s\n", str);
}
-static void
-cb_log (const char *str, void *data)
+static void cb_log(const char *str, void *data)
{
- printf ("LOG> %s\n", str);
+ printf("LOG> %s\n", str);
}
-static void
-cb_to (const char *str, void *data)
+static void cb_to(const char *str, void *data)
{
- printf (">> %s", str);
+ printf(">> %s", str);
}
-static void
-cb_from (const char *str, void *data)
+static void cb_from(const char *str, void *data)
{
- printf ("<< %s\n", str);
+ printf("<< %s\n", str);
}
-static void
-cb_async (mi_output * o, void *data)
+static void cb_async(mi_output * o, void *data)
{
- printf ("ASYNC\n");
- async_c++;
+ printf("ASYNC\n");
+ async_c++;
}
-static int
-isInCodeBase (const char *name)
+static int isInCodeBase(const char *name)
{
- struct FileName *fileName = fileNameListHead;
- while (NULL != fileName)
- {
- if (strcmp (fileName->name, name) == 0)
- return MONKEY_YES;
- fileName = fileName->next;
+ struct FileName *fileName = fileNameListHead;
+ while (NULL != fileName) {
+ if (strcmp(fileName->name, name) == 0)
+ return MONKEY_YES;
+ fileName = fileName->next;
}
- return MONKEY_NO;
+ return MONKEY_NO;
}
-static int
-wait_for_stop (struct MONKEY_ACTION_Context *cntxt)
+static int wait_for_stop(struct MONKEY_ACTION_Context *cntxt)
{
- static int safetyCount = 0;
+ static int safetyCount = 0;
- while (!mi_get_response (cntxt->gdb_handle))
- usleep (1000);
- /* The end of the async. */
- cntxt->gdb_stop_reason = mi_res_stop (cntxt->gdb_handle);
- if (cntxt->gdb_stop_reason)
- {
- safetyCount = 0; // reset the Safety Count whenever you stop for a
meaningful reason
+ while (!mi_get_response(cntxt->gdb_handle))
+ usleep(1000);
+ /* The end of the async. */
- switch (cntxt->gdb_stop_reason->reason)
- {
- case sr_exited_normally:
- return GDB_STATE_EXIT_NORMALLY;
+ cntxt->gdb_stop_reason = mi_res_stop(cntxt->gdb_handle);
- 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:
- {
- /* Execution stopped because of hitting a watch point */
- static int watchPointHitNumber = 0;
- struct WatchInfo *watchInfo =
- MONKEY_malloc (sizeof (struct WatchInfo));
- watchInfo->hitNumber = ++watchPointHitNumber;
- watchInfo->value = cntxt->gdb_stop_reason->wp_val;
- MONKEY_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;
- }
+ if (cntxt->gdb_stop_reason) {
+ safetyCount = 0; // reset the Safety Count whenever you
stop for a meaningful reason
- /* Reaching this line means that the program has stopped abnormally
OR we are in backtracking mode, and it's a step backward */
- cntxt->gdb_frames = gmi_stack_info_frame (cntxt->gdb_handle);
- if (NULL == cntxt->gdb_frames)
- {
- 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;
+ switch (cntxt->gdb_stop_reason->reason) {
+ case sr_exited_normally:
+ return GDB_STATE_EXIT_NORMALLY;
+ case sr_signal_received:
+ //gmi_set_unwind_on_signal_on(cntxt->gdb_handle);
// Program crashed. From now on preserve stack on any further received signals
+ break;
+ case sr_bkpt_hit:
+ {
+ /* continue execution */
+ gmi_exec_continue(cntxt->gdb_handle);
+ return wait_for_stop(cntxt);
+ }
+ case sr_wp_trigger:
+ {
+ /* Execution stopped because of hitting a watch point */
+ static int watchPointHitNumber = 0;
+ struct WatchInfo *watchInfo =
+ MONKEY_malloc(sizeof(struct WatchInfo));
+ watchInfo->hitNumber = ++watchPointHitNumber;
+ watchInfo->value = cntxt->gdb_stop_reason->wp_val;
+ MONKEY_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;
+ }
- //EXPERIMENTAL CODE:
- while (MONKEY_YES != isInCodeBase (cntxt->gdb_frames->file))
- {
- if (MONKEY_YES == cntxt->run_reverse) {
- gmi_exec_finish_reverse(cntxt->gdb_handle);
- while (!mi_get_response (cntxt->gdb_handle))
- usleep (1000);
+ /* Reaching this line means that the program has stopped
abnormally OR we are in backtracking mode, and it's a step backward */
+ cntxt->gdb_frames = gmi_stack_list_frames(cntxt->gdb_handle);
+ if (MONKEY_YES != isInCodeBase(cntxt->gdb_frames->file)) {
+ do {
+ cntxt->gdb_frames = cntxt->gdb_frames->next;
+ } while (MONKEY_YES !=
isInCodeBase(cntxt->gdb_frames->file));
- cntxt->gdb_frames =
gmi_stack_info_frame(cntxt->gdb_handle);
- if (NULL == cntxt->gdb_frames)
- cntxt->gdb_frames =
gmi_stack_list_frames(cntxt->gdb_handle);
- }
- else {
- cntxt->gdb_frames = cntxt->gdb_frames->next;
- }
+ if (MONKEY_YES == cntxt->run_reverse) {
+ /* We are in backtracking mode, we need to move
GDB from the shared library to our source code */
+ /*gmi_break_insert(cntxt->gdb_handle,
cntxt->gdb_frames->file,
+ cntxt->gdb_frames->line);
+ gmi_exec_continue_reverse(cntxt->gdb_handle);
+ while (!mi_get_response(cntxt->gdb_handle))
+ usleep(1000);
+ cntxt->gdb_frames =
gmi_stack_list_frames(cntxt->gdb_handle);*/
+ }
}
- if (NULL == cntxt->gdb_frames)
- MONKEY_break (0);
- }
+ if (NULL == cntxt->gdb_frames)
+ MONKEY_break(0); // Something really bad happened.
Abort!
- if (0 == cntxt->gdb_frames->line)
- {
- /*
- * This happens if the program stops in a shared library (inner
frames)
- * We will move to outer frames until reaching the faulty line in the
source code
- */
- cntxt->gdb_frames = gmi_stack_list_frames (cntxt->gdb_handle);
- do
- {
- cntxt->gdb_frames = cntxt->gdb_frames->next;
- }
- 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);
+ /* Change current GDB frame to the one containing source code */
+ gmi_stack_select_frame(cntxt->gdb_handle,
+ cntxt->gdb_frames->level);
- return GDB_STATE_STOPPED;
- }
- else if ((MONKEY_YES == cntxt->run_reverse) && (safetyCount <
GDB_SAFETY_COUNT)) { // GDB_SAFETY_COUNT prevents infinite analysis
- /* If the stop reason is NULL, don't bail out immediately, wait for
stop again.
- * It happens when a breakpoint is placed (for backtracking) that the
program stops for an unknown reason,
- * resulting in a NULL stop reason which causes Monkey to bail out
before finishing its analysis. This else if
- * clause prevents premature bail out
- */
- safetyCount++;
- return wait_for_stop(cntxt);
- }
+ return GDB_STATE_STOPPED;
+ }
+ else if ((MONKEY_YES == cntxt->run_reverse) && (safetyCount <
GDB_SAFETY_COUNT)) { // GDB_SAFETY_COUNT prevents infinite analysis
+ /* If the stop reason is NULL, don't bail out immediately, wait for
stop again.
+ * It happens when a breakpoint is placed (for backtracking) that the
program stops for an unknown reason,
+ * resulting in a NULL stop reason which causes Monkey to bail out
before finishing its analysis. This else if
+ * clause prevents premature bail out
+ */
+ safetyCount++;
+ return wait_for_stop(cntxt);
+ }
- return GDB_STATE_ERROR;
+ return GDB_STATE_ERROR;
}
int
-MONKEY_ACTION_report_file (struct MONKEY_ACTION_Context *cntxt,
- const char *dumpFileName, int isXML)
+MONKEY_ACTION_report_file(struct MONKEY_ACTION_Context *cntxt,
+ const char *dumpFileName, int isXML)
{
- FILE *file = NULL;
- if (!isXML) {
- file = fopen (dumpFileName, "w");
- MONKEY_assert (NULL != file);
- fprintf (file, "%s", cntxt->debug_report);
- } else {
- file = MONKEY_XML_WRITER_create_document(dumpFileName);
- MONKEY_XML_WRITER_write_document(file, cntxt->xml_report_node);
- }
+ FILE *file = NULL;
+ if (!isXML) {
+ file = fopen(dumpFileName, "w");
+ MONKEY_assert(NULL != file);
+ fprintf(file, "%s", cntxt->debug_report);
+ } else {
+ file = MONKEY_XML_WRITER_create_document(dumpFileName);
+ MONKEY_XML_WRITER_write_document(file, cntxt->xml_report_node);
+ }
- if (NULL != file)
- fclose(file);
- return MONKEY_OK;
+ if (NULL != file)
+ fclose(file);
+ return MONKEY_OK;
}
-int
-MONKEY_ACTION_report_email (struct MONKEY_ACTION_Context *cntxt)
+int MONKEY_ACTION_report_email(struct MONKEY_ACTION_Context *cntxt)
{
- if (cntxt->debug_mode == DEBUG_MODE_REPORT_READY)
- sendMail (cntxt->debug_report, cntxt->email_address);
+ if (cntxt->debug_mode == DEBUG_MODE_REPORT_READY)
+ sendMail(cntxt->debug_report, cntxt->email_address);
- return MONKEY_OK;
+ return MONKEY_OK;
}
static int
-iterateFileNames (void *cls, int numColumns, char **colValues,
- char **colNames)
+iterateFileNames(void *cls, int numColumns, char **colValues,
+ char **colNames)
{
- struct FileName *fileName;
- char *token;
- char *ext;
- int tokenLength;
+ struct FileName *fileName;
+ char *token;
+ char *ext;
+ int tokenLength;
- if (NULL == colValues[0] || NULL == colValues[1])
- return 1; /* Error */
+ 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 = MONKEY_malloc (sizeof (struct FileName));
- fileName->name = MONKEY_strdup (token);
- fileName->next = NULL;
- fileName->prev = NULL;
- MONKEY_CONTAINER_DLL_insert (fileNameListHead, fileNameListTail,
- fileName);
- return 0; /* OK */
+ /* 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 = MONKEY_malloc(sizeof(struct FileName));
+ fileName->name = MONKEY_strdup(token);
+ fileName->next = NULL;
+ fileName->prev = NULL;
+ MONKEY_CONTAINER_DLL_insert(fileNameListHead, fileNameListTail,
+ fileName);
+ return 0; /* OK */
}
- token = strtok (NULL, "/");
+ token = strtok(NULL, "/");
}
- while (NULL != token);
+ while (NULL != token);
- return 1; /* Error */
+ return 1; /* Error */
}
static int
-outerScopesCallback (void *cls, int numColumns, char **colValues,
- char **colNames)
+outerScopesCallback(void *cls, int numColumns, char **colValues,
+ char **colNames)
{
- if (NULL == colValues[0])
- return 1; /* Error */
+ if (NULL == colValues[0])
+ return 1; /* Error */
- struct ScopeEnd *scopeEnd = MONKEY_malloc(sizeof(struct ScopeEnd));
- scopeEnd->lineNo = atoi(colValues[0]);
- MONKEY_CONTAINER_DLL_insert (scopeEndListHead, scopeEndListTail,
- scopeEnd);
- return 0; /* OK */
+ struct ScopeEnd *scopeEnd = MONKEY_malloc(sizeof(struct ScopeEnd));
+ scopeEnd->lineNo = atoi(colValues[0]);
+ MONKEY_CONTAINER_DLL_insert(scopeEndListHead, scopeEndListTail,
+ scopeEnd);
+ return 0; /* OK */
}
static int
-functionStartCallback (void *cls, int numColumns, char **colValues,
- char **colNames)
+functionStartCallback(void *cls, int numColumns, char **colValues,
+ char **colNames)
{
- if (NULL == colValues[0])
- return 1; /* Error */
+ if (NULL == colValues[0])
+ return 1; /* Error */
- failureFunctionStartLine = atoi(colValues[0]);
- return 0; /* OK */
+ failureFunctionStartLine = atoi(colValues[0]);
+ return 0; /* OK */
}
static int
-iterateExpressions (void *cls, int numColumns, char **colValues,
- char **colNames)
+iterateExpressions(void *cls, int numColumns, char **colValues,
+ char **colNames)
{
- struct Expression *expression;
- struct Function *function = (struct Function *) cls;
+ struct Expression *expression;
+ struct Function *function = (struct Function *) cls;
- if (NULL == colValues[0] || NULL == colValues[1])
- return 1; /* Error */
+ if (NULL == colValues[0] || NULL == colValues[1])
+ return 1; /* Error */
- expression = MONKEY_malloc (sizeof (struct Expression));
- expression->expressionSyntax = MONKEY_strdup (colValues[0]);
- expression->lineNo = atoi (colValues[1]);
- expression->expressionValue = NULL; expression->next = NULL;
expression->prev = NULL;
+ expression = MONKEY_malloc(sizeof(struct Expression));
+ expression->expressionSyntax = MONKEY_strdup(colValues[0]);
+ expression->lineNo = atoi(colValues[1]);
+ expression->expressionValue = NULL;
+ expression->next = NULL;
+ expression->prev = NULL;
- MONKEY_CONTAINER_DLL_insert (function->expressionListHead,
function->expressionListTail,
- expression);
+ MONKEY_CONTAINER_DLL_insert(function->expressionListHead,
+ function->expressionListTail, expression);
- return 0; /* OK */
+ return 0; /* OK */
}
static int
-scopeEndCallback (void *cls, int numColumns, char **colValues,
- char **colNames)
+scopeEndCallback(void *cls, int numColumns, char **colValues,
+ char **colNames)
{
- int *scopeEnd = (int *) cls;
+ int *scopeEnd = (int *) cls;
- *scopeEnd = atoi (colValues[0]);
- if (*scopeEnd < 0)
- return 1; /* Error */
- return 0;
+ *scopeEnd = atoi(colValues[0]);
+ if (*scopeEnd < 0)
+ return 1; /* Error */
+ return 0;
}
-static struct Expression *
-getFaultyExpression (struct Function *function)
+static struct Expression *getFaultyExpression(struct Function *function)
{
- struct Expression *faultyExpression = NULL;
- struct Expression *tmp = NULL;
- int expressionLength = 0;
+ struct Expression *faultyExpression = NULL;
+ struct Expression *tmp = NULL;
+ int expressionLength = 0;
- tmp = function->expressionListHead;
- while (NULL != tmp)
- {
- if ((tmp->lineNo == function->line)
- && (strlen (tmp->expressionSyntax) > expressionLength))
- {
- expressionLength = strlen (tmp->expressionSyntax);
- faultyExpression = tmp;
+ tmp = function->expressionListHead;
+ while (NULL != tmp) {
+ if ((tmp->lineNo == function->line)
+ && (strlen(tmp->expressionSyntax) > expressionLength)) {
+ expressionLength = strlen(tmp->expressionSyntax);
+ faultyExpression = tmp;
}
- tmp = tmp->next;
+ tmp = tmp->next;
}
- return faultyExpression;
+ return faultyExpression;
}
-static int
-isAssignment(const char* expressionSyntax) {
- if (NULL != strstr(expressionSyntax, "="))
- return MONKEY_YES;
- return MONKEY_NO;
+static int isAssignment(const char *expressionSyntax)
+{
+ if (NULL != strstr(expressionSyntax, "="))
+ return MONKEY_YES;
+ return MONKEY_NO;
}
static int
-analyzeSegmentationFault (struct Function *function, struct
MONKEY_ACTION_Context *cntxt)
+analyzeSegmentationFault(struct Function *function,
+ struct MONKEY_ACTION_Context *cntxt)
{
- struct Expression *tmp;
+ struct Expression *tmp;
- faultyExpression = getFaultyExpression (function);
+ faultyExpression = getFaultyExpression(function);
- if (NULL != faultyExpression)
- {
- tmp = function->expressionListHead;
- while (NULL != tmp)
- {
- if (tmp != faultyExpression)
- {
- if (MONKEY_NO == isAssignment(tmp->expressionSyntax)) { // We
should NOT evaluate assignments, otherwise subsequent expression evaluations
will be spoiled
- tmp->expressionValue =
- gmi_data_evaluate_expression (cntxt->gdb_handle,
-
tmp->expressionSyntax);
- if (NULL != tmp->expressionValue
- && (strcmp (tmp->expressionValue, "0x0") == 0
- || 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;
- }
- }
- else {
- /* Expressions with assignments should be removed
from the list of expressions */
- struct Expression *removedExpression = tmp;
- tmp = tmp->next;
-
MONKEY_CONTAINER_DLL_remove(function->expressionListHead,
function->expressionListTail, removedExpression);
- continue;// don't progress the pointer twice
- }
+ if (NULL != faultyExpression) {
+ tmp = function->expressionListHead;
+ while (NULL != tmp) {
+ if (tmp != faultyExpression) {
+ if (MONKEY_NO == isAssignment(tmp->expressionSyntax)) { // We
should NOT evaluate assignments, otherwise subsequent expression evaluations
will be spoiled
+ tmp->expressionValue =
+ gmi_data_evaluate_expression(cntxt->gdb_handle,
+ tmp->
+ expressionSyntax);
+ if (NULL != tmp->expressionValue
+ && (strcmp(tmp->expressionValue, "0x0") == 0
+ || 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;
+ }
+ } else {
+ /* Expressions with assignments should be removed from the
list of expressions */
+ struct Expression *removedExpression = tmp;
+ tmp = tmp->next;
+ MONKEY_CONTAINER_DLL_remove(function->
+ expressionListHead,
+ function->
+ expressionListTail,
+ removedExpression);
+ continue; // don't progress the pointer twice
+ }
}
- tmp = tmp->next;
+ tmp = tmp->next;
}
}
- /* Set watch points on the faulty-expression's subexpressions */
+ /* Set watch points on the faulty-expression's subexpressions */
// if (NULL != faultyExpression) {
// tmp = expressionListHead;
// while (NULL != tmp) {
@@ -496,156 +445,170 @@
// }
// return MONKEY_OK;
// }
- return GDB_STATE_ERROR;
+ return GDB_STATE_ERROR;
}
static int
-analyzeCustomFault (struct Function *function, struct MONKEY_ACTION_Context
*cntxt)
+analyzeCustomFault(struct Function *function,
+ struct MONKEY_ACTION_Context *cntxt)
{
- struct Expression *tmp;
- faultyExpression = getFaultyExpression (function);
+ struct Expression *tmp;
+ faultyExpression = getFaultyExpression(function);
- if (NULL != faultyExpression)
- {
- tmp = function->expressionListHead;
- while (NULL != tmp)
- {
- if (MONKEY_NO == isAssignment(tmp->expressionSyntax)) {
- const char *eval;
- eval =
- gmi_data_evaluate_expression (cntxt->gdb_handle,
- tmp->expressionSyntax);
- if (NULL != eval)
- {
- tmp->expressionValue = eval;
+ if (NULL != faultyExpression) {
+ tmp = function->expressionListHead;
+ while (NULL != tmp) {
+ if (MONKEY_NO == isAssignment(tmp->expressionSyntax)) {
+ const char *eval;
+ eval =
+ gmi_data_evaluate_expression(cntxt->gdb_handle,
+ tmp->expressionSyntax);
+ if (NULL != eval) {
+ tmp->expressionValue = eval;
}
- tmp = tmp->next;
- }
- else {
- /* Expressions with assignments should be removed from the
list of expressions */
- struct Expression *removedExpression = tmp;
- tmp = tmp->next;
- MONKEY_CONTAINER_DLL_remove(function->expressionListHead,
function->expressionListTail, removedExpression);
- }
+ tmp = tmp->next;
+ } else {
+ /* Expressions with assignments should be removed from
the list of expressions */
+ struct Expression *removedExpression = tmp;
+ tmp = tmp->next;
+
MONKEY_CONTAINER_DLL_remove(function->expressionListHead,
+
function->expressionListTail,
+ removedExpression);
+ }
}
}
- return MONKEY_OK;
+ return MONKEY_OK;
}
-static int flushTrace(struct Trace *trace) {
- struct Function *functionPtr = NULL;
- struct Expression *expressionPtr = NULL;
+static int flushTrace(struct Trace *trace)
+{
+ struct Function *functionPtr = NULL;
+ struct Expression *expressionPtr = NULL;
- while (NULL != trace->functionListHead) {
- functionPtr = trace->functionListHead;
- trace->functionListHead = trace->functionListHead->next;
+ while (NULL != trace->functionListHead) {
+ functionPtr = trace->functionListHead;
+ trace->functionListHead = trace->functionListHead->next;
- while (NULL != functionPtr->expressionListHead) {
- expressionPtr = functionPtr->expressionListHead;
- functionPtr->expressionListHead =
functionPtr->expressionListHead->next;
+ while (NULL != functionPtr->expressionListHead) {
+ expressionPtr = functionPtr->expressionListHead;
+ functionPtr->expressionListHead =
+ functionPtr->expressionListHead->next;
- MONKEY_free((char *)expressionPtr->expressionSyntax);
- MONKEY_free(expressionPtr);
- }
- MONKEY_free(functionPtr);
+ MONKEY_free((char *) expressionPtr->expressionSyntax);
+ MONKEY_free(expressionPtr);
}
- return MONKEY_OK;
+ MONKEY_free(functionPtr);
+ }
+ return MONKEY_OK;
}
-static void printTrace() {
- int i = 0;
- struct Function *functionPtr;
- struct Expression *expressionPtr;
- struct Trace *tracePtr = epoch->traceListHead;
- while (NULL != tracePtr) {
- printf("Program Stack Trace: Epoch Step %d\n", i++);
- functionPtr = tracePtr->functionListHead;
- while (NULL != functionPtr) {
- printf("Function: %s, file: %s, line: %d\n",
functionPtr->name, functionPtr->file, functionPtr->line);
-
printf("--------------------------------------------------------------------------------------------------\n");
- printf("Expressions:\n");
+static void printTrace()
+{
+ int i = 0;
+ struct Function *functionPtr;
+ struct Expression *expressionPtr;
+ struct Trace *tracePtr = epoch->traceListHead;
+ while (NULL != tracePtr) {
+ printf("Program Stack Trace: Epoch Step %d\n", i++);
+ functionPtr = tracePtr->functionListHead;
+ while (NULL != functionPtr) {
+ printf("Function: %s, file: %s, line: %d\n", functionPtr->name,
+ functionPtr->file, functionPtr->line);
+ printf
+
("--------------------------------------------------------------------------------------------------\n");
+ printf("Expressions:\n");
- expressionPtr = functionPtr->expressionListHead;
- while (NULL != expressionPtr) {
- printf("%s = %s, line: %d\n",
expressionPtr->expressionSyntax, (NULL == expressionPtr->expressionValue) ? "No
Value" : expressionPtr->expressionValue , expressionPtr->lineNo);
- expressionPtr = expressionPtr->next;
- }
+ expressionPtr = functionPtr->expressionListHead;
+ while (NULL != expressionPtr) {
+ printf("%s = %s, line: %d\n",
+ expressionPtr->expressionSyntax,
+ (NULL ==
+ expressionPtr->
+ expressionValue) ? "No Value" : expressionPtr->
+ expressionValue, expressionPtr->lineNo);
+ expressionPtr = expressionPtr->next;
+ }
- functionPtr = functionPtr->next;
- }
- printf("############################## End Stack Trace
######################################################\n\n");
- tracePtr = tracePtr->next;
+ functionPtr = functionPtr->next;
}
+ printf
+ ("############################## End Stack Trace
######################################################\n\n");
+ tracePtr = tracePtr->next;
+ }
}
-int
-MONKEY_ACTION_inspect_expression_database (struct
- MONKEY_ACTION_Context
- *cntxt)
+int MONKEY_ACTION_inspect_expression_database(struct
+ MONKEY_ACTION_Context
+ *cntxt)
{
- int ret = MONKEY_OK;
- int endScope;
- struct Function *function = NULL;
+ int ret = MONKEY_OK;
+ int endScope;
+ struct Function *function = NULL;
- /* Variables used across recursive calls */
- static struct Trace *trace = NULL;
- static int stackDepth = 0;
- static struct MONKEY_EDB_Context *edbCntxt;
+ /* Variables used across recursive calls */
+ static struct Trace *trace = NULL;
+ static int stackDepth = 0;
+ static struct MONKEY_EDB_Context *edbCntxt;
- if (NULL == signalMeaning)
- signalMeaning = cntxt->gdb_stop_reason->signal_meaning;
+ if (NULL == signalMeaning)
+ signalMeaning = cntxt->gdb_stop_reason->signal_meaning;
- if (NULL == epoch) {
- epoch = MONKEY_malloc(sizeof(struct Epoch));
- epoch->traceListHead = NULL;
- epoch->traceListTail = NULL;
- }
+ if (NULL == epoch) {
+ epoch = MONKEY_malloc(sizeof(struct Epoch));
+ epoch->traceListHead = NULL;
+ epoch->traceListTail = NULL;
+ }
- if (0 == stackDepth) {
- /* Initialize the trace structure for this particular epoch step */
- trace = MONKEY_malloc(sizeof(struct Trace));
- MONKEY_CONTAINER_DLL_insert_tail(epoch->traceListHead,
epoch->traceListTail, trace);
+ if (0 == stackDepth) {
+ /* Initialize the trace structure for this particular epoch step */
+ trace = MONKEY_malloc(sizeof(struct Trace));
+ MONKEY_CONTAINER_DLL_insert_tail(epoch->traceListHead,
+ epoch->traceListTail, trace);
- /* Create a connection to the Expression Database */
- edbCntxt = MONKEY_EDB_connect (cntxt->expression_database_path);
- if (NULL == edbCntxt)
- {
- fprintf(stderr,
- "Unable to connect to Expression Database file!\n");
- return MONKEY_NO;
- }
- }
+ /* Create a connection to the Expression Database */
+ edbCntxt = MONKEY_EDB_connect(cntxt->expression_database_path);
+ if (NULL == edbCntxt) {
+ fprintf(stderr,
+ "Unable to connect to Expression Database file!\n");
+ return MONKEY_NO;
+ }
+ }
- ret = MONKEY_EDB_get_expression_scope_end (edbCntxt,
- cntxt->gdb_frames->file,
- cntxt->gdb_frames->line,
- &scopeEndCallback,
- &endScope);
- if (endScope <= 0)
- return MONKEY_NO;
+ ret = MONKEY_EDB_get_expression_scope_end(edbCntxt,
+ cntxt->gdb_frames->file,
+ cntxt->gdb_frames->line,
+ &scopeEndCallback,
+ &endScope);
+ if (endScope <= 0)
+ return MONKEY_NO;
-if (cntxt->scope_depth > 0) {
+ if (cntxt->scope_depth > 0) {
/* Means we need to look is scopes outer than the one where the problem
occurred */
- struct ScopeEnd *scopeEndPtr;
- int index = 1;
+ struct ScopeEnd *scopeEndPtr;
+ int index = 1;
- ret = MONKEY_EDB_function_start_line_for_scope(edbCntxt,
cntxt->gdb_frames->file,
- endScope,
- &functionStartCallback, NULL);
- if (ret == MONKEY_NO || failureFunctionStartLine <= 0)
- return MONKEY_NO;
+ ret =
+ MONKEY_EDB_function_start_line_for_scope(edbCntxt,
+ cntxt->gdb_frames->
+ file, endScope,
+ &functionStartCallback,
+ NULL);
+ if (ret == MONKEY_NO || failureFunctionStartLine <= 0)
+ return MONKEY_NO;
- ret = MONKEY_EDB_get_all_outer_scopes(edbCntxt,
cntxt->gdb_frames->file,
- failureFunctionStartLine,
- cntxt->gdb_frames->line,
- endScope,
- &outerScopesCallback, NULL);
- if (ret == MONKEY_NO)
- return MONKEY_NO;
+ ret =
+ MONKEY_EDB_get_all_outer_scopes(edbCntxt,
+ cntxt->gdb_frames->file,
+ failureFunctionStartLine,
+ cntxt->gdb_frames->line,
+ endScope, &outerScopesCallback,
+ NULL);
+ if (ret == MONKEY_NO)
+ return MONKEY_NO;
/**
* 1 void fun()
* 2 {
@@ -666,587 +629,612 @@
* 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)
- scopeEndPtr = scopeEndPtr->next;
- endScope = scopeEndPtr->lineNo;
- }
-}
+ if (NULL != scopeEndListHead) {
+ scopeEndPtr = scopeEndListHead;
+ while (index < cntxt->scope_depth && NULL != scopeEndPtr)
+ scopeEndPtr = scopeEndPtr->next;
+ endScope = scopeEndPtr->lineNo;
+ }
+ }
- /* Now we know the end scope of the faulty expression. We can build the
function struct */
- function = MONKEY_malloc(sizeof(struct Function));
- function->depth = stackDepth++;
- function->line = cntxt->gdb_frames->line;
- function->name = cntxt->gdb_frames->func;
- function->file = cntxt->gdb_frames->file;
- function->expressionListHead = NULL; function->expressionListTail = NULL;
function->next = NULL; function->prev = NULL;
- MONKEY_CONTAINER_DLL_insert_tail (trace->functionListHead,
trace->functionListTail,
- function);
+ /* Now we know the end scope of the faulty expression. We can build the
function struct */
+ function = MONKEY_malloc(sizeof(struct Function));
+ function->depth = stackDepth++;
+ function->line = cntxt->gdb_frames->line;
+ function->name = cntxt->gdb_frames->func;
+ function->file = cntxt->gdb_frames->file;
+ function->expressionListHead = NULL;
+ function->expressionListTail = NULL;
+ function->next = NULL;
+ function->prev = NULL;
+ MONKEY_CONTAINER_DLL_insert_tail(trace->functionListHead,
+ trace->functionListTail, function);
- if ((strcasecmp (signalMeaning, "Segmentation fault") == 0) ||
(strcasecmp(signalMeaning, "Signal 0") == 0))
- {
- MONKEY_EDB_get_expressions (edbCntxt,
- cntxt->gdb_frames->file,
- cntxt->gdb_frames->line, endScope,
- &iterateExpressions, function);
- ret = analyzeSegmentationFault (function, cntxt); // will decide whether
the problem is a NULL Pointer Exception or a Bad Memory Access
+ if ((strcasecmp(signalMeaning, "Segmentation fault") == 0)
+ || (strcasecmp(signalMeaning, "Signal 0") == 0)) {
+ MONKEY_EDB_get_expressions(edbCntxt, cntxt->gdb_frames->file,
+ cntxt->gdb_frames->line, endScope,
+ &iterateExpressions, function);
+ 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_ABORT;
+ /*
+ MONKEY_EDB_get_sub_expressions (edbCntxt,
+ cntxt->gdb_frames->file,
+ cntxt->gdb_frames->line,
+ endScope, &iterateExpressions,
+ NULL);
+ */
+ MONKEY_EDB_get_expressions(edbCntxt,
+ cntxt->gdb_frames->file,
+ cntxt->gdb_frames->line, endScope,
+ &iterateExpressions, function);
+ ret = analyzeCustomFault(function, cntxt);
+ } else if (strcasecmp(signalMeaning, "Arithmetic exception") == 0) {
+ cntxt->bug_detected = BUG_ARITHMETIC;
+ /*
+ MONKEY_EDB_get_sub_expressions (edbCntxt,
+ cntxt->gdb_frames->file,
+ cntxt->gdb_frames->line,
+ endScope, &iterateExpressions,
+ NULL);
+ */
+ if (cntxt->scope_depth > 0)
+ MONKEY_EDB_get_expressions_outer_scopes(edbCntxt,
+ cntxt->gdb_frames->
+ file,
+ cntxt->gdb_frames->
+ line, endScope,
+ &iterateExpressions,
+ function);
+ else
+ MONKEY_EDB_get_expressions(edbCntxt,
+ cntxt->gdb_frames->file,
+ cntxt->gdb_frames->line, endScope,
+ &iterateExpressions, function);
+ ret = analyzeCustomFault(function, cntxt);
}
- else if (strcasecmp (signalMeaning, "Aborted") == 0)
- {
- cntxt->bug_detected = BUG_ABORT;
- /*
- MONKEY_EDB_get_sub_expressions (edbCntxt,
- cntxt->gdb_frames->file,
- cntxt->gdb_frames->line,
- endScope, &iterateExpressions,
- NULL);
- */
- MONKEY_EDB_get_expressions (edbCntxt,
- cntxt->gdb_frames->file,
- cntxt->gdb_frames->line, endScope,
- &iterateExpressions, function);
- ret = analyzeCustomFault (function, cntxt);
- }
- else if (strcasecmp(signalMeaning, "Arithmetic exception") == 0) {
- cntxt->bug_detected = BUG_ARITHMETIC;
- /*
- MONKEY_EDB_get_sub_expressions (edbCntxt,
- cntxt->gdb_frames->file,
- cntxt->gdb_frames->line,
- endScope,
&iterateExpressions,
- NULL);
- */
- if (cntxt->scope_depth > 0)
- MONKEY_EDB_get_expressions_outer_scopes (edbCntxt,
-
cntxt->gdb_frames->file,
-
cntxt->gdb_frames->line, endScope,
-
&iterateExpressions, function);
- else
- MONKEY_EDB_get_expressions (edbCntxt,
-
cntxt->gdb_frames->file,
-
cntxt->gdb_frames->line, endScope,
-
&iterateExpressions, function);
- ret = analyzeCustomFault (function, cntxt);
- }
+ //printTrace();
- //printTrace();
+ /* Now, dive deeper into the stack trace */
+ cntxt->gdb_frames = cntxt->gdb_frames->next;
+ if (NULL == cntxt->gdb_frames) {
+ /* Cleanup function static variables that are used across recursive
calls */
+ stackDepth = 0;
+ trace = NULL;
- /* Now, dive deeper into the stack trace */
- cntxt->gdb_frames = cntxt->gdb_frames->next;
- if (NULL == cntxt->gdb_frames) {
- /* Cleanup function static variables that are used across recursive
calls */
- stackDepth = 0;
- trace = NULL;
-
- if (MONKEY_NO == cntxt->run_reverse)
- mi_disconnect(cntxt->gdb_handle); // otherwise, we will need
to use gdb mi for reverse execution
- MONKEY_EDB_disconnect (edbCntxt);
- } else {
- /* Recursively inspect the database for deeper frames */
- MONKEY_ACTION_inspect_expression_database(cntxt);
- }
- return ret;
+ if (MONKEY_NO == cntxt->run_reverse)
+ mi_disconnect(cntxt->gdb_handle); // otherwise, we will need to
use gdb mi for reverse execution
+ MONKEY_EDB_disconnect(edbCntxt);
+ } else {
+ /* Recursively inspect the database for deeper frames */
+ MONKEY_ACTION_inspect_expression_database(cntxt);
+ }
+ return ret;
}
-int MONKEY_ACTION_start_reverse_execution(struct MONKEY_ACTION_Context *
cntxt) {
- const char *failureFile = epoch->traceListHead->functionListHead->file;
- const char *failureFunction =
epoch->traceListHead->functionListHead->name;
- struct Trace *tracePtr = epoch->traceListHead;
+int MONKEY_ACTION_start_reverse_execution(struct MONKEY_ACTION_Context
+ *cntxt)
+{
+ const char *failureFile = epoch->traceListHead->functionListHead->file;
+ const char *failureFunction =
+ epoch->traceListHead->functionListHead->name;
+ struct Trace *tracePtr = epoch->traceListHead;
+ int oldLine;
- /*
- * We execute one step back operation before starting analysis. We do
that to go to the expression before the one where the crash occurred.
- * Because we already have the expression where the crash happened in
our stack structure from the previous epoch step (the initial epoch)
- */
- if (MONKEY_NO != gmi_exec_next_reverse(cntxt->gdb_handle)) {
- while (!mi_get_response (cntxt->gdb_handle))
- usleep (1000);
- }
- else {
- fprintf(stderr, "Error: Reverse Execution has failed!\n");
- mi_disconnect(cntxt->gdb_handle); // No need for gdb mi at
this point!
- return MONKEY_NO;
- }
+ /*
+ * We execute one step back operation before starting analysis. We do that
to go to the expression before the one where the crash occurred.
+ * Because we already have the expression where the crash happened in our
stack structure from the previous epoch step (the initial epoch)
+ */
+ if (MONKEY_NO != gmi_exec_next_reverse(cntxt->gdb_handle)) {
+ while (!mi_get_response(cntxt->gdb_handle))
+ usleep(1000);
+ } else {
+ fprintf(stderr, "Error: Reverse Execution has failed!\n");
+ mi_disconnect(cntxt->gdb_handle); // No need for gdb mi at this
point!
+ return MONKEY_NO;
+ }
- /* Do reverse execution for all expressions in the function in which
the failure occurred */
- do {
+ /* Do reverse execution for all expressions in the function in which the
failure occurred */
+ do {
+ oldLine = tracePtr->functionListHead->line;
if (MONKEY_NO != gmi_exec_next_reverse(cntxt->gdb_handle)) {
- if(GDB_STATE_ERROR == wait_for_stop(cntxt)) {
- fprintf(stderr, "Error: Analysis during
Reverse Execution has failed!\n");
- return MONKEY_NO;
- }
- MONKEY_ACTION_inspect_expression_database(cntxt);
- }
- else {
- fprintf(stderr, "Error: Reverse Execution has
failed!\n");
- return MONKEY_NO;
- }
+ if (GDB_STATE_ERROR == wait_for_stop(cntxt)) {
+ fprintf(stderr,
+ "Error: Analysis during Reverse Execution has
failed!\n");
+ return MONKEY_NO;
+ }
+ if (oldLine == cntxt->gdb_frames->line)
+ break;// We reached the end of record history
TODO: DIRTY SOLUTION! WILL FAIL IF TWO EXPRESSIONS ON THE SAME LINE
+ MONKEY_ACTION_inspect_expression_database(cntxt);
+ } else {
+ fprintf(stderr, "Error: Reverse Execution has failed!\n");
+ return MONKEY_NO;
+ }
- tracePtr = tracePtr->next;
- } while ((NULL != tracePtr) && (strcmp(failureFile,
tracePtr->functionListHead->file) == 0) &&
- (strcmp(failureFunction,
tracePtr->functionListHead->name) == 0));
+ tracePtr = tracePtr->next; // tracePtr will have the new trace added
after examining the expression database for this reverse execution step
+ } while ((NULL != tracePtr)
+ && (strcmp(failureFile, tracePtr->functionListHead->file) ==
+ 0)
+ && (strcmp(failureFunction, tracePtr->functionListHead->name)
+ == 0));
- return MONKEY_OK;
+ return MONKEY_OK;
}
-int
-MONKEY_ACTION_rerun_with_valgrind (struct MONKEY_ACTION_Context
- *cntxt)
+int MONKEY_ACTION_rerun_with_valgrind(struct MONKEY_ACTION_Context
+ *cntxt)
{
- char *valgrindCommand;
- FILE *valgrindPipe;
- const char *valgrindPath = cntxt->valgrind_binary_path;
+ char *valgrindCommand;
+ FILE *valgrindPipe;
+ const char *valgrindPath = cntxt->valgrind_binary_path;
- MONKEY_asprintf (&cntxt->valgrind_output_tmp_file_name, "%d", rand ());
- cntxt->debug_mode = DEBUG_MODE_VALGRIND;
- if (NULL == valgrindPath)
- valgrindPath = "/usr/bin/valgrind"; /* Assumption for valgrind
installation */
+ MONKEY_asprintf(&cntxt->valgrind_output_tmp_file_name, "%d", rand());
+ cntxt->debug_mode = DEBUG_MODE_VALGRIND;
+ if (NULL == valgrindPath)
+ valgrindPath = "/usr/bin/valgrind"; /* Assumption for valgrind
installation */
- if (0 != access(valgrindPath, X_OK)) {
- /* Valgrind is not installed, stop */
- fprintf(stderr, "Warning: Valgrind is not installed. Memory check
aborted!\n");
- return MONKEY_NO;
- }
+ if (0 != access(valgrindPath, X_OK)) {
+ /* Valgrind is not installed, stop */
+ fprintf(stderr,
+ "Warning: Valgrind is not installed. Memory check aborted!\n");
+ return MONKEY_NO;
+ }
- MONKEY_asprintf (&valgrindCommand,
- "%s --leak-check=yes --log-file=%s %s", valgrindPath,
- cntxt->valgrind_output_tmp_file_name, cntxt->binary_name);
- valgrindPipe = popen (valgrindCommand, "r");
- if (NULL == valgrindPipe)
- {
- fprintf(stderr, "Error in running Valgrind!\n");
- MONKEY_free (valgrindCommand);
- return MONKEY_NO;
+ MONKEY_asprintf(&valgrindCommand,
+ "%s --leak-check=yes --log-file=%s %s", valgrindPath,
+ cntxt->valgrind_output_tmp_file_name,
+ cntxt->binary_name);
+ valgrindPipe = popen(valgrindCommand, "r");
+ if (NULL == valgrindPipe) {
+ fprintf(stderr, "Error in running Valgrind!\n");
+ MONKEY_free(valgrindCommand);
+ return MONKEY_NO;
}
- pclose (valgrindPipe);
- MONKEY_free (valgrindCommand);
- cntxt->bug_detected = BUG_BAD_MEM_ACCESS;
- return MONKEY_OK;
+ pclose(valgrindPipe);
+ MONKEY_free(valgrindCommand);
+ cntxt->bug_detected = BUG_BAD_MEM_ACCESS;
+ return MONKEY_OK;
}
-int
-MONKEY_ACTION_rerun_with_gdb (struct MONKEY_ACTION_Context
- *cntxt)
+int MONKEY_ACTION_rerun_with_gdb(struct MONKEY_ACTION_Context
+ *cntxt)
{
- struct MONKEY_EDB_Context *edbCntxt;
- epoch = NULL; /* Initializing epoch Data Structure */
+ struct MONKEY_EDB_Context *edbCntxt;
+ epoch = NULL; /* Initializing epoch Data Structure */
- cntxt->debug_mode = DEBUG_MODE_GDB;
- /* This is like a file-handle for fopen.
- Here we have all the state of gdb "connection". */
- if (NULL != cntxt->gdb_binary_path)
- mi_set_gdb_exe (cntxt->gdb_binary_path);
- int ret;
+ cntxt->debug_mode = DEBUG_MODE_GDB;
+ /* This is like a file-handle for fopen.
+ Here we have all the state of gdb "connection". */
+ if (NULL != cntxt->gdb_binary_path)
+ mi_set_gdb_exe(cntxt->gdb_binary_path);
+ int ret;
- /* Connect to gdb child. */
- cntxt->gdb_handle = mi_connect_local ();
- if (!cntxt->gdb_handle)
- {
- printf ("Connect failed\n");
- return MONKEY_NO;
+ /* Connect to gdb child. */
+ cntxt->gdb_handle = mi_connect_local();
+ if (!cntxt->gdb_handle) {
+ printf("Connect failed\n");
+ return MONKEY_NO;
}
- printf ("Connected to gdb!\n");
+ printf("Connected to gdb!\n");
- /* Set all callbacks. */
- mi_set_console_cb (cntxt->gdb_handle, cb_console, NULL);
- mi_set_target_cb (cntxt->gdb_handle, cb_target, NULL);
- mi_set_log_cb (cntxt->gdb_handle, cb_log, NULL);
- mi_set_async_cb (cntxt->gdb_handle, cb_async, NULL);
- mi_set_to_gdb_cb (cntxt->gdb_handle, cb_to, NULL);
- mi_set_from_gdb_cb (cntxt->gdb_handle, cb_from, NULL);
+ /* Set all callbacks. */
+ mi_set_console_cb(cntxt->gdb_handle, cb_console, NULL);
+ mi_set_target_cb(cntxt->gdb_handle, cb_target, NULL);
+ mi_set_log_cb(cntxt->gdb_handle, cb_log, NULL);
+ mi_set_async_cb(cntxt->gdb_handle, cb_async, NULL);
+ mi_set_to_gdb_cb(cntxt->gdb_handle, cb_to, NULL);
+ mi_set_from_gdb_cb(cntxt->gdb_handle, cb_from, NULL);
- /* Set the name of the child and the command line arguments. */
- if (!gmi_set_exec (cntxt->gdb_handle, cntxt->binary_name, NULL))
- {
- printf ("Error setting exec y args\n");
- mi_disconnect (cntxt->gdb_handle);
- return MONKEY_NO;
+ /* Set the name of the child and the command line arguments. */
+ if (!gmi_set_exec(cntxt->gdb_handle, cntxt->binary_name, NULL)) {
+ printf("Error setting exec y args\n");
+ mi_disconnect(cntxt->gdb_handle);
+ return MONKEY_NO;
}
- /* Tell gdb to attach the child to a terminal. */
- if (!gmi_target_terminal (cntxt->gdb_handle, ttyname (STDIN_FILENO)))
- {
- printf ("Error selecting target terminal\n");
- mi_disconnect (cntxt->gdb_handle);
- return MONKEY_NO;
+ /* Tell gdb to attach the child to a terminal. */
+ if (!gmi_target_terminal(cntxt->gdb_handle, ttyname(STDIN_FILENO))) {
+ printf("Error selecting target terminal\n");
+ mi_disconnect(cntxt->gdb_handle);
+ return MONKEY_NO;
}
- if (MONKEY_YES == cntxt->run_reverse) {
- /* If Backtracking is enabled, we must set a breakpoint at the main
function, starting the program, then starting recording */
- mi_bkpt *bp =
- gmi_break_insert_full (cntxt->gdb_handle, 0, 0, NULL, -1, -1,
- "main");
- if (NULL == bp)
- {
- printf ("Error setting breakpoint at function:%s\n",
- cntxt->inspect_function);
- mi_disconnect (cntxt->gdb_handle);
- return MONKEY_NO;
+ if (MONKEY_YES == cntxt->run_reverse) {
+ /* If Backtracking is enabled, we must set a breakpoint at the main
function, starting the program, then starting recording */
+ mi_bkpt *bp =
+ gmi_break_insert_full(cntxt->gdb_handle, 0, 0, NULL, -1, -1,
+ "main");
+ if (NULL == bp) {
+ printf("Error setting breakpoint at function:%s\n",
+ cntxt->inspect_function);
+ mi_disconnect(cntxt->gdb_handle);
+ return MONKEY_NO;
}
- mi_free_bkpt (bp);
- }
+ mi_free_bkpt(bp);
+ }
- 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 MONKEY_NO;
+ 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 MONKEY_NO;
}
- mi_free_bkpt (bp);
+ mi_free_bkpt(bp);
}
- /* Prepare a list of the file names for the source files we are analyzing */
- edbCntxt = MONKEY_EDB_connect (cntxt->expression_database_path);
- if (NULL == edbCntxt)
- {
- fprintf(stderr,
- "Unable to connect to Expression Database file!\n");
- return MONKEY_NO;
+ /* Prepare a list of the file names for the source files we are analyzing
*/
+ edbCntxt = MONKEY_EDB_connect(cntxt->expression_database_path);
+ if (NULL == edbCntxt) {
+ fprintf(stderr,
+ "Unable to connect to Expression Database file!\n");
+ return MONKEY_NO;
}
- if (MONKEY_OK != MONKEY_EDB_get_file_names (edbCntxt,
- &iterateFileNames, NULL))
- {
- fprintf(stderr,
- "Error in executing Database query!\n");
+ if (MONKEY_OK != MONKEY_EDB_get_file_names(edbCntxt,
+ &iterateFileNames, NULL)) {
+ fprintf(stderr, "Error in executing Database query!\n");
}
- MONKEY_EDB_disconnect (edbCntxt);
+ MONKEY_EDB_disconnect(edbCntxt);
- /* Run the program. */
- if (!gmi_exec_run (cntxt->gdb_handle))
- {
- printf ("Error in run!\n");
- mi_disconnect (cntxt->gdb_handle);
- return MONKEY_NO;
+ /* Run the program. */
+ if (!gmi_exec_run(cntxt->gdb_handle)) {
+ printf("Error in run!\n");
+ mi_disconnect(cntxt->gdb_handle);
+ return MONKEY_NO;
}
- /* Backtracking is issued after running the program */
- if (MONKEY_YES == cntxt->run_reverse) {
- if (!gmi_exec_record_process(cntxt->gdb_handle)) {
- printf ("Error enabling Backtracking!\n");
- mi_disconnect(cntxt->gdb_handle);
- return MONKEY_NO;
- }
+ /* Backtracking is issued after running the program */
+ if (MONKEY_YES == cntxt->run_reverse) {
+ if (!gmi_exec_record_process(cntxt->gdb_handle)) {
+ printf("Error enabling Backtracking!\n");
+ mi_disconnect(cntxt->gdb_handle);
+ return MONKEY_NO;
}
+ }
- /* Here we should be stopped when the program crashes */
- ret = wait_for_stop (cntxt);
- if (ret == GDB_STATE_ERROR || ret == GDB_STATE_EXIT_NORMALLY)
- mi_disconnect (cntxt->gdb_handle);
+ /* Here we should be stopped when the program crashes */
+ ret = wait_for_stop(cntxt);
+ if (ret == GDB_STATE_ERROR || ret == GDB_STATE_EXIT_NORMALLY)
+ mi_disconnect(cntxt->gdb_handle);
- return ret;
+ return ret;
}
-static const char *
-expressionListToString (struct Expression *head)
+static const char *expressionListToString(struct Expression *head)
{
- char *string = MONKEY_strdup ("");
- char *strTmp;
- struct Expression *tmp;
+ char *string = MONKEY_strdup("");
+ char *strTmp;
+ struct Expression *tmp;
- for (tmp = head; NULL != tmp; tmp = tmp->next)
- {
- MONKEY_asprintf (&strTmp,
- "%s%s => %s\n",
- string,
- tmp->expressionSyntax,
- NULL ==
- tmp->expressionValue ? "Not evaluated" : tmp->
- expressionValue);
- MONKEY_free (string);
- string = strTmp;
+ for (tmp = head; NULL != tmp; tmp = tmp->next) {
+ MONKEY_asprintf(&strTmp,
+ "%s%s => %s\n",
+ string,
+ tmp->expressionSyntax,
+ NULL ==
+ tmp->
+ expressionValue ? "Not evaluated" :
+ tmp->expressionValue);
+ MONKEY_free(string);
+ string = strTmp;
}
- return string;
+ return string;
}
#if 0
-static int
-getWatchInfoListSize (struct WatchInfo *head)
+static int 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 = MONKEY_malloc (getWatchInfoListSize (head));
- char *strTmp;
- struct WatchInfo *tmp = head;
+ char *string = MONKEY_malloc(getWatchInfoListSize(head));
+ char *strTmp;
+ struct WatchInfo *tmp = head;
- MONKEY_asprintf (&strTmp, "%s\t \t%s\n", tmp->hitNumber, tmp->value);
- strcpy (string, strTmp);
- MONKEY_free (strTmp);
- tmp = tmp->next;
+ MONKEY_asprintf(&strTmp, "%s\t \t%s\n", tmp->hitNumber, tmp->value);
+ strcpy(string, strTmp);
+ MONKEY_free(strTmp);
+ tmp = tmp->next;
- while (NULL != tmp)
- {
- MONKEY_asprintf (&strTmp, "%s\t \t%s\n", tmp->hitNumber, tmp->value);
- strcat (string, strTmp);
- MONKEY_free (strTmp);
- tmp = tmp->next;
+ while (NULL != tmp) {
+ MONKEY_asprintf(&strTmp, "%s\t \t%s\n", tmp->hitNumber,
+ tmp->value);
+ strcat(string, strTmp);
+ MONKEY_free(strTmp);
+ tmp = tmp->next;
}
- return string;
+ return string;
}
#endif
-static const char *
-getValgrindOutput (struct MONKEY_ACTION_Context *cntxt)
+static const char *getValgrindOutput(struct 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 = MONKEY_malloc (size);
- fread (valgrindOutput, size - 1, 1, valgrindFile);
- fclose (valgrindFile);
- return valgrindOutput;
+ valgrindOutput = MONKEY_malloc(size);
+ fread(valgrindOutput, size - 1, 1, valgrindFile);
+ fclose(valgrindFile);
+ return valgrindOutput;
}
-static struct MONKEY_XML_Node * createXmlSimpleNode(const char *nodeName,
const char *nodeInnerText) {
- struct MONKEY_XML_Node *node =
- MONKEY_XML_WRITER_new_node(nodeName, nodeInnerText);
- return node;
+static struct MONKEY_XML_Node *createXmlSimpleNode(const char *nodeName,
+ const char
+ *nodeInnerText)
+{
+ struct MONKEY_XML_Node *node =
+ MONKEY_XML_WRITER_new_node(nodeName, nodeInnerText);
+ return node;
}
-static struct MONKEY_XML_Node * createXmlCrashNode(const char *category, const
char *function, int line, const char *file) {
- struct MONKEY_XML_Node * node;
- char *lineStr;
+static struct MONKEY_XML_Node *createXmlCrashNode(const char *category,
+ const char *function,
+ int line,
+ const char *file)
+{
+ struct MONKEY_XML_Node *node;
+ char *lineStr;
- MONKEY_asprintf(&lineStr, "%d", line);
- node = MONKEY_XML_WRITER_new_node("crash", NULL);
- MONKEY_XML_WRITER_add_attribute(node, "category", category);
- MONKEY_XML_WRITER_add_attribute(node, "function", function);
- MONKEY_XML_WRITER_add_attribute(node, "line", lineStr);
- MONKEY_XML_WRITER_add_attribute(node, "file", file);
- return node;
+ MONKEY_asprintf(&lineStr, "%d", line);
+ node = MONKEY_XML_WRITER_new_node("crash", NULL);
+ MONKEY_XML_WRITER_add_attribute(node, "category", category);
+ MONKEY_XML_WRITER_add_attribute(node, "function", function);
+ MONKEY_XML_WRITER_add_attribute(node, "line", lineStr);
+ MONKEY_XML_WRITER_add_attribute(node, "file", file);
+ return node;
}
-static struct MONKEY_XML_Node * createXmlEpochStep(int step) {
- struct MONKEY_XML_Node * node;
- char *stepStr;
- MONKEY_asprintf(&stepStr, "%d", step);
- node = MONKEY_XML_WRITER_new_node("epoch", NULL);
- MONKEY_XML_WRITER_add_attribute(node, "step", stepStr);
- return node;
+static struct MONKEY_XML_Node *createXmlEpochStep(int step)
+{
+ struct MONKEY_XML_Node *node;
+ char *stepStr;
+ MONKEY_asprintf(&stepStr, "%d", step);
+ node = MONKEY_XML_WRITER_new_node("epoch", NULL);
+ MONKEY_XML_WRITER_add_attribute(node, "step", stepStr);
+ return node;
}
-static struct MONKEY_XML_Node * createXmlFunctionNode(const char *name, int
line, const char *file, int depth) {
- struct MONKEY_XML_Node * node;
- char *lineStr;
- char *depthStr;
+static struct MONKEY_XML_Node *createXmlFunctionNode(const char *name,
+ int line,
+ const char *file,
+ int depth)
+{
+ struct MONKEY_XML_Node *node;
+ char *lineStr;
+ char *depthStr;
- MONKEY_asprintf(&lineStr, "%d", line);
- MONKEY_asprintf(&depthStr, "%d", depth);
- node = MONKEY_XML_WRITER_new_node("function", NULL);
- MONKEY_XML_WRITER_add_attribute(node, "name", name);
- MONKEY_XML_WRITER_add_attribute(node, "line", lineStr);
- MONKEY_XML_WRITER_add_attribute(node, "file", file);
- MONKEY_XML_WRITER_add_attribute(node, "depth", depthStr);
- return node;
+ MONKEY_asprintf(&lineStr, "%d", line);
+ MONKEY_asprintf(&depthStr, "%d", depth);
+ node = MONKEY_XML_WRITER_new_node("function", NULL);
+ MONKEY_XML_WRITER_add_attribute(node, "name", name);
+ MONKEY_XML_WRITER_add_attribute(node, "line", lineStr);
+ MONKEY_XML_WRITER_add_attribute(node, "file", file);
+ MONKEY_XML_WRITER_add_attribute(node, "depth", depthStr);
+ return node;
}
-static struct MONKEY_XML_Node * createXmlExpressionNode(const char *name,
const char *value) {
- struct MONKEY_XML_Node * node;
+static struct MONKEY_XML_Node *createXmlExpressionNode(const char *name,
+ const char *value)
+{
+ struct MONKEY_XML_Node *node;
- node = MONKEY_XML_WRITER_new_node("expression", value);
- MONKEY_XML_WRITER_add_attribute(node, "name", name);
- return node;
+ node = MONKEY_XML_WRITER_new_node("expression", value);
+ MONKEY_XML_WRITER_add_attribute(node, "name", name);
+ return node;
}
-int
-MONKEY_ACTION_format_report_xml (struct MONKEY_ACTION_Context
- *cntxt) {
- int i = 0;
- struct MONKEY_XML_Node *node;
- struct MONKEY_XML_Node *historyNode;
- struct MONKEY_XML_Node *traceNode;
- struct Trace *tracePtr = epoch->traceListHead;
- struct Function *functionPtr = tracePtr->functionListHead;
- struct Expression *expressionPtr;
+int MONKEY_ACTION_format_report_xml(struct MONKEY_ACTION_Context
+ *cntxt)
+{
+ int i = 0;
+ struct MONKEY_XML_Node *node;
+ struct MONKEY_XML_Node *historyNode;
+ struct MONKEY_XML_Node *traceNode;
+ struct Trace *tracePtr = epoch->traceListHead;
+ struct Function *functionPtr = tracePtr->functionListHead;
+ struct Expression *expressionPtr;
- switch (cntxt->bug_detected) {
- case BUG_NULL_POINTER:
- cntxt->xml_report_node = createXmlCrashNode("npe",
functionPtr->name, functionPtr->line, functionPtr->file);
- break;
- case BUG_BAD_MEM_ACCESS:
- cntxt->xml_report_node = createXmlCrashNode("Bad memory
access", functionPtr->name, functionPtr->line, functionPtr->file);
- node =
MONKEY_XML_WRITER_add_child(cntxt->xml_report_node,
createXmlSimpleNode("valgrind", getValgrindOutput(cntxt)));
- break;
- case BUG_ABORT:
- cntxt->xml_report_node = createXmlCrashNode("Assertion
Failure", functionPtr->name, functionPtr->line, functionPtr->file);
- break;
- case BUG_ARITHMETIC:
- cntxt->xml_report_node = createXmlCrashNode("Division
By Zero", functionPtr->name, functionPtr->line, functionPtr->file);
- break;
- default:
- return MONKEY_NO; //problem!
- }
+ switch (cntxt->bug_detected) {
+ case BUG_NULL_POINTER:
+ cntxt->xml_report_node =
+ createXmlCrashNode("npe", functionPtr->name, functionPtr->line,
+ functionPtr->file);
+ break;
+ case BUG_BAD_MEM_ACCESS:
+ cntxt->xml_report_node =
+ createXmlCrashNode("Bad memory access", functionPtr->name,
+ functionPtr->line, functionPtr->file);
+ node =
+ MONKEY_XML_WRITER_add_child(cntxt->xml_report_node,
+ createXmlSimpleNode("valgrind",
+ getValgrindOutput
+ (cntxt)));
+ break;
+ case BUG_ABORT:
+ cntxt->xml_report_node =
+ createXmlCrashNode("Assertion Failure", functionPtr->name,
+ functionPtr->line, functionPtr->file);
+ break;
+ case BUG_ARITHMETIC:
+ cntxt->xml_report_node =
+ createXmlCrashNode("Division By Zero", functionPtr->name,
+ functionPtr->line, functionPtr->file);
+ break;
+ default:
+ return MONKEY_NO; //problem!
+ }
- historyNode = MONKEY_XML_WRITER_add_child(cntxt->xml_report_node,
createXmlSimpleNode("history", NULL));
+ historyNode =
+ MONKEY_XML_WRITER_add_child(cntxt->xml_report_node,
+ createXmlSimpleNode("history", NULL));
- /* Adding Stack Trace Nodes to XML Report */
- while (NULL != tracePtr) {
- node = MONKEY_XML_WRITER_add_child(historyNode,
createXmlEpochStep(i));
- traceNode = MONKEY_XML_WRITER_add_child(node,
createXmlSimpleNode("trace", NULL));
+ /* Adding Stack Trace Nodes to XML Report */
+ while (NULL != tracePtr) {
+ node =
+ MONKEY_XML_WRITER_add_child(historyNode,
+ createXmlEpochStep(i));
+ traceNode =
+ MONKEY_XML_WRITER_add_child(node,
+ createXmlSimpleNode("trace",
+ NULL));
- functionPtr = tracePtr->functionListHead;
- while (NULL != functionPtr) {
- node = MONKEY_XML_WRITER_add_child(traceNode,
createXmlFunctionNode(functionPtr->name, functionPtr->line, functionPtr->file,
functionPtr->depth));
- node = MONKEY_XML_WRITER_add_child(node,
createXmlSimpleNode("expressions", NULL));
+ functionPtr = tracePtr->functionListHead;
+ while (NULL != functionPtr) {
+ node =
+ MONKEY_XML_WRITER_add_child(traceNode,
+ createXmlFunctionNode
+ (functionPtr->name,
+ functionPtr->line,
+ functionPtr->file,
+ functionPtr->depth));
+ node =
+ MONKEY_XML_WRITER_add_child(node,
+ createXmlSimpleNode
+ ("expressions", NULL));
- expressionPtr = functionPtr->expressionListHead;
- while (NULL != expressionPtr) {
- MONKEY_XML_WRITER_add_child(node,
createXmlExpressionNode(expressionPtr->expressionSyntax,
- (NULL ==
expressionPtr->expressionValue) ? "Not Evaluated" :
expressionPtr->expressionValue)); // node = "expressions" node
+ expressionPtr = functionPtr->expressionListHead;
+ while (NULL != expressionPtr) {
+ MONKEY_XML_WRITER_add_child(node,
createXmlExpressionNode(expressionPtr->expressionSyntax, (NULL ==
expressionPtr->expressionValue) ? "Not Evaluated" :
expressionPtr->expressionValue)); // node = "expressions" node
- expressionPtr = expressionPtr->next;
- }
+ expressionPtr = expressionPtr->next;
+ }
- functionPtr = functionPtr->next;
- }
-
- tracePtr = tracePtr->next;
- i++;
+ functionPtr = functionPtr->next;
}
- return MONKEY_OK;
+
+ tracePtr = tracePtr->next;
+ i++;
+ }
+ return MONKEY_OK;
}
-int
-MONKEY_ACTION_format_report (struct MONKEY_ACTION_Context
- *cntxt)
+int MONKEY_ACTION_format_report(struct MONKEY_ACTION_Context
+ *cntxt)
{
- switch (cntxt->debug_mode)
- {
+ switch (cntxt->debug_mode) {
case DEBUG_MODE_GDB:
- if (cntxt->bug_detected == BUG_NULL_POINTER)
- {
- MONKEY_asprintf (&(cntxt->debug_report),
- "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);
- }
- else if (NULL == cntxt->inspect_expression)
- {
+ if (cntxt->bug_detected == BUG_NULL_POINTER) {
+ MONKEY_asprintf(&(cntxt->debug_report),
+ "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);
+ } else if (NULL == cntxt->inspect_expression) {
const char *expToString =
- expressionListToString (expressionListHead);
+ expressionListToString(expressionListHead);
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,
-
cntxt->gdb_frames->func,
-
cntxt->gdb_frames->line,
-
cntxt->gdb_stop_reason->signal_name,
-
cntxt->gdb_stop_reason->signal_meaning,
- expToString);
+ 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,
+ cntxt->gdb_frames->func,
+ cntxt->gdb_frames->line,
+ cntxt->gdb_stop_reason->signal_name,
+ cntxt->gdb_stop_reason->signal_meaning,
+ expToString);
+ } 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",
+ cntxt->gdb_frames->file,
+ cntxt->gdb_frames->func,
+ cntxt->gdb_frames->line,
+ cntxt->gdb_stop_reason->signal_name,
+ cntxt->gdb_stop_reason->signal_meaning,
+ expToString);
}
- 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",
- cntxt->gdb_frames->file,
- cntxt->gdb_frames->func,
- cntxt->gdb_frames->line,
- cntxt->gdb_stop_reason->signal_name,
-
cntxt->gdb_stop_reason->signal_meaning,
- expToString);
- }
+ } else {
+ /* Inspection of user-defined expression */
+ /*
+ MONKEY_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));
+ */
}
- else
- {
- /* Inspection of user-defined expression */
- /*
- MONKEY_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;
+ break;
case DEBUG_MODE_VALGRIND:
- MONKEY_asprintf (&(cntxt->debug_report),
- "Bug detected in file:%s\nfunction:%s\nline:%d\nreceived
signal:%s\n%s\n Details:\n Memory Check from Valgrind:\n%s",
- cntxt->gdb_frames->file, cntxt->gdb_frames->func,
- cntxt->gdb_frames->line,
- cntxt->gdb_stop_reason->signal_name,
- cntxt->gdb_stop_reason->signal_meaning,
- getValgrindOutput (cntxt));
- break;
+ MONKEY_asprintf(&(cntxt->debug_report),
+ "Bug detected in
file:%s\nfunction:%s\nline:%d\nreceived signal:%s\n%s\n Details:\n Memory Check
from Valgrind:\n%s",
+ cntxt->gdb_frames->file, cntxt->gdb_frames->func,
+ cntxt->gdb_frames->line,
+ cntxt->gdb_stop_reason->signal_name,
+ cntxt->gdb_stop_reason->signal_meaning,
+ getValgrindOutput(cntxt));
+ break;
default:
- break;
+ break;
}
- cntxt->debug_mode = DEBUG_MODE_REPORT_READY;
- return MONKEY_OK;
+ cntxt->debug_mode = DEBUG_MODE_REPORT_READY;
+ return MONKEY_OK;
}
-int
-MONKEY_ACTION_delete_context (struct MONKEY_ACTION_Context
- *cntxt)
+int MONKEY_ACTION_delete_context(struct MONKEY_ACTION_Context
+ *cntxt)
{
- if (NULL != cntxt->gdb_handle)
+ if (NULL != cntxt->gdb_handle)
mi_disconnect(cntxt->gdb_handle);
- if (NULL != cntxt->debug_report)
- MONKEY_free (cntxt->debug_report);
- if (NULL != cntxt->valgrind_output_tmp_file_name)
- {
- remove (cntxt->valgrind_output_tmp_file_name);
- MONKEY_free (cntxt->valgrind_output_tmp_file_name);
+ if (NULL != cntxt->debug_report)
+ MONKEY_free(cntxt->debug_report);
+ if (NULL != cntxt->valgrind_output_tmp_file_name) {
+ remove(cntxt->valgrind_output_tmp_file_name);
+ MONKEY_free(cntxt->valgrind_output_tmp_file_name);
}
- if (NULL != cntxt->xml_report_node)
- MONKEY_XML_WRITER_delete_tree(cntxt->xml_report_node);
+ if (NULL != cntxt->xml_report_node)
+ MONKEY_XML_WRITER_delete_tree(cntxt->xml_report_node);
- MONKEY_free (cntxt);
- return MONKEY_OK;
+ MONKEY_free(cntxt);
+ return MONKEY_OK;
}
-int
-MONKEY_ACTION_check_bug_redundancy ()
+int MONKEY_ACTION_check_bug_redundancy()
{
- return MONKEY_OK;
+ return MONKEY_OK;
}
Modified:
monkey/branches/MonkeyBacktracking/monkey/src/monkey/bug_assertion_failure.c
===================================================================
---
monkey/branches/MonkeyBacktracking/monkey/src/monkey/bug_assertion_failure.c
2012-03-21 17:22:30 UTC (rev 20664)
+++
monkey/branches/MonkeyBacktracking/monkey/src/monkey/bug_assertion_failure.c
2012-03-21 18:36:12 UTC (rev 20665)
@@ -3,7 +3,8 @@
void assertionFailure()
{
- int x = 5;
+ int x;
+ x = 5;
printf("Assertion Failure Now!\n");
assert(x < 4);
}
Modified:
monkey/branches/MonkeyBacktracking/monkey/src/monkey/bug_assertion_failure.db
===================================================================
(Binary files differ)
Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi.h
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi.h
2012-03-21 17:22:30 UTC (rev 20664)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi.h
2012-03-21 18:36:12 UTC (rev 20665)
@@ -549,11 +549,14 @@
/* Porgram control: */
/* Specify the executable and arguments for local debug. */
+int gmi_set_unwind_on_signal_on(mi_h * h);
int gmi_set_exec(mi_h *h, const char *file, const char *args);
/* Start running the executable. Remote sessions starts running. */
int gmi_exec_run(mi_h *h);
/* Continue the execution after a "stop". */
int gmi_exec_continue(mi_h *h);
+/* Continue the execution in reverse order after a "stop". */
+int gmi_exec_continue_reverse(mi_h *h);
/* Indicate which terminal will use the target program. For local sessions. */
int gmi_target_terminal(mi_h *h, const char *tty_name);
/* Specify what's the local copy that have debug info. For remote sessions. */
Modified:
monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_prg_control.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_prg_control.c
2012-03-21 17:22:30 UTC (rev 20664)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_prg_control.c
2012-03-21 18:36:12 UTC (rev 20665)
@@ -72,6 +72,11 @@
mi_send(h,"-file-exec-and-symbols %s\n",file);
}
+void mi_set_unwind_on_signal_on(mi_h *h)
+{
+ mi_send(h, "set unwindonsignal on\n");
+}
+
void mi_exec_arguments(mi_h *h, const char *args)
{
mi_send(h,"-exec-arguments %s\n",args);
@@ -87,6 +92,11 @@
mi_send(h,"-exec-continue\n");
}
+void mi_exec_continue_reverse(mi_h *h)
+{
+ mi_send(h, "-exec-continue --reverse\n");
+}
+
void mi_target_terminal(mi_h *h, const char *tty_name)
{
mi_send(h,"tty %s\n",tty_name);
@@ -210,6 +220,12 @@
return mi_res_simple_done(h);
}
+int gmi_set_unwind_on_signal_on(mi_h * h)
+{
+ mi_set_unwind_on_signal_on(h);
+ return mi_res_simple_running(h);
+}
+
/**[txh]********************************************************************
Description:
@@ -245,6 +261,21 @@
/**[txh]********************************************************************
Description:
+ Continue the execution in reverse order after a "stop".
+
+ Command: -exec-continue --reverse
+ Return: !=0 OK
+
+***************************************************************************/
+int gmi_exec_continue_reverse(mi_h *h)
+{
+ mi_exec_continue_reverse(h);
+ return mi_res_simple_running(h);
+}
+
+/**[txh]********************************************************************
+
+ Description:
Indicate which terminal will use the target program. For local sessions.
Command: tty
Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c
2012-03-21 17:22:30 UTC (rev 20664)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c
2012-03-21 18:36:12 UTC (rev 20665)
@@ -277,7 +277,6 @@
}
else if (strcmp("-r", argv[i]) == 0) {
reverseExecutionAllowed = MONKEY_YES;
- i++;
}
}
if (MONKEY_NO == binaryCheck)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r20665 - in monkey/branches/MonkeyBacktracking/monkey: . src/monkey,
gnunet <=