Home | History | Annotate | Line # | Download | only in ddb
db_write_cmd.c revision 1.2
      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 1993/05/20 03:39:40 cgd Exp $
     28  *
     29  * HISTORY
     30  * $Log: db_write_cmd.c,v $
     31  * Revision 1.2  1993/05/20 03:39:40  cgd
     32  * add explicit rcs id
     33  *
     34  * Revision 1.1.1.1  1993/03/21  09:46:27  cgd
     35  * initial import of 386bsd-0.1 sources
     36  *
     37  * Revision 1.1  1992/03/25  21:45:42  pace
     38  * Initial revision
     39  *
     40  * Revision 2.4  91/02/05  17:07:35  mrt
     41  * 	Changed to new Mach copyright
     42  * 	[91/01/31  16:20:19  mrt]
     43  *
     44  * Revision 2.3  90/10/25  14:44:26  rwd
     45  * 	Changed db_write_cmd to print unsigned.
     46  * 	[90/10/19            rpd]
     47  *
     48  * Revision 2.2  90/08/27  21:53:54  dbg
     49  * 	Set db_prev and db_next instead of explicitly advancing dot.
     50  * 	[90/08/22            dbg]
     51  * 	Reflected changes in db_printsym()'s calling seq.
     52  * 	[90/08/20            af]
     53  * 	Warn user if nothing was written.
     54  * 	[90/08/07            dbg]
     55  * 	Created.
     56  * 	[90/07/25            dbg]
     57  *
     58  */
     59 /*
     60  *	Author: David B. Golub,  Carnegie Mellon University
     61  *	Date:	7/90
     62  */
     63 
     64 #include "param.h"
     65 #include "proc.h"
     66 #include <machine/db_machdep.h>
     67 
     68 #include <ddb/db_lex.h>
     69 #include <ddb/db_access.h>
     70 #include <ddb/db_command.h>
     71 #include <ddb/db_sym.h>
     72 
     73 /*
     74  * Write to file.
     75  */
     76 /*ARGSUSED*/
     77 void
     78 db_write_cmd(address, have_addr, count, modif)
     79 	db_expr_t	address;
     80 	boolean_t	have_addr;
     81 	db_expr_t	count;
     82 	char *		modif;
     83 {
     84 	register
     85 	db_addr_t	addr;
     86 	register
     87 	db_expr_t	old_value;
     88 	db_expr_t	new_value;
     89 	register int	size;
     90 	boolean_t	wrote_one = FALSE;
     91 
     92 	addr = (db_addr_t) address;
     93 
     94 	switch (modif[0]) {
     95 	    case 'b':
     96 		size = 1;
     97 		break;
     98 	    case 'h':
     99 		size = 2;
    100 		break;
    101 	    case 'l':
    102 	    case '\0':
    103 		size = 4;
    104 		break;
    105 	    default:
    106 		db_error("Unknown size\n");
    107 		return;
    108 	}
    109 
    110 	while (db_expression(&new_value)) {
    111 	    old_value = db_get_value(addr, size, FALSE);
    112 	    db_printsym(addr, DB_STGY_ANY);
    113 	    db_printf("\t\t%#8n\t=\t%#8n\n", old_value, new_value);
    114 	    db_put_value(addr, size, new_value);
    115 	    addr += size;
    116 
    117 	    wrote_one = TRUE;
    118 	}
    119 
    120 	if (!wrote_one)
    121 	    db_error("Nothing written.\n");
    122 
    123 	db_next = addr;
    124 	db_prev = addr - size;
    125 
    126 	db_skip_to_eol();
    127 }
    128 
    129