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