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.
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.
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]
23 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
32 #include <sys/types.h>
33 #include <sys/signal.h>
34 #include <sys/fault.h>
35 #include <sys/syscall.h>
39 #include <sys/param.h>
46 * I don't like this global but it's a work-around for the
47 * poor disassemble interface for now.
49 static struct ps_prochandle
*cur_ph
;
52 * This routine converts 'address' into it's closest symbol
55 * The following flags are used to effect the output:
58 * embed the SONAME in the symbol name
60 * if no symbol found return a null string
61 * If this flag is not set return a string displaying
62 * the 'hex' value of address.
64 * decompose the PLT symbol if possible
67 print_address_ps(struct ps_prochandle
*ph
, ulong_t address
, unsigned flags
)
74 if (addr_to_sym(ph
, address
, &sym
, &str
) == RET_OK
) {
78 if (flags
& FLG_PAP_SONAME
) {
80 * Embed SOName in symbol name
82 if ((mip
= addr_to_map(ph
, address
)) != 0) {
83 (void) strcpy(buf
, mip
->mi_name
);
84 (void) strcat(buf
, ":");
86 (void) sprintf(buf
, "0x%08lx:", address
);
90 if ((flags
& FLG_PAP_PLTDECOM
) &&
91 (pltbase
= is_plt(ph
, address
)) != 0) {
95 if (pread(ph
->pp_statusfd
, &pstatus
,
96 sizeof (pstatus
), 0) == -1)
97 perr("pap: reading pstatus");
99 if (rd_plt_resolution(ph
->pp_rap
, address
,
100 pstatus
.pr_lwp
.pr_lwpid
, pltbase
,
102 if (rp
.pi_flags
& RD_FLG_PI_PLTBOUND
) {
106 if (addr_to_sym(ph
, rp
.pi_baddr
,
107 &_sym
, &_str
) == RET_OK
) {
108 (void) snprintf(buf
, 256,
116 (void) snprintf(buf
, 256, "%s0x%lx:plt(unbound)+0x%lx",
117 buf
, address
, address
- val
);
124 (void) snprintf(buf
, 256, "%s%s+0x%lx", buf
,
127 (void) snprintf(buf
, 256, "%s%s", buf
, str
);
131 if (flags
& FLG_PAP_NOHEXNAME
)
134 (void) sprintf(buf
, "0x%lx", address
);
140 print_address(unsigned long address
)
142 return (print_address_ps(cur_ph
, address
,
143 FLG_PAP_SONAME
| FLG_PAP_PLTDECOM
));
147 disasm_addr(struct ps_prochandle
*ph
, ulong_t addr
, int num_inst
)
152 if (ph
->pp_dmodel
== PR_MODEL_LP64
)
153 vers
= V9_MODE
| V9_SGI_MODE
;
155 for (offset
= addr
, end
= addr
+ num_inst
* 4; offset
< end
;
160 if (ps_pread(ph
, offset
, (char *)&instr
,
161 sizeof (unsigned)) != PS_OK
)
162 perror("da: ps_pread");
165 instr_str
= disassemble(instr
, offset
, print_address
, 0, 0,
168 (void) printf("%-30s: %s\n", print_address(offset
), instr_str
);
174 disasm(struct ps_prochandle
*ph
, int num_inst
)
178 if (pread(ph
->pp_statusfd
, &pstat
, sizeof (pstat
), 0) == -1)
179 perr("disasm: PIOCSTATUS");
181 (void) disasm_addr(ph
, (ulong_t
)pstat
.pr_lwp
.pr_reg
[R_PC
], num_inst
);