1996-11-29 08:55:09 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml *)
|
|
|
|
(* *)
|
|
|
|
(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* Objective Caml port by John Malecki and Xavier Leroy *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1996-11-29 08:55:09 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
(* Low-level communication with the debuggee *)
|
|
|
|
|
2002-10-29 09:53:24 -08:00
|
|
|
open Int64ops
|
1996-11-29 08:55:09 -08:00
|
|
|
open Primitives
|
|
|
|
|
|
|
|
(* The current connection with the debuggee *)
|
|
|
|
|
|
|
|
let conn = ref Primitives.std_io
|
|
|
|
|
|
|
|
let set_current_connection io_chan =
|
|
|
|
conn := io_chan
|
|
|
|
|
|
|
|
(* Modify the program code *)
|
|
|
|
|
|
|
|
let set_event pos =
|
|
|
|
output_char !conn.io_out 'e';
|
1997-03-22 12:16:52 -08:00
|
|
|
output_binary_int !conn.io_out pos
|
1996-11-29 08:55:09 -08:00
|
|
|
|
|
|
|
let set_breakpoint pos =
|
|
|
|
output_char !conn.io_out 'B';
|
1997-03-22 12:16:52 -08:00
|
|
|
output_binary_int !conn.io_out pos
|
1996-11-29 08:55:09 -08:00
|
|
|
|
|
|
|
let reset_instr pos =
|
|
|
|
output_char !conn.io_out 'i';
|
1997-03-22 12:16:52 -08:00
|
|
|
output_binary_int !conn.io_out pos
|
1996-11-29 08:55:09 -08:00
|
|
|
|
|
|
|
(* Basic commands for flow control *)
|
|
|
|
|
|
|
|
type execution_summary =
|
|
|
|
Event
|
|
|
|
| Breakpoint
|
|
|
|
| Exited
|
|
|
|
| Trap_barrier
|
|
|
|
| Uncaught_exc
|
|
|
|
|
|
|
|
type report = {
|
|
|
|
rep_type : execution_summary;
|
|
|
|
rep_event_count : int;
|
|
|
|
rep_stack_pointer : int;
|
|
|
|
rep_program_pointer : int
|
|
|
|
}
|
|
|
|
|
|
|
|
type checkpoint_report =
|
|
|
|
Checkpoint_done of int
|
|
|
|
| Checkpoint_failed
|
|
|
|
|
|
|
|
(* Run the debuggee for N events *)
|
|
|
|
|
2002-10-29 09:53:24 -08:00
|
|
|
let do_go_smallint n =
|
1996-11-29 08:55:09 -08:00
|
|
|
output_char !conn.io_out 'g';
|
|
|
|
output_binary_int !conn.io_out n;
|
|
|
|
flush !conn.io_out;
|
1997-03-22 12:16:52 -08:00
|
|
|
Input_handling.execute_with_other_controller
|
|
|
|
Input_handling.exit_main_loop
|
|
|
|
!conn
|
|
|
|
(function () ->
|
|
|
|
Input_handling.main_loop ();
|
|
|
|
let summary =
|
|
|
|
match input_char !conn.io_in with
|
|
|
|
'e' -> Event
|
|
|
|
| 'b' -> Breakpoint
|
|
|
|
| 'x' -> Exited
|
|
|
|
| 's' -> Trap_barrier
|
|
|
|
| 'u' -> Uncaught_exc
|
|
|
|
| _ -> Misc.fatal_error "Debugcom.do_go" in
|
|
|
|
let event_counter = input_binary_int !conn.io_in in
|
|
|
|
let stack_pos = input_binary_int !conn.io_in in
|
|
|
|
let pc = input_binary_int !conn.io_in in
|
|
|
|
{ rep_type = summary;
|
|
|
|
rep_event_count = event_counter;
|
|
|
|
rep_stack_pointer = stack_pos;
|
|
|
|
rep_program_pointer = pc })
|
1996-11-29 08:55:09 -08:00
|
|
|
|
2002-10-29 09:53:24 -08:00
|
|
|
let rec do_go n =
|
|
|
|
assert (n >= _0);
|
|
|
|
if n > max_small_int then(
|
|
|
|
ignore (do_go_smallint max_int);
|
|
|
|
do_go (n -- max_small_int)
|
|
|
|
)else(
|
|
|
|
do_go_smallint (Int64.to_int n)
|
|
|
|
)
|
|
|
|
;;
|
|
|
|
|
1996-11-29 08:55:09 -08:00
|
|
|
(* Perform a checkpoint *)
|
|
|
|
|
|
|
|
let do_checkpoint () =
|
|
|
|
output_char !conn.io_out 'c';
|
|
|
|
flush !conn.io_out;
|
|
|
|
let pid = input_binary_int !conn.io_in in
|
|
|
|
if pid = -1 then Checkpoint_failed else Checkpoint_done pid
|
|
|
|
|
|
|
|
(* Kill the given process. *)
|
|
|
|
let stop chan =
|
|
|
|
try
|
1997-03-22 12:16:52 -08:00
|
|
|
output_char chan.io_out 's';
|
|
|
|
flush chan.io_out
|
1996-11-29 08:55:09 -08:00
|
|
|
with
|
1997-03-22 12:16:52 -08:00
|
|
|
Sys_error _ | End_of_file -> ()
|
1996-11-29 08:55:09 -08:00
|
|
|
|
|
|
|
(* Ask a process to wait for its child which has been killed. *)
|
|
|
|
(* (so as to eliminate zombies). *)
|
|
|
|
let wait_child chan =
|
|
|
|
try
|
1997-03-22 12:16:52 -08:00
|
|
|
output_char chan.io_out 'w'
|
1996-11-29 08:55:09 -08:00
|
|
|
with
|
1997-03-22 12:16:52 -08:00
|
|
|
Sys_error _ | End_of_file -> ()
|
1996-11-29 08:55:09 -08:00
|
|
|
|
|
|
|
(* Move to initial frame (that of current function). *)
|
|
|
|
(* Return stack position and current pc *)
|
|
|
|
|
|
|
|
let initial_frame () =
|
|
|
|
output_char !conn.io_out '0';
|
|
|
|
flush !conn.io_out;
|
|
|
|
let stack_pos = input_binary_int !conn.io_in in
|
|
|
|
let pc = input_binary_int !conn.io_in in
|
|
|
|
(stack_pos, pc)
|
|
|
|
|
1998-12-02 02:39:54 -08:00
|
|
|
let set_initial_frame () =
|
1999-02-24 07:21:50 -08:00
|
|
|
ignore(initial_frame ())
|
1998-12-02 02:39:54 -08:00
|
|
|
|
1996-11-29 08:55:09 -08:00
|
|
|
(* Move up one frame *)
|
|
|
|
(* Return stack position and current pc.
|
|
|
|
If there's no frame above, return (-1, 0). *)
|
|
|
|
|
|
|
|
let up_frame stacksize =
|
|
|
|
output_char !conn.io_out 'U';
|
|
|
|
output_binary_int !conn.io_out stacksize;
|
|
|
|
flush !conn.io_out;
|
|
|
|
let stack_pos = input_binary_int !conn.io_in in
|
|
|
|
let pc = if stack_pos = -1 then 0 else input_binary_int !conn.io_in in
|
|
|
|
(stack_pos, pc)
|
|
|
|
|
|
|
|
(* Get and set the current frame position *)
|
|
|
|
|
|
|
|
let get_frame () =
|
|
|
|
output_char !conn.io_out 'f';
|
|
|
|
flush !conn.io_out;
|
|
|
|
let stack_pos = input_binary_int !conn.io_in in
|
|
|
|
let pc = input_binary_int !conn.io_in in
|
|
|
|
(stack_pos, pc)
|
|
|
|
|
|
|
|
let set_frame stack_pos =
|
|
|
|
output_char !conn.io_out 'S';
|
1997-03-22 12:16:52 -08:00
|
|
|
output_binary_int !conn.io_out stack_pos
|
1996-11-29 08:55:09 -08:00
|
|
|
|
|
|
|
(* Set the trap barrier to given stack position. *)
|
|
|
|
|
|
|
|
let set_trap_barrier pos =
|
|
|
|
output_char !conn.io_out 'b';
|
1997-03-22 12:16:52 -08:00
|
|
|
output_binary_int !conn.io_out pos
|
1996-11-29 08:55:09 -08:00
|
|
|
|
|
|
|
(* Handling of remote values *)
|
|
|
|
|
|
|
|
let value_size = if 1 lsl 31 = 0 then 4 else 8
|
|
|
|
|
|
|
|
let input_remote_value ic =
|
|
|
|
let v = String.create value_size in
|
|
|
|
really_input ic v 0 value_size; v
|
|
|
|
|
|
|
|
let output_remote_value ic v =
|
|
|
|
output ic v 0 value_size
|
|
|
|
|
1997-02-14 08:30:00 -08:00
|
|
|
exception Marshalling_error
|
|
|
|
|
1997-03-22 12:16:52 -08:00
|
|
|
module Remote_value =
|
|
|
|
struct
|
1999-05-15 08:09:12 -07:00
|
|
|
type t = Remote of string | Local of Obj.t
|
1997-03-22 12:16:52 -08:00
|
|
|
|
1999-05-15 08:09:12 -07:00
|
|
|
let obj = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| Local obj -> Obj.obj obj
|
1999-05-15 08:09:12 -07:00
|
|
|
| Remote v ->
|
|
|
|
output_char !conn.io_out 'M';
|
|
|
|
output_remote_value !conn.io_out v;
|
|
|
|
flush !conn.io_out;
|
|
|
|
try
|
|
|
|
input_value !conn.io_in
|
|
|
|
with End_of_file | Failure _ ->
|
|
|
|
raise Marshalling_error
|
|
|
|
|
|
|
|
let is_block = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| Local obj -> Obj.is_block obj
|
1999-05-15 08:09:12 -07:00
|
|
|
| Remote v -> Obj.is_block (Array.unsafe_get (Obj.magic v : Obj.t array) 0)
|
|
|
|
|
|
|
|
let tag = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| Local obj -> Obj.tag obj
|
1999-05-15 08:09:12 -07:00
|
|
|
| Remote v ->
|
|
|
|
output_char !conn.io_out 'H';
|
|
|
|
output_remote_value !conn.io_out v;
|
|
|
|
flush !conn.io_out;
|
|
|
|
let header = input_binary_int !conn.io_in in
|
|
|
|
header land 0xFF
|
|
|
|
|
|
|
|
let size = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| Local obj -> Obj.size obj
|
1999-05-15 08:09:12 -07:00
|
|
|
| Remote v ->
|
|
|
|
output_char !conn.io_out 'H';
|
|
|
|
output_remote_value !conn.io_out v;
|
|
|
|
flush !conn.io_out;
|
|
|
|
let header = input_binary_int !conn.io_in in
|
2002-01-04 06:35:53 -08:00
|
|
|
if header land 0xFF = Obj.double_array_tag && Sys.word_size = 32
|
|
|
|
then header lsr 11
|
|
|
|
else header lsr 10
|
1997-03-22 12:16:52 -08:00
|
|
|
|
|
|
|
let field v n =
|
1999-05-15 08:09:12 -07:00
|
|
|
match v with
|
2000-03-06 14:12:09 -08:00
|
|
|
| Local obj -> Local(Obj.field obj n)
|
1999-05-15 08:09:12 -07:00
|
|
|
| Remote v ->
|
|
|
|
output_char !conn.io_out 'F';
|
|
|
|
output_remote_value !conn.io_out v;
|
|
|
|
output_binary_int !conn.io_out n;
|
|
|
|
flush !conn.io_out;
|
|
|
|
if input_byte !conn.io_in = 0 then
|
|
|
|
Remote(input_remote_value !conn.io_in)
|
|
|
|
else begin
|
|
|
|
let buf = String.create 8 in
|
|
|
|
really_input !conn.io_in buf 0 8;
|
|
|
|
let floatbuf = float n (* force allocation of a new float *) in
|
|
|
|
String.unsafe_blit buf 0 (Obj.magic floatbuf) 0 8;
|
|
|
|
Local(Obj.repr floatbuf)
|
|
|
|
end
|
1997-03-22 12:16:52 -08:00
|
|
|
|
|
|
|
let of_int n =
|
1999-05-15 08:09:12 -07:00
|
|
|
Local(Obj.repr n)
|
1997-03-22 12:16:52 -08:00
|
|
|
|
|
|
|
let local pos =
|
|
|
|
output_char !conn.io_out 'L';
|
|
|
|
output_binary_int !conn.io_out pos;
|
|
|
|
flush !conn.io_out;
|
1999-05-15 08:09:12 -07:00
|
|
|
Remote(input_remote_value !conn.io_in)
|
1997-03-22 12:16:52 -08:00
|
|
|
|
|
|
|
let from_environment pos =
|
|
|
|
output_char !conn.io_out 'E';
|
|
|
|
output_binary_int !conn.io_out pos;
|
|
|
|
flush !conn.io_out;
|
1999-05-15 08:09:12 -07:00
|
|
|
Remote(input_remote_value !conn.io_in)
|
1997-03-22 12:16:52 -08:00
|
|
|
|
|
|
|
let global pos =
|
|
|
|
output_char !conn.io_out 'G';
|
|
|
|
output_binary_int !conn.io_out pos;
|
|
|
|
flush !conn.io_out;
|
1999-05-15 08:09:12 -07:00
|
|
|
Remote(input_remote_value !conn.io_in)
|
1997-03-22 12:16:52 -08:00
|
|
|
|
|
|
|
let accu () =
|
|
|
|
output_char !conn.io_out 'A';
|
|
|
|
flush !conn.io_out;
|
1999-05-15 08:09:12 -07:00
|
|
|
Remote(input_remote_value !conn.io_in)
|
|
|
|
|
|
|
|
let closure_code = function
|
2000-03-06 14:12:09 -08:00
|
|
|
| Local obj -> assert false
|
1999-05-15 08:09:12 -07:00
|
|
|
| Remote v ->
|
|
|
|
output_char !conn.io_out 'C';
|
|
|
|
output_remote_value !conn.io_out v;
|
|
|
|
flush !conn.io_out;
|
|
|
|
input_binary_int !conn.io_in
|
1997-03-22 12:16:52 -08:00
|
|
|
|
2000-03-26 04:11:10 -08:00
|
|
|
let same rv1 rv2 =
|
|
|
|
match (rv1, rv2) with
|
|
|
|
(Local obj1, Local obj2) -> obj1 == obj2
|
|
|
|
| (Remote v1, Remote v2) -> v1 = v2
|
|
|
|
(* string equality -> equality of remote pointers *)
|
|
|
|
| (_, _) -> false
|
|
|
|
|
1997-03-22 12:16:52 -08:00
|
|
|
end
|