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