Home | History | Annotate | Line # | Download | only in ddb
db_write_cmd.c revision 1.2.4.1
      1 /*
      2  * Mach Operating System
      3  * Copyright (c) 1991,1990 Carnegie Mellon University
      4  * All Rights Reserved.
      5  *
      6  * Permission to use, copy, modify and distribute this software and its
      7  * documentation is hereby granted, provided that both the copyright
      8  * notice and this permission notice appear in all copies of the
      9  * software, derivative works or modified versions, and any portions
     10  * thereof, and that both notices appear in supporting documentation.
     11  *
     12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
     13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     15  *
     16  * Carnegie Mellon requests users of this software to return to
     17  *
     18  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     19  *  School of Computer Science
     20  *  Carnegie Mellon University
     21  *  Pittsburgh PA 15213-3890
     22  *
     23  * any improvements or extensions that they make and grant Carnegie the
     24  * rights to redistribute these changes.
     25  */
     26 /*
     27  * $Id: db_write_cmd.c,v 1.2.4.1 1993/11/14 22:48:50 mycroft Exp $
     28  *
     29  * HISTORY
     30  * $Log: db_write_cmd.c,v $
     31  * Revision 1.2.4.1  1993/11/14 22:48:50  mycroft
     32  * Canonicalize all #includes.
     33  *
     34  * Revision 1.2  1993/05/20  03:39:40  cgd
     35  * add explicit rcs id
     36  *
     37  * Revision 1.1.1.1  1993/03/21  09:46:27  cgd
     38  * initial import of 386bsd-0.1 sources
     39  *
     40  * Revision 1.1  1992/03/25  21:45:42  pace
     41  * Initial revision
     42  *
     43  * Revision 2.4  91/02/05  17:07:35  mrt
     44  * 	Changed to new Mach copyright
     45  * 	[91/01/31  16:20:19  mrt]
     46  *
     47  * Revision 2.3  90/10/25  14:44:26  rwd
     48  * 	Changed db_write_cmd to print unsigned.
     49  * 	[90/10/19            rpd]
     50  *
     51  * Revision 2.2  90/08/27  21:53:54  dbg
     52  * 	Set db_prev and db_next instead of explicitly advancing dot.
     53  * 	[90/08/22            dbg]
     54  * 	Reflected changes in db_printsym()'s calling seq.
     55  * 	[90/08/20            af]
     56  * 	Warn user if nothing was written.
     57  * 	[90/08/07            dbg]
     58  * 	Created.
     59  * 	[90/07/25            dbg]
     60  *
     61  */
     62 /*
     63  *	Author: David B. Golub,  Carnegie Mellon University
     64  *	Date:	7/90
     65  */
     66 
     67 #include <sys/param.h>
     68 #include <sys/proc.h>
     69 #include <machine/db_machdep.h>
     70 
     71 #include <ddb/db_lex.h>
     72 #include <ddb/db_access.h>
     73 #include <ddb/db_command.h>
     74 #include <ddb/db_sym.h>
     75 
     76 /*
     77  * Write to file.
     78  */
     79 /*ARGSUSED*/
     80 void
     81 db_write_cmd(address, have_addr, count, modif)
     82 	db_expr_t	address;
     83 	boolean_t	have_addr;
     84 	db_expr_t	count;
     85 	char *		modif;
     86 {
     87 	register
     88 	db_addr_t	addr;
     89 	register
     90 	db_expr_t	old_value;
     91 	db_expr_t	new_value;
     92 	register int	size;
     93 	boolean_t	wrote_one = FALSE;
     94 
     95 	addr = (db_addr_t) address;
     96 
     97 	switch (modif[0]) {
     98 	    case 'b':
     99 		size = 1;
    100 		break;
    101 	    case 'h':
    102 		size = 2;
    103 		break;
    104 	    case 'l':
    105 	    case '\0':
    106 		size = 4;
    107 		break;
    108 	    default:
    109 		db_error("Unknown size\n");
    110 		return;
    111 	}
    112 
    113 	while (db_expression(&new_value)) {
    114 	    old_value = db_get_value(addr, size, FALSE);
    115 	    db_printsym(addr, DB_STGY_ANY);
    116 	    db_printf("\t\t%#8n\t=\t%#8n\n", old_value, new_value);
    117 	    db_put_value(addr, size, new_value);
    118 	    addr += size;
    119 
    120 	    wrote_one = TRUE;
    121 	}
    122 
    123 	if (!wrote_one)
    124 	    db_error("Nothing written.\n");
    125 
    126 	db_next = addr;
    127 	db_prev = addr - size;
    128 
    129 	db_skip_to_eol();
    130 }
    131 
    132