[m-dev.] for review: handling layouts of compiler-generated procedures
Erwan Jahier
Erwan.Jahier at irisa.fr
Sat Feb 20 08:21:00 AEDT 1999
Once upon a time, Zoltan wrote:
[...]
| trace/mercury_trace_external.c:
| Update the code to conform to the changes in mercury_stack_layout.h,
| and add comments asking Erwan to eventually either generalize his code
| or explicitly restrict it to user-defined procedures.
|
| Zoltan.
Here we are !
______________________________________________________________________________
Estimated hours taken: 3
Generalized the code in the external debugger in order to be able to handle
inter-module inlining and compiler-generated procedures. To handle the former,
I have added the definition module as a slot to the event structure. To handle
the later, I have splitten output_current_slots() (and found_match()) in 2
differents functions; one for user defined events, the other one for compiler
generated events.
trace/mercury_trace_external.c:
browser/debugger_interface.m
Split output_current_slots() into output_current_slots_user() and
output_current_slots_comp()
Idem for found_match(), found_match_user() and found_match_comp().
Add a slot in the event for the definition module name in the case of
user-defined event.
___________________________________________________________________________
Index: browser/debugger_interface.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/debugger_interface.m,v
retrieving revision 1.7
diff -u -r1.7 debugger_interface.m
--- debugger_interface.m 1999/02/19 16:17:47 1.7
+++ debugger_interface.m 1999/02/19 21:15:58
@@ -17,11 +17,13 @@
:- interface.
% This module exports the following C functions:
-% ML_DI_output_current_slots
+% ML_DI_output_current_slots_user
+% ML_DI_output_current_slots_comp
% ML_DI_output_current_vars
% ML_DI_output_current_nth_var
% ML_DI_output_current_live_var_names
-% ML_DI_found_match
+% ML_DI_found_match_user
+% ML_DI_found_match_comp
% ML_DI_read_request_from_socket
% These are used by runtime/mercury_trace_external.c.
@@ -79,16 +81,17 @@
:- 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
+ % A `forward_move_user' request instructs the debuggee
+ % to step forward until we reach a user trace event
% which matches the specified attributes.
- ; forward_move(
+ ; forward_move_user(
match(event_number),
match(call_number),
match(depth_number),
match(trace_port_type),
match(pred_or_func),
- match(string), % module name
+ match(string), % declaration module name
+ match(string), % definition module name
match(string), % pred name
match(arity),
match(int), % mode number
@@ -98,6 +101,25 @@
% matching on arguments
match(goal_path_string)
)
+ % It is the same request as `forward_move_user' but for
+ % compiler generated events.
+ ; forward_move_comp(
+ match(event_number),
+ match(call_number),
+ match(depth_number),
+ match(trace_port_type),
+ match(string), % type name
+ match(string), % type module
+ match(string), % definition 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
@@ -168,14 +190,30 @@
; forward_move_match_found
; forward_move_match_not_found
% responses to current
- % responses to current_slots
- ; current_slots(
+ % responses to current_slots for user event
+ ; current_slots_user(
+ event_number,
+ call_number,
+ depth_number,
+ trace_port_type,
+ string,
+ string, % declaration module name
+ string, % definition module name
+ string, % pred name
+ arity,
+ int, % mode number
+ determinism,
+ goal_path_string
+ )
+ % responses to current_slots for compiler generated event
+ ; current_slots_comp(
event_number,
call_number,
depth_number,
trace_port_type,
- pred_or_func,
- string, % module name
+ string, % name type
+ string, % module type
+ string, % definition module
string, % pred name
arity,
int, % mode number
@@ -199,34 +237,63 @@
%-----------------------------------------------------------------------------%
% send to the debugger (e.g. Opium) the wanted features.
-% output_current_slots "ML_DI_output_current_slots":
+% output_current_slots_user "ML_DI_output_current_slots_user":
% 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, in, di, uo), "ML_DI_output_current_slots").
+:- pragma export(output_current_slots_user(in, in, in, in, in, in, in, in,
+ in, in, in, in, in, di, uo), "ML_DI_output_current_slots_user").
-:- pred output_current_slots(event_number, call_number, depth_number,
- trace_port_type, pred_or_func, /* 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, in,
- di, uo) is det.
+:- pred output_current_slots_user(event_number, call_number, depth_number,
+ trace_port_type, pred_or_func, /* declarated module name */ string,
+ /* definition 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_user(in, in, in, in, in, in, in, in, in, in,
+ in, in, in,di, uo) is det.
-output_current_slots(EventNumber, CallNumber, DepthNumber, Port, PredOrFunc,
- ModuleName, PredName, Arity, ModeNum, Determinism,
- Path, OutputStream) -->
+output_current_slots_user(EventNumber, CallNumber, DepthNumber, Port,
+ PredOrFunc, DeclModuleName, DefModuleName, PredName, Arity, ModeNum,
+ Determinism, Path, OutputStream) -->
- { CurrentTraceInfo = current_slots(EventNumber, CallNumber,
- DepthNumber, Port, PredOrFunc, ModuleName, PredName, Arity,
- ModeNum, Determinism, Path) },
+ { CurrentTraceInfo = current_slots_user(EventNumber, CallNumber,
+ DepthNumber, Port, PredOrFunc, DeclModuleName, DefModuleName,
+ PredName, Arity, ModeNum, Determinism, Path) },
io__write(OutputStream, CurrentTraceInfo),
io__print(OutputStream, ".\n"),
io__flush_output(OutputStream).
+% output_current_slots_comp "ML_DI_output_current_slots_comp":
+% send to the debugger (e.g. Opium) the attributes of the current event
+% except the list of arguments.
+
+:- pragma export(output_current_slots_comp(in, in, in, in, in, in, in,
+ in, in, in, in, in, in, di, uo), "ML_DI_output_current_slots_comp").
+
+:- pred output_current_slots_comp(event_number, call_number, depth_number,
+ trace_port_type, /* name type */ string, /* module type */ string,
+ /* definition module */ string, /* pred name */ string, arity,
+ /* mode num */ int, determinism, goal_path_string,
+ io__output_stream, io__state, io__state).
+:- mode output_current_slots_comp(in, in, in, in, in, in, in, in, in, in,
+ in, in, in, di, uo) is det.
+
+
+output_current_slots_comp(EventNumber, CallNumber, DepthNumber, Port,
+ NameType, ModuleType, DefModuleName, PredName, Arity,
+ ModeNum, Determinism, Path, OutputStream) -->
+
+ { CurrentTraceInfo = current_slots_comp(EventNumber, CallNumber,
+ DepthNumber, Port, NameType, ModuleType, DefModuleName,
+ 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.
+% 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").
@@ -298,35 +365,36 @@
%-----------------------------------------------------------------------------%
-:- pragma export(found_match(in, in, in, in, in, in, in, in, in, in, in,
- in, in), "ML_DI_found_match").
+:- pragma export(found_match_user(in, in, in, in, in, in, in, in, in, in, in,
+ in, in, in), "ML_DI_found_match_user").
-:- pred found_match(event_number, call_number, depth_number, trace_port_type,
- pred_or_func, /* module name */ string,
- /* pred name */ string, arity, /* mode num */ int, determinism,
- /* the arguments */ list(univ),
+:- pred found_match_user(event_number, call_number, depth_number,
+ trace_port_type, pred_or_func, /* declarated module name */ string,
+ /* defined 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, in)
+:- mode found_match_user(in, in, in, in, in, in, in, in, in, in, in, in, in, in)
is semidet.
-found_match(EventNumber, CallNumber, DepthNumber, Port, PredOrFunc, ModuleName,
- PredName, Arity, ModeNum, Determinism, Args, Path,
- DebuggerRequest) :-
+found_match_user(EventNumber, CallNumber, DepthNumber, Port, PredOrFunc,
+ DeclModuleName, DefModuleName, PredName, Arity, ModeNum,
+ Determinism, Args, Path, DebuggerRequest) :-
(
- DebuggerRequest = forward_move(MatchEventNumber,
+ DebuggerRequest = forward_move_user(MatchEventNumber,
MatchCallNumber, MatchDepthNumber, MatchPort,
- MatchPredOrFunc, MatchModuleName, MatchPredName,
- MatchArity, MatchModeNum, MatchDeterminism,
- MatchArgs, MatchPath)
+ MatchPredOrFunc, MatchDeclModuleName,
+ MatchDefModuleName, MatchPredName, MatchArity,
+ MatchModeNum, MatchDeterminism, MatchArgs, MatchPath)
->
match(MatchEventNumber, EventNumber),
match(MatchCallNumber, CallNumber),
match(MatchDepthNumber, DepthNumber),
match(MatchPort, Port),
match(MatchPredOrFunc, PredOrFunc),
- match(MatchModuleName, ModuleName),
+ match(MatchDeclModuleName, DeclModuleName),
+ match(MatchDefModuleName, DefModuleName),
match(MatchPredName, PredName),
match(MatchArity, Arity),
match(MatchModeNum, ModeNum),
@@ -354,6 +422,47 @@
(GE = (>) ; GE = (=)).
+:- pragma export(found_match_comp(in, in, in, in, in, in, in, in, in, in, in,
+ in, in, in), "ML_DI_found_match_comp").
+
+:- pred found_match_comp(event_number, call_number, depth_number,
+ trace_port_type, /* name type */ string, /* module type */ string,
+ /* definition 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_comp(in, in, in, in, in, in, in, in, in, in, in, in, in, in)
+ is semidet.
+
+found_match_comp(EventNumber, CallNumber, DepthNumber, Port, NameType,
+ ModuleType, DefModuleName, PredName, Arity, ModeNum,
+ Determinism, Args, Path, DebuggerRequest) :-
+ (
+ DebuggerRequest = forward_move_comp(MatchEventNumber,
+ MatchCallNumber, MatchDepthNumber, MatchPort,
+ MatchNameType, MatchModuleType,
+ MatchDefModuleName, MatchPredName, MatchArity,
+ MatchModeNum, MatchDeterminism, MatchArgs, MatchPath)
+ ->
+ match(MatchEventNumber, EventNumber),
+ match(MatchCallNumber, CallNumber),
+ match(MatchDepthNumber, DepthNumber),
+ match(MatchPort, Port),
+ match(MatchNameType, NameType),
+ match(MatchModuleType, ModuleType),
+ match(MatchDefModuleName, DefModuleName),
+ match(MatchPredName, PredName),
+ match(MatchArity, Arity),
+ match(MatchModeNum, ModeNum),
+ match(MatchDeterminism, Determinism),
+ match(MatchArgs, Args),
+ match(MatchPath, Path)
+ ;
+ error("found_match: forward_move expected")
+ ).
+
+
%-----------------------------------------------------------------------------%
:- pred read_request_from_socket(io__input_stream, debugger_request, int,
@@ -394,18 +503,19 @@
% 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).
-classify_request(retry, 9).
-classify_request(stack, 10).
-classify_request(nondet_stack, 11).
-classify_request(stack_regs, 12).
+classify_request(forward_move_user(_, _, _, _, _, _, _, _, _, _, _, _, _), 1).
+classify_request(forward_move_comp(_, _, _, _, _, _, _, _, _, _, _, _, _), 2).
+classify_request(current_vars, 3).
+classify_request(current_slots, 4).
+classify_request(no_trace, 5).
+classify_request(abort_prog, 6).
+classify_request(error(_), 7).
+classify_request(current_live_var_names, 8).
+classify_request(current_nth_var(_), 9).
+classify_request(retry, 10).
+classify_request(stack, 11).
+classify_request(nondet_stack, 12).
+classify_request(stack_regs, 13).
%-----------------------------------------------------------------------------%
Index: trace/mercury_trace_external.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.c,v
retrieving revision 1.9
diff -u -r1.9 mercury_trace_external.c
--- mercury_trace_external.c 1999/02/19 16:17:49 1.9
+++ mercury_trace_external.c 1999/02/19 21:16:02
@@ -46,23 +46,28 @@
typedef enum {
MR_REQUEST_HELLO_REPLY = 0, /* initiate debugging session */
- MR_REQUEST_FORWARD_MOVE = 1, /* go to the next matching trace event */
- MR_REQUEST_CURRENT_VARS = 2, /* report data for current_vars query */
- MR_REQUEST_CURRENT_SLOTS = 3, /* report data for current_slots query */
- MR_REQUEST_NO_TRACE = 4, /* continue to end, not tracing */
- MR_REQUEST_ABORT_PROG = 5, /* abort the current execution */
- MR_REQUEST_ERROR = 6, /* something went wrong */
+ MR_REQUEST_FORWARD_MOVE_USER = 1,
+ /* go to the next user-defined matching
+ trace event. */
+ MR_REQUEST_FORWARD_MOVE_COMP = 2,
+ /* go to the next compiler-generated
+ matching trace event */
+ MR_REQUEST_CURRENT_VARS = 3, /* report data for current_vars query */
+ MR_REQUEST_CURRENT_SLOTS = 4, /* report data for current_slots query */
+ MR_REQUEST_NO_TRACE = 5, /* continue to end, not tracing */
+ MR_REQUEST_ABORT_PROG = 6, /* abort the current execution */
+ MR_REQUEST_ERROR = 7, /* something went wrong */
MR_REQUEST_CURRENT_LIVE_VAR_NAMES
- = 7, /* report data for
+ = 8, /* report data for
current_live_var_names query */
MR_REQUEST_CURRENT_NTH_VAR
- = 8, /* report data for
+ = 9, /* report data for
current_nth_var query */
- MR_REQUEST_RETRY = 9, /* restart the execution to the call
+ MR_REQUEST_RETRY = 10, /* 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 nondet stack */
- MR_REQUEST_STACK_REGS = 12 /* prints the contents of the virtual
+ MR_REQUEST_STACK = 11,/* print the ancestors list */
+ MR_REQUEST_NONDET_STACK = 12,/* print the nondet stack */
+ MR_REQUEST_STACK_REGS = 13 /* prints the contents of the virtual
machine registers. */
} MR_debugger_request_type;
@@ -217,7 +222,8 @@
unix_address.sun_family = AF_UNIX;
strcpy(unix_address.sun_path, unix_socket);
addr = (struct sockaddr *) &unix_address;
- len = SUN_LEN(&unix_address);
+ len = strlen(unix_address.sun_path) +
+ sizeof(unix_address.sun_family);
} else {
char hostname[255];
char port_string[255];
@@ -396,7 +402,8 @@
fatal_error("aborting the execution on "
"user request");
- case MR_REQUEST_FORWARD_MOVE:
+ case MR_REQUEST_FORWARD_MOVE_USER:
+ case MR_REQUEST_FORWARD_MOVE_COMP:
if (MR_debug_socket) {
fprintf(stderr, "\nMercury runtime: "
"FORWARD_MOVE\n");
@@ -553,29 +560,41 @@
MR_output_current_slots(const MR_Stack_Layout_Label *layout,
MR_Trace_Port port, Unsigned seqno, Unsigned depth, const char *path)
{
- /*
- ** XXX This function and the Mercury predicates it calls
- ** ought to be generalized to handle inter-module inlining,
- ** and either further generalized to handle compiler-generated
- ** procedures or to explicitly discard events involving
- ** compiler-generated procedures.
- */
-
- MR_TRACE_CALL_MERCURY(
- ML_DI_output_current_slots(
- MR_trace_event_number,
- seqno,
- depth,
- port,
- layout->MR_sll_entry->MR_sle_user.MR_user_pred_or_func,
- layout->MR_sll_entry->MR_sle_user.MR_user_def_module,
- layout->MR_sll_entry->MR_sle_user.MR_user_name,
- layout->MR_sll_entry->MR_sle_user.MR_user_arity,
- layout->MR_sll_entry->MR_sle_user.MR_user_mode,
- layout->MR_sll_entry->MR_sle_detism,
- (String) (Word) path,
- (Word) &MR_debugger_socket_out);
- );
+ if (MR_ENTRY_LAYOUT_COMPILER_GENERATED(layout->MR_sll_entry)) {
+ MR_TRACE_CALL_MERCURY(
+ ML_DI_output_current_slots_comp(
+ MR_trace_event_number,
+ seqno,
+ depth,
+ port,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_type_name,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_type_module,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_def_module,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_pred_name,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_arity,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_mode,
+ layout->MR_sll_entry->MR_sle_detism,
+ (String) (Word) path,
+ (Word) &MR_debugger_socket_out);
+ );
+ } else {
+ MR_TRACE_CALL_MERCURY(
+ ML_DI_output_current_slots_user(
+ MR_trace_event_number,
+ seqno,
+ depth,
+ port,
+ layout->MR_sll_entry->MR_sle_user.MR_user_pred_or_func,
+ layout->MR_sll_entry->MR_sle_user.MR_user_decl_module,
+ layout->MR_sll_entry->MR_sle_user.MR_user_def_module,
+ layout->MR_sll_entry->MR_sle_user.MR_user_name,
+ layout->MR_sll_entry->MR_sle_user.MR_user_arity,
+ layout->MR_sll_entry->MR_sle_user.MR_user_mode,
+ layout->MR_sll_entry->MR_sle_detism,
+ (String) (Word) path,
+ (Word) &MR_debugger_socket_out);
+ );
+ }
}
static void
@@ -634,34 +653,45 @@
{
bool result;
- /*
- ** XXX This function and the Mercury predicates it calls
- ** ought to be generalized to handle inter-module inlining,
- ** and either further generalized to handle compiler-generated
- ** procedures or to explicitly discard events involving
- ** compiler-generated procedures.
- */
-
/* XXX get live vars from registers */
Word arguments = /* XXX FIXME!!! */ 0;
-
- MR_TRACE_CALL_MERCURY(
- result = ML_DI_found_match(
- MR_trace_event_number,
- seqno,
- depth,
- port,
- layout->MR_sll_entry->MR_sle_user.MR_user_pred_or_func,
- layout->MR_sll_entry->MR_sle_user.MR_user_def_module,
- layout->MR_sll_entry->MR_sle_user.MR_user_name,
- layout->MR_sll_entry->MR_sle_user.MR_user_arity,
- layout->MR_sll_entry->MR_sle_user.MR_user_mode,
- layout->MR_sll_entry->MR_sle_detism,
- arguments,
- (String) (Word) path,
- search_data);
- );
-
+ if (MR_ENTRY_LAYOUT_COMPILER_GENERATED(layout->MR_sll_entry)) {
+ MR_TRACE_CALL_MERCURY(
+ result = ML_DI_found_match_comp(
+ MR_trace_event_number,
+ seqno,
+ depth,
+ port,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_type_name,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_type_module,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_def_module,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_pred_name,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_arity,
+ layout->MR_sll_entry->MR_sle_comp.MR_comp_mode,
+ layout->MR_sll_entry->MR_sle_detism,
+ arguments,
+ (String) (Word) path,
+ search_data);
+ );
+ } else {
+ MR_TRACE_CALL_MERCURY(
+ result = ML_DI_found_match_user(
+ MR_trace_event_number,
+ seqno,
+ depth,
+ port,
+ layout->MR_sll_entry->MR_sle_user.MR_user_pred_or_func,
+ layout->MR_sll_entry->MR_sle_user.MR_user_decl_module,
+ layout->MR_sll_entry->MR_sle_user.MR_user_def_module,
+ layout->MR_sll_entry->MR_sle_user.MR_user_name,
+ layout->MR_sll_entry->MR_sle_user.MR_user_arity,
+ layout->MR_sll_entry->MR_sle_user.MR_user_mode,
+ layout->MR_sll_entry->MR_sle_detism,
+ arguments,
+ (String) (Word) path,
+ search_data);
+ );
+ }
return result;
}
--
R1.
More information about the developers
mailing list