1 (***********************************************************************)
5 (* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *)
6 (* Objective Caml port by John Malecki and Xavier Leroy *)
8 (* Copyright 1996 Institut National de Recherche en Informatique et *)
9 (* en Automatique. All rights reserved. This file is distributed *)
10 (* under the terms of the Q Public License version 1.0. *)
12 (***********************************************************************)
25 open Program_management
30 let line_buffer = Lexing.from_function read_user_input
33 line_loop ppf
line_buffer;
34 if !loaded
&& (not
(yes_or_no
"The program is running. Quit anyway")) then
37 let current_duration = ref (-1L)
39 let rec protect ppf restart
loop =
44 protect ppf restart
(function ppf
->
46 !current_checkpoint
.c_fd
47 !current_checkpoint
.c_pid
;
48 pp_print_flush ppf
();
52 protect ppf restart
(function ppf
->
53 pp_print_flush ppf
();
57 protect ppf restart
(function ppf
->
58 fprintf ppf
"Interrupted.@.";
59 Exec.protect (function () ->
63 show_current_event ppf
;
66 | Current_checkpoint_lost
->
67 protect ppf restart
(function ppf
->
68 fprintf ppf
"Trying to recover...@.";
72 show_current_event ppf
;
74 | Current_checkpoint_lost_start_at
(time
, init_duration
) ->
75 protect ppf restart
(function ppf
->
77 if !current_duration = -1L then begin
78 let msg = sprintf
"Restart from time %Ld and try to get closer of the problem" time
in
81 (current_duration := init_duration
; true)
90 current_duration := Int64.div
!current_duration 10L;
91 if !current_duration > 0L then
93 step
!current_duration
96 current_duration := -1L;
98 show_current_event ppf
;
105 show_current_event ppf
;
112 let toplevel_loop () = protect Format.std_formatter
loop loop
114 (* Parsing of command-line arguments *)
116 exception Found_program_name
119 program_name
:= Unix_tools.make_absolute s
; raise Found_program_name
122 Misc.expand_directory
Config.standard_library d
:: !default_load_path
125 let set_checkpoints n
=
126 checkpoint_max_count
:= n
127 let set_directory dir
=
129 let print_version () =
130 printf
"The Objective Caml debugger, version %s@." Sys.ocaml_version
;
135 "-c", Arg.Int
set_checkpoints,
136 "<count> Set max number of checkpoints kept";
137 "-cd", Arg.String
set_directory,
138 "<dir> Change working directory";
139 "-emacs", Arg.Set emacs
,
140 "For running the debugger under emacs";
141 "-I", Arg.String
add_include,
142 "<dir> Add <dir> to the list of include directories";
143 "-s", Arg.String
set_socket,
144 "<filename> Set the name of the communication socket";
145 "-version", Arg.Unit
print_version,
146 " Print version and exit";
151 socket_name
:= Filename.concat
Filename.temp_dir_name
152 ("camldebug" ^
(string_of_int
(Unix.getpid
())));
154 Arg.parse
speclist anonymous "";
156 "No program name specified\n\
157 Usage: ocamldebug [options] <program> [arguments]\n\
160 with Found_program_name
->
161 for j
= !Arg.current
+ 1 to Array.length
Sys.argv
- 1 do
162 arguments
:= !arguments ^
" " ^
(Filename.quote
Sys.argv
.(j
))
165 current_prompt
:= debugger_prompt
;
166 printf
"\tObjective Caml Debugger version %s@.@." Config.version
;
167 Config.load_path
:= !default_load_path
;
168 Clflags.recursive_types
:= true; (* Allow recursive types. *)
169 toplevel_loop (); (* Toplevel. *)
176 eprintf
"Debugger [version %s] environment error:@ @[@;" Config.version
;
177 Env.report_error err_formatter e
;
182 Printexc.catch
(Unix.handle_unix_error
main) ()