Print this page
9210 remove KMDB branch debugging support
9211 ::crregs could do with cr2/cr3 support
9209 ::ttrace should be able to filter by thread
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Yuri Pankov <yuripv@yuripv.net>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mdb/sparc/mdb/kvm_v9dep.c
+++ new/usr/src/cmd/mdb/sparc/mdb/kvm_v9dep.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
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
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 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 + *
25 + * Copyright 2018 Joyent, Inc.
24 26 */
25 27
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 -
28 28 /*
29 29 * Libkvm Kernel Target SPARC v9 component
30 30 *
31 31 * This file provides the ISA-dependent portion of the libkvm kernel target.
32 32 * For more details on the implementation refer to mdb_kvm.c. The SPARC v9
33 33 * ISA code is actually compiled into *both* the sparcv7 and sparcv9 MDB
34 34 * binaries because we need to deal with the sparcv9 CPU registers when
35 35 * debugging a 32-bit crash dump from a kernel running on a sparcv9 CPU.
36 36 */
37 37
38 38 #ifndef __sparcv9cpu
39 39 #define __sparcv9cpu
40 40 #endif
41 41
42 42 #include <sys/types.h>
43 43 #include <sys/machtypes.h>
44 44 #include <sys/regset.h>
45 45 #include <sys/frame.h>
46 46 #include <sys/stack.h>
47 47 #include <sys/sysmacros.h>
48 48 #include <sys/panic.h>
49 49 #include <strings.h>
50 50
51 51 #include <mdb/mdb_target_impl.h>
52 52 #include <mdb/mdb_disasm.h>
53 53 #include <mdb/mdb_modapi.h>
54 54 #include <mdb/mdb_conf.h>
55 55 #include <mdb/mdb_kreg_impl.h>
56 56 #include <mdb/mdb_v9util.h>
57 57 #include <mdb/mdb_kvm.h>
58 58 #include <mdb/mdb_err.h>
59 59 #include <mdb/mdb_debug.h>
60 60 #include <mdb/mdb.h>
61 61
62 62 #ifndef STACK_BIAS
63 63 #define STACK_BIAS 0
64 64 #endif
65 65
66 66 static int
67 67 kt_getareg(mdb_tgt_t *t, mdb_tgt_tid_t tid,
68 68 const char *rname, mdb_tgt_reg_t *rp)
69 69 {
70 70 const mdb_tgt_regdesc_t *rdp;
71 71 kt_data_t *kt = t->t_data;
72 72
73 73 if (tid != kt->k_tid)
74 74 return (set_errno(EMDB_NOREGS));
75 75
76 76 for (rdp = kt->k_rds; rdp->rd_name != NULL; rdp++) {
77 77 if (strcmp(rname, rdp->rd_name) == 0) {
78 78 *rp = kt->k_regs->kregs[rdp->rd_num];
79 79 return (0);
80 80 }
81 81 }
82 82
83 83 return (set_errno(EMDB_BADREG));
84 84 }
85 85
86 86 static int
87 87 kt_putareg(mdb_tgt_t *t, mdb_tgt_tid_t tid, const char *rname, mdb_tgt_reg_t r)
88 88 {
89 89 const mdb_tgt_regdesc_t *rdp;
90 90 kt_data_t *kt = t->t_data;
91 91
92 92 if (tid != kt->k_tid)
93 93 return (set_errno(EMDB_NOREGS));
94 94
95 95 for (rdp = kt->k_rds; rdp->rd_name != NULL; rdp++) {
96 96 if (strcmp(rname, rdp->rd_name) == 0) {
97 97 kt->k_regs->kregs[rdp->rd_num] = r;
98 98 return (0);
99 99 }
100 100 }
101 101
102 102 return (set_errno(EMDB_BADREG));
103 103 }
104 104
105 105 /*
106 106 * - If we got a pc, invoke the call back function starting
107 107 * with gsp.
108 108 * - If we got a saved pc (%i7), invoke the call back function
109 109 * starting with the first register window.
110 110 * - If we got neither a pc nor a saved pc, invoke the call back
111 111 * function starting with the second register window.
112 112 */
113 113
114 114 /*ARGSUSED*/
115 115 static int
116 116 kt_regs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
117 117 {
118 118 mdb_v9printregs((const mdb_tgt_gregset_t *)addr);
119 119 return (DCMD_OK);
120 120 }
121 121
122 122 static int
123 123 kt_stack_common(uintptr_t addr, uint_t flags, int argc,
124 124 const mdb_arg_t *argv, mdb_tgt_stack_f *func, kreg_t saved_pc)
125 125 {
126 126 kt_data_t *kt = mdb.m_target->t_data;
127 127 void *arg = (void *)(uintptr_t)mdb.m_nargs;
128 128 mdb_tgt_gregset_t gregs, *grp;
129 129
130 130 if (flags & DCMD_ADDRSPEC) {
131 131 bzero(&gregs, sizeof (gregs));
132 132 gregs.kregs[KREG_FP] = addr;
133 133 gregs.kregs[KREG_I7] = saved_pc;
134 134 grp = &gregs;
135 135 } else
136 136 grp = kt->k_regs;
137 137
138 138 if (argc != 0) {
139 139 if (argv->a_type == MDB_TYPE_CHAR || argc > 1)
140 140 return (DCMD_USAGE);
141 141
142 142 if (argv->a_type == MDB_TYPE_STRING)
143 143 arg = (void *)(uintptr_t)(uint_t)
144 144 mdb_strtoull(argv->a_un.a_str);
145 145 else
146 146 arg = (void *)(uintptr_t)(uint_t)argv->a_un.a_val;
147 147 }
148 148
149 149 (void) mdb_kvm_v9stack_iter(mdb.m_target, grp, func, arg);
150 150 return (DCMD_OK);
151 151 }
152 152
153 153 static int
154 154 kt_stack(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
155 155 {
156 156 return (kt_stack_common(addr, flags, argc, argv, mdb_kvm_v9frame, 0));
157 157 }
158 158
159 159 static int
160 160 kt_stackv(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
161 161 {
162 162 return (kt_stack_common(addr, flags, argc, argv, mdb_kvm_v9framev, 0));
163 163 }
164 164
165 165 static int
166 166 kt_stackr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
167 167 {
168 168 /*
169 169 * Force printing of first register window by setting the
170 170 * saved pc (%i7) to PC_FAKE.
171 171 */
172 172 return (kt_stack_common(addr, flags, argc, argv, mdb_kvm_v9framer,
173 173 PC_FAKE));
174 174 }
175 175
176 176 /*ARGSUSED*/
177 177 static int
178 178 kt_notsup(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
179 179 {
180 180 errno = EMDB_TGTNOTSUP;
181 181 return (DCMD_ERR);
182 182 }
183 183
184 184 const mdb_tgt_ops_t kt_sparcv9_ops = {
185 185 kt_setflags, /* t_setflags */
186 186 kt_setcontext, /* t_setcontext */
187 187 kt_activate, /* t_activate */
188 188 kt_deactivate, /* t_deactivate */
189 189 (void (*)()) mdb_tgt_nop, /* t_periodic */
190 190 kt_destroy, /* t_destroy */
191 191 kt_name, /* t_name */
192 192 (const char *(*)()) mdb_conf_isa, /* t_isa */
193 193 kt_platform, /* t_platform */
194 194 kt_uname, /* t_uname */
195 195 kt_dmodel, /* t_dmodel */
196 196 kt_aread, /* t_aread */
197 197 kt_awrite, /* t_awrite */
198 198 kt_vread, /* t_vread */
199 199 kt_vwrite, /* t_vwrite */
200 200 kt_pread, /* t_pread */
201 201 kt_pwrite, /* t_pwrite */
202 202 kt_fread, /* t_fread */
203 203 kt_fwrite, /* t_fwrite */
204 204 (ssize_t (*)()) mdb_tgt_notsup, /* t_ioread */
205 205 (ssize_t (*)()) mdb_tgt_notsup, /* t_iowrite */
206 206 kt_vtop, /* t_vtop */
207 207 kt_lookup_by_name, /* t_lookup_by_name */
208 208 kt_lookup_by_addr, /* t_lookup_by_addr */
209 209 kt_symbol_iter, /* t_symbol_iter */
↓ open down ↓ |
172 lines elided |
↑ open up ↑ |
210 210 kt_mapping_iter, /* t_mapping_iter */
211 211 kt_object_iter, /* t_object_iter */
212 212 kt_addr_to_map, /* t_addr_to_map */
213 213 kt_name_to_map, /* t_name_to_map */
214 214 kt_addr_to_ctf, /* t_addr_to_ctf */
215 215 kt_name_to_ctf, /* t_name_to_ctf */
216 216 kt_status, /* t_status */
217 217 (int (*)()) mdb_tgt_notsup, /* t_run */
218 218 (int (*)()) mdb_tgt_notsup, /* t_step */
219 219 (int (*)()) mdb_tgt_notsup, /* t_step_out */
220 - (int (*)()) mdb_tgt_notsup, /* t_step_branch */
221 220 (int (*)()) mdb_tgt_notsup, /* t_next */
222 221 (int (*)()) mdb_tgt_notsup, /* t_cont */
223 222 (int (*)()) mdb_tgt_notsup, /* t_signal */
224 223 (int (*)()) mdb_tgt_null, /* t_add_vbrkpt */
225 224 (int (*)()) mdb_tgt_null, /* t_add_sbrkpt */
226 225 (int (*)()) mdb_tgt_null, /* t_add_pwapt */
227 226 (int (*)()) mdb_tgt_null, /* t_add_iowapt */
228 227 (int (*)()) mdb_tgt_null, /* t_add_vwapt */
229 228 (int (*)()) mdb_tgt_null, /* t_add_sysenter */
230 229 (int (*)()) mdb_tgt_null, /* t_add_sysexit */
231 230 (int (*)()) mdb_tgt_null, /* t_add_signal */
232 231 (int (*)()) mdb_tgt_null, /* t_add_fault */
233 232 kt_getareg, /* t_getareg */
234 233 kt_putareg, /* t_putareg */
235 234 mdb_kvm_v9stack_iter, /* t_stack_iter */
236 235 (int (*)()) mdb_tgt_notsup /* t_auxv */
237 236 };
238 237
239 238 void
240 239 kt_sparcv9_init(mdb_tgt_t *t)
241 240 {
242 241 kt_data_t *kt = t->t_data;
243 242
244 243 struct rwindow rwin;
245 244 panic_data_t pd;
246 245 label_t label;
247 246 kreg_t *kregs;
248 247
249 248 uint64_t tick;
250 249 uint32_t pil;
251 250
252 251 /*
253 252 * Initialize the machine-dependent parts of the kernel target
254 253 * structure. Once this is complete and we fill in the ops
255 254 * vector, the target is now fully constructed and we can use
256 255 * the target API itself to perform the rest of our initialization.
257 256 */
258 257 kt->k_rds = mdb_sparcv9_kregs;
259 258 kt->k_regs = mdb_zalloc(sizeof (mdb_tgt_gregset_t), UM_SLEEP);
260 259 kt->k_regsize = sizeof (mdb_tgt_gregset_t);
261 260 kt->k_dcmd_regs = kt_regs;
262 261 kt->k_dcmd_stack = kt_stack;
263 262 kt->k_dcmd_stackv = kt_stackv;
264 263 kt->k_dcmd_stackr = kt_stackr;
265 264 kt->k_dcmd_cpustack = kt_notsup;
266 265 kt->k_dcmd_cpuregs = kt_notsup;
267 266
268 267 t->t_ops = &kt_sparcv9_ops;
269 268 kregs = kt->k_regs->kregs;
270 269
271 270 (void) mdb_dis_select("v9plus");
272 271
273 272 /*
274 273 * Don't attempt to load any thread or register information if
275 274 * we're examining the live operating system.
276 275 */
277 276 if (strcmp(kt->k_symfile, "/dev/ksyms") == 0)
278 277 return;
279 278
280 279 /*
281 280 * If the panicbuf symbol is present and we can consume a panicbuf
282 281 * header of the appropriate version from this address, then
283 282 * we can initialize our current register set based on its contents:
284 283 */
285 284 if (mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &pd, sizeof (pd),
286 285 MDB_TGT_OBJ_EXEC, "panicbuf") == sizeof (pd) &&
287 286 pd.pd_version == PANICBUFVERS) {
288 287
289 288 size_t pd_size = MIN(PANICBUFSIZE, pd.pd_msgoff);
290 289 panic_data_t *pdp = mdb_zalloc(pd_size, UM_SLEEP);
291 290 uint_t i, n;
292 291
293 292 (void) mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, pdp, pd_size,
294 293 MDB_TGT_OBJ_EXEC, "panicbuf");
295 294
296 295 n = (pd_size - (sizeof (panic_data_t) -
297 296 sizeof (panic_nv_t))) / sizeof (panic_nv_t);
298 297
299 298 for (i = 0; i < n; i++) {
300 299 const char *name = pdp->pd_nvdata[i].pnv_name;
301 300 uint64_t value = pdp->pd_nvdata[i].pnv_value;
302 301
303 302 if (strcmp(name, "tstate") == 0) {
304 303 kregs[KREG_CCR] = KREG_TSTATE_CCR(value);
305 304 kregs[KREG_ASI] = KREG_TSTATE_ASI(value);
306 305 kregs[KREG_PSTATE] = KREG_TSTATE_PSTATE(value);
307 306 kregs[KREG_CWP] = KREG_TSTATE_CWP(value);
308 307 } else
309 308 (void) kt_putareg(t, kt->k_tid, name, value);
310 309 }
311 310
312 311 mdb_free(pdp, pd_size);
313 312 }
314 313
315 314 /*
316 315 * Prior to the re-structuring of panicbuf, our only register data
317 316 * was the panic_regs label_t, into which a setjmp() was performed.
318 317 */
319 318 if (kregs[KREG_PC] == 0 && kregs[KREG_SP] == 0 &&
320 319 mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &label, sizeof (label),
321 320 MDB_TGT_OBJ_EXEC, "panic_regs") == sizeof (label)) {
322 321
323 322 kregs[KREG_PC] = label.val[0];
324 323 kregs[KREG_SP] = label.val[1];
325 324 }
326 325
327 326 /*
328 327 * If we can read a saved register window from the stack at %sp,
329 328 * we can also fill in the locals and inputs.
330 329 */
331 330 if (kregs[KREG_SP] != 0 && mdb_tgt_vread(t, &rwin, sizeof (rwin),
332 331 kregs[KREG_SP] + STACK_BIAS) == sizeof (rwin)) {
333 332
334 333 kregs[KREG_L0] = rwin.rw_local[0];
335 334 kregs[KREG_L1] = rwin.rw_local[1];
336 335 kregs[KREG_L2] = rwin.rw_local[2];
337 336 kregs[KREG_L3] = rwin.rw_local[3];
338 337 kregs[KREG_L4] = rwin.rw_local[4];
339 338 kregs[KREG_L5] = rwin.rw_local[5];
340 339 kregs[KREG_L6] = rwin.rw_local[6];
341 340 kregs[KREG_L7] = rwin.rw_local[7];
342 341
343 342 kregs[KREG_I0] = rwin.rw_in[0];
344 343 kregs[KREG_I1] = rwin.rw_in[1];
345 344 kregs[KREG_I2] = rwin.rw_in[2];
346 345 kregs[KREG_I3] = rwin.rw_in[3];
347 346 kregs[KREG_I4] = rwin.rw_in[4];
348 347 kregs[KREG_I5] = rwin.rw_in[5];
349 348 kregs[KREG_I6] = rwin.rw_in[6];
350 349 kregs[KREG_I7] = rwin.rw_in[7];
351 350
352 351 } else if (kregs[KREG_SP] != 0) {
353 352 warn("failed to read rwindow at %p -- current "
354 353 "frame inputs will be unavailable\n",
355 354 (void *)(uintptr_t)(kregs[KREG_SP] + STACK_BIAS));
356 355 }
357 356
358 357 /*
359 358 * The panic_ipl variable records the IPL of the panic CPU,
360 359 * which on sparcv9 is the %pil register's value.
361 360 */
362 361 if (mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &pil, sizeof (pil),
363 362 MDB_TGT_OBJ_EXEC, "panic_ipl") == sizeof (pil))
364 363 kregs[KREG_PIL] = pil;
365 364
366 365 /*
367 366 * The panic_tick variable records %tick at the approximate
368 367 * time of the panic in a DEBUG kernel.
369 368 */
370 369 if (mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &tick, sizeof (tick),
371 370 MDB_TGT_OBJ_EXEC, "panic_tick") == sizeof (tick))
372 371 kregs[KREG_TICK] = tick;
373 372 }
↓ open down ↓ |
143 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX