1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 /*
27  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
28  * Copyright (c) 2018, Joyent, Inc.
29  * Copyright 2020 Oxide Computer Company
30  */
31 
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <sys/types.h>
36 #include <unistd.h>
37 #include <sys/corectl.h>
38 #include <procfs.h>
39 #include <msg.h>
40 #include <_elfdump.h>
41 #include <struct_layout.h>
42 #include <conv.h>
43 #include <ctype.h>
44 #include <sys/sysmacros.h>
45 
46 
47 /*
48  * This module contains the code that displays data from the note
49  * sections found in Solaris core files. The format of these
50  * note sections are described in the core(4) manpage.
51  */
52 
53 
54 
55 
56 /*
57  * Much of the code in this file uses the "%*s" format to set
58  * the left margin indentation. This macro combines the indent
59  * integer argument and the NULL string that follows it.
60  */
61 #define	INDENT state->ns_indent, MSG_ORIG(MSG_STR_EMPTY)
62 
63 /*
64  * Indent unit, used for each nesting
65  */
66 #define	INDENT_STEP 4
67 
68 /*
69  * The PRINT_ macros are convenience wrappers on print_num(),
70  * print_subtype(), and print_strbuf(). They reduce code
71  * clutter by hiding the boilerplate arguments.
72  *
73  * Assumptions:
74  *	- A variable named "layout" exists in the compilation
75  *		environment, referencing the layout information for the
76  *		current type.
77  *	- The variable "state" references the current note state.
78  */
79 #define	PRINT_DEC(_title, _field) \
80 	print_num(state, _title, &layout->_field, SL_FMT_NUM_DEC)
81 #define	PRINT_DEC_2UP(_title1, _field1, _title2, _field2) \
82 	print_num_2up(state, _title1, &layout->_field1, SL_FMT_NUM_DEC, \
83 	    _title2, &layout->_field2, SL_FMT_NUM_DEC)
84 #define	PRINT_HEX(_title, _field) \
85 	print_num(state, _title, &layout->_field, SL_FMT_NUM_HEX)
86 #define	PRINT_HEX_2UP(_title1, _field1, _title2, _field2) \
87 	print_num_2up(state, _title1, &layout->_field1, SL_FMT_NUM_HEX, \
88 	    _title2, &layout->_field2, SL_FMT_NUM_HEX)
89 #define	PRINT_ZHEX(_title, _field) \
90 	print_num(state, _title, &layout->_field, SL_FMT_NUM_ZHEX)
91 #define	PRINT_ZHEX_2UP(_title1, _field1, _title2, _field2) \
92 	print_num_2up(state, _title1, &layout->_field1, SL_FMT_NUM_ZHEX, \
93 	    _title2, &layout->_field2, SL_FMT_NUM_ZHEX)
94 #define	PRINT_SUBTYPE(_title, _field, _func) \
95 	print_subtype(state, _title, &layout->_field, _func)
96 #define	PRINT_STRBUF(_title, _field) \
97 	print_strbuf(state, _title, &layout->_field)
98 
99 
100 /*
101  * Structure used to maintain state data for a core note, or a subregion
102  * (sub-struct) of a core note. These values would otherwise need to be
103  * passed to nearly every routine.
104  */
105 typedef struct {
106 	Half		ns_mach;	/* ELF machine type of core file */
107 	const sl_arch_layout_t *ns_arch; /* structure layout def for mach */
108 	int		ns_swap;	/* True if byte swapping is needed */
109 	int		ns_indent;	/* Left margin indentation */
110 	int		ns_vcol;	/* Column where value starts */
111 	int		ns_t2col;	/* Column where 2up title starts */
112 	int		ns_v2col;	/* Column where 2up value starts */
113 	const char	*ns_data;	/* Pointer to struct data area */
114 	Word		ns_len;		/* Length of struct data area */
115 } note_state_t;
116 
117 /*
118  * Standard signature for a dump function used to process a note
119  * or a sub-structure within a note.
120  */
121 typedef void (* dump_func_t)(note_state_t *state, const char *title);
122 
123 
124 
125 
126 
127 
128 /*
129  * Some core notes contain string buffers of fixed size
130  * that are expected to contain NULL terminated strings.
131  * If the NULL is there, we can print these strings directly.
132  * However, the potential exists for a corrupt file to have
133  * a non-terminated buffer. This routine examines the given
134  * string, and if the string is terminated, the string itself
135  * is returned. Otherwise, it is copied to a static buffer,
136  * and a pointer to the buffer is returned.
137  */
138 static const char *
safe_str(const char * str,size_t n)139 safe_str(const char *str, size_t n)
140 {
141 	static char	buf[2048];
142 	size_t		i, used;
143 
144 	if (n == 0)
145 		return (MSG_ORIG(MSG_STR_EMPTY));
146 
147 	/*
148 	 * If the string is terminated and doesn't need escaping, we can return
149 	 * it as is.
150 	 */
151 	for (i = 0; i < n; i++) {
152 		if (str[i] == '\0')
153 			return (str);
154 
155 		if (!isascii(str[i]) || !isprint(str[i])) {
156 			break;
157 		}
158 	}
159 
160 	for (i = 0, used = 0; i < n; i++) {
161 		if (str[i] == '\0') {
162 			if (used + 1 > sizeof (buf))
163 				break;
164 			buf[used++] = str[i];
165 			return (buf);
166 		} else if (isascii(str[i]) && isprint(str[i])) {
167 			if (used + 1 > sizeof (buf))
168 				break;
169 			buf[used++] = str[i];
170 		} else {
171 			size_t len = snprintf(NULL, 0, "\\x%02x", str[i]);
172 			if (used + len > sizeof (buf))
173 				break;
174 			(void) snprintf(buf + used, sizeof (buf) - used,
175 			    "\\x%02x", str[i]);
176 			used += len;
177 		}
178 	}
179 
180 	if (i == n && used < sizeof (buf)) {
181 		buf[used] = '\0';
182 		return (buf);
183 	}
184 
185 	/*
186 	 * If we got here, we would have overflowed. Figure out where we need to
187 	 * start and truncate.
188 	 */
189 	used = MIN(used, sizeof (buf) - 4);
190 	buf[used++] = '.';
191 	buf[used++] = '.';
192 	buf[used++] = '.';
193 	buf[used++] = '\0';
194 	return (buf);
195 }
196 
197 /*
198  * Convenience wrappers on top of the corresponding sl_XXX() functions.
199  */
200 static Word
extract_as_word(note_state_t * state,const sl_field_t * fdesc)201 extract_as_word(note_state_t *state, const sl_field_t *fdesc)
202 {
203 	return (sl_extract_as_word(state->ns_data, state->ns_swap, fdesc));
204 }
205 static Lword
extract_as_lword(note_state_t * state,const sl_field_t * fdesc)206 extract_as_lword(note_state_t *state, const sl_field_t *fdesc)
207 {
208 	return (sl_extract_as_lword(state->ns_data, state->ns_swap, fdesc));
209 }
210 static int
extract_as_sword(note_state_t * state,const sl_field_t * fdesc)211 extract_as_sword(note_state_t *state, const sl_field_t *fdesc)
212 {
213 	return (sl_extract_as_sword(state->ns_data, state->ns_swap, fdesc));
214 }
215 static const char *
fmt_num(note_state_t * state,const sl_field_t * fdesc,sl_fmt_num_t fmt_type,sl_fmtbuf_t buf)216 fmt_num(note_state_t *state, const sl_field_t *fdesc,
217     sl_fmt_num_t fmt_type, sl_fmtbuf_t buf)
218 {
219 	return (sl_fmt_num(state->ns_data, state->ns_swap, fdesc,
220 	    fmt_type, buf));
221 }
222 
223 
224 /*
225  * Return true of the data for the specified field is available.
226  */
227 inline static int
data_present(note_state_t * state,const sl_field_t * fdesc)228 data_present(note_state_t *state, const sl_field_t *fdesc)
229 {
230 	return ((fdesc->slf_offset + fdesc->slf_eltlen) <= state->ns_len);
231 }
232 
233 /*
234  * indent_enter/exit are used to start/end output for a subitem.
235  * On entry, a title is output, and the indentation level is raised
236  * by one unit. On exit, the indentation level is restored to its
237  * previous value.
238  */
239 static void
indent_enter(note_state_t * state,const char * title,const sl_field_t * first_fdesc)240 indent_enter(note_state_t *state, const char *title,
241     const sl_field_t *first_fdesc)
242 {
243 	/*
244 	 * If the first field offset and extent fall past the end of the
245 	 * available data, then return without printing a title. That note
246 	 * is from an older core file that doesn't have all the fields
247 	 * that we know about.
248 	 */
249 	if (data_present(state, first_fdesc))
250 		dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_TITLE), INDENT, title);
251 
252 	state->ns_indent += INDENT_STEP;
253 }
254 static void
indent_exit(note_state_t * state)255 indent_exit(note_state_t *state)
256 {
257 	state->ns_indent -= INDENT_STEP;
258 }
259 
260 
261 /*
262  * print_num outputs a field on one line, in the format:
263  *
264  *	title: value
265  */
266 static void
print_num(note_state_t * state,const char * title,const sl_field_t * fdesc,sl_fmt_num_t fmt_type)267 print_num(note_state_t *state, const char *title,
268     const sl_field_t *fdesc, sl_fmt_num_t fmt_type)
269 {
270 	sl_fmtbuf_t	buf;
271 
272 	/*
273 	 * If the field offset and extent fall past the end of the
274 	 * available data, then return without doing anything. That note
275 	 * is from an older core file that doesn't have all the fields
276 	 * that we know about.
277 	 */
278 	if (!data_present(state, fdesc))
279 		return;
280 
281 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE), INDENT,
282 	    state->ns_vcol - state->ns_indent, title,
283 	    fmt_num(state, fdesc, fmt_type, buf));
284 }
285 
286 /*
287  * print_num_2up outputs two fields on one line, in the format:
288  *
289  *	title1: value1	title2: value2
290  */
291 static void
print_num_2up(note_state_t * state,const char * title1,const sl_field_t * fdesc1,sl_fmt_num_t fmt_type1,const char * title2,const sl_field_t * fdesc2,sl_fmt_num_t fmt_type2)292 print_num_2up(note_state_t *state, const char *title1,
293     const sl_field_t *fdesc1, sl_fmt_num_t fmt_type1, const char *title2,
294     const sl_field_t *fdesc2, sl_fmt_num_t fmt_type2)
295 {
296 	sl_fmtbuf_t	buf1, buf2;
297 
298 	/*
299 	 * If the field offset and extent fall past the end of the
300 	 * available data, then return without doing anything. That note
301 	 * is from an older core file that doesn't have all the fields
302 	 * that we know about.
303 	 */
304 	if (!(data_present(state, fdesc1) &&
305 	    data_present(state, fdesc2)))
306 		return;
307 
308 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
309 	    state->ns_vcol - state->ns_indent, title1,
310 	    state->ns_t2col - state->ns_vcol,
311 	    fmt_num(state, fdesc1, fmt_type1, buf1),
312 	    state->ns_v2col - state->ns_t2col, title2,
313 	    fmt_num(state, fdesc2, fmt_type2, buf2));
314 }
315 
316 /*
317  * print_strbuf outputs a fixed sized character buffer field
318  * on one line, in the format:
319  *
320  *	title: value
321  */
322 static void
print_strbuf(note_state_t * state,const char * title,const sl_field_t * fdesc)323 print_strbuf(note_state_t *state, const char *title,
324     const sl_field_t *fdesc)
325 {
326 	Word	n;
327 
328 	/*
329 	 * If we are past the end of the data area, then return
330 	 * without doing anything. That note is from an older core
331 	 * file that doesn't have all the fields that we know about.
332 	 *
333 	 * Note that we are willing to accept a partial buffer,
334 	 * so we don't use data_present() for this test.
335 	 */
336 	if (fdesc->slf_offset >= state->ns_len)
337 		return;
338 
339 	/*
340 	 * We expect the full buffer to be present, but if there
341 	 * is less than that, we will still proceed. The use of safe_str()
342 	 * protects us from the effect of printing garbage data.
343 	 */
344 	n = state->ns_len - fdesc->slf_offset;
345 	if (n > fdesc->slf_nelts)
346 		n = fdesc->slf_nelts;
347 
348 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE), INDENT,
349 	    state->ns_vcol - state->ns_indent,
350 	    title, safe_str(fdesc->slf_offset + state->ns_data, n));
351 }
352 
353 /*
354  * print_str outputs an arbitrary string value item
355  * on one line, in the format:
356  *
357  *	title: str
358  */
359 static void
print_str(note_state_t * state,const char * title,const char * str)360 print_str(note_state_t *state, const char *title, const char *str)
361 {
362 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE), INDENT,
363 	    state->ns_vcol - state->ns_indent, title, str);
364 }
365 
366 /*
367  * Used when one dump function needs to call another dump function
368  * in order to display a subitem. This routine constructs a state
369  * block for the sub-region, and then calls the dump function with it.
370  * This limits the amount of data visible to the sub-function to that
371  * for the sub-item.
372  */
373 static void
print_subtype(note_state_t * state,const char * title,const sl_field_t * fdesc,dump_func_t dump_func)374 print_subtype(note_state_t *state, const char *title,
375     const sl_field_t *fdesc, dump_func_t dump_func)
376 {
377 	note_state_t sub_state;
378 
379 	/*
380 	 * If there is no data for the sub-item, return immediately.
381 	 * Partial data is left to the dump function to handle,
382 	 * as that can be a sign of an older core file with less data,
383 	 * which can still be interpreted.
384 	 */
385 	if (fdesc->slf_offset >= state->ns_len)
386 		return;
387 
388 	/*
389 	 * Construct a state block that reflects the sub-item
390 	 */
391 	sub_state = *state;
392 	sub_state.ns_data += fdesc->slf_offset;
393 	sub_state.ns_len -= fdesc->slf_offset;
394 	if (sub_state.ns_len > fdesc->slf_eltlen)
395 		sub_state.ns_len = fdesc->slf_eltlen;
396 
397 	(* dump_func)(&sub_state, title);
398 }
399 
400 
401 /*
402  * Output a sequence of array elements, giving each
403  * element an index, in the format:
404  *
405  *	[ndx] value
406  *
407  * entry:
408  *	state - Current state
409  *	base_desc - Field descriptor for 1st element of array
410  *	nelts - # of array elements to display
411  *	check_nelts - If True (1), nelts is clipped to fdesc->slf_nelts.
412  *		If False (1), nelts is not clipped.
413  *	title - Name of array
414  */
415 static void
print_array(note_state_t * state,const sl_field_t * base_desc,sl_fmt_num_t fmt_type,int nelts,int check_nelts,const char * title)416 print_array(note_state_t *state, const sl_field_t *base_desc,
417     sl_fmt_num_t fmt_type, int nelts, int check_nelts, const char *title)
418 {
419 	char		index1[MAXNDXSIZE], index2[MAXNDXSIZE];
420 	int		i;
421 	sl_field_t	fdesc1, fdesc2;
422 
423 	if (check_nelts && (check_nelts > base_desc->slf_nelts))
424 		nelts = base_desc->slf_nelts;
425 	if (nelts == 0)
426 		return;
427 
428 	indent_enter(state, title, base_desc);
429 
430 	fdesc1 = fdesc2 = *base_desc;
431 	for (i = 0; i < nelts; ) {
432 		if (i == (nelts - 1)) {
433 			/*  One final value is left  */
434 			if (!data_present(state, &fdesc1))
435 				break;
436 			(void) snprintf(index1, sizeof (index1),
437 			    MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(i));
438 			print_num(state, index1, &fdesc1, fmt_type);
439 			fdesc1.slf_offset += fdesc1.slf_eltlen;
440 			i++;
441 			continue;
442 		}
443 
444 		/* There are at least 2 items left. Show 2 up. */
445 		fdesc2.slf_offset = fdesc1.slf_offset + fdesc1.slf_eltlen;
446 		if (!(data_present(state, &fdesc1) &&
447 		    data_present(state, &fdesc2)))
448 			break;
449 		(void) snprintf(index1, sizeof (index1),
450 		    MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(i));
451 		(void) snprintf(index2, sizeof (index2),
452 		    MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(i + 1));
453 		print_num_2up(state, index1, &fdesc1, fmt_type,
454 		    index2, &fdesc2, fmt_type);
455 		fdesc1.slf_offset += 2 * fdesc1.slf_eltlen;
456 		i += 2;
457 	}
458 
459 	indent_exit(state);
460 }
461 
462 
463 /*
464  * Output information from auxv_t structure.
465  */
466 static void
dump_auxv(note_state_t * state,const char * title)467 dump_auxv(note_state_t *state, const char *title)
468 {
469 	const sl_auxv_layout_t	*layout = state->ns_arch->auxv;
470 	union {
471 		Conv_cap_val_hw1_buf_t		hw1;
472 		Conv_cap_val_hw2_buf_t		hw2;
473 		Conv_cnote_auxv_af_buf_t	auxv_af;
474 		Conv_ehdr_flags_buf_t		ehdr_flags;
475 		Conv_secflags_buf_t		secflags;
476 		Conv_inv_buf_t			inv;
477 	} conv_buf;
478 	sl_fmtbuf_t	buf;
479 	int		ndx, ndx_start;
480 	Word		sizeof_auxv;
481 
482 	sizeof_auxv = layout->sizeof_struct.slf_eltlen;
483 
484 	indent_enter(state, title, &layout->sizeof_struct);
485 
486 	/*
487 	 * Immediate indent_exit() restores the indent level to
488 	 * that of the title. We include indentation as part of
489 	 * the index string, which is right justified, and don't
490 	 * want the usual indentation spacing.
491 	 */
492 	indent_exit(state);
493 
494 	ndx = 0;
495 	while (state->ns_len > sizeof_auxv) {
496 		char		index[(MAXNDXSIZE * 2) + 1];
497 		sl_fmt_num_t	num_fmt = SL_FMT_NUM_ZHEX;
498 		const char	*vstr = NULL;
499 		Word		w;
500 		int		type;
501 		sl_field_t	a_type_next;
502 
503 		type = extract_as_word(state, &layout->a_type);
504 		ndx_start = ndx;
505 		switch (type) {
506 		case AT_NULL:
507 			a_type_next = layout->a_type;
508 			a_type_next.slf_offset += sizeof_auxv;
509 			while ((state->ns_len - sizeof_auxv) >= sizeof_auxv) {
510 				type = extract_as_word(state, &a_type_next);
511 				if (type != AT_NULL)
512 					break;
513 				ndx++;
514 				state->ns_data += sizeof_auxv;
515 				state->ns_len -= sizeof_auxv;
516 			}
517 			num_fmt = SL_FMT_NUM_HEX;
518 			break;
519 
520 
521 
522 		case AT_IGNORE:
523 		case AT_SUN_IFLUSH:
524 			num_fmt = SL_FMT_NUM_HEX;
525 			break;
526 
527 		case AT_EXECFD:
528 		case AT_PHENT:
529 		case AT_PHNUM:
530 		case AT_PAGESZ:
531 		case AT_SUN_UID:
532 		case AT_SUN_RUID:
533 		case AT_SUN_GID:
534 		case AT_SUN_RGID:
535 		case AT_SUN_LPAGESZ:
536 		case AT_SUN_FPSIZE:
537 		case AT_SUN_FPTYPE:
538 			num_fmt = SL_FMT_NUM_DEC;
539 			break;
540 
541 		case AT_FLAGS:	/* processor flags */
542 			w = extract_as_word(state, &layout->a_val);
543 			vstr = conv_ehdr_flags(state->ns_mach, w,
544 			    0, &conv_buf.ehdr_flags);
545 			break;
546 
547 		case AT_SUN_HWCAP:
548 			w = extract_as_word(state, &layout->a_val);
549 			vstr = conv_cap_val_hw1(w, state->ns_mach,
550 			    0, &conv_buf.hw1);
551 			/*
552 			 * conv_cap_val_hw1() produces output like:
553 			 *
554 			 *	0xfff [ flg1 flg2 0xff]
555 			 *
556 			 * where the first hex value is the complete value,
557 			 * and the second is the leftover bits. We only
558 			 * want the part in brackets, and failing that,
559 			 * would rather fall back to formatting the full
560 			 * value ourselves.
561 			 */
562 			while ((*vstr != '\0') && (*vstr != '['))
563 				vstr++;
564 			if (*vstr != '[')
565 				vstr = NULL;
566 			num_fmt = SL_FMT_NUM_HEX;
567 			break;
568 		case AT_SUN_HWCAP2:
569 			w = extract_as_word(state, &layout->a_val);
570 			vstr = conv_cap_val_hw2(w, state->ns_mach,
571 			    0, &conv_buf.hw2);
572 			/*
573 			 * conv_cap_val_hw2() produces output like:
574 			 *
575 			 *	0xfff [ flg1 flg2 0xff]
576 			 *
577 			 * where the first hex value is the complete value,
578 			 * and the second is the leftover bits. We only
579 			 * want the part in brackets, and failing that,
580 			 * would rather fall back to formatting the full
581 			 * value ourselves.
582 			 */
583 			while ((*vstr != '\0') && (*vstr != '['))
584 				vstr++;
585 			if (*vstr != '[')
586 				vstr = NULL;
587 			num_fmt = SL_FMT_NUM_HEX;
588 			break;
589 
590 
591 
592 		case AT_SUN_AUXFLAGS:
593 			w = extract_as_word(state, &layout->a_val);
594 			vstr = conv_cnote_auxv_af(w, 0, &conv_buf.auxv_af);
595 			num_fmt = SL_FMT_NUM_HEX;
596 			break;
597 		}
598 
599 		if (ndx == ndx_start)
600 			(void) snprintf(index, sizeof (index),
601 			    MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(ndx));
602 		else
603 			(void) snprintf(index, sizeof (index),
604 			    MSG_ORIG(MSG_FMT_INDEXRNG),
605 			    EC_WORD(ndx_start), EC_WORD(ndx));
606 
607 		if (vstr == NULL)
608 			vstr = fmt_num(state, &layout->a_val, num_fmt, buf);
609 		dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_AUXVLINE), INDENT, index,
610 		    state->ns_vcol - state->ns_indent,
611 		    conv_cnote_auxv_type(type, CONV_FMT_DECIMAL,
612 		    &conv_buf.inv), vstr);
613 
614 		state->ns_data += sizeof_auxv;
615 		state->ns_len -= sizeof_auxv;
616 		ndx++;
617 	}
618 }
619 
620 
621 /*
622  * Output information from fltset_t structure.
623  */
624 static void
dump_fltset(note_state_t * state,const char * title)625 dump_fltset(note_state_t *state, const char *title)
626 {
627 #define	NELTS 4
628 
629 	const sl_fltset_layout_t	*layout = state->ns_arch->fltset;
630 	Conv_cnote_fltset_buf_t	buf;
631 	sl_field_t		fdesc;
632 	uint32_t		mask[NELTS];
633 	int			i, nelts;
634 
635 	if (!data_present(state, &layout->sizeof_struct))
636 		return;
637 
638 	fdesc = layout->word;
639 	nelts = fdesc.slf_nelts;
640 	if (nelts > NELTS)	/* Type has grown? Show what we understand */
641 		nelts = NELTS;
642 	for (i = 0; i < nelts; i++) {
643 		mask[i] = extract_as_word(state, &fdesc);
644 		fdesc.slf_offset += fdesc.slf_eltlen;
645 	}
646 
647 	print_str(state, title, conv_cnote_fltset(mask, nelts, 0, &buf));
648 
649 #undef NELTS
650 }
651 
652 
653 /*
654  * Output information from sigset_t structure.
655  */
656 static void
dump_sigset(note_state_t * state,const char * title)657 dump_sigset(note_state_t *state, const char *title)
658 {
659 #define	NELTS 4
660 
661 	const sl_sigset_layout_t	*layout = state->ns_arch->sigset;
662 	Conv_cnote_sigset_buf_t	buf;
663 	sl_field_t		fdesc;
664 	uint32_t		mask[NELTS];
665 	int			i, nelts;
666 
667 	if (!data_present(state, &layout->sizeof_struct))
668 		return;
669 
670 	fdesc = layout->sigbits;
671 	nelts = fdesc.slf_nelts;
672 	if (nelts > NELTS)	/* Type has grown? Show what we understand */
673 		nelts = NELTS;
674 	for (i = 0; i < nelts; i++) {
675 		mask[i] = extract_as_word(state, &fdesc);
676 		fdesc.slf_offset += fdesc.slf_eltlen;
677 	}
678 
679 	print_str(state, title, conv_cnote_sigset(mask, nelts, 0, &buf));
680 
681 #undef NELTS
682 }
683 
684 
685 /*
686  * Output information from sigaction structure.
687  */
688 static void
dump_sigaction(note_state_t * state,const char * title)689 dump_sigaction(note_state_t *state, const char *title)
690 {
691 	const sl_sigaction_layout_t	*layout = state->ns_arch->sigaction;
692 	Conv_cnote_sa_flags_buf_t	conv_buf;
693 	Word	w;
694 
695 	indent_enter(state, title, &layout->sa_flags);
696 
697 	if (data_present(state, &layout->sa_flags)) {
698 		w = extract_as_word(state, &layout->sa_flags);
699 		print_str(state, MSG_ORIG(MSG_CNOTE_T_SA_FLAGS),
700 		    conv_cnote_sa_flags(w, 0, &conv_buf));
701 	}
702 
703 	PRINT_ZHEX_2UP(MSG_ORIG(MSG_CNOTE_T_SA_HANDLER), sa_hand,
704 	    MSG_ORIG(MSG_CNOTE_T_SA_SIGACTION), sa_sigact);
705 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_SA_MASK), sa_mask, dump_sigset);
706 
707 	indent_exit(state);
708 }
709 
710 
711 /*
712  * Output information from siginfo structure.
713  */
714 static void
dump_siginfo(note_state_t * state,const char * title)715 dump_siginfo(note_state_t *state, const char *title)
716 {
717 	const sl_siginfo_layout_t	*layout = state->ns_arch->siginfo;
718 	Conv_inv_buf_t	inv_buf;
719 	Word		w;
720 	int		v_si_code, v_si_signo;
721 
722 	if (!data_present(state, &layout->sizeof_struct))
723 		return;
724 
725 	indent_enter(state, title, &layout->f_si_signo);
726 
727 	v_si_signo = extract_as_sword(state, &layout->f_si_signo);
728 	print_str(state, MSG_ORIG(MSG_CNOTE_T_SI_SIGNO),
729 	    conv_cnote_signal(v_si_signo, CONV_FMT_DECIMAL, &inv_buf));
730 
731 	w = extract_as_word(state, &layout->f_si_errno);
732 	print_str(state, MSG_ORIG(MSG_CNOTE_T_SI_ERRNO),
733 	    conv_cnote_errno(w, CONV_FMT_DECIMAL, &inv_buf));
734 
735 	v_si_code = extract_as_sword(state, &layout->f_si_code);
736 	print_str(state, MSG_ORIG(MSG_CNOTE_T_SI_CODE),
737 	    conv_cnote_si_code(state->ns_mach, v_si_signo, v_si_code,
738 	    CONV_FMT_DECIMAL, &inv_buf));
739 
740 	if ((v_si_signo == 0) || (v_si_code == SI_NOINFO)) {
741 		indent_exit(state);
742 		return;
743 	}
744 
745 	/* User generated signals have (si_code <= 0) */
746 	if (v_si_code <= 0) {
747 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_PID), f_si_pid);
748 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_UID), f_si_uid);
749 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_CTID), f_si_ctid);
750 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_ZONEID), f_si_zoneid);
751 		switch (v_si_code) {
752 		case SI_QUEUE:
753 		case SI_TIMER:
754 		case SI_ASYNCIO:
755 		case SI_MESGQ:
756 			indent_enter(state, MSG_ORIG(MSG_CNOTE_T_SI_VALUE),
757 			    &layout->f_si_value_int);
758 			PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_SIVAL_INT),
759 			    f_si_value_int);
760 			PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_SIVAL_PTR),
761 			    f_si_value_ptr);
762 			indent_exit(state);
763 			break;
764 		}
765 		indent_exit(state);
766 		return;
767 	}
768 
769 	/*
770 	 * Remaining cases are kernel generated signals. Output any
771 	 * signal or code specific information.
772 	 */
773 	if (v_si_code == SI_RCTL)
774 		PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_SI_ENTITY), f_si_entity);
775 	switch (v_si_signo) {
776 	case SIGILL:
777 	case SIGFPE:
778 	case SIGSEGV:
779 	case SIGBUS:
780 		PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_SI_ADDR), f_si_addr);
781 		break;
782 	case SIGCHLD:
783 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_PID), f_si_pid);
784 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_STATUS), f_si_status);
785 		break;
786 	case SIGPOLL:
787 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_BAND), f_si_band);
788 		break;
789 	}
790 
791 	indent_exit(state);
792 }
793 
794 
795 /*
796  * Output information from stack_t structure.
797  */
798 static void
dump_stack(note_state_t * state,const char * title)799 dump_stack(note_state_t *state, const char *title)
800 {
801 	const sl_stack_layout_t		*layout = state->ns_arch->stack;
802 	Conv_cnote_ss_flags_buf_t	conv_buf;
803 	Word		w;
804 
805 	indent_enter(state, title, &layout->ss_size);
806 
807 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_SS_SP), &layout->ss_sp,
808 	    SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_SS_SIZE), &layout->ss_size,
809 	    SL_FMT_NUM_HEX);
810 
811 	if (data_present(state, &layout->ss_flags)) {
812 		w = extract_as_word(state, &layout->ss_flags);
813 		print_str(state, MSG_ORIG(MSG_CNOTE_T_SS_FLAGS),
814 		    conv_cnote_ss_flags(w, 0, &conv_buf));
815 	}
816 
817 	indent_exit(state);
818 }
819 
820 
821 /*
822  * Output information from sysset_t structure.
823  */
824 static void
dump_sysset(note_state_t * state,const char * title)825 dump_sysset(note_state_t *state, const char *title)
826 {
827 #define	NELTS 16
828 
829 	const sl_sysset_layout_t	*layout = state->ns_arch->sysset;
830 	Conv_cnote_sysset_buf_t	buf;
831 	sl_field_t		fdesc;
832 	uint32_t		mask[NELTS];
833 	int			i, nelts;
834 
835 	if (!data_present(state, &layout->sizeof_struct))
836 		return;
837 
838 	fdesc = layout->word;
839 	nelts = fdesc.slf_nelts;
840 	if (nelts > NELTS)	/* Type has grown? Show what we understand */
841 		nelts = NELTS;
842 	for (i = 0; i < nelts; i++) {
843 		mask[i] = extract_as_word(state, &fdesc);
844 		fdesc.slf_offset += fdesc.slf_eltlen;
845 	}
846 
847 	print_str(state, title, conv_cnote_sysset(mask, nelts, 0, &buf));
848 
849 #undef NELTS
850 }
851 
852 
853 /*
854  * Output information from timestruc_t structure.
855  */
856 static void
dump_timestruc(note_state_t * state,const char * title)857 dump_timestruc(note_state_t *state, const char *title)
858 {
859 	const sl_timestruc_layout_t *layout = state->ns_arch->timestruc;
860 
861 	indent_enter(state, title, &layout->tv_sec);
862 
863 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_TV_SEC), tv_sec,
864 	    MSG_ORIG(MSG_CNOTE_T_TV_NSEC), tv_nsec);
865 
866 	indent_exit(state);
867 }
868 
869 /*
870  * Output information from prsecflags_t structure.
871  */
872 static void
dump_secflags(note_state_t * state,const char * title)873 dump_secflags(note_state_t *state, const char *title)
874 {
875 	const sl_prsecflags_layout_t *layout = state->ns_arch->prsecflags;
876 	Conv_secflags_buf_t inv;
877 	Lword lw;
878 	Word w;
879 
880 	indent_enter(state, title, &layout->pr_version);
881 
882 	w = extract_as_word(state, &layout->pr_version);
883 
884 	if (w != PRSECFLAGS_VERSION_1) {
885 		PRINT_DEC(MSG_INTL(MSG_NOTE_BAD_SECFLAGS_VER), pr_version);
886 		dump_hex_bytes(state->ns_data, state->ns_len, state->ns_indent,
887 		    4, 3);
888 	} else {
889 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_VERSION), pr_version);
890 		lw = extract_as_lword(state, &layout->pr_effective);
891 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_EFFECTIVE),
892 		    conv_prsecflags(lw, 0, &inv));
893 
894 		lw = extract_as_lword(state, &layout->pr_inherit);
895 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_INHERIT),
896 		    conv_prsecflags(lw, 0, &inv));
897 
898 		lw = extract_as_lword(state, &layout->pr_lower);
899 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_LOWER),
900 		    conv_prsecflags(lw, 0, &inv));
901 
902 		lw = extract_as_lword(state, &layout->pr_upper);
903 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_UPPER),
904 		    conv_prsecflags(lw, 0, &inv));
905 	}
906 
907 	indent_exit(state);
908 }
909 
910 /*
911  * Output information from utsname structure.
912  */
913 static void
dump_utsname(note_state_t * state,const char * title)914 dump_utsname(note_state_t *state, const char *title)
915 {
916 	const sl_utsname_layout_t	*layout = state->ns_arch->utsname;
917 
918 	indent_enter(state, title, &layout->sysname);
919 
920 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_SYSNAME), sysname);
921 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_NODENAME), nodename);
922 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_RELEASE), release);
923 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_VERSION), version);
924 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_MACHINE), machine);
925 
926 	indent_exit(state);
927 }
928 
929 
930 /*
931  * Dump register contents
932  */
933 static void
dump_prgregset(note_state_t * state,const char * title)934 dump_prgregset(note_state_t *state, const char *title)
935 {
936 	sl_field_t	fdesc1, fdesc2;
937 	sl_fmtbuf_t	buf1, buf2;
938 	Conv_inv_buf_t	inv_buf1, inv_buf2;
939 	Word		w;
940 
941 	fdesc1 = fdesc2 = state->ns_arch->prgregset->elt0;
942 	indent_enter(state, title, &fdesc1);
943 
944 	for (w = 0; w < fdesc1.slf_nelts; ) {
945 		if (w == (fdesc1.slf_nelts - 1)) {
946 			/* One last register is left */
947 			if (!data_present(state, &fdesc1))
948 				break;
949 			dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE),
950 			    INDENT, state->ns_vcol - state->ns_indent,
951 			    conv_cnote_pr_regname(state->ns_mach, w,
952 			    CONV_FMT_DECIMAL, &inv_buf1),
953 			    fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1));
954 			fdesc1.slf_offset += fdesc1.slf_eltlen;
955 			w++;
956 			continue;
957 		}
958 
959 		/* There are at least 2 more registers left. Show 2 up */
960 		fdesc2.slf_offset = fdesc1.slf_offset + fdesc1.slf_eltlen;
961 		if (!(data_present(state, &fdesc1) &&
962 		    data_present(state, &fdesc2)))
963 			break;
964 		dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
965 		    state->ns_vcol - state->ns_indent,
966 		    conv_cnote_pr_regname(state->ns_mach, w,
967 		    CONV_FMT_DECIMAL, &inv_buf1),
968 		    state->ns_t2col - state->ns_vcol,
969 		    fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1),
970 		    state->ns_v2col - state->ns_t2col,
971 		    conv_cnote_pr_regname(state->ns_mach, w + 1,
972 		    CONV_FMT_DECIMAL, &inv_buf2),
973 		    fmt_num(state, &fdesc2, SL_FMT_NUM_ZHEX, buf2));
974 		fdesc1.slf_offset += 2 * fdesc1.slf_eltlen;
975 		w += 2;
976 	}
977 
978 	indent_exit(state);
979 }
980 
981 /*
982  * Output information from lwpstatus_t structure.
983  */
984 static void
dump_lwpstatus(note_state_t * state,const char * title)985 dump_lwpstatus(note_state_t *state, const char *title)
986 {
987 	const sl_lwpstatus_layout_t	*layout = state->ns_arch->lwpstatus;
988 	Word		w, w2;
989 	int32_t		i;
990 	union {
991 		Conv_inv_buf_t			inv;
992 		Conv_cnote_pr_flags_buf_t	flags;
993 	} conv_buf;
994 
995 	indent_enter(state, title, &layout->pr_flags);
996 
997 	if (data_present(state, &layout->pr_flags)) {
998 		w = extract_as_word(state, &layout->pr_flags);
999 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAGS),
1000 		    conv_cnote_pr_flags(w, 0, &conv_buf.flags));
1001 	}
1002 
1003 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_LWPID), pr_lwpid);
1004 
1005 	if (data_present(state, &layout->pr_why)) {
1006 		w = extract_as_word(state, &layout->pr_why);
1007 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHY),
1008 		    conv_cnote_pr_why(w, 0, &conv_buf.inv));
1009 
1010 		if (data_present(state, &layout->pr_what)) {
1011 			w2 = extract_as_word(state, &layout->pr_what);
1012 			print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHAT),
1013 			    conv_cnote_pr_what(w, w2, 0, &conv_buf.inv));
1014 		}
1015 	}
1016 
1017 	if (data_present(state, &layout->pr_cursig)) {
1018 		w = extract_as_word(state, &layout->pr_cursig);
1019 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_CURSIG),
1020 		    conv_cnote_signal(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1021 	}
1022 
1023 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_INFO), pr_info, dump_siginfo);
1024 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWPPEND), pr_lwppend,
1025 	    dump_sigset);
1026 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWPHOLD), pr_lwphold,
1027 	    dump_sigset);
1028 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ACTION), pr_action,
1029 	    dump_sigaction);
1030 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ALTSTACK), pr_altstack,
1031 	    dump_stack);
1032 
1033 	PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_PR_OLDCONTEXT), pr_oldcontext);
1034 
1035 	if (data_present(state, &layout->pr_syscall)) {
1036 		w = extract_as_word(state, &layout->pr_syscall);
1037 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
1038 		    conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1039 	}
1040 
1041 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NSYSARG), pr_nsysarg);
1042 
1043 	if (data_present(state, &layout->pr_errno)) {
1044 		w = extract_as_word(state, &layout->pr_errno);
1045 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_ERRNO),
1046 		    conv_cnote_errno(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1047 	}
1048 
1049 	if (data_present(state, &layout->pr_nsysarg)) {
1050 		w2 = extract_as_word(state, &layout->pr_nsysarg);
1051 		print_array(state, &layout->pr_sysarg, SL_FMT_NUM_ZHEX, w2, 1,
1052 		    MSG_ORIG(MSG_CNOTE_T_PR_SYSARG));
1053 	}
1054 
1055 	PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RVAL1), pr_rval1,
1056 	    MSG_ORIG(MSG_CNOTE_T_PR_RVAL2), pr_rval2);
1057 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
1058 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TSTAMP), pr_tstamp,
1059 	    dump_timestruc);
1060 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_UTIME), pr_utime, dump_timestruc);
1061 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_STIME), pr_stime, dump_timestruc);
1062 
1063 	if (data_present(state, &layout->pr_errpriv)) {
1064 		i = extract_as_sword(state, &layout->pr_errpriv);
1065 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_ERRPRIV),
1066 		    conv_cnote_priv(i, CONV_FMT_DECIMAL, &conv_buf.inv));
1067 	}
1068 
1069 	PRINT_ZHEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_USTACK), pr_ustack,
1070 	    MSG_ORIG(MSG_CNOTE_T_PR_INSTR), pr_instr);
1071 
1072 	/*
1073 	 * In order to line up all the values in a single column,
1074 	 * we would have to set vcol to a very high value, which results
1075 	 * in ugly looking output that runs off column 80. So, we use
1076 	 * two levels of vcol, one for the contents so far, and a
1077 	 * higher one for the pr_reg sub-struct.
1078 	 */
1079 	state->ns_vcol += 3;
1080 	state->ns_t2col += 3;
1081 	state->ns_v2col += 2;
1082 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_REG), pr_reg, dump_prgregset);
1083 	state->ns_vcol -= 3;
1084 	state->ns_t2col -= 3;
1085 	state->ns_v2col -= 2;
1086 
1087 	/*
1088 	 * The floating point register state is complex, and highly
1089 	 * platform dependent. For now, we simply display it as
1090 	 * a hex dump. This can be replaced if better information
1091 	 * is required.
1092 	 */
1093 	if (data_present(state, &layout->pr_fpreg)) {
1094 		indent_enter(state, MSG_ORIG(MSG_CNOTE_T_PR_FPREG),
1095 		    &layout->pr_fpreg);
1096 		dump_hex_bytes(layout->pr_fpreg.slf_offset + state->ns_data,
1097 		    layout->pr_fpreg.slf_eltlen, state->ns_indent, 4, 3);
1098 		indent_exit(state);
1099 	}
1100 
1101 	indent_exit(state);
1102 }
1103 
1104 
1105 /*
1106  * Output information from pstatus_t structure.
1107  */
1108 static void
dump_pstatus(note_state_t * state,const char * title)1109 dump_pstatus(note_state_t *state, const char *title)
1110 {
1111 	const sl_pstatus_layout_t	*layout = state->ns_arch->pstatus;
1112 	Word				w;
1113 	union {
1114 		Conv_inv_buf_t			inv;
1115 		Conv_cnote_pr_flags_buf_t	flags;
1116 	} conv_buf;
1117 
1118 	indent_enter(state, title, &layout->pr_flags);
1119 
1120 	if (data_present(state, &layout->pr_flags)) {
1121 		w = extract_as_word(state, &layout->pr_flags);
1122 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAGS),
1123 		    conv_cnote_pr_flags(w, 0, &conv_buf.flags));
1124 	}
1125 
1126 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NLWP), pr_nlwp);
1127 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
1128 	    MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
1129 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGID), pr_pgid,
1130 	    MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
1131 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ASLWPID), pr_aslwpid,
1132 	    MSG_ORIG(MSG_CNOTE_T_PR_AGENTID), pr_agentid);
1133 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGPEND), pr_sigpend,
1134 	    dump_sigset);
1135 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_BRKBASE),
1136 	    &layout->pr_brkbase, SL_FMT_NUM_ZHEX,
1137 	    MSG_ORIG(MSG_CNOTE_T_PR_BRKSIZE),
1138 	    &layout->pr_brksize, SL_FMT_NUM_HEX);
1139 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_STKBASE),
1140 	    &layout->pr_stkbase, SL_FMT_NUM_ZHEX,
1141 	    MSG_ORIG(MSG_CNOTE_T_PR_STKSIZE),
1142 	    &layout->pr_stksize, SL_FMT_NUM_HEX);
1143 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_UTIME), pr_utime, dump_timestruc);
1144 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_STIME), pr_stime, dump_timestruc);
1145 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CUTIME), pr_cutime,
1146 	    dump_timestruc);
1147 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CSTIME), pr_cstime,
1148 	    dump_timestruc);
1149 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGTRACE), pr_sigtrace,
1150 	    dump_sigset);
1151 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_FLTTRACE), pr_flttrace,
1152 	    dump_fltset);
1153 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SYSENTRY), pr_sysentry,
1154 	    dump_sysset);
1155 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SYSEXIT), pr_sysexit,
1156 	    dump_sysset);
1157 
1158 	if (data_present(state, &layout->pr_dmodel)) {
1159 		w = extract_as_word(state, &layout->pr_dmodel);
1160 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_DMODEL),
1161 		    conv_cnote_pr_dmodel(w, 0, &conv_buf.inv));
1162 	}
1163 
1164 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_TASKID), pr_taskid,
1165 	    MSG_ORIG(MSG_CNOTE_T_PR_PROJID), pr_projid);
1166 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_NZOMB), pr_nzomb,
1167 	    MSG_ORIG(MSG_CNOTE_T_PR_ZONEID), pr_zoneid);
1168 
1169 	/*
1170 	 * In order to line up all the values in a single column,
1171 	 * we would have to set vcol to a very high value, which results
1172 	 * in ugly looking output that runs off column 80. So, we use
1173 	 * two levels of vcol, one for the contents so far, and a
1174 	 * higher one for the pr_lwp sub-struct.
1175 	 */
1176 	state->ns_vcol += 5;
1177 	state->ns_t2col += 5;
1178 	state->ns_v2col += 5;
1179 
1180 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWP), pr_lwp, dump_lwpstatus);
1181 	state->ns_vcol -= 5;
1182 	state->ns_t2col -= 5;
1183 	state->ns_v2col -= 5;
1184 
1185 	indent_exit(state);
1186 }
1187 
1188 
1189 /*
1190  * Output information from prstatus_t (<sys/old_procfs.h>) structure.
1191  */
1192 static void
dump_prstatus(note_state_t * state,const char * title)1193 dump_prstatus(note_state_t *state, const char *title)
1194 {
1195 	const sl_prstatus_layout_t	*layout = state->ns_arch->prstatus;
1196 	Word				w, w2;
1197 	int				i;
1198 	union {
1199 		Conv_inv_buf_t			inv;
1200 		Conv_cnote_old_pr_flags_buf_t	flags;
1201 	} conv_buf;
1202 
1203 	indent_enter(state, title, &layout->pr_flags);
1204 
1205 	if (data_present(state, &layout->pr_flags)) {
1206 		w = extract_as_word(state, &layout->pr_flags);
1207 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAGS),
1208 		    conv_cnote_old_pr_flags(w, 0, &conv_buf.flags));
1209 	}
1210 
1211 	if (data_present(state, &layout->pr_why)) {
1212 		w = extract_as_word(state, &layout->pr_why);
1213 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHY),
1214 		    conv_cnote_pr_why(w, 0, &conv_buf.inv));
1215 
1216 
1217 		if (data_present(state, &layout->pr_what)) {
1218 			w2 = extract_as_word(state, &layout->pr_what);
1219 			print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHAT),
1220 			    conv_cnote_pr_what(w, w2, 0, &conv_buf.inv));
1221 		}
1222 	}
1223 
1224 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_INFO), pr_info, dump_siginfo);
1225 
1226 	if (data_present(state, &layout->pr_cursig)) {
1227 		w = extract_as_word(state, &layout->pr_cursig);
1228 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_CURSIG),
1229 		    conv_cnote_signal(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1230 	}
1231 
1232 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NLWP), pr_nlwp);
1233 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGPEND), pr_sigpend,
1234 	    dump_sigset);
1235 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGHOLD), pr_sighold,
1236 	    dump_sigset);
1237 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ALTSTACK), pr_altstack,
1238 	    dump_stack);
1239 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ACTION), pr_action,
1240 	    dump_sigaction);
1241 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
1242 	    MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
1243 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGRP), pr_pgrp,
1244 	    MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
1245 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_UTIME), pr_utime, dump_timestruc);
1246 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_STIME), pr_stime, dump_timestruc);
1247 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CUTIME), pr_cutime,
1248 	    dump_timestruc);
1249 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CSTIME), pr_cstime,
1250 	    dump_timestruc);
1251 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
1252 
1253 	if (data_present(state, &layout->pr_syscall)) {
1254 		w = extract_as_word(state, &layout->pr_syscall);
1255 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
1256 		    conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1257 	}
1258 
1259 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NSYSARG), pr_nsysarg);
1260 
1261 	if (data_present(state, &layout->pr_nsysarg)) {
1262 		w2 = extract_as_word(state, &layout->pr_nsysarg);
1263 		print_array(state, &layout->pr_sysarg, SL_FMT_NUM_ZHEX, w2, 1,
1264 		    MSG_ORIG(MSG_CNOTE_T_PR_SYSARG));
1265 	}
1266 
1267 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_WHO), pr_who);
1268 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWPPEND), pr_sigpend,
1269 	    dump_sigset);
1270 	PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_PR_OLDCONTEXT), pr_oldcontext);
1271 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_BRKBASE),
1272 	    &layout->pr_brkbase, SL_FMT_NUM_ZHEX,
1273 	    MSG_ORIG(MSG_CNOTE_T_PR_BRKSIZE),
1274 	    &layout->pr_brksize, SL_FMT_NUM_HEX);
1275 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_STKBASE),
1276 	    &layout->pr_stkbase, SL_FMT_NUM_ZHEX,
1277 	    MSG_ORIG(MSG_CNOTE_T_PR_STKSIZE),
1278 	    &layout->pr_stksize, SL_FMT_NUM_HEX);
1279 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_PROCESSOR), pr_processor);
1280 
1281 	if (data_present(state, &layout->pr_bind)) {
1282 		i = extract_as_sword(state, &layout->pr_bind);
1283 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_BIND),
1284 		    conv_cnote_psetid(i, CONV_FMT_DECIMAL, &conv_buf.inv));
1285 	}
1286 
1287 	PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_PR_INSTR), pr_instr);
1288 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_REG), pr_reg, dump_prgregset);
1289 
1290 	indent_exit(state);
1291 }
1292 
1293 
1294 static void
dump_lwpname(note_state_t * state,const char * title)1295 dump_lwpname(note_state_t *state, const char *title)
1296 {
1297 	const sl_prlwpname_layout_t *layout = state->ns_arch->prlwpname;
1298 
1299 	indent_enter(state, title, &layout->pr_lwpid);
1300 
1301 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_LWPID), pr_lwpid);
1302 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_LWPNAME), pr_lwpname);
1303 
1304 	indent_exit(state);
1305 }
1306 
1307 
1308 /*
1309  * Print percent from 16-bit binary fraction [0 .. 1]
1310  * Round up .01 to .1 to indicate some small percentage (the 0x7000 below).
1311  *
1312  * Note: This routine was copied from ps(1) and then modified.
1313  */
1314 static const char *
prtpct_value(note_state_t * state,const sl_field_t * fdesc,sl_fmtbuf_t buf)1315 prtpct_value(note_state_t *state, const sl_field_t *fdesc,
1316     sl_fmtbuf_t buf)
1317 {
1318 	uint_t value;		/* need 32 bits to compute with */
1319 
1320 	value = extract_as_word(state, fdesc);
1321 	value = ((value * 1000) + 0x7000) >> 15;	/* [0 .. 1000] */
1322 	if (value >= 1000)
1323 		value = 999;
1324 
1325 	(void) snprintf(buf, sizeof (sl_fmtbuf_t),
1326 	    MSG_ORIG(MSG_CNOTE_FMT_PRTPCT), value / 10, value % 10);
1327 
1328 	return (buf);
1329 }
1330 
1331 
1332 
1333 /*
1334  * Version of prtpct() used for a 2-up display of two adjacent percentages.
1335  */
1336 static void
prtpct_2up(note_state_t * state,const sl_field_t * fdesc1,const char * title1,const sl_field_t * fdesc2,const char * title2)1337 prtpct_2up(note_state_t *state, const sl_field_t *fdesc1,
1338     const char *title1, const sl_field_t *fdesc2, const char *title2)
1339 {
1340 	sl_fmtbuf_t	buf1, buf2;
1341 
1342 	if (!(data_present(state, fdesc1) &&
1343 	    data_present(state, fdesc2)))
1344 		return;
1345 
1346 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
1347 	    state->ns_vcol - state->ns_indent, title1,
1348 	    state->ns_t2col - state->ns_vcol,
1349 	    prtpct_value(state, fdesc1, buf1),
1350 	    state->ns_v2col - state->ns_t2col, title2,
1351 	    prtpct_value(state, fdesc2, buf2));
1352 }
1353 
1354 
1355 /*
1356  * The psinfo_t and prpsinfo_t structs have pr_state and pr_sname
1357  * fields that we wish to print in a 2up format. The pr_state is
1358  * an integer, while pr_sname is a single character.
1359  */
1360 static void
print_state_sname_2up(note_state_t * state,const sl_field_t * state_fdesc,const sl_field_t * sname_fdesc)1361 print_state_sname_2up(note_state_t *state,
1362     const sl_field_t *state_fdesc,
1363     const sl_field_t *sname_fdesc)
1364 {
1365 	sl_fmtbuf_t	buf1, buf2;
1366 	int		sname;
1367 
1368 	/*
1369 	 * If the field slf_offset and extent fall past the end of the
1370 	 * available data, then return without doing anything. That note
1371 	 * is from an older core file that doesn't have all the fields
1372 	 * that we know about.
1373 	 */
1374 	if (!(data_present(state, state_fdesc) &&
1375 	    data_present(state, sname_fdesc)))
1376 		return;
1377 
1378 	sname = extract_as_sword(state, sname_fdesc);
1379 	buf2[0] = sname;
1380 	buf2[1] = '\0';
1381 
1382 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
1383 	    state->ns_vcol - state->ns_indent, MSG_ORIG(MSG_CNOTE_T_PR_STATE),
1384 	    state->ns_t2col - state->ns_vcol,
1385 	    fmt_num(state, state_fdesc, SL_FMT_NUM_DEC, buf1),
1386 	    state->ns_v2col - state->ns_t2col, MSG_ORIG(MSG_CNOTE_T_PR_SNAME),
1387 	    buf2);
1388 }
1389 
1390 /*
1391  * Output information from lwpsinfo_t structure.
1392  */
1393 static void
dump_lwpsinfo(note_state_t * state,const char * title)1394 dump_lwpsinfo(note_state_t *state, const char *title)
1395 {
1396 	const sl_lwpsinfo_layout_t	*layout = state->ns_arch->lwpsinfo;
1397 	Word			w;
1398 	int32_t			i;
1399 	union {
1400 		Conv_cnote_proc_flag_buf_t	proc_flag;
1401 		Conv_inv_buf_t			inv;
1402 	} conv_buf;
1403 
1404 	indent_enter(state, title, &layout->pr_flag);
1405 
1406 	if (data_present(state, &layout->pr_flag)) {
1407 		w = extract_as_word(state, &layout->pr_flag);
1408 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAG),
1409 		    conv_cnote_proc_flag(w, 0, &conv_buf.proc_flag));
1410 	}
1411 
1412 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_LWPID), &layout->pr_lwpid,
1413 	    SL_FMT_NUM_DEC, MSG_ORIG(MSG_CNOTE_T_PR_ADDR), &layout->pr_addr,
1414 	    SL_FMT_NUM_ZHEX);
1415 	PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PR_WCHAN), pr_wchan);
1416 
1417 	if (data_present(state, &layout->pr_stype)) {
1418 		w = extract_as_word(state, &layout->pr_stype);
1419 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_STYPE),
1420 		    conv_cnote_pr_stype(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1421 	}
1422 
1423 	print_state_sname_2up(state, &layout->pr_state, &layout->pr_sname);
1424 
1425 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NICE), pr_nice);
1426 
1427 	if (data_present(state, &layout->pr_syscall)) {
1428 		w = extract_as_word(state, &layout->pr_syscall);
1429 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
1430 		    conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1431 	}
1432 
1433 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_OLDPRI), pr_oldpri,
1434 	    MSG_ORIG(MSG_CNOTE_T_PR_CPU), pr_cpu);
1435 
1436 	if (data_present(state, &layout->pr_pri) &&
1437 	    data_present(state, &layout->pr_pctcpu)) {
1438 		sl_fmtbuf_t	buf1, buf2;
1439 
1440 		dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
1441 		    state->ns_vcol - state->ns_indent,
1442 		    MSG_ORIG(MSG_CNOTE_T_PR_PRI),
1443 		    state->ns_t2col - state->ns_vcol,
1444 		    fmt_num(state, &layout->pr_pri, SL_FMT_NUM_DEC, buf1),
1445 		    state->ns_v2col - state->ns_t2col,
1446 		    MSG_ORIG(MSG_CNOTE_T_PR_PCTCPU),
1447 		    prtpct_value(state, &layout->pr_pctcpu, buf2));
1448 	}
1449 
1450 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_START), pr_start, dump_timestruc);
1451 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TIME), pr_time, dump_timestruc);
1452 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
1453 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_NAME), pr_name);
1454 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ONPRO), pr_onpro,
1455 	    MSG_ORIG(MSG_CNOTE_T_PR_BINDPRO), pr_bindpro);
1456 
1457 	if (data_present(state, &layout->pr_bindpset)) {
1458 		i = extract_as_sword(state, &layout->pr_bindpset);
1459 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_BINDPSET),
1460 		    conv_cnote_psetid(i, CONV_FMT_DECIMAL, &conv_buf.inv));
1461 	}
1462 
1463 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_LGRP), pr_lgrp);
1464 
1465 	indent_exit(state);
1466 }
1467 
1468 
1469 /*
1470  * Output information from psinfo_t structure.
1471  */
1472 static void
dump_psinfo(note_state_t * state,const char * title)1473 dump_psinfo(note_state_t *state, const char *title)
1474 {
1475 	const sl_psinfo_layout_t	*layout = state->ns_arch->psinfo;
1476 	Word				w;
1477 	union {
1478 		Conv_cnote_proc_flag_buf_t	proc_flag;
1479 		Conv_inv_buf_t			inv;
1480 	} conv_buf;
1481 
1482 	indent_enter(state, title, &layout->pr_flag);
1483 
1484 	if (data_present(state, &layout->pr_flag)) {
1485 		w = extract_as_word(state, &layout->pr_flag);
1486 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAG),
1487 		    conv_cnote_proc_flag(w, 0, &conv_buf.proc_flag));
1488 	}
1489 
1490 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NLWP), pr_nlwp);
1491 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
1492 	    MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
1493 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGID), pr_pgid,
1494 	    MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
1495 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_UID), pr_uid,
1496 	    MSG_ORIG(MSG_CNOTE_T_PR_EUID), pr_euid);
1497 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_GID), pr_gid,
1498 	    MSG_ORIG(MSG_CNOTE_T_PR_EGID), pr_egid);
1499 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ADDR), &layout->pr_addr,
1500 	    SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_PR_SIZE), &layout->pr_size,
1501 	    SL_FMT_NUM_HEX);
1502 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_RSSIZE),
1503 	    &layout->pr_rssize, SL_FMT_NUM_HEX, MSG_ORIG(MSG_CNOTE_T_PR_TTYDEV),
1504 	    &layout->pr_ttydev, SL_FMT_NUM_DEC);
1505 	prtpct_2up(state, &layout->pr_pctcpu, MSG_ORIG(MSG_CNOTE_T_PR_PCTCPU),
1506 	    &layout->pr_pctmem, MSG_ORIG(MSG_CNOTE_T_PR_PCTMEM));
1507 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_START), pr_start, dump_timestruc);
1508 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TIME), pr_time, dump_timestruc);
1509 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CTIME), pr_ctime, dump_timestruc);
1510 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_FNAME), pr_fname);
1511 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_PSARGS), pr_psargs);
1512 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_WSTAT), &layout->pr_wstat,
1513 	    SL_FMT_NUM_HEX, MSG_ORIG(MSG_CNOTE_T_PR_ARGC), &layout->pr_argc,
1514 	    SL_FMT_NUM_DEC);
1515 	PRINT_ZHEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ARGV), pr_argv,
1516 	    MSG_ORIG(MSG_CNOTE_T_PR_ENVP), pr_envp);
1517 
1518 	if (data_present(state, &layout->pr_dmodel)) {
1519 		w = extract_as_word(state, &layout->pr_dmodel);
1520 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_DMODEL),
1521 		    conv_cnote_pr_dmodel(w, 0, &conv_buf.inv));
1522 	}
1523 
1524 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_TASKID), pr_taskid,
1525 	    MSG_ORIG(MSG_CNOTE_T_PR_PROJID), pr_projid);
1526 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_NZOMB), pr_nzomb,
1527 	    MSG_ORIG(MSG_CNOTE_T_PR_POOLID), pr_poolid);
1528 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ZONEID), pr_zoneid,
1529 	    MSG_ORIG(MSG_CNOTE_T_PR_CONTRACT), pr_contract);
1530 
1531 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWP), pr_lwp, dump_lwpsinfo);
1532 
1533 	indent_exit(state);
1534 }
1535 
1536 /*
1537  * Output information from prpsinfo_t structure.
1538  */
1539 static void
dump_prpsinfo(note_state_t * state,const char * title)1540 dump_prpsinfo(note_state_t *state, const char *title)
1541 {
1542 	const sl_prpsinfo_layout_t	*layout = state->ns_arch->prpsinfo;
1543 	Word				w;
1544 	union {
1545 		Conv_cnote_proc_flag_buf_t	proc_flag;
1546 		Conv_inv_buf_t			inv;
1547 	} conv_buf;
1548 
1549 	indent_enter(state, title, &layout->pr_state);
1550 
1551 	print_state_sname_2up(state, &layout->pr_state, &layout->pr_sname);
1552 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ZOMB), pr_zomb,
1553 	    MSG_ORIG(MSG_CNOTE_T_PR_NICE), pr_nice);
1554 
1555 	if (data_present(state, &layout->pr_flag)) {
1556 		w = extract_as_word(state, &layout->pr_flag);
1557 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAG),
1558 		    conv_cnote_proc_flag(w, 0, &conv_buf.proc_flag));
1559 	}
1560 
1561 
1562 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_UID), pr_uid,
1563 	    MSG_ORIG(MSG_CNOTE_T_PR_GID), pr_gid);
1564 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
1565 	    MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
1566 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGRP), pr_pgrp,
1567 	    MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
1568 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ADDR), &layout->pr_addr,
1569 	    SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_PR_SIZE), &layout->pr_size,
1570 	    SL_FMT_NUM_HEX);
1571 	PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RSSIZE), pr_rssize,
1572 	    MSG_ORIG(MSG_CNOTE_T_PR_WCHAN), pr_wchan);
1573 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_START), pr_start, dump_timestruc);
1574 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TIME), pr_time, dump_timestruc);
1575 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PRI), pr_pri,
1576 	    MSG_ORIG(MSG_CNOTE_T_PR_OLDPRI), pr_oldpri);
1577 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_CPU), pr_cpu);
1578 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_OTTYDEV), pr_ottydev,
1579 	    MSG_ORIG(MSG_CNOTE_T_PR_LTTYDEV), pr_lttydev);
1580 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
1581 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_FNAME), pr_fname);
1582 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_PSARGS), pr_psargs);
1583 
1584 	if (data_present(state, &layout->pr_syscall)) {
1585 		w = extract_as_word(state, &layout->pr_syscall);
1586 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
1587 		    conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1588 	}
1589 
1590 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CTIME), pr_ctime, dump_timestruc);
1591 	PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_BYSIZE), pr_bysize,
1592 	    MSG_ORIG(MSG_CNOTE_T_PR_BYRSSIZE), pr_byrssize);
1593 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ARGC), &layout->pr_argc,
1594 	    SL_FMT_NUM_DEC, MSG_ORIG(MSG_CNOTE_T_PR_ARGV), &layout->pr_argv,
1595 	    SL_FMT_NUM_ZHEX);
1596 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ENVP), &layout->pr_envp,
1597 	    SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_PR_WSTAT), &layout->pr_wstat,
1598 	    SL_FMT_NUM_HEX);
1599 	prtpct_2up(state, &layout->pr_pctcpu, MSG_ORIG(MSG_CNOTE_T_PR_PCTCPU),
1600 	    &layout->pr_pctmem, MSG_ORIG(MSG_CNOTE_T_PR_PCTMEM));
1601 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_EUID), pr_euid,
1602 	    MSG_ORIG(MSG_CNOTE_T_PR_EGID), pr_egid);
1603 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_ASLWPID), pr_aslwpid);
1604 
1605 	if (data_present(state, &layout->pr_dmodel)) {
1606 		w = extract_as_word(state, &layout->pr_dmodel);
1607 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_DMODEL),
1608 		    conv_cnote_pr_dmodel(w, 0, &conv_buf.inv));
1609 	}
1610 
1611 	indent_exit(state);
1612 }
1613 
1614 
1615 /*
1616  * Output information from prcred_t structure.
1617  */
1618 static void
dump_prcred(note_state_t * state,const char * title)1619 dump_prcred(note_state_t *state, const char *title)
1620 {
1621 	const sl_prcred_layout_t *layout = state->ns_arch->prcred;
1622 	Word		ngroups;
1623 
1624 	indent_enter(state, title, &layout->pr_euid);
1625 
1626 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_EUID), pr_euid,
1627 	    MSG_ORIG(MSG_CNOTE_T_PR_RUID), pr_ruid);
1628 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_SUID), pr_suid,
1629 	    MSG_ORIG(MSG_CNOTE_T_PR_EGID), pr_egid);
1630 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RGID), pr_rgid,
1631 	    MSG_ORIG(MSG_CNOTE_T_PR_SGID), pr_sgid);
1632 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NGROUPS), pr_ngroups);
1633 
1634 	if (data_present(state, &layout->pr_ngroups)) {
1635 		ngroups = extract_as_word(state, &layout->pr_ngroups);
1636 		print_array(state, &layout->pr_groups, SL_FMT_NUM_DEC, ngroups,
1637 		    0, MSG_ORIG(MSG_CNOTE_T_PR_GROUPS));
1638 	}
1639 
1640 	indent_exit(state);
1641 }
1642 
1643 
1644 /*
1645  * Output information from prpriv_t structure.
1646  */
1647 static void
dump_prpriv(note_state_t * state,const char * title)1648 dump_prpriv(note_state_t *state, const char *title)
1649 {
1650 	const sl_prpriv_layout_t *layout = state->ns_arch->prpriv;
1651 	Word		nsets;
1652 
1653 	indent_enter(state, title, &layout->pr_nsets);
1654 
1655 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NSETS), pr_nsets);
1656 	PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PR_SETSIZE), pr_setsize);
1657 	PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PR_INFOSIZE), pr_infosize);
1658 
1659 	if (data_present(state, &layout->pr_nsets)) {
1660 		nsets = extract_as_word(state, &layout->pr_nsets);
1661 		print_array(state, &layout->pr_sets, SL_FMT_NUM_ZHEX, nsets,
1662 		    0, MSG_ORIG(MSG_CNOTE_T_PR_SETS));
1663 	}
1664 
1665 	indent_exit(state);
1666 }
1667 
1668 static void
dump_prfdinfo(note_state_t * state,const char * title)1669 dump_prfdinfo(note_state_t *state, const char *title)
1670 {
1671 	const sl_prfdinfo_layout_t *layout = state->ns_arch->prfdinfo;
1672 	char buf[1024];
1673 	uint32_t fileflags, mode;
1674 
1675 	indent_enter(state, title, &layout->pr_fd);
1676 
1677 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_FD), pr_fd);
1678 	mode = extract_as_word(state, &layout->pr_mode);
1679 
1680 	print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_MODE),
1681 	    conv_cnote_filemode(mode, 0, buf, sizeof (buf)));
1682 
1683 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_UID), pr_uid,
1684 	    MSG_ORIG(MSG_CNOTE_T_PR_GID), pr_gid);
1685 
1686 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_MAJOR), pr_major,
1687 	    MSG_ORIG(MSG_CNOTE_T_PR_MINOR), pr_minor);
1688 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RMAJOR), pr_rmajor,
1689 	    MSG_ORIG(MSG_CNOTE_T_PR_RMINOR), pr_rminor);
1690 
1691 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_INO), pr_ino);
1692 
1693 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_SIZE), pr_size,
1694 	    MSG_ORIG(MSG_CNOTE_T_PR_OFFSET), pr_offset);
1695 
1696 	fileflags = extract_as_word(state, &layout->pr_fileflags);
1697 
1698 	print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FILEFLAGS),
1699 	    conv_cnote_fileflags(fileflags, 0, buf, sizeof (buf)));
1700 
1701 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_FDFLAGS), pr_fdflags);
1702 
1703 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_PATH), pr_path);
1704 
1705 	indent_exit(state);
1706 }
1707 
1708 /*
1709  * Output information from priv_impl_info_t structure.
1710  */
1711 static void
dump_priv_impl_info(note_state_t * state,const char * title)1712 dump_priv_impl_info(note_state_t *state, const char *title)
1713 {
1714 	const sl_priv_impl_info_layout_t *layout;
1715 
1716 	layout = state->ns_arch->priv_impl_info;
1717 	indent_enter(state, title, &layout->priv_headersize);
1718 
1719 	PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PRIV_HEADERSIZE), priv_headersize,
1720 	    MSG_ORIG(MSG_CNOTE_T_PRIV_FLAGS), priv_flags);
1721 
1722 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PRIV_NSETS),
1723 	    &layout->priv_nsets, SL_FMT_NUM_DEC,
1724 	    MSG_ORIG(MSG_CNOTE_T_PRIV_SETSIZE), &layout->priv_setsize,
1725 	    SL_FMT_NUM_HEX);
1726 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PRIV_MAX), &layout->priv_max,
1727 	    SL_FMT_NUM_DEC, MSG_ORIG(MSG_CNOTE_T_PRIV_INFOSIZE),
1728 	    &layout->priv_infosize, SL_FMT_NUM_HEX);
1729 	PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PRIV_GLOBALINFOSIZE),
1730 	    priv_globalinfosize);
1731 
1732 	indent_exit(state);
1733 }
1734 
1735 
1736 /*
1737  * Dump information from an asrset_t array. This data
1738  * structure is specific to sparcv9, and does not appear
1739  * on any other platform.
1740  *
1741  * asrset_t is a simple array, defined in <sys/regset.h> as
1742  *	typedef	int64_t	asrset_t[16];	 %asr16 - > %asr31
1743  *
1744  * As such, we do not make use of the struct_layout facilities
1745  * for this routine.
1746  */
1747 static void
dump_asrset(note_state_t * state,const char * title)1748 dump_asrset(note_state_t *state, const char *title)
1749 {
1750 	static const sl_field_t ftemplate = { 0, sizeof (int64_t), 16, 0 };
1751 	sl_field_t	fdesc1, fdesc2;
1752 	sl_fmtbuf_t	buf1, buf2;
1753 	char		index1[MAXNDXSIZE * 2], index2[MAXNDXSIZE * 2];
1754 	Word		w, nelts;
1755 
1756 	fdesc1 = fdesc2 =  ftemplate;
1757 
1758 	/* We expect 16 values, but will print whatever is actually there */
1759 	nelts = state->ns_len / ftemplate.slf_eltlen;
1760 	if (nelts == 0)
1761 		return;
1762 
1763 	indent_enter(state, title, &fdesc1);
1764 
1765 	for (w = 0; w < nelts; ) {
1766 		(void) snprintf(index1, sizeof (index1),
1767 		    MSG_ORIG(MSG_FMT_ASRINDEX), w + 16);
1768 
1769 		if (w == (nelts - 1)) {
1770 			/* One last register is left */
1771 			dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE),
1772 			    INDENT, state->ns_vcol - state->ns_indent, index1,
1773 			    fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1));
1774 			fdesc1.slf_offset += fdesc1.slf_eltlen;
1775 			w++;
1776 			continue;
1777 		}
1778 
1779 		/* There are at least 2 more registers left. Show 2 up */
1780 		(void) snprintf(index2, sizeof (index2),
1781 		    MSG_ORIG(MSG_FMT_ASRINDEX), w + 17);
1782 
1783 		fdesc2.slf_offset = fdesc1.slf_offset + fdesc1.slf_eltlen;
1784 		dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
1785 		    state->ns_vcol - state->ns_indent, index1,
1786 		    state->ns_t2col - state->ns_vcol,
1787 		    fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1),
1788 		    state->ns_v2col - state->ns_t2col, index2,
1789 		    fmt_num(state, &fdesc2, SL_FMT_NUM_ZHEX, buf2));
1790 		fdesc1.slf_offset += 2 * fdesc1.slf_eltlen;
1791 		w += 2;
1792 	}
1793 
1794 	indent_exit(state);
1795 }
1796 
1797 static void
dump_upanic(note_state_t * state,const char * title)1798 dump_upanic(note_state_t *state, const char *title)
1799 {
1800 	const sl_prupanic_layout_t *layout = state->ns_arch->prupanic;
1801 	Conv_upanic_buf_t inv;
1802 	Word w;
1803 
1804 	indent_enter(state, title, &layout->pru_version);
1805 	w = extract_as_word(state, &layout->pru_version);
1806 	if (w != PRUPANIC_VERSION_1) {
1807 		PRINT_DEC(MSG_INTL(MSG_NOTE_BAD_UPANIC_VER), pru_version);
1808 		dump_hex_bytes(state->ns_data, state->ns_len, state->ns_indent,
1809 		    4, 3);
1810 	} else {
1811 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PRU_VERSION), pru_version);
1812 		w = extract_as_word(state, &layout->pru_flags);
1813 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PRU_FLAGS),
1814 		    conv_prupanic(w, 0, &inv));
1815 
1816 		if ((w & PRUPANIC_FLAG_MSG_VALID) != 0) {
1817 			/*
1818 			 * We have a message that is _probably_ a text string,
1819 			 * but the interface allows for arbitrary data. The only
1820 			 * guarantee is that someone using this is probably up
1821 			 * to no good. As a result, we basically try to print
1822 			 * this as a string, but in the face of certain types of
1823 			 * data, we hex escape it.
1824 			 */
1825 			print_strbuf(state, MSG_ORIG(MSG_CNOTE_T_PRU_DATA),
1826 			    &layout->pru_data);
1827 		}
1828 	}
1829 }
1830 
1831 corenote_ret_t
corenote(Half mach,int do_swap,Word type,const char * desc,Word descsz)1832 corenote(Half mach, int do_swap, Word type,
1833     const char *desc, Word descsz)
1834 {
1835 	note_state_t		state;
1836 
1837 	/*
1838 	 * Get the per-architecture layout definition
1839 	 */
1840 	state.ns_mach = mach;
1841 	state.ns_arch = sl_mach(state.ns_mach);
1842 	if (sl_mach(state.ns_mach) == NULL)
1843 		return (CORENOTE_R_BADARCH);
1844 
1845 	state.ns_swap = do_swap;
1846 	state.ns_indent = 4;
1847 	state.ns_t2col = state.ns_v2col = 0;
1848 	state.ns_data = desc;
1849 	state.ns_len = descsz;
1850 
1851 	switch (type) {
1852 	case NT_PRSTATUS:		/* prstatus_t <sys/old_procfs.h> */
1853 		state.ns_vcol = 26;
1854 		state.ns_t2col = 46;
1855 		state.ns_v2col = 60;
1856 		dump_prstatus(&state, MSG_ORIG(MSG_CNOTE_DESC_PRSTATUS_T));
1857 		return (CORENOTE_R_OK);
1858 
1859 	case NT_PRFPREG:		/* prfpregset_t	<sys/procfs_isa.h> */
1860 		return (CORENOTE_R_OK_DUMP);
1861 
1862 	case NT_PRPSINFO:		/* prpsinfo_t	<sys/old_procfs.h> */
1863 		state.ns_vcol = 20;
1864 		state.ns_t2col = 41;
1865 		state.ns_v2col = 54;
1866 		dump_prpsinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PRPSINFO_T));
1867 		return (CORENOTE_R_OK);
1868 
1869 	case NT_PRXREG:			/* prxregset_t <sys/procfs_isa.h> */
1870 		return (CORENOTE_R_OK_DUMP);
1871 
1872 	case NT_PLATFORM:		/* string from sysinfo(SI_PLATFORM) */
1873 		dbg_print(0, MSG_ORIG(MSG_NOTE_DESC));
1874 		dbg_print(0, MSG_ORIG(MSG_FMT_INDENT), safe_str(desc, descsz));
1875 		return (CORENOTE_R_OK);
1876 
1877 	case NT_AUXV:			/* auxv_t array	<sys/auxv.h> */
1878 		state.ns_vcol = 18;
1879 		dump_auxv(&state, MSG_ORIG(MSG_CNOTE_DESC_AUXV_T));
1880 		return (CORENOTE_R_OK);
1881 
1882 	case NT_GWINDOWS:		/* gwindows_t SPARC only */
1883 		return (CORENOTE_R_OK_DUMP);
1884 
1885 	case NT_ASRS:			/* asrset_t <sys/regset> sparcv9 only */
1886 		state.ns_vcol = 18;
1887 		state.ns_t2col = 38;
1888 		state.ns_v2col = 46;
1889 		dump_asrset(&state, MSG_ORIG(MSG_CNOTE_DESC_ASRSET_T));
1890 		return (CORENOTE_R_OK);
1891 
1892 	case NT_LDT:			/* ssd array <sys/sysi86.h> IA32 only */
1893 		return (CORENOTE_R_OK_DUMP);
1894 
1895 	case NT_PSTATUS:		/* pstatus_t <sys/procfs.h> */
1896 		state.ns_vcol = 22;
1897 		state.ns_t2col = 42;
1898 		state.ns_v2col = 54;
1899 		dump_pstatus(&state, MSG_ORIG(MSG_CNOTE_DESC_PSTATUS_T));
1900 		return (CORENOTE_R_OK);
1901 
1902 	case NT_PSINFO:			/* psinfo_t <sys/procfs.h> */
1903 		state.ns_vcol = 25;
1904 		state.ns_t2col = 45;
1905 		state.ns_v2col = 58;
1906 		dump_psinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PSINFO_T));
1907 		return (CORENOTE_R_OK);
1908 
1909 	case NT_PRCRED:			/* prcred_t <sys/procfs.h> */
1910 		state.ns_vcol = 20;
1911 		state.ns_t2col = 34;
1912 		state.ns_v2col = 44;
1913 		dump_prcred(&state, MSG_ORIG(MSG_CNOTE_DESC_PRCRED_T));
1914 		return (CORENOTE_R_OK);
1915 
1916 	case NT_UTSNAME:		/* struct utsname <sys/utsname.h> */
1917 		state.ns_vcol = 18;
1918 		dump_utsname(&state, MSG_ORIG(MSG_CNOTE_DESC_STRUCT_UTSNAME));
1919 		return (CORENOTE_R_OK);
1920 
1921 	case NT_LWPSTATUS:		/* lwpstatus_t <sys/procfs.h> */
1922 		state.ns_vcol = 24;
1923 		state.ns_t2col = 44;
1924 		state.ns_v2col = 54;
1925 		dump_lwpstatus(&state, MSG_ORIG(MSG_CNOTE_DESC_LWPSTATUS_T));
1926 		return (CORENOTE_R_OK);
1927 
1928 	case NT_LWPSINFO:		/* lwpsinfo_t <sys/procfs.h> */
1929 		state.ns_vcol = 22;
1930 		state.ns_t2col = 42;
1931 		state.ns_v2col = 54;
1932 		dump_lwpsinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_LWPSINFO_T));
1933 		return (CORENOTE_R_OK);
1934 
1935 	case NT_PRPRIV:			/* prpriv_t <sys/procfs.h> */
1936 		state.ns_vcol = 21;
1937 		state.ns_t2col = 34;
1938 		state.ns_v2col = 38;
1939 		dump_prpriv(&state, MSG_ORIG(MSG_CNOTE_DESC_PRPRIV_T));
1940 		return (CORENOTE_R_OK);
1941 
1942 	case NT_PRPRIVINFO:		/* priv_impl_info_t <sys/priv.h> */
1943 		state.ns_vcol = 29;
1944 		state.ns_t2col = 41;
1945 		state.ns_v2col = 56;
1946 		dump_priv_impl_info(&state,
1947 		    MSG_ORIG(MSG_CNOTE_DESC_PRIV_IMPL_INFO_T));
1948 		return (CORENOTE_R_OK);
1949 
1950 	case NT_CONTENT:		/* core_content_t <sys/corectl.h> */
1951 		if (sizeof (core_content_t) > descsz)
1952 			return (CORENOTE_R_BADDATA);
1953 		{
1954 			static sl_field_t fdesc = { 0, 8, 0, 0 };
1955 			Conv_cnote_cc_content_buf_t conv_buf;
1956 			core_content_t content;
1957 
1958 			state.ns_vcol = 8;
1959 			indent_enter(&state,
1960 			    MSG_ORIG(MSG_CNOTE_DESC_CORE_CONTENT_T),
1961 			    &fdesc);
1962 			content = extract_as_lword(&state, &fdesc);
1963 			print_str(&state, MSG_ORIG(MSG_STR_EMPTY),
1964 			    conv_cnote_cc_content(content, 0, &conv_buf));
1965 			indent_exit(&state);
1966 		}
1967 		return (CORENOTE_R_OK);
1968 
1969 	case NT_ZONENAME:		/* string from getzonenamebyid(3C) */
1970 		dbg_print(0, MSG_ORIG(MSG_NOTE_DESC));
1971 		dbg_print(0, MSG_ORIG(MSG_FMT_INDENT), safe_str(desc, descsz));
1972 		return (CORENOTE_R_OK);
1973 
1974 
1975 	case NT_FDINFO:
1976 		state.ns_vcol = 22;
1977 		state.ns_t2col = 41;
1978 		state.ns_v2col = 54;
1979 		dump_prfdinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PRFDINFO_T));
1980 		return (CORENOTE_R_OK);
1981 
1982 	case NT_SPYMASTER:
1983 		state.ns_vcol = 25;
1984 		state.ns_t2col = 45;
1985 		state.ns_v2col = 58;
1986 		dump_psinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PSINFO_T));
1987 		return (CORENOTE_R_OK);
1988 
1989 	case NT_SECFLAGS:
1990 		state.ns_vcol = 23;
1991 		state.ns_t2col = 41;
1992 		state.ns_v2col = 54;
1993 		dump_secflags(&state, MSG_ORIG(MSG_CNOTE_DESC_PRSECFLAGS_T));
1994 		return (CORENOTE_R_OK);
1995 
1996 	case NT_LWPNAME:
1997 		state.ns_vcol = 20;
1998 		dump_lwpname(&state, MSG_ORIG(MSG_CNOTE_DESC_PRLWPNAME_T));
1999 		return (CORENOTE_R_OK);
2000 
2001 	case NT_UPANIC:
2002 		state.ns_vcol = 23;
2003 		dump_upanic(&state, MSG_ORIG(MSG_CNOTE_DESC_PRUPANIC_T));
2004 		return (CORENOTE_R_OK);
2005 	}
2006 
2007 	return (CORENOTE_R_BADTYPE);
2008 }
2009