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/reg.h>
31#include <sys/machelf.h>
32
33#include "rdb.h"
34
35static void
36disp_reg_line(struct ps_prochandle *ph, pstatus_t *prst, char *r1, int ind1,
37    char *r2, int ind2)
38{
39	char	str1[MAXPATHLEN], str2[MAXPATHLEN];
40
41	(void) strcpy(str1, print_address_ps(ph, prst->pr_lwp.pr_reg[ind1],
42	    FLG_PAP_NOHEXNAME));
43
44	(void) strcpy(str2, print_address_ps(ph, prst->pr_lwp.pr_reg[ind2],
45	    FLG_PAP_NOHEXNAME));
46
47	(void) printf("%8s: 0x%08x %-16s %8s: 0x%08x %-16s\n", r1,
48	    EC_WORD(prst->pr_lwp.pr_reg[ind1]), str1, r2,
49	    EC_WORD(prst->pr_lwp.pr_reg[ind2]), str2);
50}
51
52retc_t
53display_all_regs(struct ps_prochandle *ph)
54{
55	pstatus_t	pstatus;
56
57	if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
58	    0) == -1) {
59		perror("dar: reading status");
60		return (RET_FAILED);
61	}
62	(void) printf("registers:\n");
63	disp_reg_line(ph, &pstatus, "gs", REG_GS, "fs", REG_FS);
64	disp_reg_line(ph, &pstatus, "es", REG_ES, "ds", REG_DS);
65	disp_reg_line(ph, &pstatus, "rdi", REG_RDI, "rsi", REG_RSI);
66	disp_reg_line(ph, &pstatus, "rbp", REG_RBP, "rsp", REG_RSP);
67	disp_reg_line(ph, &pstatus, "rbx", REG_RBX, "rdx", REG_RDX);
68	disp_reg_line(ph, &pstatus, "rcx", REG_RCX, "rax", REG_RAX);
69	disp_reg_line(ph, &pstatus, "trapno", REG_TRAPNO, "err", REG_ERR);
70	disp_reg_line(ph, &pstatus, "rip", REG_RIP, "cs", REG_CS);
71	disp_reg_line(ph, &pstatus, "rfl", REG_RFL, "uesp", REG_RSP);
72	return (RET_OK);
73}
74