1 /* $OpenBSD: db_write_cmd.c,v 1.8 2006/03/13 06:23:20 jsg Exp $ */
2 /* $NetBSD: db_write_cmd.c,v 1.6 1996/02/05 01:57:25 christos Exp $ */
3
4 /*
5 * Mach Operating System
6 * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University
7 * All Rights Reserved.
8 *
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie Mellon
27 * the rights to redistribute these changes.
28 *
29 * Author: David B. Golub, Carnegie Mellon University
30 * Date: 7/90
31 */
32
33 #include <sys/param.h>
34 #include <sys/proc.h>
35
36 #include <uvm/uvm_extern.h>
37
38 #include <machine/db_machdep.h>
39
40 #include <ddb/db_lex.h>
41 #include <ddb/db_access.h>
42 #include <ddb/db_command.h>
43 #include <ddb/db_sym.h>
44 #include <ddb/db_extern.h>
45 #include <ddb/db_output.h>
46
47 /*
48 * Write to file.
49 */
50 /*ARGSUSED*/
51 void
52 db_write_cmd(db_expr_t address, boolean_t have_addr, db_expr_t count,
53 char *modif)
54 {
55 db_addr_t addr;
56 db_expr_t old_value;
57 db_expr_t new_value;
58 int size;
59 boolean_t wrote_one = FALSE;
60
61 addr = (db_addr_t) address;
62
63 switch (modif[0]) {
64 case 'b':
65 size = 1;
66 break;
67 case 'h':
68 size = 2;
69 break;
70 case 'l':
71 case '\0':
72 size = 4;
73 break;
74 default:
75 size = -1;
76 db_error("Unknown size\n");
77 /*NOTREACHED*/
78 }
79
80 while (db_expression(&new_value)) {
81 old_value = db_get_value(addr, size, FALSE);
82 db_printsym(addr, DB_STGY_ANY, db_printf);
83 db_printf("\t\t%#8n\t=\t%#8n\n", old_value, new_value);
84 db_put_value(addr, size, new_value);
85 addr += size;
86
87 wrote_one = TRUE;
88 }
89
90 if (!wrote_one) {
91 db_error("Nothing written.\n");
92 /*NOTREACHED*/
93 }
94
95 db_next = addr;
96 db_prev = addr - size;
97
98 db_skip_to_eol();
99 }
100