xref: /illumos-gate/usr/src/cmd/sgs/demo_rdb/i386/regs.c (revision d9328cd43f1300af79f6fc8a3ad4760137618c63)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #include <stdio.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <sys/param.h>
30 #include <sys/regset.h>
31 
32 #include "rdb.h"
33 
34 static void
disp_reg_line(struct ps_prochandle * ph,pstatus_t * prst,char * r1,int ind1,char * r2,int ind2)35 disp_reg_line(struct ps_prochandle *ph, pstatus_t *prst, char *r1, int ind1,
36     char *r2, int ind2)
37 {
38 	char	str1[MAXPATHLEN], str2[MAXPATHLEN];
39 
40 	(void) strcpy(str1, print_address_ps(ph, prst->pr_lwp.pr_reg[ind1],
41 	    FLG_PAP_NOHEXNAME));
42 	(void) strcpy(str2, print_address_ps(ph, prst->pr_lwp.pr_reg[ind2],
43 	    FLG_PAP_NOHEXNAME));
44 
45 	(void) printf("%8s: 0x%08x %-16s %8s: 0x%08x %-16s\n", r1,
46 	    prst->pr_lwp.pr_reg[ind1], str1, r2, prst->pr_lwp.pr_reg[ind2],
47 	    str2);
48 }
49 
50 retc_t
display_all_regs(struct ps_prochandle * ph)51 display_all_regs(struct ps_prochandle *ph)
52 {
53 	pstatus_t	pstatus;
54 
55 	if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
56 	    0) == -1) {
57 		perror("dar: reading status");
58 		return (RET_FAILED);
59 	}
60 	(void) printf("registers:\n");
61 	disp_reg_line(ph, &pstatus, "gs", GS, "fs", FS);
62 	disp_reg_line(ph, &pstatus, "es", ES, "ds", DS);
63 	disp_reg_line(ph, &pstatus, "edi", EDI, "esi", ESI);
64 	disp_reg_line(ph, &pstatus, "ebp", EBP, "esp", ESP);
65 	disp_reg_line(ph, &pstatus, "ebx", EBX, "edx", EDX);
66 	disp_reg_line(ph, &pstatus, "ecx", ECX, "eax", EAX);
67 	disp_reg_line(ph, &pstatus, "trapno", TRAPNO, "err", ERR);
68 	disp_reg_line(ph, &pstatus, "eip", EIP, "cs", CS);
69 	disp_reg_line(ph, &pstatus, "efl", EFL, "uesp", UESP);
70 	return (RET_OK);
71 }
72