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