[m-dev.] For review: Incorporate the term brower stuff in the external debugger. [part 1/2]
Erwan Jahier
Erwan.Jahier at irisa.fr
Thu May 20 23:58:24 AEST 1999
I have posted this in mercury-dev half an hour ago and nothing happens. I have
reposted it again because another post I made was delivered and because the
last message I've posted in mercury-user took 9 days to be delivered... so I
though it migth be worth trying again...
On a second thought, I realised the reason why my first post wasn't delivered
is that it was too big. So I try again splitting it.
So, sorry if you receive it again.
-------------------------------------------------------------------------------
I suppose Bert could review that change but I don't know if he's still around.
__
Estimated hours taken: 15
Incorporate the term brower stuff in the external debugger.
browser/browse.m:
Define browse__browse_external() which is the same as browse__browse()
but for the case where the term browser is called from the external
debugger.
Add an argument in predicates that need it to indicate whether the term
browser was called from the external or the internal debugger.
Define write_string_debugger/4, nl_debugger/3, write_int_debugger/4,
print_format_debugger/4 predicates and call them in place of
io__write_string/4, io__nl/3, io__write_int/4, and io__print/4
respectively. If the term browser is called from the internal debugger,
those predicates call the predicates they replace; otherwise, they
send their argument to the socket via a term of type
term_browser_response.
browser/debugger_interface.m
Define a new debugger request `browse/1'.
Define get_variable_name/2 that allows to retrieve from
mercury_trace_external.c the name of the variable to browse.
browser/parse.m:
Define parse__read_command_external/3 that parses the browser command
sent through the socket.
runtime/mercury_layout_util.c:
trace/mercury_trace_internal.c:
Move the definition of MR_trace_find_var() and
MR_trace_validate_var_count() from mercury_trace_internal.c to
mercury_layout_util.c to make it available to the external debugger.
runtime/mercury_layout_util.h:
trace/mercury_trace_internal.c:
Move the definition of MR_Var_Spec_Kind and MR_Var_Spec from
mercury_trace_internal.c to mercury_layout_util.h to make it
available to mercury_layout_util.c.
trace/mercury_trace_browser.ch:
Define the function MR_trace_browse_external() which is the same
as MR_trace_browse() except it uses the external debugger socket
instead of mdb_in and mdb_out.
trace/mercury_trace_external.c:
Define MR_trace_browse_one_external(), MR_trace_browse_var_external()
which are the same as MR_trace_browse_one() and MR_trace_browse_var()
of mercury_trace_internal.c, but for the use of the external debugger.
Define MR_get_variable_name() that calls get_variable_name/2 defined
in debugger_interface.m.
Index: browser/browse.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/browse.m,v
retrieving revision 1.8
diff -u -r1.8 browse.m
--- browse.m 1999/05/14 02:24:35 1.8
+++ browse.m 1999/05/20 12:03:13
@@ -35,6 +35,10 @@
browser_state, browser_state, io__state, io__state).
:- mode browse__browse(in, in, in, in, out, di, uo) is det.
+:- pred browse__browse_external(T, io__input_stream, io__output_stream,
+ browser_state, browser_state, io__state, io__state).
+:- mode browse__browse_external(in, in, in, in, out, di, uo) is det.
+
% The non-interactive term browser.
:- pred browse__print(T, io__output_stream, browser_state,
io__state, io__state).
@@ -61,6 +65,27 @@
:- pragma export(browse__browser_state_type(out),
"ML_BROWSE_browser_state_type").
+:- pragma export(browse__browse_external(in, in, in, in, out, di, uo),
+ "ML_BROWSE_browse_external").
+
+%---------------------------------------------------------------------------%
+% If the term browser is called from the internal debugger, Input/Output are
+% done via MR_mdb_in/MR_mdb_out. If it is called from the external debugger,
+% Input/Output are done via MR_debugger_socket_in/MR_debugger_socket_out.
+% Hence we need to output terms ; their type is term_browser_response.
+
+
+:- type term_browser_response
+ ---> browser_str(string)
+ ; browser_int(int)
+ ; browser_nl
+ ; browser_end_command
+ ; browser_quit.
+
+:- type debugger
+ ---> internal
+ ; external.
+
%---------------------------------------------------------------------------%
browse__init_state(State) -->
@@ -104,9 +129,15 @@
io__write_univ(Univ),
io__nl
;
- portray_fmt(State, flat)
+ portray_fmt(internal, State, flat)
).
+:- pred browse__print_external(browser_state, io__state, io__state).
+:- mode browse__print_external(in, di, uo) is det.
+
+browse__print_external(State) -->
+ portray_fmt(external, State, flat).
+
% The maximum estimated size for which we use `io__write'.
:- pred max_print_size(int::out) is det.
max_print_size(60).
@@ -162,49 +193,73 @@
%
browse__browse(Object, InputStream, OutputStream, State0, State) -->
+ browse_common(internal, Object, InputStream, OutputStream,
+ State0, State).
+
+browse__browse_external(Object, InputStream, OutputStream, State0, State) -->
+ browse_common(external, Object, InputStream, OutputStream,
+ State0, State).
+
+
+:- pred browse_common(debugger, T, io__input_stream, io__output_stream,
+ browser_state, browser_state, io__state, io__state).
+:- mode browse_common(in, in, in, in, in, out, di, uo) is det.
+browse_common(Debugger, Object, InputStream, OutputStream, State0, State) -->
{ type_to_univ(Object, Univ) },
{ set_term(Univ, State0, State1) },
io__set_input_stream(InputStream, OldInputStream),
io__set_output_stream(OutputStream, OldOutputStream),
% startup_message,
- browse_main_loop(State1, State),
+ browse_main_loop(Debugger, State1, State),
io__set_input_stream(OldInputStream, _),
io__set_output_stream(OldOutputStream, _).
-:- pred browse_main_loop(browser_state, browser_state, io__state, io__state).
-:- mode browse_main_loop(in, out, di, uo) is det.
-browse_main_loop(State0, State) -->
+:- pred browse_main_loop(debugger, browser_state, browser_state,
+ io__state, io__state).
+:- mode browse_main_loop(in, in, out, di, uo) is det.
+browse_main_loop(Debugger, State0, State) -->
{ prompt(Prompt) },
- parse__read_command(Prompt, Command),
+ ( { Debugger = internal } ->
+ parse__read_command(Prompt, Command)
+ ;
+ parse__read_command_external(Command)
+ ),
( { Command = quit } ->
- % io__write_string("quitting...\n")
+ % write_string_debugger(Debugger, "quitting...\n")
+ ( { Debugger = external } ->
+ send_term_to_socket(browser_quit)
+ ;
+ { true }
+ ),
{ State = State0 }
;
- run_command(Command, State0, State1),
- browse_main_loop(State1, State)
+ run_command(Debugger, Command, State0, State1),
+ browse_main_loop(Debugger, State1, State)
).
-:- pred startup_message(io__state::di, io__state::uo) is det.
-startup_message -->
- io__write_string("-- Simple Mercury Term Browser.\n"),
- io__write_string("-- Type \"help\" for help.\n\n").
+:- pred startup_message(debugger::in, io__state::di, io__state::uo) is det.
+startup_message(Debugger) -->
+ write_string_debugger(Debugger, "-- Simple Mercury Term Browser.\n"),
+ write_string_debugger(Debugger, "-- Type \"help\" for help.\n\n").
:- pred prompt(string::out) is det.
prompt("browser> ").
-:- pred run_command(command, browser_state, browser_state,
+:- pred run_command(debugger, command, browser_state, browser_state,
io__state, io__state).
-:- mode run_command(in, in, out, di, uo) is det.
-run_command(Command, State, NewState) -->
+:- mode run_command(in, in, in, out, di, uo) is det.
+run_command(Debugger, Command, State, NewState) -->
( { Command = unknown } ->
- io__write_string("Error: unknown command or syntax error.\nType \"help\" for help.\n"),
+ write_string_debugger(Debugger,
+ "Error: unknown command or syntax error.\n"),
+ write_string_debugger(Debugger, "Type \"help\" for help.\n"),
{ NewState = State }
; { Command = help } ->
- help,
+ help(Debugger),
{ NewState = State }
; { Command = set } ->
- show_settings(State),
+ show_settings(Debugger, State),
{ NewState = State }
; { Command = set(Setting) } ->
( { Setting = depth(MaxDepth) } ->
@@ -218,14 +273,15 @@
; { Setting = format(Fmt) } ->
{ set_fmt(Fmt, State, NewState) }
;
- io__write_string("error: unknown setting.\n"),
+ write_string_debugger(Debugger,
+ "error: unknown setting.\n"),
{ NewState = State }
)
; { Command = ls } ->
- portray(State),
+ portray(Debugger, State),
{ NewState = State }
; { Command = ls(Path) } ->
- portray_path(State, Path),
+ portray_path(Debugger, State, Path),
{ NewState = State }
; { Command = cd } ->
{ set_path(root_rel([]), State, NewState) }
@@ -236,25 +292,35 @@
( { deref_subterm(Univ, NewPwd, _SubUniv) } ->
{ set_path(Path, State, NewState) }
;
- io__write_string("error: cannot change to subterm\n"),
+ write_string_debugger(Debugger,
+ "error: cannot change to subterm\n"),
{ NewState = State }
)
; { Command = print } ->
- browse__print(State),
+ ( { Debugger = internal} ->
+ browse__print(State)
+ ;
+ browse__print_external(State)
+ ),
{ NewState = State }
; { Command = pwd } ->
{ get_dirs(State, Path) },
- write_path(Path),
- io__nl,
+ write_path(Debugger, Path),
+ nl_debugger(Debugger),
{ NewState = State }
;
- io__write_string("command not yet implemented\n"),
+ write_string_debugger(Debugger, "command not yet implemented\n"),
{ NewState = State }
+ ),
+ ( { Debugger = external } ->
+ send_term_to_socket(browser_end_command)
+ ;
+ { true }
).
% XXX: default depth is hardwired to 10.
-:- pred help(io__state::di, io__state::uo) is det.
-help -->
+:- pred help(debugger::in, io__state::di, io__state::uo) is det.
+help(internal) -->
io__write_string(
"Commands are:\n\
\tls [path] -- list subterm (expanded)\n\
@@ -277,66 +343,90 @@
\n"
).
+help(external) -->
+ write_string_debugger(external,
+"Commands are:\n\
+\t'ls [path]'. -- list subterm (expanded)\n\
+\t'cd [path]'. -- cd current subterm (default is root)\n\
+\thelp. -- show this help message\n\
+\t'set var value'. -- set a setting\n\
+\tset. -- show settings\n\
+\tprint. -- show single line representation of current term\n\
+\tquit. -- quit browser\n\
+SICStus Prolog style commands are:\n\
+\tp. -- print\n\
+\t'< [n]'. -- set depth (default is 10)\n\
+\t'^ [path]'. -- cd [path]\n\
+\t'?'. -- help\n\
+\th. -- help\n\
+\n\
+-- settings:\n\
+-- size; depth; path; format (flat pretty verbose); clipx; clipy\n\
+-- Paths can be Unix-style or SICStus-style: /2/3/1 or ^2^3^1\n\
+\n"
+ ).
+
%---------------------------------------------------------------------------%
%
% Various pretty-print routines
%
-:- pred portray(browser_state, io__state, io__state).
-:- mode portray(in, di, uo) is det.
-portray(State) -->
+:- pred portray(debugger, browser_state, io__state, io__state).
+:- mode portray(in, in, di, uo) is det.
+portray(Debugger, State) -->
{ get_fmt(State, Fmt) },
(
{ Fmt = flat },
- portray_flat(State)
+ portray_flat(Debugger, State)
;
{ Fmt = pretty },
- portray_pretty(State)
+ portray_pretty(Debugger, State)
;
{ Fmt = verbose },
- portray_verbose(State)
+ portray_verbose(Debugger, State)
).
-:- pred portray_path(browser_state, path, io__state, io__state).
-:- mode portray_path(in, in, di, uo) is det.
-portray_path(State, Path) -->
+:- pred portray_path(debugger, browser_state, path, io__state, io__state).
+:- mode portray_path(in, in, in, di, uo) is det.
+portray_path(Debugger, State, Path) -->
{ set_path(Path, State, NewState) },
- portray(NewState).
+ portray(Debugger, NewState).
-:- pred portray_fmt(browser_state, portray_format, io__state, io__state).
-:- mode portray_fmt(in, in, di, uo) is det.
-portray_fmt(State, Format) -->
+:- pred portray_fmt(debugger, browser_state, portray_format,
+ io__state, io__state).
+:- mode portray_fmt(in, in, in, di, uo) is det.
+portray_fmt(Debugger, State, Format) -->
(
{ Format = flat },
- portray_flat(State)
+ portray_flat(Debugger, State)
;
{ Format = pretty },
- portray_pretty(State)
+ portray_pretty(Debugger, State)
;
{ Format = verbose },
- portray_verbose(State)
+ portray_verbose(Debugger, State)
).
% XXX: could abstract out the code common to the following preds.
-:- pred portray_flat(browser_state, io__state, io__state).
-:- mode portray_flat(in, di, uo) is det.
-portray_flat(State) -->
+:- pred portray_flat(debugger, browser_state, io__state, io__state).
+:- mode portray_flat(in, in, di, uo) is det.
+portray_flat(Debugger, State) -->
{ get_term(State, Univ) },
{ get_size(State, MaxSize) },
{ get_depth(State, MaxDepth) },
{ get_dirs(State, Dir) },
( { deref_subterm(Univ, Dir, SubUniv) } ->
{ term_to_string(SubUniv, MaxSize, MaxDepth, Str) },
- io__write_string(Str)
+ write_string_debugger(Debugger, Str)
;
- io__write_string("error: no such subterm")
+ write_string_debugger(Debugger, "error: no such subterm")
),
- io__nl.
+ nl_debugger(Debugger).
-:- pred portray_verbose(browser_state, io__state, io__state).
-:- mode portray_verbose(in, di, uo) is det.
-portray_verbose(State) -->
+:- pred portray_verbose(debugger, browser_state, io__state, io__state).
+:- mode portray_verbose(in, in, di, uo) is det.
+portray_verbose(Debugger, State) -->
{ get_size(State, MaxSize) },
{ get_depth(State, MaxDepth) },
{ get_term(State, Univ) },
@@ -346,27 +436,27 @@
( { deref_subterm(Univ, Dir, SubUniv) } ->
{ term_to_string_verbose(SubUniv, MaxSize,
MaxDepth, X, Y, Str) },
- io__write_string(Str)
+ write_string_debugger(Debugger, Str)
;
- io__write_string("error: no such subterm")
+ write_string_debugger(Debugger, "error: no such subterm")
),
- io__nl.
+ nl_debugger(Debugger).
-:- pred portray_pretty(browser_state, io__state, io__state).
-:- mode portray_pretty(in, di, uo) is det.
-portray_pretty(State) -->
+:- pred portray_pretty(debugger, browser_state, io__state, io__state).
+:- mode portray_pretty(in, in, di, uo) is det.
+portray_pretty(Debugger, State) -->
{ get_size(State, MaxSize) },
{ get_depth(State, MaxDepth) },
{ get_term(State, Univ) },
{ get_dirs(State, Dir) },
( { deref_subterm(Univ, Dir, SubUniv) } ->
{ term_to_string_pretty(SubUniv, MaxSize, MaxDepth, Str) },
- io__write_string(Str)
+ write_string_debugger(Debugger, Str)
;
- io__write_string("error: no such subterm")
+ write_string_debugger(Debugger, "error: no such subterm")
),
- io__nl.
+ nl_debugger(Debugger).
%---------------------------------------------------------------------------%
%
@@ -617,43 +707,46 @@
% Miscellaneous path handling
%
-:- pred write_path(list(dir), io__state, io__state).
-:- mode write_path(in, di, uo) is det.
-write_path([]) -->
- io__write_string("/").
-write_path([Dir]) -->
+:- pred write_path(debugger, list(dir), io__state, io__state).
+:- mode write_path(in, in, di, uo) is det.
+write_path(Debugger, []) -->
+ write_string_debugger(Debugger, "/").
+write_path(Debugger, [Dir]) -->
(
{ Dir = parent },
- io__write_string("/")
+ write_string_debugger(Debugger, "/")
;
{ Dir = child(N) },
- io__write_string("/"), io__write_int(N)
+ write_string_debugger(Debugger, "/"),
+ write_int_debugger(Debugger, N)
).
-write_path([Dir, Dir2 | Dirs]) -->
- write_path_2([Dir, Dir2 | Dirs]).
+write_path(Debugger, [Dir, Dir2 | Dirs]) -->
+ write_path_2(Debugger, [Dir, Dir2 | Dirs]).
-:- pred write_path_2(list(dir), io__state, io__state).
-:- mode write_path_2(in, di, uo) is det.
-write_path_2([]) -->
- io__write_string("/").
-write_path_2([Dir]) -->
+:- pred write_path_2(debugger, list(dir), io__state, io__state).
+:- mode write_path_2(in, in, di, uo) is det.
+write_path_2(Debugger, []) -->
+ write_string_debugger(Debugger, "/").
+write_path_2(Debugger, [Dir]) -->
(
{ Dir = parent },
- io__write_string("/..")
+ write_string_debugger(Debugger, "/..")
;
{ Dir = child(N) },
- io__write_string("/"), io__write_int(N)
+ write_string_debugger(Debugger, "/"),
+ write_int_debugger(Debugger, N)
).
-write_path_2([Dir, Dir2 | Dirs]) -->
+write_path_2(Debugger, [Dir, Dir2 | Dirs]) -->
(
{ Dir = parent },
- io__write_string("/.."),
- write_path_2([Dir2 | Dirs])
+ write_string_debugger(Debugger, "/.."),
+ write_path_2(Debugger, [Dir2 | Dirs])
;
{ Dir = child(N) },
- io__write_string("/"), io__write_int(N),
- write_path_2([Dir2 | Dirs])
+ write_string_debugger(Debugger, "/"),
+ write_int_debugger(Debugger, N),
+ write_path_2(Debugger, [Dir2 | Dirs])
).
% We assume a root-relative path. We assume Term is the entire term
@@ -820,20 +913,27 @@
% Display predicates.
%
-:- pred show_settings(browser_state, io__state, io__state).
-:- mode show_settings(in, di, uo) is det.
-show_settings(State) -->
+:- pred show_settings(debugger, browser_state, io__state, io__state).
+:- mode show_settings(in, in, di, uo) is det.
+show_settings(Debugger, State) -->
{ State = browser_state(_Univ, MaxDepth, MaxSize,
CurPath, Fmt, X, Y) },
- io__write_string("Max depth is: "), io__write_int(MaxDepth), io__nl,
- io__write_string("Max size is: "), io__write_int(MaxSize), io__nl,
- io__write_string("X clip is: "), io__write_int(X), io__nl,
- io__write_string("Y clip is: "), io__write_int(Y), io__nl,
- io__write_string("Current path is: "),
- write_path(CurPath), io__nl,
- io__write_string("Print format is "),
- io__print(Fmt),
- io__nl.
+ write_string_debugger(Debugger, "Max depth is: "),
+ write_int_debugger(Debugger, MaxDepth),
+ nl_debugger(Debugger),
+ write_string_debugger(Debugger, "Max size is: "),
+ write_int_debugger(Debugger, MaxSize),
+ nl_debugger(Debugger),
+ write_string_debugger(Debugger, "X clip is: "),
+ write_int_debugger(Debugger, X),
+ nl_debugger(Debugger),
+ write_string_debugger(Debugger, "Y clip is: "),
+ write_int_debugger(Debugger, Y), nl_debugger(Debugger),
+ write_string_debugger(Debugger, "Current path is: "),
+ write_path(Debugger, CurPath), nl_debugger(Debugger),
+ write_string_debugger(Debugger, "Print format is "),
+ print_format_debugger(Debugger, Fmt),
+ nl_debugger(Debugger).
:- pred string_to_path(string, path).
:- mode string_to_path(in, out) is semidet.
@@ -919,5 +1019,59 @@
simplify([child(_Dir), parent | Dirs], Dirs).
simplify([child(Dir1), child(Dir2) | Dirs], [child(Dir1) | Rest]) :-
simplify([child(Dir2) | Dirs], Rest).
+
+%---------------------------------------------------------------------------%
+
+:- pred write_string_debugger(debugger, string, io__state, io__state).
+:- mode write_string_debugger(in, in, di, uo) is det.
+write_string_debugger(Debugger, String) -->
+ ( { Debugger = internal } ->
+ io__write_string(String)
+ ;
+ send_term_to_socket(browser_str(String))
+ ).
+
+:- pred nl_debugger(debugger, io__state, io__state).
+:- mode nl_debugger(in, di, uo) is det.
+nl_debugger(Debugger) -->
+ ( { Debugger = internal } ->
+ io__nl
+ ;
+ send_term_to_socket(browser_nl)
+ ).
+
+:- pred write_int_debugger(debugger, int, io__state, io__state).
+:- mode write_int_debugger(in, in, di, uo) is det.
+write_int_debugger(Debugger, Int) -->
+ ( { Debugger = internal } ->
+ io__write_int(Int)
+ ;
+ send_term_to_socket(browser_int(Int))
+ ).
+
+
+:- pred print_format_debugger(debugger, portray_format, io__state, io__state).
+:- mode print_format_debugger(in, in, di, uo) is det.
+print_format_debugger(internal, X) -->
+ io__print(X).
+print_format_debugger(external, X) -->
+ (
+ { X = flat },
+ send_term_to_socket(browser_str("flat"))
+ ;
+ { X = pretty },
+ send_term_to_socket(browser_str("pretty"))
+ ;
+ { X = verbose },
+ send_term_to_socket(browser_str("verbose"))
+ ).
+
+:- pred send_term_to_socket(term_browser_response, io__state, io__state).
+:- mode send_term_to_socket(in, di, uo) is det.
+send_term_to_socket(Term) -->
+ write(Term),
+ print(".\n"),
+ flush_output.
%---------------------------------------------------------------------------%
--
R1.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list