ia64/xen-unstable

changeset 5827:9697bc63d403

pdb: read/write registers for process target
author ach61@arcadians.cl.cam.ac.uk
date Sun Jul 17 14:16:21 2005 +0000 (2005-07-17)
parents 722c372fe201
children 43564304cf94
files .hgignore tools/debugger/pdb/PDB.ml tools/debugger/pdb/Process.ml tools/debugger/pdb/Process.mli tools/debugger/pdb/Util.ml tools/debugger/pdb/Xen_domain.ml tools/debugger/pdb/Xen_domain.mli tools/debugger/pdb/debugger.ml tools/debugger/pdb/linux-2.6-module/Makefile tools/debugger/pdb/linux-2.6-module/debug.c tools/debugger/pdb/linux-2.6-module/module.c tools/debugger/pdb/linux-2.6-module/pdb_module.h tools/debugger/pdb/pdb_caml_process.c tools/debugger/pdb/pdb_caml_xen.h tools/debugger/pdb/server.ml
line diff
     1.1 --- a/.hgignore	Sat Jul 16 16:45:24 2005 +0000
     1.2 +++ b/.hgignore	Sun Jul 17 14:16:21 2005 +0000
     1.3 @@ -87,6 +87,11 @@
     1.4  ^tools/cmdline/.*$
     1.5  ^tools/cmdline/xen/.*$
     1.6  ^tools/debugger/pdb/pdb$
     1.7 +^tools/debugger/pdb/linux-[0-9.]*-module/.*\.ko$
     1.8 +^tools/debugger/pdb/linux-[0-9.]*-module/.*\.mod.c$
     1.9 +^tools/debugger/pdb/linux-[0-9.]*-module/\..*\.cmd$
    1.10 +^tools/debugger/pdb/linux-[0-9.]*-module/.tmp_versions/.*$
    1.11 +^tools/debugger/pdb/._bcdi/.*$
    1.12  ^tools/firmware/acpi/acpigen$
    1.13  ^tools/firmware/.*\.bin$
    1.14  ^tools/firmware/.*\.sym$
     2.1 --- a/tools/debugger/pdb/PDB.ml	Sat Jul 16 16:45:24 2005 +0000
     2.2 +++ b/tools/debugger/pdb/PDB.ml	Sun Jul 17 14:16:21 2005 +0000
     2.3 @@ -7,9 +7,12 @@
     2.4   *  @version 1
     2.5   *)
     2.6  
     2.7 +open Util
     2.8 +
     2.9  exception Unimplemented of string
    2.10  exception Unknown_context of string
    2.11  exception Unknown_domain
    2.12 +exception Unknown_process
    2.13  
    2.14  type context_t =
    2.15    | Void
    2.16 @@ -45,6 +48,31 @@ let find_context key =
    2.17  let delete_context key =
    2.18    Hashtbl.remove hash key
    2.19  
    2.20 +
    2.21 +(**
    2.22 +   find_process : Locate the socket associated with the context(s)
    2.23 +   matching a particular (domain, process id) pair.  if there are multiple
    2.24 +   contexts (there shouldn't be), then return the first one.
    2.25 + *)
    2.26 +
    2.27 +let find_process dom pid =
    2.28 +    let find key ctx list =
    2.29 +      match ctx with
    2.30 +      |	Process p ->
    2.31 +	  if (((Process.get_domain p) = dom) &&
    2.32 +	      ((Process.get_process p) = pid))
    2.33 +	  then
    2.34 +	    key :: list
    2.35 +	  else
    2.36 +	    list
    2.37 +      | _ -> list
    2.38 +    in
    2.39 +    let sock_list = Hashtbl.fold find hash [] in
    2.40 +    match sock_list with
    2.41 +    | hd::tl -> hd
    2.42 +    | [] -> raise Unknown_process
    2.43 +
    2.44 +
    2.45  (**
    2.46     find_domain : Locate the socket associated with the context(s)
    2.47     matching a particular (domain, vcpu) pair.  if there are multiple
    2.48 @@ -98,10 +126,13 @@ let attach_debugger ctx =
    2.49        begin
    2.50  	let xdom_sock = find_xen_domain_context (Process.get_domain p) in
    2.51  	let xdom_ctx = find_context xdom_sock in
    2.52 -	match xdom_ctx with
    2.53 -	  | Xen_domain d ->
    2.54 -	      Process.attach_debugger p d
    2.55 -	  | _ -> failwith ("context has wrong xen domain type")
    2.56 +	begin
    2.57 +	  match xdom_ctx with
    2.58 +	    | Xen_domain d ->
    2.59 +		Process.attach_debugger p d
    2.60 +	    | _ -> failwith ("context has wrong xen domain type")
    2.61 +	end;
    2.62 +	raise No_reply
    2.63        end
    2.64    | _ -> raise (Unimplemented "attach debugger")
    2.65  
    2.66 @@ -158,8 +189,8 @@ let add_context (key:Unix.file_descr) co
    2.67  	match params with
    2.68  	| dom::pid::_ ->
    2.69  	    let p = Process(Process.new_context dom pid) in
    2.70 -	    attach_debugger p;
    2.71 -	    Hashtbl.replace hash key p
    2.72 +	    Hashtbl.replace hash key p;
    2.73 +	    attach_debugger p
    2.74  	| _ -> failwith "bogus parameters to process context"
    2.75        end
    2.76    | "xen domain"
    2.77 @@ -188,13 +219,21 @@ let read_registers ctx =
    2.78    match ctx with
    2.79    | Void -> Intel.null_registers                    (* default for startup *)
    2.80    | Domain d  -> Domain.read_registers d 
    2.81 -  | Process p -> Process.read_registers p
    2.82 +  | Process p ->
    2.83 +      begin
    2.84 +	Process.read_registers p;
    2.85 +	raise No_reply
    2.86 +      end
    2.87    | _ -> raise (Unimplemented "read registers")
    2.88  
    2.89  let write_register ctx register value =
    2.90    match ctx with
    2.91    | Domain d  -> Domain.write_register d register value
    2.92 -  | Process p -> Process.write_register p register value
    2.93 +  | Process p ->
    2.94 +      begin
    2.95 +	Process.write_register p register value;
    2.96 +	raise No_reply
    2.97 +      end
    2.98    | _ -> raise (Unimplemented "write register")
    2.99  
   2.100  
     3.1 --- a/tools/debugger/pdb/Process.ml	Sat Jul 16 16:45:24 2005 +0000
     3.2 +++ b/tools/debugger/pdb/Process.ml	Sun Jul 17 14:16:21 2005 +0000
     3.3 @@ -54,7 +54,7 @@ let attach_debugger proc_ctx dom_ctx =
     3.4    proc_ctx.ring   <- Xen_domain.get_ring   dom_ctx;
     3.5    _attach_debugger proc_ctx
     3.6  
     3.7 -external read_registers : context_t -> registers = "proc_read_registers"
     3.8 +external read_registers : context_t -> unit = "proc_read_registers"
     3.9  external write_register : context_t -> register -> int32 -> unit =
    3.10    "proc_write_register"
    3.11  external read_memory : context_t -> int32 -> int -> int list = 
     4.1 --- a/tools/debugger/pdb/Process.mli	Sat Jul 16 16:45:24 2005 +0000
     4.2 +++ b/tools/debugger/pdb/Process.mli	Sun Jul 17 14:16:21 2005 +0000
     4.3 @@ -27,7 +27,7 @@ val detach_debugger : context_t -> unit
     4.4  val pause : context_t -> unit
     4.5  
     4.6  
     4.7 -val read_registers : context_t -> registers
     4.8 +val read_registers : context_t -> unit
     4.9  val write_register : context_t -> register -> int32 -> unit
    4.10  val read_memory : context_t -> int32 -> int -> int list
    4.11  val write_memory : context_t -> int32 -> int list -> unit
     5.1 --- a/tools/debugger/pdb/Util.ml	Sat Jul 16 16:45:24 2005 +0000
     5.2 +++ b/tools/debugger/pdb/Util.ml	Sun Jul 17 14:16:21 2005 +0000
     5.3 @@ -154,3 +154,12 @@ let send_reply fd reply =
     5.4     * BUG NEED TO LISTEN FOR REPLY +/- AND POSSIBLY RE-TRANSMIT
     5.5     *)
     5.6  
     5.7 +
     5.8 +(** A few debugger commands such as step 's' and continue 'c' do 
     5.9 + *  not immediately return a response to the debugger.  In these 
    5.10 + *  cases we raise No_reply instead. 
    5.11 + *  This is also used by some contexts (such as Linux processes)
    5.12 + *  which utilize an asynchronous request / response protocol when
    5.13 + *  communicating with their respective backends.
    5.14 + *)
    5.15 +exception No_reply
     6.1 --- a/tools/debugger/pdb/Xen_domain.ml	Sat Jul 16 16:45:24 2005 +0000
     6.2 +++ b/tools/debugger/pdb/Xen_domain.ml	Sun Jul 17 14:16:21 2005 +0000
     6.3 @@ -40,4 +40,4 @@ let get_ring ctx =
     6.4  let string_of_context ctx =
     6.5        Printf.sprintf "{xen domain assist} domain: %d" ctx.domain 
     6.6  
     6.7 -external process_response : int32 -> unit = "process_handle_response"
     6.8 +external process_response : int32 -> int * int * string = "process_handle_response"
     7.1 --- a/tools/debugger/pdb/Xen_domain.mli	Sat Jul 16 16:45:24 2005 +0000
     7.2 +++ b/tools/debugger/pdb/Xen_domain.mli	Sun Jul 17 14:16:21 2005 +0000
     7.3 @@ -21,5 +21,5 @@ val get_ring   : context_t -> int32
     7.4  
     7.5  val string_of_context : context_t -> string
     7.6  
     7.7 -val process_response : int32 -> unit
     7.8 +val process_response : int32 -> int * int * string
     7.9  
     8.1 --- a/tools/debugger/pdb/debugger.ml	Sat Jul 16 16:45:24 2005 +0000
     8.2 +++ b/tools/debugger/pdb/debugger.ml	Sun Jul 17 14:16:21 2005 +0000
     8.3 @@ -12,12 +12,6 @@ open PDB
     8.4  open Util
     8.5  open Str
     8.6  
     8.7 -(** a few debugger commands such as step 's' and continue 'c' do 
     8.8 - *  not immediately return a response to the debugger.  in these 
     8.9 - *  cases we raise No_reply instead. 
    8.10 - *)
    8.11 -exception No_reply
    8.12 -
    8.13  let initialize_debugger () =
    8.14    ()
    8.15  
    8.16 @@ -295,12 +289,17 @@ let process_xen_domain fd =
    8.17    let channel = Evtchn.read fd in
    8.18    let ctx = find_context fd in
    8.19    
    8.20 +  let (dom, pid, str) =
    8.21    begin
    8.22      match ctx with
    8.23        | Xen_domain d -> Xen_domain.process_response (Xen_domain.get_ring d)
    8.24        | _ -> failwith ("process_xen_domain called without Xen_domain context")
    8.25 -  end;
    8.26 -    
    8.27 +  end 
    8.28 +  in
    8.29 +  let sock = PDB.find_process dom pid in
    8.30 +  print_endline (Printf.sprintf "(linux) dom:%d pid:%d  %s  %s" 
    8.31 +		   dom pid str (Util.get_connection_info sock));
    8.32 +  Util.send_reply sock str;
    8.33    Evtchn.unmask fd channel                                (* allow next virq *)
    8.34    
    8.35  
     9.1 --- a/tools/debugger/pdb/linux-2.6-module/Makefile	Sat Jul 16 16:45:24 2005 +0000
     9.2 +++ b/tools/debugger/pdb/linux-2.6-module/Makefile	Sun Jul 17 14:16:21 2005 +0000
     9.3 @@ -1,4 +1,4 @@
     9.4 -XEN_ROOT=../../../..
     9.5 +XEN_ROOT   = ../../../..
     9.6  LINUX_DIR  = linux-2.6.12-xenU
     9.7  KDIR       = $(XEN_ROOT)/$(LINUX_DIR)
     9.8  
    10.1 --- a/tools/debugger/pdb/linux-2.6-module/debug.c	Sat Jul 16 16:45:24 2005 +0000
    10.2 +++ b/tools/debugger/pdb/linux-2.6-module/debug.c	Sun Jul 17 14:16:21 2005 +0000
    10.3 @@ -55,15 +55,47 @@ pdb_detach (int pid)
    10.4  /*
    10.5   * from linux-2.6.11/arch/i386/kernel/ptrace.c::getreg()
    10.6   */
    10.7 +
    10.8 +static unsigned long
    10.9 +_pdb_get_register (struct task_struct *target, int reg)
   10.10 +{
   10.11 +    unsigned long result = ~0UL;
   10.12 +    unsigned long offset;
   10.13 +    unsigned char *stack = 0L;
   10.14 +
   10.15 +    switch (reg)
   10.16 +    {
   10.17 +    case FS:
   10.18 +        result = target->thread.fs;
   10.19 +        break;
   10.20 +    case GS:
   10.21 +        result = target->thread.gs;
   10.22 +        break;
   10.23 +    case DS:
   10.24 +    case ES:
   10.25 +    case SS:
   10.26 +    case CS:
   10.27 +        result = 0xffff;
   10.28 +        /* fall through */
   10.29 +    default:
   10.30 +        if (reg > GS)
   10.31 +            reg -= 2;
   10.32 +
   10.33 +        offset = reg * sizeof(long);
   10.34 +        offset -= sizeof(struct pt_regs);
   10.35 +        stack = (unsigned char *)target->thread.esp0;
   10.36 +        stack += offset;
   10.37 +        result &= *((int *)stack);
   10.38 +    }
   10.39 +
   10.40 +    return result;
   10.41 +}
   10.42 +
   10.43  int
   10.44 -pdb_read_register (int pid, pdb_op_rd_reg_p op, unsigned long *dest)
   10.45 +pdb_read_register (int pid, pdb_op_rd_regs_p op)
   10.46  {
   10.47      int rc = 0;
   10.48      struct task_struct *target;
   10.49 -    unsigned long offset;
   10.50 -    unsigned char *stack = 0L;
   10.51 -
   10.52 -    *dest = ~0UL;
   10.53  
   10.54      read_lock(&tasklist_lock);
   10.55      target = find_task_by_pid(pid);
   10.56 @@ -71,35 +103,23 @@ pdb_read_register (int pid, pdb_op_rd_re
   10.57          get_task_struct(target);
   10.58      read_unlock(&tasklist_lock);
   10.59  
   10.60 -    switch (op->reg)
   10.61 -    {
   10.62 -    case FS:
   10.63 -        *dest = target->thread.fs;
   10.64 -        break;
   10.65 -    case GS:
   10.66 -        *dest = target->thread.gs;
   10.67 -        break;
   10.68 -    case DS:
   10.69 -    case ES:
   10.70 -    case SS:
   10.71 -    case CS:
   10.72 -        *dest = 0xffff;
   10.73 -        /* fall through */
   10.74 -    default:
   10.75 -        if (op->reg > GS)
   10.76 -            op->reg -= 2;
   10.77 +    op->reg[ 0] = _pdb_get_register(target, LINUX_EAX);
   10.78 +    op->reg[ 1] = _pdb_get_register(target, LINUX_ECX);
   10.79 +    op->reg[ 2] = _pdb_get_register(target, LINUX_EDX);
   10.80 +    op->reg[ 3] = _pdb_get_register(target, LINUX_EBX);
   10.81 +    op->reg[ 4] = _pdb_get_register(target, LINUX_ESP);
   10.82 +    op->reg[ 5] = _pdb_get_register(target, LINUX_EBP);
   10.83 +    op->reg[ 6] = _pdb_get_register(target, LINUX_ESI);
   10.84 +    op->reg[ 7] = _pdb_get_register(target, LINUX_EDI);
   10.85 +    op->reg[ 8] = _pdb_get_register(target, LINUX_EIP);
   10.86 +    op->reg[ 9] = _pdb_get_register(target, LINUX_EFL);
   10.87  
   10.88 -        offset = op->reg * sizeof(long);
   10.89 -        offset -= sizeof(struct pt_regs);
   10.90 -        stack = (unsigned char *)target->thread.esp0;
   10.91 -        stack += offset;
   10.92 -        *dest &= *((int *)stack);
   10.93 -    }
   10.94 -
   10.95 -    /*
   10.96 -    printk ("pdb read register: 0x%x %2d 0x%p 0x%lx\n", 
   10.97 -            pid, op->reg, stack, *dest);
   10.98 -    */
   10.99 +    op->reg[10] = _pdb_get_register(target, LINUX_CS);
  10.100 +    op->reg[11] = _pdb_get_register(target, LINUX_SS);
  10.101 +    op->reg[12] = _pdb_get_register(target, LINUX_DS);
  10.102 +    op->reg[13] = _pdb_get_register(target, LINUX_ES);
  10.103 +    op->reg[14] = _pdb_get_register(target, LINUX_FS);
  10.104 +    op->reg[15] = _pdb_get_register(target, LINUX_GS);
  10.105  
  10.106      return rc;
  10.107  }
    11.1 --- a/tools/debugger/pdb/linux-2.6-module/module.c	Sat Jul 16 16:45:24 2005 +0000
    11.2 +++ b/tools/debugger/pdb/linux-2.6-module/module.c	Sun Jul 17 14:16:21 2005 +0000
    11.3 @@ -54,6 +54,10 @@ pdb_process_request (pdb_request_t *requ
    11.4  {
    11.5      pdb_response_t resp;
    11.6  
    11.7 +    resp.operation = request->operation;
    11.8 +    resp.domain    = request->domain;
    11.9 +    resp.process   = request->process;
   11.10 +
   11.11      switch (request->operation)
   11.12      {
   11.13      case PDB_OPCODE_ATTACH :
   11.14 @@ -64,9 +68,8 @@ pdb_process_request (pdb_request_t *requ
   11.15          pdb_detach(request->process);
   11.16          resp.status = PDB_RESPONSE_OKAY;
   11.17          break;
   11.18 -    case PDB_OPCODE_RD_REG :
   11.19 -        pdb_read_register(request->process, &request->u.rd_reg, 
   11.20 -                          (unsigned long *)&resp.value);
   11.21 +    case PDB_OPCODE_RD_REGS :
   11.22 +        pdb_read_register(request->process, &resp.u.rd_regs);
   11.23          resp.status = PDB_RESPONSE_OKAY;
   11.24          break;
   11.25      case PDB_OPCODE_WR_REG :
   11.26 @@ -78,8 +81,6 @@ pdb_process_request (pdb_request_t *requ
   11.27          resp.status = PDB_RESPONSE_ERROR;
   11.28      }
   11.29          
   11.30 -    resp.operation = request->operation;
   11.31 -            
   11.32      pdb_send_response (&resp);
   11.33      return;
   11.34  }
    12.1 --- a/tools/debugger/pdb/linux-2.6-module/pdb_module.h	Sat Jul 16 16:45:24 2005 +0000
    12.2 +++ b/tools/debugger/pdb/linux-2.6-module/pdb_module.h	Sun Jul 17 14:16:21 2005 +0000
    12.3 @@ -2,14 +2,16 @@
    12.4  #ifndef __XEN_PDB_H_
    12.5  #define __XEN_PDB_H_
    12.6  
    12.7 +#include "../pdb_caml_xen.h"
    12.8 +
    12.9  #define PDB_OPCODE_ATTACH 1
   12.10  #define PDB_OPCODE_DETACH 2
   12.11  
   12.12 -#define PDB_OPCODE_RD_REG 3
   12.13 -typedef struct pdb_op_rd_reg
   12.14 +#define PDB_OPCODE_RD_REGS 3
   12.15 +typedef struct pdb_op_rd_regs
   12.16  {
   12.17 -    u32 reg;
   12.18 -} pdb_op_rd_reg_t, *pdb_op_rd_reg_p;
   12.19 +    u32 reg[GDB_REGISTER_FRAME_SIZE];
   12.20 +} pdb_op_rd_regs_t, *pdb_op_rd_regs_p;
   12.21  
   12.22  #define PDB_OPCODE_WR_REG 4
   12.23  typedef struct pdb_op_wr_reg
   12.24 @@ -25,8 +27,7 @@ typedef struct
   12.25      u32  process;
   12.26      union
   12.27      {
   12.28 -        pdb_op_rd_reg_t rd_reg;
   12.29 -        pdb_op_wr_reg_t wr_reg;
   12.30 +        pdb_op_wr_reg_t  wr_reg;
   12.31      } u;
   12.32  } pdb_request_t, *pdb_request_p;
   12.33   
   12.34 @@ -36,8 +37,13 @@ typedef struct
   12.35  
   12.36  typedef struct {
   12.37      u8   operation;       /* copied from request */
   12.38 +    u32  domain;          
   12.39 +    u32  process;
   12.40      s16  status;          /* PDB_RESPONSE_???    */
   12.41 -    u32  value;
   12.42 +    union
   12.43 +    {
   12.44 +        pdb_op_rd_regs_t rd_regs;
   12.45 +    } u;
   12.46  } pdb_response_t, *pdb_response_p;
   12.47  
   12.48  
   12.49 @@ -46,7 +52,7 @@ DEFINE_RING_TYPES(pdb, pdb_request_t, pd
   12.50  
   12.51  int pdb_attach (int pid);
   12.52  int pdb_detach (int pid);
   12.53 -int pdb_read_register (int pid, pdb_op_rd_reg_p op, unsigned long *dest);
   12.54 +int pdb_read_register (int pid, pdb_op_rd_regs_p op);
   12.55  int pdb_write_register (int pid, pdb_op_wr_reg_p op);
   12.56  
   12.57  
    13.1 --- a/tools/debugger/pdb/pdb_caml_process.c	Sat Jul 16 16:45:24 2005 +0000
    13.2 +++ b/tools/debugger/pdb/pdb_caml_process.c	Sun Jul 17 14:16:21 2005 +0000
    13.3 @@ -66,49 +66,89 @@ send_request (pdb_front_ring_t *pdb_ring
    13.4  }
    13.5  
    13.6  /*
    13.7 - * read a response from a pdb domain backend.
    13.8 + * process_handle_response : int32 -> int * int * string
    13.9   *
   13.10 - * grabs the response off a ring.
   13.11 + * A backend domain has notified pdb (via an event channel)
   13.12 + * that a command has finished.
   13.13 + * We read the result from the channel and formulate a response
   13.14 + * as a single string.  Also return the domain and process.
   13.15   */
   13.16 -static void
   13.17 -read_response (pdb_front_ring_t *pdb_ring, pdb_response_p response)
   13.18 -{
   13.19 -    RING_IDX loop, rp;
   13.20 -
   13.21 -    rp = pdb_ring->sring->rsp_prod;
   13.22 -    rmb(); /* Ensure we see queued responses up to 'rp'. */
   13.23  
   13.24 -    for ( loop = pdb_ring->rsp_cons; loop != rp; loop++ )
   13.25 -    {
   13.26 -        pdb_response_p resp;
   13.27 -
   13.28 -        resp = RING_GET_RESPONSE(pdb_ring, loop);
   13.29 -        memcpy(response, resp, sizeof(pdb_response_t));
   13.30 -
   13.31 -        /*        
   13.32 -        printf ("got response %x %x %x\n", response->operation, 
   13.33 -                response->status, response->value);
   13.34 -        */
   13.35 -    }
   13.36 -    pdb_ring->rsp_cons = loop;
   13.37 +static inline unsigned int
   13.38 +_flip (unsigned int orig)
   13.39 +{
   13.40 +    return (((orig << 24) & 0xff000000) | ((orig <<  8) & 0x00ff0000) |
   13.41 +            ((orig >>  8) & 0x0000ff00) | ((orig >> 24) & 0x000000ff));
   13.42  }
   13.43  
   13.44 -/*
   13.45 - * process_handle_response : int32 -> unit
   13.46 - */
   13.47 -
   13.48  value
   13.49  process_handle_response (value ring)
   13.50  {
   13.51      CAMLparam1(ring);
   13.52 -
   13.53 -    pdb_front_ring_t *my_ring = (pdb_front_ring_t *)Int32_val(ring);
   13.54 -    pdb_response_t resp;
   13.55 +    CAMLlocal2(result, str);
   13.56  
   13.57 -    if ( my_ring )
   13.58 -        read_response(my_ring, &resp);
   13.59 +    RING_IDX rp;
   13.60 +    pdb_response_p resp;
   13.61 +    pdb_front_ring_t *my_ring = (pdb_front_ring_t *)Int32_val(ring);
   13.62 +    char msg[2048];
   13.63 +    int msglen;
   13.64  
   13.65 -    CAMLreturn(Val_unit);
   13.66 +    memset(msg, 0, sizeof(msg));
   13.67 +
   13.68 +    rp = my_ring->sring->rsp_prod;
   13.69 +    rmb(); /* Ensure we see queued responses up to 'rp'. */
   13.70 +
   13.71 +    sprintf(msg, "OK");
   13.72 +
   13.73 +    /* for ( loop = my_ring->rsp_cons; loop != rp; loop++ ) */
   13.74 +    if (my_ring->rsp_cons != rp)
   13.75 +    {
   13.76 +        resp = RING_GET_RESPONSE(my_ring, my_ring->rsp_cons);
   13.77 +
   13.78 +        switch (resp->operation)
   13.79 +        {
   13.80 +        case PDB_OPCODE_ATTACH :
   13.81 +        case PDB_OPCODE_DETACH :
   13.82 +            break;
   13.83 +            
   13.84 +        case PDB_OPCODE_RD_REGS :
   13.85 +        {
   13.86 +            int loop;
   13.87 +            pdb_op_rd_regs_p regs = &resp->u.rd_regs;
   13.88 +            
   13.89 +            for (loop = 0; loop < GDB_REGISTER_FRAME_SIZE * 8; loop += 8)
   13.90 +            {
   13.91 +                sprintf(&msg[loop], "%08x", _flip(regs->reg[loop >> 3]));
   13.92 +            }
   13.93 +                
   13.94 +            break;
   13.95 +        }
   13.96 +
   13.97 +        case PDB_OPCODE_WR_REG :
   13.98 +        {
   13.99 +            printf("(linux) wr regs\n");
  13.100 +            /* should check the return status */
  13.101 +            break;
  13.102 +        }
  13.103 +        default :
  13.104 +            printf("(process) UNKNOWN MESSAGE TYPE IN RESPONSE\n");
  13.105 +            break;
  13.106 +        }
  13.107 +
  13.108 +        my_ring->rsp_cons++;
  13.109 +    }
  13.110 +    /* my_ring->rsp_cons = loop; */
  13.111 +
  13.112 +    msglen = strlen(msg);
  13.113 +    result = caml_alloc(3,0);
  13.114 +    str = alloc_string(msglen);
  13.115 +    memmove(&Byte(str,0), msg, msglen);
  13.116 +
  13.117 +    Store_field(result, 0, Val_int(resp->domain));
  13.118 +    Store_field(result, 1, Val_int(resp->process));
  13.119 +    Store_field(result, 2, str);
  13.120 +
  13.121 +    CAMLreturn(result);
  13.122  }
  13.123  
  13.124  /*
  13.125 @@ -120,28 +160,15 @@ proc_attach_debugger (value context)
  13.126      CAMLparam1(context);
  13.127      context_t ctx;
  13.128      pdb_request_t req;
  13.129 -    pdb_response_t resp;
  13.130  
  13.131      decode_context(&ctx, context);
  13.132  
  13.133 -    printf("(pdb) attach process [%d.%d] %d %p\n", ctx.domain, ctx.process,
  13.134 -           ctx.evtchn, ctx.ring);
  13.135 -    fflush(stdout);
  13.136 -
  13.137      req.operation = PDB_OPCODE_ATTACH;
  13.138      req.domain  = ctx.domain;
  13.139      req.process = ctx.process;
  13.140  
  13.141      send_request (ctx.ring, ctx.evtchn, &req);
  13.142  
  13.143 -    printf("awaiting response\n");
  13.144 -    fflush(stdout);
  13.145 -
  13.146 -    read_response (ctx.ring, &resp);
  13.147 -
  13.148 -    printf("response %d %d\n", resp.operation, resp.status);
  13.149 -    fflush(stdout);
  13.150 -
  13.151      CAMLreturn(Val_unit);
  13.152  }
  13.153  
  13.154 @@ -191,56 +218,25 @@ proc_pause_target (value context)
  13.155  
  13.156  
  13.157  /*
  13.158 - * proc_read_registers : context_t -> int32
  13.159 + * proc_read_registers : context_t -> unit
  13.160   */
  13.161  value
  13.162  proc_read_registers (value context)
  13.163  {
  13.164      CAMLparam1(context);
  13.165 -    CAMLlocal1(result);
  13.166 -
  13.167 -    u32 regs[REGISTER_FRAME_SIZE];
  13.168  
  13.169      pdb_request_t req;
  13.170      context_t ctx;
  13.171 -    int loop;
  13.172  
  13.173      decode_context(&ctx, context);
  13.174  
  13.175 -    req.operation = PDB_OPCODE_RD_REG;
  13.176 +    req.operation = PDB_OPCODE_RD_REGS;
  13.177      req.domain  = ctx.domain;
  13.178      req.process = ctx.process;
  13.179  
  13.180 -    for (loop = 0; loop < REGISTER_FRAME_SIZE; loop++)
  13.181 -    {
  13.182 -        pdb_response_t resp;
  13.183 -
  13.184 -        req.u.rd_reg.reg = loop;
  13.185 -        send_request(ctx.ring, ctx.evtchn, &req);
  13.186 -        read_response(ctx.ring, &resp);
  13.187 -        regs[loop] = resp.value;
  13.188 -    }
  13.189 -
  13.190 -    result = caml_alloc_tuple(16);
  13.191 +    send_request (ctx.ring, ctx.evtchn, &req);
  13.192  
  13.193 -    Store_field(result,  0, caml_copy_int32(regs[LINUX_EAX]));
  13.194 -    Store_field(result,  1, caml_copy_int32(regs[LINUX_ECX]));
  13.195 -    Store_field(result,  2, caml_copy_int32(regs[LINUX_EDX]));
  13.196 -    Store_field(result,  3, caml_copy_int32(regs[LINUX_EBX]));
  13.197 -    Store_field(result,  4, caml_copy_int32(regs[LINUX_ESP]));
  13.198 -    Store_field(result,  5, caml_copy_int32(regs[LINUX_EBP]));
  13.199 -    Store_field(result,  6, caml_copy_int32(regs[LINUX_ESI]));
  13.200 -    Store_field(result,  7, caml_copy_int32(regs[LINUX_EDI]));
  13.201 -    Store_field(result,  8, caml_copy_int32(regs[LINUX_EIP]));
  13.202 -    Store_field(result,  9, caml_copy_int32(regs[LINUX_EFL]));
  13.203 -    Store_field(result, 10, caml_copy_int32(regs[LINUX_CS]));          /* 16 */
  13.204 -    Store_field(result, 11, caml_copy_int32(regs[LINUX_SS]));          /* 16 */
  13.205 -    Store_field(result, 12, caml_copy_int32(regs[LINUX_DS]));          /* 16 */
  13.206 -    Store_field(result, 13, caml_copy_int32(regs[LINUX_ES]));          /* 16 */
  13.207 -    Store_field(result, 14, caml_copy_int32(regs[LINUX_FS]));          /* 16 */
  13.208 -    Store_field(result, 15, caml_copy_int32(regs[LINUX_GS]));          /* 16 */
  13.209 -
  13.210 -    CAMLreturn(result);
  13.211 +    CAMLreturn(Val_unit);
  13.212  }
  13.213  
  13.214  
  13.215 @@ -257,7 +253,6 @@ proc_write_register (value context, valu
  13.216  
  13.217      context_t ctx;
  13.218      pdb_request_t req;
  13.219 -    pdb_response_t resp;
  13.220  
  13.221      decode_context(&ctx, context);
  13.222  
  13.223 @@ -290,7 +285,6 @@ proc_write_register (value context, valu
  13.224      }
  13.225  
  13.226      send_request(ctx.ring, ctx.evtchn, &req);
  13.227 -    read_response(ctx.ring, &resp);
  13.228  
  13.229      CAMLreturn(Val_unit);
  13.230  }
    14.1 --- a/tools/debugger/pdb/pdb_caml_xen.h	Sat Jul 16 16:45:24 2005 +0000
    14.2 +++ b/tools/debugger/pdb/pdb_caml_xen.h	Sun Jul 17 14:16:21 2005 +0000
    14.3 @@ -10,11 +10,12 @@
    14.4  #ifndef _PDB_CAML_XEN_DEFINED_
    14.5  #define _PDB_CAML_XEN_DEFINED_
    14.6  
    14.7 -enum gdb_registers { GDB_EAX, GDB_ECX, GDB_EDX, GDB_EBX,
    14.8 -                     GDB_ESP, GDB_EBP, GDB_ESI, GDB_EDI,
    14.9 -                     GDB_EIP, GDB_EFL, 
   14.10 -                     GDB_CS,  GDB_SS,  GDB_DS,  GDB_ES,
   14.11 -                     GDB_FS,  GDB_GS };
   14.12 +enum gdb_registers { /* 32 */ GDB_EAX, GDB_ECX, GDB_EDX, GDB_EBX,
   14.13 +                              GDB_ESP, GDB_EBP, GDB_ESI, GDB_EDI,
   14.14 +                              GDB_EIP, GDB_EFL, 
   14.15 +                     /* 16 */ GDB_CS,  GDB_SS,  GDB_DS,  GDB_ES,
   14.16 +                              GDB_FS,  GDB_GS };
   14.17 +#define GDB_REGISTER_FRAME_SIZE 16
   14.18  
   14.19  /* this order comes from linux-2.6.11/include/asm-i386/ptrace.h */
   14.20  enum x86_registers { LINUX_EBX, LINUX_ECX, LINUX_EDX, LINUX_ESI, LINUX_EDI,
   14.21 @@ -24,7 +25,11 @@ enum x86_registers { LINUX_EBX, LINUX_EC
   14.22  #define REGISTER_FRAME_SIZE 17
   14.23  
   14.24  
   14.25 +/* hack: this is also included from the pdb linux module which
   14.26 +   has PAGE_SIZE defined */
   14.27 +#ifndef PAGE_SIZE
   14.28  #define PAGE_SIZE 4096
   14.29 +#endif
   14.30  
   14.31  extern int xc_handle;
   14.32  
    15.1 --- a/tools/debugger/pdb/server.ml	Sat Jul 16 16:45:24 2005 +0000
    15.2 +++ b/tools/debugger/pdb/server.ml	Sun Jul 17 14:16:21 2005 +0000
    15.3 @@ -9,7 +9,7 @@
    15.4  
    15.5  open Unix
    15.6  open Buffer
    15.7 -
    15.8 +open Util
    15.9  
   15.10  (**
   15.11   * connection_t: The state for each connection.
   15.12 @@ -98,7 +98,7 @@ let process_input conn sock =
   15.13  			       (String.escaped reply));
   15.14  	      Util.send_reply sock reply
   15.15  	    with
   15.16 -	      Debugger.No_reply ->
   15.17 +	      Util.No_reply ->
   15.18  		print_endline (Printf.sprintf "[%s] %s -> null" 
   15.19  				 (Util.get_connection_info sock)
   15.20  				 (String.escaped command))