[m-dev.] For review: Stacks dump in the external debugger
Erwan Jahier
Erwan.Jahier at irisa.fr
Fri Feb 12 09:22:21 AEDT 1999
| On 11-Feb-1999, Erwan Jahier <Erwan.Jahier at irisa.fr> wrote:
| > Estimated hours taken: 1
| >
| > This change implement stack dump commands for the external debugger.
| >
| > browser/debugger_interface.m:
| > Add three new kinds of requests: stack, nondet_stack and stack_regs.
| >
| > trace/mercury_trace_external.c:
| > Implement the ancestors, non det and registers stack dump.
|
| Is there much point in implementing the `nondet_stack' and `stack_regs'
| commands in the external debugger?
| These commands are intended for developers of the Mercury implementation only,
| to debug the low-level execution mechanism.
|
| I suppose it can't do much harm...
That's what I thougth...
Futhermore, maybe developpers will use my debugger one day ? ;)
| > + case MR_REQUEST_STACK:
| > + if (MR_debug_socket) {
| > + fprintf(stderr, "\nMercury runtime: "
| > + "REQUEST_STACK\n");
| > + }
| > + include_trace_data = TRUE;
| > + do_init_modules();
| > + message = MR_dump_stack_from_layout(stdout,
|
| I think stdout is not a good place to send such things.
| That might interfere with the output of the program being debugged.
| Shouldn't they be sent down the socket?
Well the problem is that I only read Prolog terms from the socket.
One thing I can do is create a temporary file, put in it the output of
MR_dump_stack_from_layout, reread it word by word and send them to the socket.
Do you see some simpler to do that? (without rewriting all the stack_dump stuff)
I can't do that for the nondet_stack since not all the outputs are done in the
* FILE argument (some are done in stderr). So I let it as it was in my previous
diff.
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.6
diff -u -r1.6 mercury_trace_external.c
--- mercury_trace_external.c 1999/02/10 22:31:23 1.6
+++ mercury_trace_external.c 1999/02/11 22:11:30
@@ -53,12 +53,16 @@
MR_REQUEST_ERROR = 6, /* something went wrong */
MR_REQUEST_CURRENT_LIVE_VAR_NAMES
= 7, /* report data for
- current_live_var_names query */
+ current_live_var_names query */
MR_REQUEST_CURRENT_NTH_VAR
= 8, /* report data for
- current_nth_var query */
- MR_REQUEST_RETRY = 9 /* restart the execution to the call
+ current_nth_var query */
+ MR_REQUEST_RETRY = 9, /* restart the execution to the call
port of the current event */
+ MR_REQUEST_STACK = 10,/* print the ancestors list */
+ MR_REQUEST_NONDET_STACK = 11,/* print the non det stack */
+ MR_REQUEST_STACK_REGS = 12 /* prints the contents of the virtual
+ machine registers. */
} MR_debugger_request_type;
@@ -443,6 +447,79 @@
MR_send_message_to_socket_format(
"error(\"%s\").\n", message);
}
+ break;
+
+ case MR_REQUEST_STACK: {
+ FILE *file_temp_in;
+ FILE *file_temp_out;
+ char res;
+ bool include_trace_data = TRUE;
+
+ if (MR_debug_socket) {
+ fprintf(stderr, "\nMercury runtime: "
+ "REQUEST_STACK\n");
+ }
+ file_temp_out = fopen("MR_temp_file", "w");
+ if (file_temp_out == NULL) {
+ fprintf(stderr, " fopen() failed.\n");
+ break;
+ }
+ do_init_modules();
+ message = MR_dump_stack_from_layout(
+ file_temp_out,
+ layout->MR_sll_entry,
+ MR_saved_sp(saved_regs),
+ MR_saved_curfr(saved_regs),
+ include_trace_data);
+
+ fclose(file_temp_out);
+ file_temp_in = fopen("MR_temp_file", "r");
+ if (file_temp_in == NULL) {
+ fprintf(stderr, " fdopen() failed.\n");
+ break;
+ }
+ while (fscanf(file_temp_in, "%s", &res) != EOF) {
+ MR_send_message_to_socket_format(
+ "stack(\"%s\").\n", &res);
+ }
+ fclose(file_temp_in);
+ remove("MR_temp_file");
+ MR_send_message_to_socket("end_stack");
+
+ if (message != NULL) {
+ MR_send_message_to_socket_format(
+ "error(\"%s\").\n", message);
+ } else {
+ MR_send_message_to_socket("ok");
+ }
+ break;
+ }
+
+ case MR_REQUEST_NONDET_STACK:
+ if (MR_debug_socket) {
+ fprintf(stderr, "\nMercury runtime: "
+ "REQUEST_NONDET_STACK\n");
+ }
+ do_init_modules();
+ MR_dump_nondet_stack_from_layout(stdout,
+ MR_saved_maxfr(saved_regs));
+ MR_send_message_to_socket("ok");
+ break;
+
+ case MR_REQUEST_STACK_REGS:
+ if (MR_debug_socket) {
+ fprintf(stderr, "\nMercury runtime: "
+ "REQUEST_STACK_REGS\n");
+ }
+ MR_send_message_to_socket_format(
+ "sp(\"%p\").\n",
+ (char *) MR_saved_sp(saved_regs));
+ MR_send_message_to_socket_format(
+ "curfr(\"%p\").\n",
+ (char *) MR_saved_curfr(saved_regs));
+ MR_send_message_to_socket_format(
+ "maxfr(\"%p\").\n",
+ (char *) MR_saved_maxfr(saved_regs));
break;
case MR_REQUEST_NO_TRACE:
--
R1.
More information about the developers
mailing list