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/intel/mdb/kvm_ia32dep.c
+++ new/usr/src/cmd/mdb/intel/mdb/kvm_ia32dep.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 Intel 32-bit 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.
33 33 */
34 34
35 35 #include <sys/types.h>
36 36 #include <sys/regset.h>
37 37 #include <sys/frame.h>
38 38 #include <sys/stack.h>
39 39 #include <sys/sysmacros.h>
40 40 #include <sys/panic.h>
41 41 #include <strings.h>
42 42
43 43 #include <mdb/mdb_target_impl.h>
44 44 #include <mdb/mdb_disasm.h>
45 45 #include <mdb/mdb_modapi.h>
46 46 #include <mdb/mdb_conf.h>
47 47 #include <mdb/mdb_kreg_impl.h>
48 48 #include <mdb/mdb_ia32util.h>
49 49 #include <mdb/kvm_isadep.h>
50 50 #include <mdb/mdb_kvm.h>
51 51 #include <mdb/mdb_err.h>
52 52 #include <mdb/mdb_debug.h>
53 53 #include <mdb/mdb.h>
54 54
55 55
56 56 /*ARGSUSED*/
57 57 int
58 58 kt_regs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
59 59 {
60 60 mdb_ia32_printregs((const mdb_tgt_gregset_t *)addr);
61 61 return (DCMD_OK);
62 62 }
63 63
64 64 static int
65 65 kt_stack_common(uintptr_t addr, uint_t flags, int argc,
66 66 const mdb_arg_t *argv, mdb_tgt_stack_f *func)
67 67 {
68 68 kt_data_t *kt = mdb.m_target->t_data;
69 69 void *arg = (void *)mdb.m_nargs;
70 70 mdb_tgt_gregset_t gregs, *grp;
71 71
72 72 if (flags & DCMD_ADDRSPEC) {
73 73 bzero(&gregs, sizeof (gregs));
74 74 gregs.kregs[KREG_EBP] = addr;
75 75 grp = &gregs;
76 76 } else
77 77 grp = kt->k_regs;
78 78
79 79 if (argc != 0) {
80 80 if (argv->a_type == MDB_TYPE_CHAR || argc > 1)
81 81 return (DCMD_USAGE);
82 82
83 83 if (argv->a_type == MDB_TYPE_STRING)
84 84 arg = (void *)(uint_t)mdb_strtoull(argv->a_un.a_str);
85 85 else
86 86 arg = (void *)(uint_t)argv->a_un.a_val;
87 87 }
88 88
89 89 (void) mdb_ia32_kvm_stack_iter(mdb.m_target, grp, func, arg);
90 90 return (DCMD_OK);
91 91 }
92 92
93 93 int
94 94 kt_stack(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
95 95 {
96 96 return (kt_stack_common(addr, flags, argc, argv, mdb_ia32_kvm_frame));
97 97 }
98 98
99 99 int
100 100 kt_stackv(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
101 101 {
102 102 return (kt_stack_common(addr, flags, argc, argv, mdb_ia32_kvm_framev));
103 103 }
104 104
105 105 const mdb_tgt_ops_t kt_ia32_ops = {
106 106 kt_setflags, /* t_setflags */
107 107 kt_setcontext, /* t_setcontext */
108 108 kt_activate, /* t_activate */
109 109 kt_deactivate, /* t_deactivate */
110 110 (void (*)()) mdb_tgt_nop, /* t_periodic */
111 111 kt_destroy, /* t_destroy */
112 112 kt_name, /* t_name */
113 113 (const char *(*)()) mdb_conf_isa, /* t_isa */
114 114 kt_platform, /* t_platform */
115 115 kt_uname, /* t_uname */
116 116 kt_dmodel, /* t_dmodel */
117 117 kt_aread, /* t_aread */
118 118 kt_awrite, /* t_awrite */
119 119 kt_vread, /* t_vread */
120 120 kt_vwrite, /* t_vwrite */
121 121 kt_pread, /* t_pread */
122 122 kt_pwrite, /* t_pwrite */
123 123 kt_fread, /* t_fread */
124 124 kt_fwrite, /* t_fwrite */
125 125 (ssize_t (*)()) mdb_tgt_notsup, /* t_ioread */
126 126 (ssize_t (*)()) mdb_tgt_notsup, /* t_iowrite */
127 127 kt_vtop, /* t_vtop */
128 128 kt_lookup_by_name, /* t_lookup_by_name */
129 129 kt_lookup_by_addr, /* t_lookup_by_addr */
130 130 kt_symbol_iter, /* t_symbol_iter */
↓ open down ↓ |
93 lines elided |
↑ open up ↑ |
131 131 kt_mapping_iter, /* t_mapping_iter */
132 132 kt_object_iter, /* t_object_iter */
133 133 kt_addr_to_map, /* t_addr_to_map */
134 134 kt_name_to_map, /* t_name_to_map */
135 135 kt_addr_to_ctf, /* t_addr_to_ctf */
136 136 kt_name_to_ctf, /* t_name_to_ctf */
137 137 kt_status, /* t_status */
138 138 (int (*)()) mdb_tgt_notsup, /* t_run */
139 139 (int (*)()) mdb_tgt_notsup, /* t_step */
140 140 (int (*)()) mdb_tgt_notsup, /* t_step_out */
141 - (int (*)()) mdb_tgt_notsup, /* t_step_branch */
142 141 (int (*)()) mdb_tgt_notsup, /* t_next */
143 142 (int (*)()) mdb_tgt_notsup, /* t_cont */
144 143 (int (*)()) mdb_tgt_notsup, /* t_signal */
145 144 (int (*)()) mdb_tgt_null, /* t_add_vbrkpt */
146 145 (int (*)()) mdb_tgt_null, /* t_add_sbrkpt */
147 146 (int (*)()) mdb_tgt_null, /* t_add_pwapt */
148 147 (int (*)()) mdb_tgt_null, /* t_add_vwapt */
149 148 (int (*)()) mdb_tgt_null, /* t_add_iowapt */
150 149 (int (*)()) mdb_tgt_null, /* t_add_sysenter */
151 150 (int (*)()) mdb_tgt_null, /* t_add_sysexit */
152 151 (int (*)()) mdb_tgt_null, /* t_add_signal */
153 152 (int (*)()) mdb_tgt_null, /* t_add_fault */
154 153 kt_getareg, /* t_getareg */
155 154 kt_putareg, /* t_putareg */
156 155 mdb_ia32_kvm_stack_iter, /* t_stack_iter */
157 156 (int (*)()) mdb_tgt_notsup /* t_auxv */
158 157 };
159 158
160 159 void
161 160 kt_regs_to_kregs(struct regs *regs, mdb_tgt_gregset_t *gregs)
162 161 {
163 162 gregs->kregs[KREG_SAVFP] = regs->r_savfp;
164 163 gregs->kregs[KREG_SAVPC] = regs->r_savpc;
165 164 gregs->kregs[KREG_EAX] = regs->r_eax;
166 165 gregs->kregs[KREG_EBX] = regs->r_ebx;
167 166 gregs->kregs[KREG_ECX] = regs->r_ecx;
168 167 gregs->kregs[KREG_EDX] = regs->r_edx;
169 168 gregs->kregs[KREG_ESI] = regs->r_esi;
170 169 gregs->kregs[KREG_EDI] = regs->r_edi;
171 170 gregs->kregs[KREG_EBP] = regs->r_ebp;
172 171 gregs->kregs[KREG_ESP] = regs->r_esp;
173 172 gregs->kregs[KREG_CS] = regs->r_cs;
174 173 gregs->kregs[KREG_DS] = regs->r_ds;
175 174 gregs->kregs[KREG_SS] = regs->r_ss;
176 175 gregs->kregs[KREG_ES] = regs->r_es;
177 176 gregs->kregs[KREG_FS] = regs->r_fs;
178 177 gregs->kregs[KREG_GS] = regs->r_gs;
179 178 gregs->kregs[KREG_EFLAGS] = regs->r_efl;
180 179 gregs->kregs[KREG_EIP] = regs->r_eip;
181 180 gregs->kregs[KREG_UESP] = regs->r_uesp;
182 181 gregs->kregs[KREG_TRAPNO] = regs->r_trapno;
183 182 gregs->kregs[KREG_ERR] = regs->r_err;
184 183 }
185 184
186 185 void
187 186 kt_ia32_init(mdb_tgt_t *t)
188 187 {
189 188 kt_data_t *kt = t->t_data;
190 189 panic_data_t pd;
191 190 label_t label;
192 191 struct regs regs;
193 192 kreg_t *kregs;
194 193 uintptr_t addr;
195 194
196 195 /*
197 196 * Initialize the machine-dependent parts of the kernel target
198 197 * structure. Once this is complete and we fill in the ops
199 198 * vector, the target is now fully constructed and we can use
200 199 * the target API itself to perform the rest of our initialization.
201 200 */
202 201 kt->k_rds = mdb_ia32_kregs;
203 202 kt->k_regs = mdb_zalloc(sizeof (mdb_tgt_gregset_t), UM_SLEEP);
204 203 kt->k_regsize = sizeof (mdb_tgt_gregset_t);
205 204 kt->k_dcmd_regs = kt_regs;
206 205 kt->k_dcmd_stack = kt_stack;
207 206 kt->k_dcmd_stackv = kt_stackv;
208 207 kt->k_dcmd_stackr = kt_stackv;
209 208 kt->k_dcmd_cpustack = kt_cpustack;
210 209 kt->k_dcmd_cpuregs = kt_cpuregs;
211 210
212 211 t->t_ops = &kt_ia32_ops;
213 212 kregs = kt->k_regs->kregs;
214 213
215 214 (void) mdb_dis_select("ia32");
216 215
217 216 /*
218 217 * Lookup the symbols corresponding to subroutines in locore.s where
219 218 * we expect a saved regs structure to be pushed on the stack. When
220 219 * performing stack tracebacks we will attempt to detect interrupt
221 220 * frames by comparing the %eip value to these symbols.
222 221 */
223 222 (void) mdb_tgt_lookup_by_name(t, MDB_TGT_OBJ_EXEC,
224 223 "cmnint", &kt->k_intr_sym, NULL);
225 224
226 225 (void) mdb_tgt_lookup_by_name(t, MDB_TGT_OBJ_EXEC,
227 226 "cmntrap", &kt->k_trap_sym, NULL);
228 227
229 228 /*
230 229 * Don't attempt to load any thread or register information if
231 230 * we're examining the live operating system.
232 231 */
233 232 if (kt->k_symfile != NULL && strcmp(kt->k_symfile, "/dev/ksyms") == 0)
234 233 return;
235 234
236 235 /*
237 236 * If the panicbuf symbol is present and we can consume a panicbuf
238 237 * header of the appropriate version from this address, then we can
239 238 * initialize our current register set based on its contents.
240 239 * Prior to the re-structuring of panicbuf, our only register data
241 240 * was the panic_regs label_t, into which a setjmp() was performed,
242 241 * or the panic_reg register pointer, which was only non-zero if
243 242 * the system panicked as a result of a trap calling die().
244 243 */
245 244 if (mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &pd, sizeof (pd),
246 245 MDB_TGT_OBJ_EXEC, "panicbuf") == sizeof (pd) &&
247 246 pd.pd_version == PANICBUFVERS) {
248 247
249 248 size_t pd_size = MIN(PANICBUFSIZE, pd.pd_msgoff);
250 249 panic_data_t *pdp = mdb_zalloc(pd_size, UM_SLEEP);
251 250 uint_t i, n;
252 251
253 252 (void) mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, pdp, pd_size,
254 253 MDB_TGT_OBJ_EXEC, "panicbuf");
255 254
256 255 n = (pd_size - (sizeof (panic_data_t) -
257 256 sizeof (panic_nv_t))) / sizeof (panic_nv_t);
258 257
259 258 for (i = 0; i < n; i++) {
260 259 (void) kt_putareg(t, kt->k_tid,
261 260 pdp->pd_nvdata[i].pnv_name,
262 261 pdp->pd_nvdata[i].pnv_value);
263 262 }
264 263
265 264 mdb_free(pdp, pd_size);
266 265
267 266 return;
268 267 }
269 268
270 269 if (mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &addr, sizeof (addr),
271 270 MDB_TGT_OBJ_EXEC, "panic_reg") == sizeof (addr) && addr != NULL &&
272 271 mdb_tgt_vread(t, ®s, sizeof (regs), addr) == sizeof (regs)) {
273 272 kt_regs_to_kregs(®s, kt->k_regs);
274 273 return;
275 274 }
276 275
277 276 /*
278 277 * If we can't read any panic regs, then our penultimate try is for any
279 278 * CPU context that may have been stored (for example, in Xen core
280 279 * dumps). As this can only succeed for kernels with the above
281 280 * methods available, we let it over-ride the older panic_regs method,
282 281 * which will always manage to read the label_t, even if there's
283 282 * nothing useful there.
284 283 */
285 284 if (kt_kvmregs(t, 0, kt->k_regs) == 0)
286 285 return;
287 286
288 287 if (mdb_tgt_readsym(t, MDB_TGT_AS_VIRT, &label, sizeof (label),
289 288 MDB_TGT_OBJ_EXEC, "panic_regs") == sizeof (label)) {
290 289 kregs[KREG_EDI] = label.val[0];
291 290 kregs[KREG_ESI] = label.val[1];
292 291 kregs[KREG_EBX] = label.val[2];
293 292 kregs[KREG_EBP] = label.val[3];
294 293 kregs[KREG_ESP] = label.val[4];
295 294 kregs[KREG_EIP] = label.val[5];
296 295 return;
297 296 }
298 297
299 298 warn("failed to read panicbuf, panic_reg and panic_regs -- "
300 299 "current register set will be unavailable\n");
301 300 }
↓ open down ↓ |
150 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX