ia64/xen-unstable

changeset 2099:89db7ebcd2ef

bitkeeper revision 1.1108.1.46 (4113562eu-sF6gHOCgaXbievSRzwpw)

Merge with Alex.
author sos22@donkeykong.cl.cam.ac.uk
date Fri Aug 06 09:58:06 2004 +0000 (2004-08-06)
parents 7731e79b4f83 41e236de2205
children 777ddc539761
files xen/arch/x86/pdb-linux.c xen/arch/x86/pdb-stub.c xen/include/asm-x86/pdb.h
line diff
     1.1 --- a/xen/arch/x86/pdb-linux.c	Fri Aug 06 09:51:34 2004 +0000
     1.2 +++ b/xen/arch/x86/pdb-linux.c	Fri Aug 06 09:58:06 2004 +0000
     1.3 @@ -99,22 +99,22 @@ pdb_linux_syscall_exit_bkpt (struct pt_r
     1.4  
     1.5      /* set a breakpoint when we exit */
     1.6      {
     1.7 -        pdb_bwcpoint_p bwc = (pdb_bwcpoint_p) xmalloc(sizeof(pdb_bwcpoint_t));
     1.8 +        pdb_bwcpoint_p bwc;
     1.9 +
    1.10 +	bwc = (pdb_bwcpoint_p) xmalloc(sizeof(pdb_bwcpoint_t));
    1.11 +	if (!bwc)
    1.12 +	{
    1.13 +	    printk ("pdb error: can't allocate bwc %d\n", __LINE__);
    1.14 +	}
    1.15  
    1.16  	bwc->address = pdb_system_call_next_addr;
    1.17  	bwc->length = 1;
    1.18  	bwc->type = PDB_BP_SOFTWARE;
    1.19  	bwc->user_type = PDB_BP_SOFTWARE;
    1.20 -	bwc->original = pdb_system_call_leave_instr;
    1.21 +	bwc->action = PDB_BWC_DELETE;
    1.22 +	bwc->comments = "pdb linux syscall exit";
    1.23  	memcpy (&bwc->context, pdb_ctx, sizeof(pdb_context_t));
    1.24  
    1.25 -	/* this is always in a process context */
    1.26 -	pdb_read_memory (pdb_system_call_next_addr, 1, 
    1.27 -			 &pdb_system_call_leave_instr,
    1.28 -			 (pdb_context_p) pdb_ctx);
    1.29 -	pdb_write_memory (pdb_system_call_next_addr, pdb_x86_bkpt_length,
    1.30 -			  &pdb_x86_bkpt, (pdb_context_p) pdb_ctx);
    1.31 -
    1.32 -	pdb_bwc_list_add (bwc);
    1.33 +	pdb_set_breakpoint(bwc);
    1.34      }
    1.35  }
     2.1 --- a/xen/arch/x86/pdb-stub.c	Fri Aug 06 09:51:34 2004 +0000
     2.2 +++ b/xen/arch/x86/pdb-stub.c	Fri Aug 06 09:58:06 2004 +0000
     2.3 @@ -69,7 +69,8 @@ enum pdb_visit_page_action
     2.4    PDB_VISIT_PAGE_PROCESS_WRITE,
     2.5  };
     2.6  static char *pdb_visit_page_action_s[] =
     2.7 -  { "xen rd", "xen wr", "dom rd", "dom wr", "proc rd", "proc wr" };
     2.8 +  { "xen read", "xen write", "domain read", "domain write", 
     2.9 +    "process read", "process write" };
    2.10  
    2.11  int pdb_visit_page (int action, unsigned long addr, int length,
    2.12                      pdb_context_p ctx, int offset, void *s);
    2.13 @@ -136,7 +137,7 @@ typedef struct pdb_invoke_args
    2.14   */
    2.15  
    2.16  int
    2.17 -pdb_invoke(pdb_invoke_ftype *function, pdb_invoke_args_p args)
    2.18 +pdb_invoke (pdb_invoke_ftype *function, pdb_invoke_args_p args)
    2.19  {
    2.20    int remaining;
    2.21    int bytes = 0;
    2.22 @@ -164,6 +165,9 @@ pdb_invoke(pdb_invoke_ftype *function, p
    2.23  char *pdb_bwcpoint_type_s[] =                      /* enum pdb_bwcpoint_type */
    2.24    { "BP_SOFTWARE", "BP_HARDWARE", "WP_WRITE", "WP_READ", "WP_ACCESS" };
    2.25  
    2.26 +char *pdb_bwcpoint_action_s[] =                  /* enum pdb_bwcpoint_action */
    2.27 +  { "UNKNOWN", "STOP", "DELETE" };
    2.28 +
    2.29  int pdb_set_watchpoint (pdb_bwcpoint_p bwc); 
    2.30  int pdb_clear_watchpoint (pdb_bwcpoint_p bwc);
    2.31  
    2.32 @@ -172,62 +176,68 @@ struct list_head pdb_bwc_list = LIST_HEA
    2.33  void
    2.34  pdb_bwc_list_add (pdb_bwcpoint_p bwc)
    2.35  {
    2.36 -  list_add_tail(&bwc->list, &pdb_bwc_list);
    2.37 +    list_add_tail(&bwc->list, &pdb_bwc_list);
    2.38  }
    2.39  
    2.40  void
    2.41  pdb_bwc_list_remove (pdb_bwcpoint_p bwc)
    2.42  {
    2.43 -  list_del(&bwc->list);
    2.44 +    list_del(&bwc->list);
    2.45  }
    2.46  
    2.47  pdb_bwcpoint_p
    2.48  pdb_bwc_list_search (unsigned long address, int length, pdb_context_p ctx)
    2.49  {
    2.50 -  struct list_head *ptr;
    2.51 +    struct list_head *ptr;
    2.52  
    2.53 -  list_for_each (ptr, &pdb_bwc_list)
    2.54 -  {
    2.55 -    pdb_bwcpoint_p bwc = list_entry(ptr, pdb_bwcpoint_t, list);
    2.56 +    list_for_each(ptr, &pdb_bwc_list)
    2.57 +    {
    2.58 +        pdb_bwcpoint_p bwc = list_entry(ptr, pdb_bwcpoint_t, list);
    2.59  
    2.60 -    if (bwc->address == address &&
    2.61 -        bwc->length  == length)
    2.62 -    {
    2.63 -      return bwc;
    2.64 +	if (bwc->address == address &&
    2.65 +	    bwc->length  == length)
    2.66 +	{
    2.67 +	    return bwc;
    2.68 +	}
    2.69      }
    2.70 -  }
    2.71 -  return (pdb_bwcpoint_p) 0;
    2.72 +    return (pdb_bwcpoint_p) 0;
    2.73  }
    2.74  
    2.75  pdb_bwcpoint_p
    2.76  pdb_bwcpoint_search (unsigned long cr3, unsigned long address)
    2.77  {
    2.78 -  pdb_context_t ctx;
    2.79 +    pdb_context_t ctx;
    2.80  
    2.81 -  ctx.ptbr = cr3;
    2.82 -  return pdb_bwc_list_search (address, pdb_x86_bkpt_length, &ctx);
    2.83 +    ctx.ptbr = cr3;
    2.84 +    return pdb_bwc_list_search(address, pdb_x86_bkpt_length, &ctx);
    2.85  }
    2.86  
    2.87  void
    2.88  pdb_bwc_print (pdb_bwcpoint_p bwc)
    2.89  {
    2.90 -    printk ("address: 0x%08lx, length: 0x%02x, type: 0x%x %s", 
    2.91 +    printk ("addr:0x%08lx, len:0x%02x, type:0x%x %s, action:0x%x %s [%s]",
    2.92  	    bwc->address, bwc->length,
    2.93 -	    bwc->type, pdb_bwcpoint_type_s[bwc->type]);
    2.94 +	    bwc->type, pdb_bwcpoint_type_s[bwc->type],
    2.95 +	    bwc->action, pdb_bwcpoint_action_s[bwc->action], bwc->comments);
    2.96  }
    2.97  
    2.98  void
    2.99  pdb_bwc_print_list ()
   2.100  {
   2.101 -  struct list_head *ptr;
   2.102 -  int counter = 0;
   2.103 +    struct list_head *ptr;
   2.104 +    int counter = 0;
   2.105  
   2.106 -  list_for_each (ptr, &pdb_bwc_list)
   2.107 -  {
   2.108 -    pdb_bwcpoint_p bwc = list_entry(ptr, pdb_bwcpoint_t, list);
   2.109 -    printk ("  [%02d]  ", counter);   pdb_bwc_print(bwc);   printk ("\n");
   2.110 -    counter++;
   2.111 -  }
   2.112 +    list_for_each (ptr, &pdb_bwc_list)
   2.113 +    {
   2.114 +        pdb_bwcpoint_p bwc = list_entry(ptr, pdb_bwcpoint_t, list);
   2.115 +	printk ("  [%02d]  ", counter);   pdb_bwc_print(bwc);   printk ("\n");
   2.116 +	counter++;
   2.117 +    }
   2.118 +    
   2.119 +    if (counter == 0)
   2.120 +    {
   2.121 +        printk ("  empty list\n");
   2.122 +    }
   2.123  }
   2.124  
   2.125  /***********************************************************************/
   2.126 @@ -312,35 +322,33 @@ pdb_process_z (int onoff, char *ptr)
   2.127  	{
   2.128  	    if (onoff == 1)
   2.129  	    {
   2.130 -	        pdb_bwcpoint_p bwc = (pdb_bwcpoint_p) xmalloc(sizeof(pdb_bwcpoint_t));
   2.131 +	        pdb_bwcpoint_p bwc;
   2.132 +
   2.133 +		bwc = (pdb_bwcpoint_p) xmalloc(sizeof(pdb_bwcpoint_t));
   2.134 +		if (!bwc)
   2.135 +		{
   2.136 +		    printk ("pdb error: can't allocate bwc %d\n", __LINE__);
   2.137 +		    break;
   2.138 +		}
   2.139  
   2.140  		bwc->address = addr;
   2.141  		bwc->length = pdb_x86_bkpt_length;
   2.142  		bwc->type = PDB_BP_SOFTWARE;
   2.143  		bwc->user_type = type;
   2.144 -		memcpy (&bwc->context, &pdb_ctx, sizeof(pdb_context_t));
   2.145 +		bwc->action = PDB_BWC_STOP;
   2.146 +		bwc->comments = "gdb breakpoint";
   2.147 +		memcpy(&bwc->context, &pdb_ctx, sizeof(pdb_context_t));
   2.148  
   2.149  		if (length != pdb_x86_bkpt_length)
   2.150  		{
   2.151  		    printk("pdb warning: x86 bkpt length should be 1\n");
   2.152  		}
   2.153  
   2.154 -		pdb_set_breakpoint (bwc);
   2.155 +		pdb_set_breakpoint(bwc);
   2.156  	    }
   2.157  	    else
   2.158  	    {
   2.159 -	        pdb_clear_breakpoint (addr, pdb_x86_bkpt_length, &pdb_ctx);
   2.160 -	        pdb_bwcpoint_p bwc = pdb_bwc_list_search (addr, 1, &pdb_ctx);
   2.161 -
   2.162 -		if (bwc == 0)
   2.163 -		{
   2.164 -		    error = "E03";                   /* breakpoint not found */
   2.165 -		    break;
   2.166 -		}
   2.167 -
   2.168 -		pdb_write_memory (addr, 1, &bwc->original, &pdb_ctx);
   2.169 -
   2.170 -		pdb_bwc_list_remove (bwc);
   2.171 +	        pdb_clear_breakpoint(addr, &pdb_ctx);
   2.172  	    }
   2.173  	    break;
   2.174  	}
   2.175 @@ -350,12 +358,21 @@ pdb_process_z (int onoff, char *ptr)
   2.176  	{
   2.177  	    if (onoff == 1)
   2.178  	    {
   2.179 -	        pdb_bwcpoint_p bwc = (pdb_bwcpoint_p) xmalloc(sizeof(pdb_bwcpoint_t));
   2.180 +	        pdb_bwcpoint_p bwc;
   2.181 +
   2.182 +		bwc = (pdb_bwcpoint_p) xmalloc(sizeof(pdb_bwcpoint_t));
   2.183 +		if (!bwc)
   2.184 +		{
   2.185 +		    printk ("pdb error: can't allocate bwc %d\n", __LINE__);
   2.186 +		    break;
   2.187 +		}
   2.188  
   2.189  		bwc->address = addr;
   2.190  		bwc->length = length;
   2.191  		bwc->type = type;
   2.192  		bwc->user_type = type;
   2.193 +		bwc->action = PDB_BWC_UNKNOWN;
   2.194 +		bwc->comments = "gdb writepoint";
   2.195  		memcpy (&bwc->context, &pdb_ctx, sizeof(pdb_context_t));
   2.196  
   2.197  		pdb_set_watchpoint (bwc);
   2.198 @@ -373,8 +390,8 @@ pdb_process_z (int onoff, char *ptr)
   2.199  		}
   2.200  
   2.201  		pdb_clear_watchpoint (bwc);
   2.202 -
   2.203  		pdb_bwc_list_remove (bwc);
   2.204 +		xfree (bwc);
   2.205  	    }
   2.206  	    break;
   2.207  	}
   2.208 @@ -724,20 +741,20 @@ pdb_process_command (char *ptr, struct p
   2.209      case 'm':
   2.210      {
   2.211          /* TRY TO READ %x,%x.  IF SUCCEED, SET PTR = 0 */
   2.212 -        if (hexToInt (&ptr, (int *)&addr))
   2.213 -            if (*(ptr++) == ',')
   2.214 -                if (hexToInt (&ptr, &length))
   2.215 -                {
   2.216 -                    ptr = 0;
   2.217 +        if (   hexToInt (&ptr, (int *)&addr)
   2.218 +	    && *(ptr++) == ','
   2.219 +	    && hexToInt (&ptr, &length))
   2.220 +	{
   2.221 +	    ptr = 0;
   2.222  
   2.223 -		    pdb_page_fault_possible = 2;
   2.224 -		    pdb_page_fault = 0;
   2.225 +	    pdb_page_fault_possible = 2;
   2.226 +	    pdb_page_fault = 0;
   2.227  
   2.228  	    {
   2.229  	        u_char *buffer = (u_char *) xmalloc (length);
   2.230  		if (!buffer)
   2.231  		{
   2.232 -		    printk ("pdb error: xmalloc failure\n");
   2.233 +		    printk ("pdb error: xmalloc failure %d\n", __LINE__);
   2.234  		    break;
   2.235  		}
   2.236  		pdb_read_memory (addr, length, buffer, &pdb_ctx);
   2.237 @@ -745,12 +762,12 @@ pdb_process_command (char *ptr, struct p
   2.238  		xfree(buffer);
   2.239  	    }
   2.240  
   2.241 -		    pdb_page_fault_possible = 0;
   2.242 -		    if (pdb_page_fault)
   2.243 -		    {
   2.244 -                        strcpy (pdb_out_buffer, "E03");
   2.245 -		    }
   2.246 -                }
   2.247 +	    pdb_page_fault_possible = 0;
   2.248 +	    if (pdb_page_fault)
   2.249 +	    {
   2.250 +	        strcpy (pdb_out_buffer, "E03");
   2.251 +	    }
   2.252 +	}
   2.253  	    
   2.254          if (ptr)
   2.255          {
   2.256 @@ -775,7 +792,7 @@ pdb_process_command (char *ptr, struct p
   2.257  	        u_char *buffer = (u_char *) xmalloc (length);
   2.258  		if (!buffer)
   2.259  		{
   2.260 -		    printk ("pdb error: xmalloc failure\n");
   2.261 +		    printk ("pdb error: xmalloc failure %d\n", __LINE__);
   2.262  		    break;
   2.263  		}
   2.264  	        hex2mem (ptr, buffer, length);
   2.265 @@ -1268,8 +1285,10 @@ exit2:
   2.266  int
   2.267  pdb_set_breakpoint (pdb_bwcpoint_p bwc)
   2.268  {
   2.269 -    pdb_read_memory (bwc->address, 1, &bwc->original, &bwc->context);
   2.270 -    pdb_write_memory (bwc->address, 1, &pdb_x86_bkpt, &bwc->context);
   2.271 +    pdb_read_memory (bwc->address, pdb_x86_bkpt_length, 
   2.272 +		     &bwc->original, &bwc->context);
   2.273 +    pdb_write_memory (bwc->address, pdb_x86_bkpt_length, 
   2.274 +		      &pdb_x86_bkpt, &bwc->context);
   2.275  
   2.276      pdb_bwc_list_add (bwc);
   2.277  
   2.278 @@ -1277,21 +1296,22 @@ pdb_set_breakpoint (pdb_bwcpoint_p bwc)
   2.279  }
   2.280  
   2.281  int
   2.282 -pdb_clear_breakpoint (unsigned long address, int length, pdb_context_p ctx)
   2.283 +pdb_clear_breakpoint (unsigned long address, pdb_context_p ctx)
   2.284  {
   2.285 -    int error = 0;
   2.286 -    pdb_bwcpoint_p bwc = pdb_bwc_list_search (address, 1, &pdb_ctx);
   2.287 +    pdb_bwcpoint_p bwc = pdb_bwc_list_search(address, pdb_x86_bkpt_length,
   2.288 +					     ctx);
   2.289  
   2.290      if (bwc == 0)
   2.291      {
   2.292 -      error = 3;                                     /* breakpoint not found */
   2.293 +        printk("pdb error: unknown breakpoint 0x%lx\n", address);
   2.294 +	return 0;
   2.295      }
   2.296  
   2.297 -    pdb_write_memory (address, 1, &bwc->original, &pdb_ctx);
   2.298 -    
   2.299 +    pdb_write_memory (address, pdb_x86_bkpt_length, &bwc->original, ctx);
   2.300      pdb_bwc_list_remove (bwc);
   2.301 +    xfree (bwc);
   2.302  
   2.303 -    return error;
   2.304 +    return 0;
   2.305  }
   2.306  
   2.307  /***********************************************************************/
   2.308 @@ -1537,8 +1557,8 @@ PDBTRC(4,printk("    system_call: 0x%x\n
   2.309  	 (exceptionVector != KEYPRESS_EXCEPTION) &&
   2.310  	 xen_regs->eip < 0xc0000000)  /* Linux-specific for now! */
   2.311      {
   2.312 -        PDBTRC(1,printk("pdb: user bkpt (0x%x) at 0x%lx:0x%lx\n", 
   2.313 -		     exceptionVector, cr3, xen_regs->eip));
   2.314 +        PDBTRC(1, printk("pdb: user bkpt (0x%x) at 0x%lx:0x%lx\n", 
   2.315 +			 exceptionVector, cr3, xen_regs->eip));
   2.316  	return 1;
   2.317      }
   2.318  
   2.319 @@ -1572,26 +1592,20 @@ PDBTRC(4,printk("    system_call: 0x%x\n
   2.320      /* returning to user space after a system call */
   2.321      if ( xen_regs->eip == pdb_system_call_next_addr + 1)
   2.322      {
   2.323 -	 printk("BUG ******** \n");
   2.324 -         printk("BUG return to user space bug\n");
   2.325 -	 printk("BUG ******** \n");
   2.326 -
   2.327 -        /*
   2.328 -	 * BUG: remember to delete the breakpoint!!!
   2.329 -	 *       
   2.330 -	 */
   2.331 -
   2.332          /* this is always in a process context */
   2.333 +	 /*
   2.334          pdb_write_memory (pdb_system_call_next_addr,
   2.335  			  sizeof(pdb_system_call_leave_instr),
   2.336  			  &pdb_system_call_leave_instr, &pdb_ctx);
   2.337 +	 */
   2.338 +        printk ("RETURNING TO USER SPACE AFTER SYSTEM CALL\n");
   2.339 +	pdb_bwc_print_list();
   2.340 +        pdb_clear_breakpoint(pdb_system_call_next_addr, &pdb_ctx);
   2.341 +	pdb_bwc_print_list();
   2.342   
   2.343  	pdb_system_call_next_addr = 0;
   2.344  	pdb_system_call_leave_instr = 0;
   2.345  
   2.346 -	/* manually rewind eip */
   2.347 -	xen_regs->eip--;
   2.348 -
   2.349  	/* if the user doesn't care about breaking when returning 
   2.350  	   to user space after a system call then we'll just ignore 
   2.351  	   the exception */
     3.1 --- a/xen/include/asm-x86/pdb.h	Fri Aug 06 09:51:34 2004 +0000
     3.2 +++ b/xen/include/asm-x86/pdb.h	Fri Aug 06 09:58:06 2004 +0000
     3.3 @@ -77,6 +77,13 @@ enum pdb_bwcpoint_type
     3.4    PDB_WP_ACCESS   = 4
     3.5  };
     3.6  
     3.7 +enum pdb_bwcpoint_action
     3.8 +{
     3.9 +  PDB_BWC_UNKNOWN = 0,                                            /* default */
    3.10 +  PDB_BWC_STOP,         /* stop execution and return control to the debugger */
    3.11 +  PDB_BWC_DELETE                                    /* delete the breakpoint */
    3.12 +};
    3.13 +
    3.14  typedef struct pdb_bwcpoint
    3.15  {
    3.16    struct list_head list;
    3.17 @@ -84,10 +91,11 @@ typedef struct pdb_bwcpoint
    3.18    int length;
    3.19    enum pdb_bwcpoint_type type;                            /* how implemented */
    3.20    enum pdb_bwcpoint_type user_type;                    /* what was requested */
    3.21 +  enum pdb_bwcpoint_action action;                         /* action to take */
    3.22    pdb_context_t context;
    3.23  
    3.24 -  /* original value for breakpoint, one byte for x86 */
    3.25 -  unsigned char original;
    3.26 +  unsigned char original; /* original value for breakpoint, one byte for x86 */
    3.27 +  char *comments;                                                /* comments */
    3.28  } pdb_bwcpoint_t, *pdb_bwcpoint_p;
    3.29  
    3.30  void pdb_bwc_list_add (pdb_bwcpoint_p bwc);
    3.31 @@ -95,8 +103,7 @@ void pdb_bwc_list_remove (pdb_bwcpoint_p
    3.32  pdb_bwcpoint_p pdb_bwcpoint_search (unsigned long cr3, unsigned long address);
    3.33  
    3.34  int pdb_set_breakpoint (pdb_bwcpoint_p bwc);
    3.35 -int pdb_clear_breakpoint (unsigned long address, int length, 
    3.36 -			  pdb_context_p ctx);
    3.37 +int pdb_clear_breakpoint (unsigned long address, pdb_context_p ctx);
    3.38  
    3.39  
    3.40  /* Conversions. */