Print this page
3440 librtld_db demos need warnings gagged
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sgs/librtld_db/demo/common/dis.c
+++ new/usr/src/cmd/sgs/librtld_db/demo/common/dis.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 #include <stdio.h>
27 27 #include <stdlib.h>
28 28 #include <unistd.h>
29 29 #include <fcntl.h>
30 30 #include <string.h>
31 31 #include <errno.h>
32 32 #include <sys/types.h>
33 33 #include <sys/signal.h>
34 34 #include <sys/fault.h>
35 35 #include <sys/syscall.h>
36 36 #include <procfs.h>
37 37 #include <sys/auxv.h>
38 38 #include <libelf.h>
39 39 #include <sys/param.h>
40 40 #include <stdarg.h>
41 41
42 42 #include "rdb.h"
43 43 #include "disasm.h"
44 44
45 45 /*
46 46 * I don't like this global but it's a work-around for the
47 47 * poor disassemble interface for now.
48 48 */
49 49 static struct ps_prochandle *cur_ph;
50 50
51 51 /*
52 52 * This routine converts 'address' into it's closest symbol
53 53 * representation.
54 54 *
55 55 * The following flags are used to effect the output:
56 56 *
57 57 * FLG_PAP_SONAME
58 58 * embed the SONAME in the symbol name
59 59 * FLG_PAP_NOHEXNAME
60 60 * if no symbol found return a null string
61 61 * If this flag is not set return a string displaying
62 62 * the 'hex' value of address.
63 63 * FLG_PAP_PLTDECOM
64 64 * decompose the PLT symbol if possible
65 65 */
66 66 char *
67 67 print_address_ps(struct ps_prochandle *ph, ulong_t address, unsigned flags)
68 68 {
69 69 static char buf[256];
70 70 GElf_Sym sym;
71 71 char *str;
↓ open down ↓ |
71 lines elided |
↑ open up ↑ |
72 72 ulong_t val;
73 73
74 74 if (addr_to_sym(ph, address, &sym, &str) == RET_OK) {
75 75 map_info_t *mip;
76 76 ulong_t pltbase;
77 77
78 78 if (flags & FLG_PAP_SONAME) {
79 79 /*
80 80 * Embed SOName in symbol name
81 81 */
82 - if (mip = addr_to_map(ph, address)) {
82 + if ((mip = addr_to_map(ph, address)) != 0) {
83 83 (void) strcpy(buf, mip->mi_name);
84 84 (void) strcat(buf, ":");
85 85 } else
86 86 (void) sprintf(buf, "0x%08lx:", address);
87 87 } else
88 88 buf[0] = '\0';
89 89
90 90 if ((flags & FLG_PAP_PLTDECOM) &&
91 91 (pltbase = is_plt(ph, address)) != 0) {
92 92 rd_plt_info_t rp;
93 93 pstatus_t pstatus;
94 94
95 95 if (pread(ph->pp_statusfd, &pstatus,
96 96 sizeof (pstatus), 0) == -1)
97 97 perr("pap: reading pstatus");
98 98
99 99 if (rd_plt_resolution(ph->pp_rap, address,
100 100 pstatus.pr_lwp.pr_lwpid, pltbase,
101 101 &rp) == RD_OK) {
102 102 if (rp.pi_flags & RD_FLG_PI_PLTBOUND) {
103 103 GElf_Sym _sym;
104 104 char *_str;
105 105
106 106 if (addr_to_sym(ph, rp.pi_baddr,
107 107 &_sym, &_str) == RET_OK) {
108 108 (void) snprintf(buf, 256,
109 109 "%s0x%lx:plt(%s)",
110 110 buf, address, _str);
111 111 return (buf);
112 112 }
113 113 }
114 114 }
115 115 val = sym.st_value;
116 116 (void) snprintf(buf, 256, "%s0x%lx:plt(unbound)+0x%lx",
117 117 buf, address, address - val);
118 118 return (buf);
119 119 } else {
120 120
121 121 val = sym.st_value;
122 122
123 123 if (val < address)
124 124 (void) snprintf(buf, 256, "%s%s+0x%lx", buf,
125 125 str, address - val);
126 126 else
127 127 (void) snprintf(buf, 256, "%s%s", buf, str);
128 128 return (buf);
129 129 }
130 130 } else {
131 131 if (flags & FLG_PAP_NOHEXNAME)
132 132 buf[0] = '\0';
133 133 else
134 134 (void) sprintf(buf, "0x%lx", address);
135 135 return (buf);
136 136 }
137 137 }
138 138
139 139 char *
140 140 print_address(unsigned long address)
141 141 {
142 142 return (print_address_ps(cur_ph, address,
143 143 FLG_PAP_SONAME| FLG_PAP_PLTDECOM));
144 144 }
145 145
146 146 retc_t
147 147 disasm_addr(struct ps_prochandle *ph, ulong_t addr, int num_inst)
148 148 {
149 149 ulong_t offset, end;
150 150 int vers = V8_MODE;
151 151
152 152 if (ph->pp_dmodel == PR_MODEL_LP64)
153 153 vers = V9_MODE | V9_SGI_MODE;
154 154
155 155 for (offset = addr, end = addr + num_inst * 4; offset < end;
156 156 offset += 4) {
157 157 char *instr_str;
158 158 unsigned int instr;
159 159
160 160 if (ps_pread(ph, offset, (char *)&instr,
161 161 sizeof (unsigned)) != PS_OK)
162 162 perror("da: ps_pread");
163 163
164 164 cur_ph = ph;
165 165 instr_str = disassemble(instr, offset, print_address, 0, 0,
166 166 vers);
167 167
168 168 (void) printf("%-30s: %s\n", print_address(offset), instr_str);
169 169 }
170 170 return (RET_OK);
171 171 }
172 172
173 173 void
174 174 disasm(struct ps_prochandle *ph, int num_inst)
175 175 {
176 176 pstatus_t pstat;
177 177
178 178 if (pread(ph->pp_statusfd, &pstat, sizeof (pstat), 0) == -1)
179 179 perr("disasm: PIOCSTATUS");
180 180
181 181 (void) disasm_addr(ph, (ulong_t)pstat.pr_lwp.pr_reg[R_PC], num_inst);
182 182 }
↓ open down ↓ |
90 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX