xref: /freebsd-src/sys/ddb/db_print.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
1dd3cb568SWarner Losh /*-
2796df753SPedro F. Giffuni  * SPDX-License-Identifier: MIT-CMU
3796df753SPedro F. Giffuni  *
45b81b6b3SRodney W. Grimes  * Mach Operating System
55b81b6b3SRodney W. Grimes  * Copyright (c) 1991,1990 Carnegie Mellon University
65b81b6b3SRodney W. Grimes  * All Rights Reserved.
75b81b6b3SRodney W. Grimes  *
85b81b6b3SRodney W. Grimes  * Permission to use, copy, modify and distribute this software and its
95b81b6b3SRodney W. Grimes  * documentation is hereby granted, provided that both the copyright
105b81b6b3SRodney W. Grimes  * notice and this permission notice appear in all copies of the
115b81b6b3SRodney W. Grimes  * software, derivative works or modified versions, and any portions
125b81b6b3SRodney W. Grimes  * thereof, and that both notices appear in supporting documentation.
135b81b6b3SRodney W. Grimes  *
145b81b6b3SRodney W. Grimes  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
155b81b6b3SRodney W. Grimes  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
165b81b6b3SRodney W. Grimes  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
175b81b6b3SRodney W. Grimes  *
185b81b6b3SRodney W. Grimes  * Carnegie Mellon requests users of this software to return to
195b81b6b3SRodney W. Grimes  *
205b81b6b3SRodney W. Grimes  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
215b81b6b3SRodney W. Grimes  *  School of Computer Science
225b81b6b3SRodney W. Grimes  *  Carnegie Mellon University
235b81b6b3SRodney W. Grimes  *  Pittsburgh PA 15213-3890
245b81b6b3SRodney W. Grimes  *
255b81b6b3SRodney W. Grimes  * any improvements or extensions that they make and grant Carnegie the
265b81b6b3SRodney W. Grimes  * rights to redistribute these changes.
270edf66ecSRodney W. Grimes  *
285b81b6b3SRodney W. Grimes  */
295b81b6b3SRodney W. Grimes /*
305b81b6b3SRodney W. Grimes  *	Author: David B. Golub, Carnegie Mellon University
315b81b6b3SRodney W. Grimes  *	Date:	7/90
325b81b6b3SRodney W. Grimes  */
335b81b6b3SRodney W. Grimes 
345b81b6b3SRodney W. Grimes /*
355b81b6b3SRodney W. Grimes  * Miscellaneous printing.
365b81b6b3SRodney W. Grimes  */
37753960f7SDavid E. O'Brien 
38f540b106SGarrett Wollman #include <sys/param.h>
3937224cd3SMarcel Moolenaar #include <sys/kdb.h>
4020984f2fSPeter Wemm #include <sys/proc.h>
4137224cd3SMarcel Moolenaar 
4237224cd3SMarcel Moolenaar #include <machine/pcb.h>
435b81b6b3SRodney W. Grimes 
44f540b106SGarrett Wollman #include <ddb/ddb.h>
455b81b6b3SRodney W. Grimes #include <ddb/db_variables.h>
465b81b6b3SRodney W. Grimes #include <ddb/db_sym.h>
475b81b6b3SRodney W. Grimes 
485b81b6b3SRodney W. Grimes void
db_show_regs(db_expr_t _1,bool _2,db_expr_t _3,char * modif)49*088a7eefSmhorne db_show_regs(db_expr_t _1, bool _2, db_expr_t _3, char *modif)
505b81b6b3SRodney W. Grimes {
51*088a7eefSmhorne 	struct trapframe *oldtf;
5237224cd3SMarcel Moolenaar 	struct db_variable *regp;
535b81b6b3SRodney W. Grimes 	db_expr_t value, offset;
54fe08c21aSMatthew Dillon 	const char *name;
555b81b6b3SRodney W. Grimes 
56*088a7eefSmhorne 	/*
57*088a7eefSmhorne 	 * The 'u' modifier instructs us to print the previous trapframe, most
58*088a7eefSmhorne 	 * often containing state from userspace. This is done by temporarily
59*088a7eefSmhorne 	 * switching out kdb_frame.
60*088a7eefSmhorne 	 *
61*088a7eefSmhorne 	 * NB: curthread is used instead of kdb_thread, so that behaviour is
62*088a7eefSmhorne 	 * consistent with regular `show registers`, which always prints
63*088a7eefSmhorne 	 * curthread's trapframe.
64*088a7eefSmhorne 	 */
65*088a7eefSmhorne 	oldtf = kdb_frame;
66*088a7eefSmhorne 	if (modif[0] == 'u') {
67*088a7eefSmhorne 		if (curthread->td_frame == NULL ||
68*088a7eefSmhorne 		    curthread->td_frame == oldtf) {
69*088a7eefSmhorne 			db_printf("previous trapframe unavailable");
70*088a7eefSmhorne 			return;
71*088a7eefSmhorne 		}
72*088a7eefSmhorne 		kdb_frame = curthread->td_frame;
73*088a7eefSmhorne 	}
74*088a7eefSmhorne 
755b81b6b3SRodney W. Grimes 	for (regp = db_regs; regp < db_eregs; regp++) {
7637224cd3SMarcel Moolenaar 		if (!db_read_variable(regp, &value))
7737224cd3SMarcel Moolenaar 			continue;
789a2d6ab9SJohn Baldwin 		db_printf("%-12s%#*lr", regp->name,
799a2d6ab9SJohn Baldwin 		    (int)(sizeof(unsigned long) * 2 + 2), (unsigned long)value);
805b81b6b3SRodney W. Grimes 		db_find_xtrn_sym_and_offset((db_addr_t)value, &name, &offset);
81fe08c21aSMatthew Dillon 		if (name != NULL && offset <= (unsigned long)db_maxoff &&
823da6ef3cSBruce Evans 		    offset != value) {
835b81b6b3SRodney W. Grimes 			db_printf("\t%s", name);
845b81b6b3SRodney W. Grimes 			if (offset != 0)
851c6989faSPeter Wemm 				db_printf("+%+#lr", (long)offset);
865b81b6b3SRodney W. Grimes 		}
875b81b6b3SRodney W. Grimes 		db_printf("\n");
885b81b6b3SRodney W. Grimes 	}
8937224cd3SMarcel Moolenaar 	db_print_loc_and_inst(PC_REGS());
90*088a7eefSmhorne 
91*088a7eefSmhorne 	kdb_frame = oldtf;
925b81b6b3SRodney W. Grimes }
93