[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r20637 - monkey/branches/MonkeyBacktracking/monkey/src/monk
From: |
gnunet |
Subject: |
[GNUnet-SVN] r20637 - monkey/branches/MonkeyBacktracking/monkey/src/monkey |
Date: |
Tue, 20 Mar 2012 18:46:07 +0100 |
Author: safey
Date: 2012-03-20 18:46:07 +0100 (Tue, 20 Mar 2012)
New Revision: 20637
Modified:
monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
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
monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h
Log:
Backtracking works for Bad Memory Access.
No unnecessary calls for wait_for_stop().
Backtracking still not working properly for both Assertion Failure, and
Division By Zero.
Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
2012-03-20 17:41:35 UTC (rev 20636)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/action_api.c
2012-03-20 17:46:07 UTC (rev 20637)
@@ -157,112 +157,119 @@
while (!mi_get_response (cntxt->gdb_handle))
usleep (1000);
- if (MONKEY_NO == cntxt->gdb_ignore_analysis) {
- /* 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
+ /* 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
- switch (cntxt->gdb_stop_reason->reason)
+ 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:
+ {
+ /* 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;
+ }
+
+ /* 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;
+
+ //EXPERIMENTAL CODE:
+ while (MONKEY_YES != isInCodeBase (cntxt->gdb_frames->file))
{
- case sr_exited_normally:
- return GDB_STATE_EXIT_NORMALLY;
+ if (MONKEY_YES == cntxt->run_reverse) {
+ gmi_exec_finish_reverse(cntxt->gdb_handle);
+ while (!mi_get_response (cntxt->gdb_handle))
+ usleep (1000);
- 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);
+ 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);
}
- 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);
+ else {
+ cntxt->gdb_frames = cntxt->gdb_frames->next;
}
- 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 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;
+ if (NULL == cntxt->gdb_frames)
+ MONKEY_break (0);
+ }
- //EXPERIMENTAL CODE:
- while (MONKEY_YES != isInCodeBase (cntxt->gdb_frames->file))
- {
- cntxt->gdb_frames = cntxt->gdb_frames->next;
- }
-
- if (NULL == cntxt->gdb_frames)
- MONKEY_break (0);
- }
-
- if (0 == cntxt->gdb_frames->line)
+ 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
{
- /*
- * 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);
+ cntxt->gdb_frames = cntxt->gdb_frames->next;
}
- /* Change current GDB frame to the one containing source code
*/
- gmi_stack_select_frame (cntxt->gdb_handle,
cntxt->gdb_frames->level);
+ 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);
- 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++;
- wait_for_stop(cntxt);
- return GDB_STATE_STOPPED;
- }
+ 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_EXIT_NORMALLY; // gdb analysis ignored
+ return GDB_STATE_ERROR;
}
@@ -677,7 +684,7 @@
MONKEY_CONTAINER_DLL_insert_tail (trace->functionListHead,
trace->functionListTail,
function);
- if (strcasecmp (signalMeaning, "Segmentation fault") == 0)
+ if ((strcasecmp (signalMeaning, "Segmentation fault") == 0) ||
(strcasecmp(signalMeaning, "Signal 0") == 0))
{
MONKEY_EDB_get_expressions (edbCntxt,
cntxt->gdb_frames->file,
@@ -723,7 +730,7 @@
ret = analyzeCustomFault (function, cntxt);
}
- printTrace();
+ //printTrace();
/* Now, dive deeper into the stack trace */
cntxt->gdb_frames = cntxt->gdb_frames->next;
@@ -749,20 +756,18 @@
struct Trace *tracePtr = epoch->traceListHead;
/*
- * We ignore gdb analysis only after the first step back operation.
- * The reason is that after crash, step back gets us to the expression
where the crash happened.
- * We already have this expression in our stack structure from the
previous epoch step (the initial epoch)
+ * 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)
*/
- cntxt->gdb_ignore_analysis = MONKEY_YES;
- if (MONKEY_NO != gmi_exec_next_reverse(cntxt->gdb_handle)) {
- wait_for_stop(cntxt);
- cntxt->gdb_ignore_analysis = MONKEY_NO;
- }
- else {
+ 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 {
@@ -782,7 +787,6 @@
} while ((NULL != tracePtr) && (strcmp(failureFile,
tracePtr->functionListHead->file) == 0) &&
(strcmp(failureFunction,
tracePtr->functionListHead->name) == 0));
- mi_disconnect(cntxt->gdb_handle); // No need for gdb mi at this point!
return MONKEY_OK;
}
@@ -1224,6 +1228,8 @@
MONKEY_ACTION_delete_context (struct MONKEY_ACTION_Context
*cntxt)
{
+ 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)
Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi.h
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi.h
2012-03-20 17:41:35 UTC (rev 20636)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi.h
2012-03-20 17:46:07 UTC (rev 20637)
@@ -561,6 +561,9 @@
/* Continue until function return, the return value is included in the async
response. */
int gmi_exec_finish(mi_h *h);
+/* Continue backwardly until function return, the return value is included in
+ the async response.*/
+int gmi_exec_finish_reverse(mi_h *h);
/* Stop the program using SIGINT. */
int gmi_exec_interrupt(mi_h *h);
/* Next line of code. */
Modified:
monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_prg_control.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_prg_control.c
2012-03-20 17:41:35 UTC (rev 20636)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/gdbmi_prg_control.c
2012-03-20 17:46:07 UTC (rev 20637)
@@ -105,6 +105,10 @@
mi_send(h,"-exec-finish\n");
}
+void mi_exec_finish_reverse(mi_h * h)
+{
+ mi_send(h, "-exec-finish --reverse\n");
+}
void mi_exec_interrupt(mi_h *h)
{
mi_send(h,"-exec-interrupt\n");
@@ -291,6 +295,22 @@
/**[txh]********************************************************************
Description:
+ Continue backwardly until function return, the return value is included in
+ the async response.
+
+ Command: -exec-finish --reverse
+ Return: !=0 OK.
+
+***************************************************************************/
+int gmi_exec_finish_reverse(mi_h *h)
+{
+ mi_exec_finish_reverse(h);
+ return mi_res_simple_running(h);
+}
+
+/**[txh]********************************************************************
+
+ Description:
Stop the program using SIGINT. The corresponding command should be
-exec-interrupt but not even gdb 6.1.1 can do it because the "async" mode
isn't really working.
Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c
2012-03-20 17:41:35 UTC (rev 20636)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey.c
2012-03-20 17:46:07 UTC (rev 20637)
@@ -97,7 +97,6 @@
cntxt->scope_depth = (NULL == scopeDepth) ? 0 : atoi(scopeDepth);
cntxt->xml_report_node = NULL;
cntxt->run_reverse = reverseExecutionAllowed;
- cntxt->gdb_ignore_analysis = MONKEY_NO;
result = MONKEY_ACTION_rerun_with_gdb (cntxt);
switch (result)
@@ -130,18 +129,18 @@
break;
}
}
- else {
- /* Monkey was able to detect problem using GDB, start
backtracking if requested by user */
- if (cntxt->run_reverse) {
- retVal = MONKEY_ACTION_start_reverse_execution(cntxt);
- if (MONKEY_NO == retVal) {
- fprintf(stderr, "Error during Backtracking!\n");
- ret = 1;
- break;
- }
- }
+
+ /* Start backtracking if enabled by user */
+ if (cntxt->run_reverse) {
+ retVal = MONKEY_ACTION_start_reverse_execution(cntxt);
+ if (MONKEY_NO == retVal) {
+ fprintf(stderr, "Error during Backtracking!\n");
+ ret = 1;
+ break;
+ }
}
+
/* REPORTING
*/
if (MONKEY_OK != MONKEY_ACTION_format_report_xml (cntxt))
{
Modified: monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h
2012-03-20 17:41:35 UTC (rev 20636)
+++ monkey/branches/MonkeyBacktracking/monkey/src/monkey/monkey_action.h
2012-03-20 17:46:07 UTC (rev 20637)
@@ -51,7 +51,6 @@
/* gdb debugging attributes */
int run_reverse;
int scope_depth;
- int gdb_ignore_analysis;
mi_h *gdb_handle;
const char *gdb_in_use;
mi_stop *gdb_stop_reason;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r20637 - monkey/branches/MonkeyBacktracking/monkey/src/monkey,
gnunet <=