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