[m-rev.] diff: debugging the declarative debugger
Mark Anthony BROWN
dougl at cs.mu.OZ.AU
Fri Apr 27 04:41:32 AEST 2001
Hi,
This change will allow me to debug another change I am working on.
Cheers,
Mark.
Estimated hours taken: 2
Branches: main
Improve meta-debugging of the declarative debugger. Add a declarative
debugging mode which leaves MR_trace_enabled equal to TRUE when the
front end is called, so that it generates trace events. This mode is
used by invoking the mdb command 'dd_dd' with no parameters. This is a
developer-only command.
Rearrange code to reduce duplication.
trace/mercury_trace_declarative.h:
trace/mercury_trace_declarative.c:
- Handle all debugging modes via MR_decl_diagnosis (subsuming
the functionality of MR_decl_diagnosis_test).
- Add an argument for the trace mode to MR_trace_start_decl_debug,
and use this information to determine its behaviour.
- Add a missing fflush of MR_mdb_out.
trace/mercury_trace_internal.c:
- Implement the new version of dd_dd.
- Move the code for checking the current port into
MR_trace_start_decl_debug.
trace/mercury_trace_internal.h:
- Add the new mode to MR_Trace_Mode.
- Rename MR_TRACE_DECL_DEBUG_TEST to MR_TRACE_DECL_DEBUG_DUMP,
since there are now two modes for testing.
Index: trace/mercury_trace_declarative.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_declarative.c,v
retrieving revision 1.42
diff -u -r1.42 mercury_trace_declarative.c
--- trace/mercury_trace_declarative.c 2001/03/18 23:10:16 1.42
+++ trace/mercury_trace_declarative.c 2001/04/26 17:38:59
@@ -255,9 +255,6 @@
MR_decl_diagnosis(MR_Trace_Node root, MR_Trace_Cmd_Info *cmd,
MR_Event_Info *event_info, MR_Event_Details *event_details);
-static void
-MR_decl_diagnosis_test(MR_Trace_Node root);
-
static MR_Code *
MR_decl_handle_bug_found(MR_Unsigned event, MR_Trace_Cmd_Info *cmd,
MR_Event_Info *event_info, MR_Event_Details *event_details);
@@ -448,22 +445,8 @@
/*
** Call the front end.
*/
- switch (MR_trace_decl_mode) {
- case MR_TRACE_DECL_DEBUG:
- return MR_decl_diagnosis(
- MR_trace_current_node, cmd,
- event_info, &event_details);
-
- case MR_TRACE_DECL_DEBUG_TEST:
- MR_decl_diagnosis_test(MR_trace_current_node);
- break;
-
- default:
- MR_fatal_error("MR_trace_decl_debug: "
- "unexpected mode");
- }
- MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
- return MR_trace_event_internal(cmd, TRUE, event_info);
+ return MR_decl_diagnosis(MR_trace_current_node, cmd,
+ event_info, &event_details);
}
MR_trace_enabled = TRUE;
@@ -1163,9 +1146,9 @@
}
bool
-MR_trace_start_decl_debug(const char *outfile, MR_Trace_Cmd_Info *cmd,
- MR_Event_Info *event_info, MR_Event_Details *event_details,
- MR_Code **jumpaddr)
+MR_trace_start_decl_debug(MR_Trace_Mode trace_mode, const char *outfile,
+ MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
+ MR_Event_Details *event_details, MR_Code **jumpaddr)
{
MR_Retry_Result result;
const MR_Proc_Layout *entry;
@@ -1174,6 +1157,14 @@
const char *message;
MR_Trace_Level trace_level;
+ if (!MR_port_is_final(event_info->MR_trace_port)) {
+ fflush(MR_mdb_out);
+ fprintf(MR_mdb_err,
+ "mdb: declarative debugging is only available"
+ " from EXIT, FAIL or EXCP events.\n");
+ return FALSE;
+ }
+
entry = event_info->MR_event_sll->MR_sll_entry;
if (!MR_ENTRY_LAYOUT_HAS_EXEC_TRACE(entry)) {
fflush(MR_mdb_out);
@@ -1212,11 +1203,7 @@
}
#endif /* MR_USE_DECL_STACK_SLOT */
- if (outfile == (const char *) NULL) {
- /* Normal debugging mode */
- MR_trace_decl_mode = MR_TRACE_DECL_DEBUG;
- } else {
- /* Test mode */
+ if (trace_mode == MR_TRACE_DECL_DEBUG_DUMP) {
out = fopen(outfile, "w");
if (out == NULL) {
fflush(MR_mdb_out);
@@ -1225,11 +1212,12 @@
outfile, strerror(errno));
return FALSE;
} else {
- MR_trace_decl_mode = MR_TRACE_DECL_DEBUG_TEST;
MR_trace_store_file = out;
}
}
+ MR_trace_decl_mode = trace_mode;
+
MR_trace_decl_ensure_init();
depth_limit = event_info->MR_call_depth + MR_EDT_DEPTH_STEP_SIZE;
message = MR_trace_start_collecting(event_info->MR_event_number,
@@ -1339,21 +1327,37 @@
MR_Unsigned bug_event;
MR_Unsigned final_event;
MR_Unsigned topmost_seqno;
+ MercuryFile stream;
-#if 0
- /*
- ** This is a quick and dirty way to debug the front end.
- */
- MR_trace_enabled = TRUE;
-#endif
-
if (MR_edt_compiler_flag_warning) {
+ fflush(MR_mdb_out);
fprintf(MR_mdb_err, "Warning: some modules were compiled with"
" a trace level lower than `decl'.\n"
"This may result in calls being omitted from"
" the debugging tree.\n");
}
+ if (MR_trace_decl_mode == MR_TRACE_DECL_DEBUG_DUMP) {
+ MR_mercuryfile_init(MR_trace_store_file, 1, &stream);
+
+ MR_TRACE_CALL_MERCURY(
+ MR_DD_save_trace((MR_Word) &stream,
+ MR_trace_node_store, root);
+ );
+
+ fclose(MR_trace_store_file);
+ MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
+ MR_trace_enabled = TRUE;
+ return MR_trace_event_internal(cmd, TRUE, event_info);
+ }
+
+ if (MR_trace_decl_mode == MR_TRACE_DECL_DEBUG_DEBUG) {
+ /*
+ ** This is a quick and dirty way to debug the front end.
+ */
+ MR_trace_enabled = TRUE;
+ }
+
MR_TRACE_CALL_MERCURY(
MR_DD_decl_diagnosis(MR_trace_node_store, root, &response,
MR_trace_front_end_state,
@@ -1435,20 +1439,6 @@
MR_trace_decl_mode = MR_TRACE_INTERACTIVE;
MR_trace_enabled = TRUE;
return jumpaddr;
-}
-
-static void
-MR_decl_diagnosis_test(MR_Trace_Node root)
-{
- MercuryFile stream;
-
- MR_mercuryfile_init(MR_trace_store_file, 1, &stream);
-
- MR_TRACE_CALL_MERCURY(
- MR_DD_save_trace((MR_Word) &stream, MR_trace_node_store, root);
- );
-
- fclose(MR_trace_store_file);
}
static MR_String
Index: trace/mercury_trace_declarative.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_declarative.h,v
retrieving revision 1.11
diff -u -r1.11 mercury_trace_declarative.h
--- trace/mercury_trace_declarative.h 2000/10/16 01:34:10 1.11
+++ trace/mercury_trace_declarative.h 2001/04/26 17:38:59
@@ -9,6 +9,7 @@
#include "mercury_imp.h"
#include "mercury_trace.h"
+#include "mercury_trace_internal.h"
/*
** When in declarative debugging mode, the internal debugger calls
@@ -25,8 +26,9 @@
** being entered.
*/
-extern bool MR_trace_start_decl_debug(const char *out,
- MR_Trace_Cmd_Info *cmd, MR_Event_Info *event_info,
+extern bool MR_trace_start_decl_debug(MR_Trace_Mode trace_mode,
+ const char *out, MR_Trace_Cmd_Info *cmd,
+ MR_Event_Info *event_info,
MR_Event_Details *event_details, MR_Code **jumpaddr);
/*
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.101
diff -u -r1.101 mercury_trace_internal.c
--- trace/mercury_trace_internal.c 2001/04/03 05:33:51 1.101
+++ trace/mercury_trace_internal.c 2001/04/26 17:38:59
@@ -2076,44 +2076,42 @@
}
#ifdef MR_USE_DECLARATIVE_DEBUGGER
} else if (streq(words[0], "dd")) {
- MR_Trace_Port port = event_info->MR_trace_port;
-
if (word_count != 1) {
fflush(MR_mdb_out);
fprintf(MR_mdb_err,
"mdb: dd requires no arguments.\n");
- } else if (MR_port_is_final(port)) {
- if (MR_trace_start_decl_debug((const char *) NULL, cmd,
+ } else {
+ if (MR_trace_start_decl_debug(MR_TRACE_DECL_DEBUG,
+ (const char *) NULL, cmd,
event_info, event_details,
jumpaddr))
{
return STOP_INTERACTING;
}
- } else {
- fflush(MR_mdb_out);
- fprintf(MR_mdb_err,
- "mdb: declarative debugging is only "
- "available from EXIT, FAIL or EXCP events.\n");
}
} else if (streq(words[0], "dd_dd")) {
- MR_Trace_Port port = event_info->MR_trace_port;
+ MR_Trace_Mode trace_mode;
+ const char *filename;
- if (word_count != 2) {
+ if (word_count > 2) {
fflush(MR_mdb_out);
fprintf(MR_mdb_err,
- "mdb: dd_dd requires one argument.\n");
- } else if (MR_port_is_final(port)) {
- if (MR_trace_start_decl_debug((const char *) words[1],
+ "mdb: dd_dd takes at most one argument.\n");
+ } else {
+ if (word_count == 2) {
+ trace_mode = MR_TRACE_DECL_DEBUG_DUMP;
+ filename = (const char *) words[1];
+ } else {
+ trace_mode = MR_TRACE_DECL_DEBUG_DEBUG;
+ filename = (const char *) NULL;
+ }
+
+ if (MR_trace_start_decl_debug(trace_mode, filename,
cmd, event_info, event_details,
jumpaddr))
{
return STOP_INTERACTING;
}
- } else {
- fflush(MR_mdb_out);
- fprintf(MR_mdb_err,
- "mdb: declarative debugging is only "
- "available from EXIT, FAIL or EXCP events.\n");
}
#endif /* MR_USE_DECLARATIVE_DEBUGGER */
} else {
Index: trace/mercury_trace_internal.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.h,v
retrieving revision 1.13
diff -u -r1.13 mercury_trace_internal.h
--- trace/mercury_trace_internal.h 2000/10/16 01:34:14 1.13
+++ trace/mercury_trace_internal.h 2001/04/26 18:34:52
@@ -24,7 +24,14 @@
typedef enum {
MR_TRACE_INTERACTIVE, /* Use internal debugger. */
MR_TRACE_DECL_DEBUG, /* Normal declarative debugging. */
- MR_TRACE_DECL_DEBUG_TEST /* Test mode declarative debugging. */
+ MR_TRACE_DECL_DEBUG_DUMP, /*
+ ** Output debugging info to a file
+ ** for separate analysis.
+ */
+ MR_TRACE_DECL_DEBUG_DEBUG /*
+ ** Generate trace events for the
+ ** debugging front end.
+ */
} MR_Trace_Mode;
/*
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list