db_write_cmd.c revision 1.27 1 1.27 matt /* $NetBSD: db_write_cmd.c,v 1.27 2015/06/06 22:06:05 matt Exp $ */
2 1.4 cgd
3 1.16 simonb /*
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.16 simonb *
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.16 simonb *
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.16 simonb *
18 1.1 cgd * Carnegie Mellon requests users of this software to return to
19 1.16 simonb *
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.16 simonb *
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.27 matt __KERNEL_RCSID(0, "$NetBSD: db_write_cmd.c,v 1.27 2015/06/06 22:06:05 matt 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.23 ad #include <ddb/ddb.h>
39 1.1 cgd
40 1.1 cgd /*
41 1.1 cgd * Write to file.
42 1.1 cgd */
43 1.1 cgd /*ARGSUSED*/
44 1.1 cgd void
45 1.21 thorpej db_write_cmd(db_expr_t address, bool have_addr,
46 1.20 christos db_expr_t count, const char *modif)
47 1.1 cgd {
48 1.1 cgd db_addr_t addr;
49 1.1 cgd db_expr_t old_value;
50 1.1 cgd db_expr_t new_value;
51 1.12 augustss int size;
52 1.24 phx bool wrote_one;
53 1.24 phx bool show_old_val;
54 1.1 cgd
55 1.1 cgd addr = (db_addr_t) address;
56 1.24 phx wrote_one = false;
57 1.24 phx show_old_val = islower((unsigned char)modif[0]);
58 1.1 cgd
59 1.24 phx switch (tolower((unsigned char)modif[0])) {
60 1.16 simonb case 'b':
61 1.1 cgd size = 1;
62 1.1 cgd break;
63 1.16 simonb case 'h':
64 1.1 cgd size = 2;
65 1.1 cgd break;
66 1.16 simonb case 'l':
67 1.16 simonb case '\0':
68 1.1 cgd size = 4;
69 1.1 cgd break;
70 1.27 matt case 'q':
71 1.27 matt if (sizeof(db_expr_t) != sizeof(uint64_t)) {
72 1.27 matt size = -1;
73 1.27 matt db_error("q not supported\n");
74 1.27 matt /*NOTREACHED*/
75 1.27 matt }
76 1.27 matt case 'L':
77 1.27 matt size = sizeof(db_expr_t);
78 1.27 matt break;
79 1.16 simonb default:
80 1.6 christos size = -1;
81 1.1 cgd db_error("Unknown size\n");
82 1.5 mycroft /*NOTREACHED*/
83 1.1 cgd }
84 1.1 cgd
85 1.1 cgd while (db_expression(&new_value)) {
86 1.16 simonb db_printsym(addr, DB_STGY_ANY, db_printf);
87 1.24 phx if (show_old_val) {
88 1.24 phx old_value = db_get_value(addr, size, false);
89 1.24 phx db_printf("\t\t%s = ", db_num_to_str(old_value));
90 1.24 phx db_printf("%s\n", db_num_to_str(new_value));
91 1.24 phx }
92 1.24 phx else
93 1.24 phx db_printf("\t\t= %s\n", db_num_to_str(new_value));
94 1.16 simonb db_put_value(addr, size, new_value);
95 1.16 simonb addr += size;
96 1.1 cgd
97 1.22 thorpej wrote_one = true;
98 1.1 cgd }
99 1.1 cgd
100 1.5 mycroft if (!wrote_one) {
101 1.16 simonb db_error("Nothing written.\n");
102 1.16 simonb /*NOTREACHED*/
103 1.5 mycroft }
104 1.1 cgd
105 1.1 cgd db_next = addr;
106 1.1 cgd db_prev = addr - size;
107 1.1 cgd
108 1.1 cgd db_skip_to_eol();
109 1.1 cgd }
110