Files
mercury/browser/debugger_interface.m
Zoltan Somogyi 8a0ceb49aa This checkin has several major purposes, set out in the sections below,
Estimated hours taken: 240

This checkin has several major purposes, set out in the sections below,
all connected with the implementation of the new debugger command set.

DOCUMENT NEW DEBUG COMMAND SET

doc/user_guide.texi:
	Add a new section on the debugger. The description of the commands
	is complete, but some of the background sections, and the section
	about how to build debuggable executables, are not yet done.

	Update the documentation of the tracing options.

doc/generate_mdb_doc:
	A new shell script that automatically converts some of the new
	sections of the user guide into the online documentation of the
	debugger.

doc/mdb_categories:
	The fixed initial part of the online documentation.

doc/Mmakefile:
	Add rules for creating mdb_doc, the file that is the online
	documentation of the debugger, and for installing it together
	with mdbrc.

Mmake.common.in:
	Define INSTALL_DOC_DIR for doc/Mmakefile.

scripts/mdbrc.in:
	A debugger command script that reads in the online documentation
	and then defines some standard aliases.

configure.in:
	Define the variable that scripts/mdb.in and scripts/mdbrc.in use
	to find the right files, and get configure to perform the
	substitutions.

configure.in:
scripts/mdb:
scripts/mdb.in:
	Replace mdb with mdb.in. Mdb is now created during configuration
	from mdb.in, filling in the name of the file that contains the default
	debugger initialization commands.

util/info_to_mdb.c:
	A program that does most of the work involved in automatically
	converting user guide sections into online documentation.
	(This couldn't easily be written in sh, because sh's read
	command has no notion of pushback.)

util/Mmakefile:
	Add info_to_mdb to the list of targets.

tools/bootcheck:
	Make sure that the tests in tests/debugger are executed with an
	initialization setup that is equivalent to what users will see
	by default.

REORGANIZE TRACING OPTIONS

compiler/globals.m:
compiler/handle_options.m:
compiler/options.m:
compiler/trace.m:
	Reorganize the handling of trace levels around the new options
	--trace-internal, --trace-redo, and --trace-return.

