|
root / base / usr / src / cmd / sgs / demo_rdb / amd64
amd64 Plain Text 191 lines 5.1 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
#

include		../Makefile.com

CPPFLAGS +=	-D_SYSCALL32

# DEMO DELETE START
CCVERBOSE=

LDFLAGS=	-L ../../$(MACH64) \
		-L ../../../libelf/$(MACH64)

# DEMO DELETE END

# Change -m64 to -xarch=generic64 for use with older Sun compilers.
DEMOCFLAGS=	-m64

.KEEP_STATE:

all:		$(OBJDIR) .WAIT $(PROG)

test:		$(TESTS)

# DEMO DELETE START
DEMOCFLAGS=

catalog:

install:	all $(ROOTONLDBINPROG64)
# DEMO DELETE END

include		../Makefile.targ

$(OBJDIR)/%.o:	../i386/%.c
		$(COMPILE.c) $< -o $@
		$(POST_PROCESS_O)

# DEMO DELETE START
include		../../../../Makefile.master.64
# DEMO DELETE END
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
 */
#ifndef _RDB_MACH_H
#define	_RDB_MACH_H

#include <sys/regset.h>
#include <sys/psw.h>

#ifdef	__cplusplus
extern "C" {
#endif

#define	ERRBIT	PS_C
#define	R_PS	REG_RFL

/*
 * Breakpoint instruction
 */
typedef	unsigned char	bptinstr_t;
#define	BPINSTR		0xcc		/* int	3 */

/*
 * PLT section type
 */
#define	PLTSECTT	SHT_PROGBITS

#ifdef __cplusplus
}
#endif

#endif	/* _RDB_MACH_H */
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
 */

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/param.h>
#include <sys/reg.h>
#include <sys/machelf.h>

#include "rdb.h"

static void
disp_reg_line(struct ps_prochandle *ph, pstatus_t *prst, char *r1, int ind1,
    char *r2, int ind2)
{
	char	str1[MAXPATHLEN], str2[MAXPATHLEN];

	(void) strcpy(str1, print_address_ps(ph, prst->pr_lwp.pr_reg[ind1],
	    FLG_PAP_NOHEXNAME));

	(void) strcpy(str2, print_address_ps(ph, prst->pr_lwp.pr_reg[ind2],
	    FLG_PAP_NOHEXNAME));

	(void) printf("%8s: 0x%08x %-16s %8s: 0x%08x %-16s\n", r1,
	    EC_WORD(prst->pr_lwp.pr_reg[ind1]), str1, r2,
	    EC_WORD(prst->pr_lwp.pr_reg[ind2]), str2);
}

retc_t
display_all_regs(struct ps_prochandle *ph)
{
	pstatus_t	pstatus;

	if (pread(ph->pp_statusfd, &pstatus, sizeof (pstatus),
	    0) == -1) {
		perror("dar: reading status");
		return (RET_FAILED);
	}
	(void) printf("registers:\n");
	disp_reg_line(ph, &pstatus, "gs", REG_GS, "fs", REG_FS);
	disp_reg_line(ph, &pstatus, "es", REG_ES, "ds", REG_DS);
	disp_reg_line(ph, &pstatus, "rdi", REG_RDI, "rsi", REG_RSI);
	disp_reg_line(ph, &pstatus, "rbp", REG_RBP, "rsp", REG_RSP);
	disp_reg_line(ph, &pstatus, "rbx", REG_RBX, "rdx", REG_RDX);
	disp_reg_line(ph, &pstatus, "rcx", REG_RCX, "rax", REG_RAX);
	disp_reg_line(ph, &pstatus, "trapno", REG_TRAPNO, "err", REG_ERR);
	disp_reg_line(ph, &pstatus, "rip", REG_RIP, "cs", REG_CS);
	disp_reg_line(ph, &pstatus, "rfl", REG_RFL, "uesp", REG_RSP);
	return (RET_OK);
}