compiler/*.m:
	Use the new ways of getting at trace levels.

tests/hard_coded/typeclasses/Mmakefile:
	s/--trace all/--trace deep/

SUPPORT RETRY

compiler/trace.m:
	After every call to MR_trace(), emit code that checks whether it
	should jump away, and if yes, performs the jump. This is used to
	implement retry. (The debugger cannot execute the jump itself
	because it is in the wrong C stack frame.)

compiler/llds.m:
compiler/continuation_info.m:
compiler/stack_layout.m:
	Modify the data structures that record information about live
	value at program points, to record the identity of each variable.
	This is necessary for the implementation of the restart command,
	since we do not want to confuse two distinct variables just because
	they have the same name. For example, a variable whose name is X
	and number is 5 is now recorded in the name array as "5:X".

	Clean up the data structure a bit, so that we don't have to store
	dummy names for values that are not variables.

compiler/*.m:
	Minor changes to conform to the data structure changes.

runtime/mercury_stack_layout.h:
	Redefine an existing macro to strip away the initial number: prefix
	from the "name" of a variable (keeping its original function on
	changed data), and add a new one to access the raw unstripped data.

runtime/mercury_init.h:
runtime/mercury_wrapper.h:
	Update the prototype of MR_trace_{fake,real}, and the type of the
	global that points to them.

runtime/mercury_layout_util.h:
	Add an extra function, MR_get_register_number, for use by retry.

USE FIXED STACK SLOTS FOR TRACE INFO

compiler/code_gen.m:
compiler/code_info.m:
compiler/live_vars.m:
compiler/trace.m:
	If execution tracing is enabled, reserve the first few stack slots
	to hold the event number of the call event, the call number, the
	call depth, the redo layout structure address (if generating redo
	events) and the from_full flag at the time of call (if we are doing
	shallow tracing). By allocating the first four of these to fixed stack
	slots, the debugger knows where to look for them without having
	to be told. It finds out the location of the fifth, if needed,
	from a new slot in the proc layout structure. (It is not possible
	to allocate all five to fixed stack slots without wasting stack space
	in some cases.)

compiler/trace.m:
	Remove from the call to MR_trace the parameters that are now in fixed
	stack slots, since MR_trace can now look them up itself.

compiler/continuation_info.m:
compiler/stack_layout.m:
	Add an extra field to the proc_layout_info. If the module is shallow
	traced, this field says which stack slot holds the saved value of
	MR_from_full. If it is not shallow traced, this field says that
	there is no such stack slot.

runtime/mercury_stack_layout.h:
	Add macros for accessing the fixed stack slots holding the event
	number of the call event, the call number, the call depth, and,
	at a redo event, the redo layout structure address.

	Support the new field in proc layouts that gives the location of the
	from-full flag (if any).

runtime/mercury_trace_base.[ch]:
trace/mercury_trace.[ch]:
	Remove the call number and call depth arguments from MR_trace
	and its avatars, since this info is now in fixed stack slots
	in every procedure that can call MR_trace. This should reduce
	the size of the executable significantly, since there are lots
	of calls to MR_trace.

runtime/mercury_init.h:
runtime/mercury_wrapper.h:
	Update the prototype of MR_trace_{fake,real}, and the type of the
	global that points to them.

START NUMBERING FRAMEVARS FROM ONE

compiler/code_info.m:
compiler/live_vars.m:
compiler/llds_out.m:
compiler/trace.m:
	Start numbering framevars from 1 internally to the compiler;
	the runtime already starts from 1. This simplifies several tasks.

ADD REDO EVENTS

compiler/trace.m:
compiler/code_gen.m:
	Before the code that executes "succeed()", emit code to push a
	a temp nondet frame whose redoip points to a label in the runtime
	that calls MR_trace for a REDO event and then fails, provided
	--trace-redo is set.

compiler/llds.m:
	Add a new code address constant, do_trace_redo_fail, which stands
	for the address in the trace system to which calls MR_trace for
	the redo event and then fails.

compiler/trace.m:
compiler/llds_out.m:
	Provided we are doing redo tracing, fill in the slot that holds
	the layout information for the REDO event.

compiler/*.m:
	Minor changes to conform to handle the new code address constant.

browser/debugger_interface.m:
	Add redo to trace_port_type.

runtime/mercury_trace_base.[ch]:
	Add a C module containing the code that calls MR_trace for REDO
	events.

ENSURE THAT INPUT ARGUMENTS ARE ALWAYS VISIBLE

compiler/trace.m:
	When generating the set of live variables at internal ports,
	the variables that are in the pre-death set of the goal into which
	we are entering may not be available. However, the variables in the
	pre-death set that are also in the resume vars set will be available,
	so now include info about them in the layout structure for the event.
	Since with tracing the non-clobbered input args are in all resume vars
	sets, this ensures that these input args will be available from all
	internal events.

compiler/code_info.m:
	Export a previously internal predicate (current_resume_point_vars)
	to make this possible.

BUG FIX: WANT RETURN LAYOUTS

compiler/globals.m:
compiler/call_gen.m:
compiler/code_info.m:
compiler/mercury_compile.m:
	Add a new pred globals__want_return_layouts, which says whether the
	compiler should generate layout structures for call returns. This pred
	centralizes the several previous copies of the test. One of those
	copies (the one in call_gen) was faulty, leading to a bug: in the
	presence of execution tracing but the absence of accurate gc,
	information about the variables that are live at the call return
	wasn't being gathered properly.

BUG FIX: #include mercury_trace_base.h

compiler/llds_out.m:
	#include mercury_trace_base.h, not mercury_trace.h, since now
	mercury_trace_base.h defines everything directly accessible from
	modules compiled with tracing.

RECAST MERCURY_TRACE_UTIL AS MERCURY_LAYOUT_UTIL

runtime/mercury_trace_util.[ch]:
runtime/mercury_layout_util.[ch]:
	Rename this module from trace_util to layout_util, since it is also
	used by the native garbage collector. Remove "trace" from the names
	of functions.

	Get rid of the global variable MR_saved_regs, and instead thread
	a pointer to this data structure through the relevant functions
	as an extra argument.

	Add a lot more documentation in the header file.

runtime/Mmakefile:
	Reflect the module rename.

runtime/*.c:
	Refer to the new module.

DELETE EASY-TO-MISUSE MACROS

runtime/mercury_stacks.h:
	Delete the based_framevar and based_detstackvar macros, since their
	continued use can lead to off-by-one errors, and the saved_framevar
	and saved_detstackvar macros, since they are no longer used.

runtime/*.c
	Update any references to any macros removed from mercury_stacks.h.

MISC RUNTIME CHANGES

runtime/mercury_trace_base.[ch]:
trace/mercury_trace*.[ch]:
	Make typedef'd names conform to the naming convention.

	Make MR_trace_call_{seqno,depth} consistently Unsigned, rather than
	sometimes Word and sometimes Unsigned.

FIX BUG: MAKE THE DEBUGGER PRINT TO STDOUT, NOT THE CURRENT STREAM

library/io.m:
	Export to C code the predicates that return the identities and types
	of stdin, stdout and stderr, as well as io__print/[34].

library/std_util.m:
	Export to C code a predicate that returns the type_info for the
	type stdutil:type_info. This type_info is required if C code
	wants to invoke make_permanent on any type_info structure,
	as the debugger does.

runtime/mercury_init.h:
	Add extern declarations for the C functions now exported from io.m.

runtime/mercury_wrapper.[ch]:
	Add new global variables to hold the addresses of these C functions.

runtime/mercury_layout_util.c:
	Use indirect calls through these global variables to print Mercury
	values, instead of lower-level code.

util/mkinit.c:
	Assign the addresses of the functions exported from io.m to the
	global variables defined in mercury_wrapper.h.

BUG FIX: STACK TRACE FUNCTIONS DEPEND ON THE LABEL TABLE

runtime/mercury_stack_trace.c:
	On entry to any of the functions exported from this module,
	ensure that the label table is loaded by calling do_init_modules.
	Without a filled-in label table, the stack trace will not be able to
	find any stack layout info.

BUG FIX: REMOVE BROWSER/*.C

configure.in:
	When removing .c files generated by the C compiler, remove those
	in the browser directory as well as the compiler, library and
	profiler directories.

IMPLEMENT NEW DEBUGGER COMMAND SET

runtime/mercury_stack_trace.[ch]:
	Factor out the code that prints the id of a procedure into a function
	of its own, so that it can also be used from the debugger, ensuring
	appearance commonality.

	Add more documentation in the header file.

trace/mercury_trace_internal.c:
	Implement the proposed command set. Command names are now words,
	and several commands now have options allowing the user to override
	the default print level or strictness of the command, or the
	invocation conditions or action of a break point. Allows control
	over command echoing and the scrolling of sequences of event reports.
	Supports aliases, command file sourcing etc. Implements the retry
	command, using the info in the fixed stack slots.

trace/mercury_trace.[ch]:
	Extend the trace controls to support the new functionalities
	required by the new debugger language, which are print levels,
	variable-strictness commands, a more flexible finish command,
	and the retry command.

	Pass the command structure to MR_trace_event_report, since
	the user can now forcibly terminate the scrolling of reports.

trace/mercury_trace_alias.[ch]:
	New module to manage aliases for the debugger.

trace/mercury_trace_help.[ch]:
	New module to interface to browser/help.m.

trace/mercury_trace_spy.[ch]:
	New module to manage break points. The test of whether an event
	matches a break point is now much more efficient than before.
	The new module also allows several breakpoints with different
	actions and different invocation conditions (e.g. all ports,
	entry port, interface ports or specific (possibly internal) port)
	to be defined on the same procedure.

trace/mercury_trace_tables.[ch]:
	New module to manage a table of the debuggable modules, in which
	each such module is linked to the list of the layouts of all the
	procedures defined in that module. This information allows the
	debugger to turn the name of a predicate/function (possibly together
	with its arity and mode number) into the procedure layout structure
	required by the spy point module. Eventually it may also be useful
	in supplying lists of identifiers for command line completion.

	Modules for which no stack layout information is available will
	not be included in the table, since do_init_modules will not
	register any labels for them in the label table.

trace/Mmakefile:
	Mention the new files.

runtime/mercury_array_macros.h:
	A new file holding macros that can be useful in more than one module.

runtime/Mmakefile:
	Mention the new file.

runtime/mercury_conf.h.in:
	Mention a new configuration macro, MR_CANNOT_USE_STRUCTURE_ASSIGNMENT,
	used by runtime/mercury_array_macros.h.

configure.in:
	Find out whether we need to define MR_CANNOT_USE_STRUCTURE_ASSIGNMENT.

ADD TRACE DEPTH HISTOGRAMS

runtime/mercury_conf_param.h:
	Document MR_TRACE_HISTOGRAM.

runtime/mercury_trace_base.[ch]:
	Define the data structures for the histogram, and print the histogram
	when a traced program exits if MR_TRACE_HISTOGRAM is set.

trace/mercury_trace.[ch]:
	If MR_TRACE_HISTOGRAM is defined, record a count of the number of
	events at each depth. This information can help us evaluate space-time
	tradeoffs.

FACTOR OUT SHELL CODE HANDLING GRADE IMPLICATIONS

scripts/final_grade_options.sh-subr:
	A new file to contain any code that implements implications between
	grade flags; currently implements the implication debug -> use trail.

scripts/mgnuc.in:
scripts/ml.in:
	Replace the code that is now in final_grade_options.sh-subr with
	an inclusion of final_grade_options.sh-subr.

configure.in:
	Handle final_grade_options.sh-subr as {init,parse}_grade_options.sh-subr
	are handled.

SIMPLIFY THE MAINTAINANCE OF CONSISTENCY BETWEEN DEBUGGER CODE AND DOCUMENTATION

doc/Mmakefile:
	Add rules for creating mdb_command_list, a C code fragment
	that can included manually in trace/mercury_trace_internal.c
	to supply the list of valid commands, and mdb_command_test.inp,
	which is a list of invalid invocations of debugger commands,
	which tests whether the help message for such invocations
	can be located as expected.

doc/generate_mdb_command_list:
doc/generate_mdb_command_test:
	Awk scripts to create mdb_command_list and mdb_command_test.inp
	respectively from mdb_doc.

tools/bootcheck:
	Copy mdb_command_test.inp from doc to tests/debugger.

tests/debugger/Mmakefile:
	Add a new test that checks whether we get an internal error, unable
	to locate the right help node, for each invalid command invocation in
	mdb_command_test.inp.

UPDATE TEST CASES

tests/debugger/Mmakefile:
	Reenable queens. Conform to the new set of options.

tests/debugger/*.inp:
tests/debugger/*.exp:
	Update the inputs and expected outputs of the debugger test cases
	to use the new command set and output formats.
1998-10-16 06:20:28 +00:00

380 lines
12 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Copyright (C) 1998 The University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%-----------------------------------------------------------------------------%
% File: debugger_interface.m
% Authors: fjh, jahier
% Purpose:
% This module provide support routines needed by
% runtime/mercury_trace_external.c for interfacing to an external
% (in a different process) debugger, in particular an Opium-style
% debugger.
%
% This module corresponds to what is called the "Query Handler" in Opium.
:- module debugger_interface.
:- interface.
% This module exports the following C functions:
% ML_DI_output_current
% ML_DI_found_match
% ML_DI_read_request_from_socket
% These are used by runtime/mercury_trace_external.c.
:- pred dummy_pred_to_avoid_warning_about_nothing_exported is det.
:- implementation.
:- import_module io, require.
:- import_module list, bool, std_util.
dummy_pred_to_avoid_warning_about_nothing_exported.
% The stuff defined below is also defined in modules prog_data, hlds_data.
:- type arity == int.
:- type determinism == int.
% encoded as specified in ../runtime/mercury_stack_layout.h
% and ../compiler/stack_layout.m.
% The stuff defined below is similar to types goal_path and trace_port
% defined in modules compiler/hlds_goal.m and compiler/trace.m.
% This enumeration must be EXACTLY the same as the MR_trace_port enum in
% runtime/mercury_trace.h, and in the same order, since the code assumes
% the representation is the same.
:- type trace_port_type
---> call
; exit
; redo
; fail
; ite_then
; ite_else
; disj
; switch
; nondet_pragma_first
; nondet_pragma_later
.
:- type goal_path_string == string.
% This is known as "debugger_query" in the Opium documentation.
% The debugger_request type is used for request sent
% from the debugger process to the Mercury program being debugged.
% This type would need to be extended to handle spypoints, etc.
:- type debugger_request
---> hello_reply % yes, I'm here
% A `forward_move' request instructs the debuggee
% to step forward until we reach a trace event
% which matches the specified attributes.
; forward_move(
match(event_number),
match(call_number),
match(depth_number),
match(trace_port_type),
match(string), % module name
match(string), % pred name
match(arity),
match(int), % mode number
match(determinism),
match(list(univ)), % the arguments
% XXX we could provide better ways of
% matching on arguments
match(goal_path_string)
)
% A `current_slots' request instructs the debuggee to
% retrieve the attributes of the current trace
% event (except for argument slot) and report them
% to the debugger via the socket.
; current_slots
% A `current_vars' request instructs the debuggee to
% retrieve the list of values and the list of internal
% names of live variables of the current event and
% report it to the debugger via the socket.
; current_vars %
% XXX should provide a way of getting
% just part of the arguments
% (to reduce unnecessary socket traffic)
% A `current_live_var_names' request instructs the debuggee to
% retrieve the list of internal names of the currently
% live variables and a list of their corresponding types.
; current_live_var_names
% A 'current_nth_var' request instructs the debuggee to
% retrieve the specified live variable.
; current_nth_var(int)
; abort_prog
% just abort the program
; no_trace
% stop tracing, and run the program to completion
; error(string)
% something went wrong when trying to get the
% next request
.
:- type event_number == int.
:- type call_number == int.
:- type depth_number == int.
% `match' is called "get status" in the Opium documentation.
% This type defines a unary predicate which determines whether
% or not a particular value will be selected.
:- type match(T)
---> nop % nop: value = -
; exact(T) % exact(X): value = X
; neg(T) % neg(X): value \= X
; list(list(T)) % list(L): list__member(value, L)
; interval(T,T) % interval(Low, High): Low =< X, X =< High
.
% The debugger_response type is used for response sent
% to the debugger process from the Mercury program being debugged.
% This type would need to be extended.
:- type debugger_response
% sending hello
---> hello % are you there?
% start the synchronous communication with the debugger
; start
% responses to forward_move
; forward_move_match_found
; forward_move_match_not_found
% responses to current
% responses to current_slots
; current_slots(
event_number,
call_number,
depth_number,
trace_port_type,
string, % module name
string, % pred name
arity,
int, % mode number
determinism,
goal_path_string
)
% responses to current_vars
; current_vars(list(univ), list(string))
% reponse to current_nth_var
; current_nth_var(univ)
% responses to current_live_var_names
; current_live_var_names(list(string), list(string))
% response sent when the last event is reached
; last_event
% responses to abort_prog or no_trace
; ok
% responses to anything
; error(string)
.
%-----------------------------------------------------------------------------%
% send to the debugger (e.g. Opium) the wanted features.
% output_current_slots "ML_DI_output_current_slots":
% send to the debugger (e.g. Opium) the attributes of the current event
% except the list of arguments.
:- pragma export(output_current_slots(in, in, in, in, in, in, in, in, in,
in, in, di, uo), "ML_DI_output_current_slots").
:- pred output_current_slots(event_number, call_number, depth_number,
trace_port_type, /* module name */ string, /* pred name */ string,
arity, /* mode num */ int, determinism, goal_path_string,
io__output_stream, io__state, io__state).
:- mode output_current_slots(in, in, in, in, in, in, in, in, in, in, in,
di, uo) is det.
output_current_slots(EventNumber, CallNumber, DepthNumber, Port,
ModuleName, PredName, Arity, ModeNum, Determinism,
Path, OutputStream) -->
{ CurrentTraceInfo = current_slots(EventNumber, CallNumber,
DepthNumber, Port, ModuleName, PredName, Arity,
ModeNum, Determinism, Path) },
io__write(OutputStream, CurrentTraceInfo),
io__print(OutputStream, ".\n"),
io__flush_output(OutputStream).
% output_current_vars "ML_DI_output_current_vars":
% send to the debugger the list of the live variables of the current event.
:- pragma export(output_current_vars(in, in, in, di, uo), "ML_DI_output_current_vars").
:- pred output_current_vars(list(univ), list(string),
io__output_stream, io__state, io__state).
:- mode output_current_vars(in, in, in, di, uo) is det.
output_current_vars(VarList, StringList, OutputStream) -->
{ CurrentTraceInfo = current_vars(VarList, StringList) },
io__write(OutputStream, CurrentTraceInfo),
io__print(OutputStream, ".\n"),
io__flush_output(OutputStream).
% output_current_nth_var "ML_DI_output_current_nth_var":
% send to the debugger the requested live variable of the current event.
:- pragma export(output_current_nth_var(in, in, di, uo), "ML_DI_output_current_nth_var").
:- pred output_current_nth_var(univ, io__output_stream, io__state, io__state).
:- mode output_current_nth_var(in, in, di, uo) is det.
output_current_nth_var(Var, OutputStream) -->
{ CurrentTraceInfo = current_nth_var(Var) },
io__write(OutputStream, CurrentTraceInfo),
io__print(OutputStream, ".\n"),
io__flush_output(OutputStream).
:- pragma export(output_current_live_var_names(in, in, in, di, uo),
"ML_DI_output_current_live_var_names").
:- pred output_current_live_var_names(list(string), list(string),
io__output_stream, io__state, io__state).
:- mode output_current_live_var_names(in, in, in, di, uo) is det.
output_current_live_var_names(LiveVarNameList, LiveVarTypeList,
OutputStream) -->
{ CurrentTraceInfo = current_live_var_names(
LiveVarNameList, LiveVarTypeList) },
io__write(OutputStream, CurrentTraceInfo),
io__print(OutputStream, ".\n"),
io__flush_output(OutputStream).
%-----------------------------------------------------------------------------%
:- pragma export(get_var_number(in) = out, "ML_DI_get_var_number").
:- func get_var_number(debugger_request) = int.
:- mode get_var_number(in) = out is det.
% This function is intended to retrieve the integer in
% "current_nth_var(int)" requests.
get_var_number(DebuggerRequest) = VarNumber :-
(
DebuggerRequest = current_nth_var(Var)
->
Var = VarNumber
;
error("get_var_number: not a current_nth_var request")
).
%-----------------------------------------------------------------------------%
:- pragma export(found_match(in, in, in, in, in, in, in, in, in, in,
in, in), "ML_DI_found_match").
:- pred found_match(event_number, call_number, depth_number, trace_port_type,
/* module name */ string, /* pred name */ string, arity,
/* mode num */ int, determinism, /* the arguments */ list(univ),
% XXX we could provide better ways of
% matching on arguments
goal_path_string, debugger_request).
:- mode found_match(in, in, in, in, in, in, in, in, in, in, in, in)
is semidet.
found_match(EventNumber, CallNumber, DepthNumber, Port, ModuleName,
PredName, Arity, ModeNum, Determinism, Args, Path,
DebuggerRequest) :-
(
DebuggerRequest = forward_move(MatchEventNumber,
MatchCallNumber, MatchDepthNumber, MatchPort,
MatchModuleName, MatchPredName, MatchArity,
MatchModeNum, MatchDeterminism, MatchArgs, MatchPath)
->
match(MatchEventNumber, EventNumber),
match(MatchCallNumber, CallNumber),
match(MatchDepthNumber, DepthNumber),
match(MatchPort, Port),
match(MatchModuleName, ModuleName),
match(MatchPredName, PredName),
match(MatchArity, Arity),
match(MatchModeNum, ModeNum),
match(MatchDeterminism, Determinism),
match(MatchArgs, Args),
match(MatchPath, Path)
;
error("found_match: forward_move expected")
).
% match(MatchPattern, Value) is true iff Value matches the specified pattern.
:- pred match(match(T), T).
:- mode match(in, in) is semidet.
match(nop, _).
match(exact(X), X).
match(neg(X), Y) :- X \= Y.
match(list(L), X) :- list__member(X, L).
match(interval(Low, High), X) :-
% X >= Low, X =< High
compare(LE, X, High),
(LE = (<) ; LE = (=)),
compare(GE, X, Low),
(GE = (>) ; GE = (=)).
%-----------------------------------------------------------------------------%
:- pred read_request_from_socket(io__input_stream, debugger_request, int,
io__state, io__state).
:- mode read_request_from_socket(in, out, out, di, uo) is det.
:- pragma export(read_request_from_socket(in, out, out, di, uo),
"ML_DI_read_request_from_socket").
read_request_from_socket(SocketStream, Request, RequestType) -->
io__read(SocketStream, MaybeRequest),
( { MaybeRequest = ok(Request0) },
{ Request = Request0 }
; { MaybeRequest = error(ErrorMsg, _LineNum) },
{ Request = error(ErrorMsg) }
; { MaybeRequest = eof },
{ Request = error("end of file") }
),
{ classify_request(Request, RequestType) }.
/***********
% debugging stuff.
io__stderr_stream(StdErr),
io__print(StdErr, "debugger_interface: Receive the Request:+"),
io__print(StdErr, Request),
io__print(StdErr, "+ from opium\ndebugger_interface: RequestType = "),
io__print(StdErr, RequestType),
io__print(StdErr, ".\n").
***********/
:- pred classify_request(debugger_request, int).
:- mode classify_request(in, out) is det.
% the numbers here should match the definition of
% MR_debugger_request_type in runtime/mercury_trace_external.c.
classify_request(hello_reply, 0).
classify_request(forward_move(_, _, _, _, _, _, _, _, _, _, _), 1).
classify_request(current_vars, 2).
classify_request(current_slots, 3).
classify_request(no_trace, 4).
classify_request(abort_prog, 5).
classify_request(error(_), 6).
classify_request(current_live_var_names, 7).
classify_request(current_nth_var(_), 8).
%-----------------------------------------------------------------------------%