xref: /illumos-gate/usr/src/cmd/sgs/elfdump/common/corenote.c (revision a6f561b4aee75d0d028e7b36b151c8ed8a86bc76)
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  */
29 
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <sys/types.h>
34 #include <unistd.h>
35 #include <sys/corectl.h>
36 #include <msg.h>
37 #include <_elfdump.h>
38 #include <struct_layout.h>
39 #include <conv.h>
40 
41 
42 /*
43  * This module contains the code that displays data from the note
44  * sections found in Solaris core files. The format of these
45  * note sections are described in the core(4) manpage.
46  */
47 
48 
49 
50 
51 /*
52  * Much of the code in this file uses the "%*s" format to set
53  * the left margin indentation. This macro combines the indent
54  * integer argument and the NULL string that follows it.
55  */
56 #define	INDENT state->ns_indent, MSG_ORIG(MSG_STR_EMPTY)
57 
58 /*
59  * Indent unit, used for each nesting
60  */
61 #define	INDENT_STEP 4
62 
63 /*
64  * The PRINT_ macros are convenience wrappers on print_num(),
65  * print_subtype(), and print_strbuf(). They reduce code
66  * clutter by hiding the boilerplate arguments.
67  *
68  * Assumptions:
69  *	- A variable named "layout" exists in the compilation
70  *		environment, referencing the layout information for the
71  *		current type.
72  *	- The variable "state" references the current note state.
73  */
74 #define	PRINT_DEC(_title, _field) \
75 	print_num(state, _title, &layout->_field, SL_FMT_NUM_DEC)
76 #define	PRINT_DEC_2UP(_title1, _field1, _title2, _field2) \
77 	print_num_2up(state, _title1, &layout->_field1, SL_FMT_NUM_DEC, \
78 	    _title2, &layout->_field2, SL_FMT_NUM_DEC)
79 #define	PRINT_HEX(_title, _field) \
80 	print_num(state, _title, &layout->_field, SL_FMT_NUM_HEX)
81 #define	PRINT_HEX_2UP(_title1, _field1, _title2, _field2) \
82 	print_num_2up(state, _title1, &layout->_field1, SL_FMT_NUM_HEX, \
83 	    _title2, &layout->_field2, SL_FMT_NUM_HEX)
84 #define	PRINT_ZHEX(_title, _field) \
85 	print_num(state, _title, &layout->_field, SL_FMT_NUM_ZHEX)
86 #define	PRINT_ZHEX_2UP(_title1, _field1, _title2, _field2) \
87 	print_num_2up(state, _title1, &layout->_field1, SL_FMT_NUM_ZHEX, \
88 	    _title2, &layout->_field2, SL_FMT_NUM_ZHEX)
89 #define	PRINT_SUBTYPE(_title, _field, _func) \
90 	print_subtype(state, _title, &layout->_field, _func)
91 #define	PRINT_STRBUF(_title, _field) \
92 	print_strbuf(state, _title, &layout->_field)
93 
94 
95 
96 /*
97  * Structure used to maintain state data for a core note, or a subregion
98  * (sub-struct) of a core note. These values would otherwise need to be
99  * passed to nearly every routine.
100  */
101 typedef struct {
102 	Half		ns_mach;	/* ELF machine type of core file */
103 	const sl_arch_layout_t *ns_arch; /* structure layout def for mach */
104 	int		ns_swap;	/* True if byte swapping is needed */
105 	int		ns_indent;	/* Left margin indentation */
106 	int		ns_vcol;	/* Column where value starts */
107 	int		ns_t2col;	/* Column where 2up title starts */
108 	int		ns_v2col;	/* Column where 2up value starts */
109 	const char	*ns_data;	/* Pointer to struct data area */
110 	Word		ns_len;		/* Length of struct data area */
111 } note_state_t;
112 
113 /*
114  * Standard signature for a dump function used to process a note
115  * or a sub-structure within a note.
116  */
117 typedef void (* dump_func_t)(note_state_t *state, const char *title);
118 
119 
120 
121 
122 
123 
124 /*
125  * Some core notes contain string buffers of fixed size
126  * that are expected to contain NULL terminated strings.
127  * If the NULL is there, we can print these strings directly.
128  * However, the potential exists for a corrupt file to have
129  * a non-terminated buffer. This routine examines the given
130  * string, and if the string is terminated, the string itself
131  * is returned. Otherwise, it is copied to a static buffer,
132  * and a pointer to the buffer is returned.
133  */
134 static const char *
135 safe_str(const char *str, size_t n)
136 {
137 	static char	buf[512];
138 	char		*s;
139 	size_t		i;
140 
141 	if (n == 0)
142 		return (MSG_ORIG(MSG_STR_EMPTY));
143 
144 	for (i = 0; i < n; i++)
145 		if (str[i] == '\0')
146 			return (str);
147 
148 	i = (n >= sizeof (buf)) ? (sizeof (buf) - 4) : (n - 1);
149 	(void) memcpy(buf, str, i);
150 	s = buf + i;
151 	if (n >= sizeof (buf)) {
152 		*s++ = '.';
153 		*s++ = '.';
154 		*s++ = '.';
155 	}
156 	*s = '\0';
157 	return (buf);
158 }
159 
160 /*
161  * Convenience wrappers on top of the corresponding sl_XXX() functions.
162  */
163 static Word
164 extract_as_word(note_state_t *state, const sl_field_t *fdesc)
165 {
166 	return (sl_extract_as_word(state->ns_data, state->ns_swap, fdesc));
167 }
168 static Word
169 extract_as_lword(note_state_t *state, const sl_field_t *fdesc)
170 {
171 	return (sl_extract_as_lword(state->ns_data, state->ns_swap, fdesc));
172 }
173 static int
174 extract_as_sword(note_state_t *state, const sl_field_t *fdesc)
175 {
176 	return (sl_extract_as_sword(state->ns_data, state->ns_swap, fdesc));
177 }
178 static const char *
179 fmt_num(note_state_t *state, const sl_field_t *fdesc,
180     sl_fmt_num_t fmt_type, sl_fmtbuf_t buf)
181 {
182 	return (sl_fmt_num(state->ns_data, state->ns_swap, fdesc,
183 	    fmt_type, buf));
184 }
185 
186 
187 /*
188  * Return true of the data for the specified field is available.
189  */
190 inline static int
191 data_present(note_state_t *state, const sl_field_t *fdesc)
192 {
193 	return ((fdesc->slf_offset + fdesc->slf_eltlen) <= state->ns_len);
194 }
195 
196 /*
197  * indent_enter/exit are used to start/end output for a subitem.
198  * On entry, a title is output, and the indentation level is raised
199  * by one unit. On exit, the indentation level is restrored to its
200  * previous value.
201  */
202 static void
203 indent_enter(note_state_t *state, const char *title,
204     const sl_field_t *first_fdesc)
205 {
206 	/*
207 	 * If the first field offset and extent fall past the end of the
208 	 * available data, then return without printing a title. That note
209 	 * is from an older core file that doesn't have all the fields
210 	 * that we know about.
211 	 */
212 	if (data_present(state, first_fdesc))
213 		dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_TITLE), INDENT, title);
214 
215 	state->ns_indent += INDENT_STEP;
216 }
217 static void
218 indent_exit(note_state_t *state)
219 {
220 	state->ns_indent -= INDENT_STEP;
221 }
222 
223 
224 /*
225  * print_num outputs a field on one line, in the format:
226  *
227  *	title: value
228  */
229 static void
230 print_num(note_state_t *state, const char *title,
231     const sl_field_t *fdesc, sl_fmt_num_t fmt_type)
232 {
233 	sl_fmtbuf_t	buf;
234 
235 	/*
236 	 * If the field offset and extent fall past the end of the
237 	 * available data, then return without doing anything. That note
238 	 * is from an older core file that doesn't have all the fields
239 	 * that we know about.
240 	 */
241 	if (!data_present(state, fdesc))
242 		return;
243 
244 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE), INDENT,
245 	    state->ns_vcol - state->ns_indent, title,
246 	    fmt_num(state, fdesc, fmt_type, buf));
247 }
248 
249 /*
250  * print_num_2up outputs two fields on one line, in the format:
251  *
252  *	title1: value1	title2: value2
253  */
254 static void
255 print_num_2up(note_state_t *state, const char *title1,
256     const sl_field_t *fdesc1, sl_fmt_num_t fmt_type1, const char *title2,
257     const sl_field_t *fdesc2, sl_fmt_num_t fmt_type2)
258 {
259 	sl_fmtbuf_t	buf1, buf2;
260 
261 	/*
262 	 * If the field offset and extent fall past the end of the
263 	 * available data, then return without doing anything. That note
264 	 * is from an older core file that doesn't have all the fields
265 	 * that we know about.
266 	 */
267 	if (!(data_present(state, fdesc1) &&
268 	    data_present(state, fdesc2)))
269 		return;
270 
271 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
272 	    state->ns_vcol - state->ns_indent, title1,
273 	    state->ns_t2col - state->ns_vcol,
274 	    fmt_num(state, fdesc1, fmt_type1, buf1),
275 	    state->ns_v2col - state->ns_t2col, title2,
276 	    fmt_num(state, fdesc2, fmt_type2, buf2));
277 }
278 
279 /*
280  * print_strbuf outputs a fixed sized character buffer field
281  * on one line, in the format:
282  *
283  *	title: value
284  */
285 static void
286 print_strbuf(note_state_t *state, const char *title,
287     const sl_field_t *fdesc)
288 {
289 	Word	n;
290 
291 	/*
292 	 * If we are past the end of the data area, then return
293 	 * without doing anything. That note is from an older core
294 	 * file that doesn't have all the fields that we know about.
295 	 *
296 	 * Note that we are willing to accept a partial buffer,
297 	 * so we don't use data_present() for this test.
298 	 */
299 	if (fdesc->slf_offset >= state->ns_len)
300 		return;
301 
302 	/*
303 	 * We expect the full buffer to be present, but if there
304 	 * is less than that, we will still proceed. The use of safe_str()
305 	 * protects us from the effect of printing garbage data.
306 	 */
307 	n = state->ns_len - fdesc->slf_offset;
308 	if (n > fdesc->slf_nelts)
309 		n = fdesc->slf_nelts;
310 
311 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE), INDENT,
312 	    state->ns_vcol - state->ns_indent,
313 	    title, safe_str(fdesc->slf_offset + state->ns_data, n));
314 }
315 
316 /*
317  * print_str outputs an arbitrary string value item
318  * on one line, in the format:
319  *
320  *	title: str
321  */
322 static void
323 print_str(note_state_t *state, const char *title, const char *str)
324 {
325 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE), INDENT,
326 	    state->ns_vcol - state->ns_indent, title, str);
327 }
328 
329 /*
330  * Used when one dump function needs to call another dump function
331  * in order to display a subitem. This routine constructs a state
332  * block for the sub-region, and then calls the dump function with it.
333  * This limits the amount of data visible to the sub-function to that
334  * for the sub-item.
335  */
336 static void
337 print_subtype(note_state_t *state, const char *title,
338     const sl_field_t *fdesc, dump_func_t dump_func)
339 {
340 	note_state_t sub_state;
341 
342 	/*
343 	 * If there is no data for the sub-item, return immediately.
344 	 * Partial data is left to the dump function to handle,
345 	 * as that can be a sign of an older core file with less data,
346 	 * which can still be interpreted.
347 	 */
348 	if (fdesc->slf_offset >= state->ns_len)
349 		return;
350 
351 	/*
352 	 * Construct a state block that reflects the sub-item
353 	 */
354 	sub_state = *state;
355 	sub_state.ns_data += fdesc->slf_offset;
356 	sub_state.ns_len -= fdesc->slf_offset;
357 	if (sub_state.ns_len > fdesc->slf_eltlen)
358 		sub_state.ns_len = fdesc->slf_eltlen;
359 
360 	(* dump_func)(&sub_state, title);
361 }
362 
363 
364 /*
365  * Output a sequence of array elements, giving each
366  * element an index, in the format:
367  *
368  *	[ndx] value
369  *
370  * entry:
371  *	state - Current state
372  *	base_desc - Field descriptor for 1st element of array
373  *	nelts - # of array elements to display
374  *	check_nelts - If True (1), nelts is clipped to fdesc->slf_nelts.
375  *		If False (1), nelts is not clipped.
376  *	title - Name of array
377  */
378 static void
379 print_array(note_state_t *state, const sl_field_t *base_desc,
380     sl_fmt_num_t fmt_type, int nelts, int check_nelts, const char *title)
381 {
382 	char		index1[MAXNDXSIZE], index2[MAXNDXSIZE];
383 	int		i;
384 	sl_field_t	fdesc1, fdesc2;
385 
386 	if (check_nelts && (check_nelts > base_desc->slf_nelts))
387 		nelts = base_desc->slf_nelts;
388 	if (nelts == 0)
389 		return;
390 
391 	indent_enter(state, title, base_desc);
392 
393 	fdesc1 = fdesc2 = *base_desc;
394 	for (i = 0; i < nelts; ) {
395 		if (i == (nelts - 1)) {
396 			/*  One final value is left  */
397 			if (!data_present(state, &fdesc1))
398 				break;
399 			(void) snprintf(index1, sizeof (index1),
400 			    MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(i));
401 			print_num(state, index1, &fdesc1, fmt_type);
402 			fdesc1.slf_offset += fdesc1.slf_eltlen;
403 			i++;
404 			continue;
405 		}
406 
407 		/* There are at least 2 items left. Show 2 up. */
408 		fdesc2.slf_offset = fdesc1.slf_offset + fdesc1.slf_eltlen;
409 		if (!(data_present(state, &fdesc1) &&
410 		    data_present(state, &fdesc2)))
411 			break;
412 		(void) snprintf(index1, sizeof (index1),
413 		    MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(i));
414 		(void) snprintf(index2, sizeof (index2),
415 		    MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(i + 1));
416 		print_num_2up(state, index1, &fdesc1, fmt_type,
417 		    index2, &fdesc2, fmt_type);
418 		fdesc1.slf_offset += 2 * fdesc1.slf_eltlen;
419 		i += 2;
420 	}
421 
422 	indent_exit(state);
423 }
424 
425 
426 /*
427  * Output information from auxv_t structure.
428  */
429 static void
430 dump_auxv(note_state_t *state, const char *title)
431 {
432 	const sl_auxv_layout_t	*layout = state->ns_arch->auxv;
433 	union {
434 		Conv_cap_val_hw1_buf_t		hw1;
435 		Conv_cap_val_hw2_buf_t		hw2;
436 		Conv_cnote_auxv_af_buf_t	auxv_af;
437 		Conv_ehdr_flags_buf_t		ehdr_flags;
438 		Conv_inv_buf_t			inv;
439 	} conv_buf;
440 	sl_fmtbuf_t	buf;
441 	int		ndx, ndx_start;
442 	Word		sizeof_auxv;
443 
444 	sizeof_auxv = layout->sizeof_struct.slf_eltlen;
445 
446 	indent_enter(state, title, &layout->sizeof_struct);
447 
448 	/*
449 	 * Immediate indent_exit() restores the indent level to
450 	 * that of the title. We include indentation as part of
451 	 * the index string, which is right justified, and don't
452 	 * want the usual indentation spacing.
453 	 */
454 	indent_exit(state);
455 
456 	ndx = 0;
457 	while (state->ns_len > sizeof_auxv) {
458 		char		index[(MAXNDXSIZE * 2) + 1];
459 		sl_fmt_num_t	num_fmt = SL_FMT_NUM_ZHEX;
460 		const char	*vstr = NULL;
461 		Word		w;
462 		int		type;
463 		sl_field_t	a_type_next;
464 
465 		type = extract_as_word(state, &layout->a_type);
466 		ndx_start = ndx;
467 		switch (type) {
468 		case AT_NULL:
469 			a_type_next = layout->a_type;
470 			a_type_next.slf_offset += sizeof_auxv;
471 			while ((state->ns_len - sizeof_auxv) >= sizeof_auxv) {
472 				type = extract_as_word(state, &a_type_next);
473 				if (type != AT_NULL)
474 					break;
475 				ndx++;
476 				state->ns_data += sizeof_auxv;
477 				state->ns_len -= sizeof_auxv;
478 			}
479 			num_fmt = SL_FMT_NUM_HEX;
480 			break;
481 
482 
483 
484 		case AT_IGNORE:
485 		case AT_SUN_IFLUSH:
486 			num_fmt = SL_FMT_NUM_HEX;
487 			break;
488 
489 		case AT_EXECFD:
490 		case AT_PHENT:
491 		case AT_PHNUM:
492 		case AT_PAGESZ:
493 		case AT_SUN_UID:
494 		case AT_SUN_RUID:
495 		case AT_SUN_GID:
496 		case AT_SUN_RGID:
497 		case AT_SUN_LPAGESZ:
498 			num_fmt = SL_FMT_NUM_DEC;
499 			break;
500 
501 		case AT_FLAGS:	/* processor flags */
502 			w = extract_as_word(state, &layout->a_val);
503 			vstr = conv_ehdr_flags(state->ns_mach, w,
504 			    0, &conv_buf.ehdr_flags);
505 			break;
506 
507 		case AT_SUN_HWCAP:
508 			w = extract_as_word(state, &layout->a_val);
509 			vstr = conv_cap_val_hw1(w, state->ns_mach,
510 			    0, &conv_buf.hw1);
511 			/*
512 			 * conv_cap_val_hw1() produces output like:
513 			 *
514 			 *	0xfff [ flg1 flg2 0xff]
515 			 *
516 			 * where the first hex value is the complete value,
517 			 * and the second is the leftover bits. We only
518 			 * want the part in brackets, and failing that,
519 			 * would rather fall back to formatting the full
520 			 * value ourselves.
521 			 */
522 			while ((*vstr != '\0') && (*vstr != '['))
523 				vstr++;
524 			if (*vstr != '[')
525 				vstr = NULL;
526 			num_fmt = SL_FMT_NUM_HEX;
527 			break;
528 		case AT_SUN_HWCAP2:
529 			w = extract_as_word(state, &layout->a_val);
530 			vstr = conv_cap_val_hw2(w, state->ns_mach,
531 			    0, &conv_buf.hw2);
532 			/*
533 			 * conv_cap_val_hw2() produces output like:
534 			 *
535 			 *	0xfff [ flg1 flg2 0xff]
536 			 *
537 			 * where the first hex value is the complete value,
538 			 * and the second is the leftover bits. We only
539 			 * want the part in brackets, and failing that,
540 			 * would rather fall back to formatting the full
541 			 * value ourselves.
542 			 */
543 			while ((*vstr != '\0') && (*vstr != '['))
544 				vstr++;
545 			if (*vstr != '[')
546 				vstr = NULL;
547 			num_fmt = SL_FMT_NUM_HEX;
548 			break;
549 
550 
551 
552 		case AT_SUN_AUXFLAGS:
553 			w = extract_as_word(state, &layout->a_val);
554 			vstr = conv_cnote_auxv_af(w, 0, &conv_buf.auxv_af);
555 			num_fmt = SL_FMT_NUM_HEX;
556 			break;
557 		}
558 
559 		if (ndx == ndx_start)
560 			(void) snprintf(index, sizeof (index),
561 			    MSG_ORIG(MSG_FMT_INDEX2), EC_WORD(ndx));
562 		else
563 			(void) snprintf(index, sizeof (index),
564 			    MSG_ORIG(MSG_FMT_INDEXRNG),
565 			    EC_WORD(ndx_start), EC_WORD(ndx));
566 
567 		if (vstr == NULL)
568 			vstr = fmt_num(state, &layout->a_val, num_fmt, buf);
569 		dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_AUXVLINE), INDENT, index,
570 		    state->ns_vcol - state->ns_indent,
571 		    conv_cnote_auxv_type(type, CONV_FMT_DECIMAL,
572 		    &conv_buf.inv), vstr);
573 
574 		state->ns_data += sizeof_auxv;
575 		state->ns_len -= sizeof_auxv;
576 		ndx++;
577 	}
578 }
579 
580 
581 /*
582  * Output information from fltset_t structure.
583  */
584 static void
585 dump_fltset(note_state_t *state, const char *title)
586 {
587 #define	NELTS 4
588 
589 	const sl_fltset_layout_t	*layout = state->ns_arch->fltset;
590 	Conv_cnote_fltset_buf_t	buf;
591 	sl_field_t		fdesc;
592 	uint32_t		mask[NELTS];
593 	int			i, nelts;
594 
595 	if (!data_present(state, &layout->sizeof_struct))
596 		return;
597 
598 	fdesc = layout->word;
599 	nelts = fdesc.slf_nelts;
600 	if (nelts > NELTS)	/* Type has grown? Show what we understand */
601 		nelts = NELTS;
602 	for (i = 0; i < nelts; i++) {
603 		mask[i] = extract_as_word(state, &fdesc);
604 		fdesc.slf_offset += fdesc.slf_eltlen;
605 	}
606 
607 	print_str(state, title, conv_cnote_fltset(mask, nelts, 0, &buf));
608 
609 #undef NELTS
610 }
611 
612 
613 /*
614  * Output information from sigset_t structure.
615  */
616 static void
617 dump_sigset(note_state_t *state, const char *title)
618 {
619 #define	NELTS 4
620 
621 	const sl_sigset_layout_t	*layout = state->ns_arch->sigset;
622 	Conv_cnote_sigset_buf_t	buf;
623 	sl_field_t		fdesc;
624 	uint32_t		mask[NELTS];
625 	int			i, nelts;
626 
627 	if (!data_present(state, &layout->sizeof_struct))
628 		return;
629 
630 	fdesc = layout->sigbits;
631 	nelts = fdesc.slf_nelts;
632 	if (nelts > NELTS)	/* Type has grown? Show what we understand */
633 		nelts = NELTS;
634 	for (i = 0; i < nelts; i++) {
635 		mask[i] = extract_as_word(state, &fdesc);
636 		fdesc.slf_offset += fdesc.slf_eltlen;
637 	}
638 
639 	print_str(state, title, conv_cnote_sigset(mask, nelts, 0, &buf));
640 
641 #undef NELTS
642 }
643 
644 
645 /*
646  * Output information from sigaction structure.
647  */
648 static void
649 dump_sigaction(note_state_t *state, const char *title)
650 {
651 	const sl_sigaction_layout_t	*layout = state->ns_arch->sigaction;
652 	Conv_cnote_sa_flags_buf_t	conv_buf;
653 	Word	w;
654 
655 	indent_enter(state, title, &layout->sa_flags);
656 
657 	if (data_present(state, &layout->sa_flags)) {
658 		w = extract_as_word(state, &layout->sa_flags);
659 		print_str(state, MSG_ORIG(MSG_CNOTE_T_SA_FLAGS),
660 		    conv_cnote_sa_flags(w, 0, &conv_buf));
661 	}
662 
663 	PRINT_ZHEX_2UP(MSG_ORIG(MSG_CNOTE_T_SA_HANDLER), sa_hand,
664 	    MSG_ORIG(MSG_CNOTE_T_SA_SIGACTION), sa_sigact);
665 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_SA_MASK), sa_mask, dump_sigset);
666 
667 	indent_exit(state);
668 }
669 
670 
671 /*
672  * Output information from siginfo structure.
673  */
674 static void
675 dump_siginfo(note_state_t *state, const char *title)
676 {
677 	const sl_siginfo_layout_t	*layout = state->ns_arch->siginfo;
678 	Conv_inv_buf_t	inv_buf;
679 	Word		w;
680 	int		v_si_code, v_si_signo;
681 
682 	if (!data_present(state, &layout->sizeof_struct))
683 		return;
684 
685 	indent_enter(state, title, &layout->f_si_signo);
686 
687 	v_si_signo = extract_as_sword(state, &layout->f_si_signo);
688 	print_str(state, MSG_ORIG(MSG_CNOTE_T_SI_SIGNO),
689 	    conv_cnote_signal(v_si_signo, CONV_FMT_DECIMAL, &inv_buf));
690 
691 	w = extract_as_word(state, &layout->f_si_errno);
692 	print_str(state, MSG_ORIG(MSG_CNOTE_T_SI_ERRNO),
693 	    conv_cnote_errno(w, CONV_FMT_DECIMAL, &inv_buf));
694 
695 	v_si_code = extract_as_sword(state, &layout->f_si_code);
696 	print_str(state, MSG_ORIG(MSG_CNOTE_T_SI_CODE),
697 	    conv_cnote_si_code(state->ns_mach, v_si_signo, v_si_code,
698 	    CONV_FMT_DECIMAL, &inv_buf));
699 
700 	if ((v_si_signo == 0) || (v_si_code == SI_NOINFO)) {
701 		indent_exit(state);
702 		return;
703 	}
704 
705 	/* User generated signals have (si_code <= 0) */
706 	if (v_si_code <= 0) {
707 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_PID), f_si_pid);
708 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_UID), f_si_uid);
709 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_CTID), f_si_ctid);
710 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_ZONEID), f_si_zoneid);
711 		switch (v_si_code) {
712 		case SI_QUEUE:
713 		case SI_TIMER:
714 		case SI_ASYNCIO:
715 		case SI_MESGQ:
716 			indent_enter(state, MSG_ORIG(MSG_CNOTE_T_SI_VALUE),
717 			    &layout->f_si_value_int);
718 			PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_SIVAL_INT),
719 			    f_si_value_int);
720 			PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_SIVAL_PTR),
721 			    f_si_value_ptr);
722 			indent_exit(state);
723 			break;
724 		}
725 		indent_exit(state);
726 		return;
727 	}
728 
729 	/*
730 	 * Remaining cases are kernel generated signals. Output any
731 	 * signal or code specific information.
732 	 */
733 	if (v_si_code == SI_RCTL)
734 		PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_SI_ENTITY), f_si_entity);
735 	switch (v_si_signo) {
736 	case SIGILL:
737 	case SIGFPE:
738 	case SIGSEGV:
739 	case SIGBUS:
740 		PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_SI_ADDR), f_si_addr);
741 		break;
742 	case SIGCHLD:
743 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_PID), f_si_pid);
744 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_STATUS), f_si_status);
745 		break;
746 	case SIGPOLL:
747 		PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_SI_BAND), f_si_band);
748 		break;
749 	}
750 
751 	indent_exit(state);
752 }
753 
754 
755 /*
756  * Output information from stack_t structure.
757  */
758 static void
759 dump_stack(note_state_t *state, const char *title)
760 {
761 	const sl_stack_layout_t		*layout = state->ns_arch->stack;
762 	Conv_cnote_ss_flags_buf_t	conv_buf;
763 	Word		w;
764 
765 	indent_enter(state, title, &layout->ss_size);
766 
767 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_SS_SP), &layout->ss_sp,
768 	    SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_SS_SIZE), &layout->ss_size,
769 	    SL_FMT_NUM_HEX);
770 
771 	if (data_present(state, &layout->ss_flags)) {
772 		w = extract_as_word(state, &layout->ss_flags);
773 		print_str(state, MSG_ORIG(MSG_CNOTE_T_SS_FLAGS),
774 		    conv_cnote_ss_flags(w, 0, &conv_buf));
775 	}
776 
777 	indent_exit(state);
778 }
779 
780 
781 /*
782  * Output information from sysset_t structure.
783  */
784 static void
785 dump_sysset(note_state_t *state, const char *title)
786 {
787 #define	NELTS 16
788 
789 	const sl_sysset_layout_t	*layout = state->ns_arch->sysset;
790 	Conv_cnote_sysset_buf_t	buf;
791 	sl_field_t		fdesc;
792 	uint32_t		mask[NELTS];
793 	int			i, nelts;
794 
795 	if (!data_present(state, &layout->sizeof_struct))
796 		return;
797 
798 	fdesc = layout->word;
799 	nelts = fdesc.slf_nelts;
800 	if (nelts > NELTS)	/* Type has grown? Show what we understand */
801 		nelts = NELTS;
802 	for (i = 0; i < nelts; i++) {
803 		mask[i] = extract_as_word(state, &fdesc);
804 		fdesc.slf_offset += fdesc.slf_eltlen;
805 	}
806 
807 	print_str(state, title, conv_cnote_sysset(mask, nelts, 0, &buf));
808 
809 #undef NELTS
810 }
811 
812 
813 /*
814  * Output information from timestruc_t structure.
815  */
816 static void
817 dump_timestruc(note_state_t *state, const char *title)
818 {
819 	const sl_timestruc_layout_t *layout = state->ns_arch->timestruc;
820 
821 	indent_enter(state, title, &layout->tv_sec);
822 
823 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_TV_SEC), tv_sec,
824 	    MSG_ORIG(MSG_CNOTE_T_TV_NSEC), tv_nsec);
825 
826 	indent_exit(state);
827 }
828 
829 
830 /*
831  * Output information from utsname structure.
832  */
833 static void
834 dump_utsname(note_state_t *state, const char *title)
835 {
836 	const sl_utsname_layout_t	*layout = state->ns_arch->utsname;
837 
838 	indent_enter(state, title, &layout->sysname);
839 
840 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_SYSNAME), sysname);
841 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_NODENAME), nodename);
842 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_RELEASE), release);
843 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_VERSION), version);
844 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_UTS_MACHINE), machine);
845 
846 	indent_exit(state);
847 }
848 
849 
850 /*
851  * Dump register contents
852  */
853 static void
854 dump_prgregset(note_state_t *state, const char *title)
855 {
856 	sl_field_t	fdesc1, fdesc2;
857 	sl_fmtbuf_t	buf1, buf2;
858 	Conv_inv_buf_t	inv_buf1, inv_buf2;
859 	Word		w;
860 
861 	indent_enter(state, title, &fdesc1);
862 
863 	fdesc1 = fdesc2 = state->ns_arch->prgregset->elt0;
864 	for (w = 0; w < fdesc1.slf_nelts; ) {
865 		if (w == (fdesc1.slf_nelts - 1)) {
866 			/* One last register is left */
867 			if (!data_present(state, &fdesc1))
868 				break;
869 			dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE),
870 			    INDENT, state->ns_vcol - state->ns_indent,
871 			    conv_cnote_pr_regname(state->ns_mach, w,
872 			    CONV_FMT_DECIMAL, &inv_buf1),
873 			    fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1));
874 			fdesc1.slf_offset += fdesc1.slf_eltlen;
875 			w++;
876 			continue;
877 		}
878 
879 		/* There are at least 2 more registers left. Show 2 up */
880 		fdesc2.slf_offset = fdesc1.slf_offset + fdesc1.slf_eltlen;
881 		if (!(data_present(state, &fdesc1) &&
882 		    data_present(state, &fdesc2)))
883 			break;
884 		dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
885 		    state->ns_vcol - state->ns_indent,
886 		    conv_cnote_pr_regname(state->ns_mach, w,
887 		    CONV_FMT_DECIMAL, &inv_buf1),
888 		    state->ns_t2col - state->ns_vcol,
889 		    fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1),
890 		    state->ns_v2col - state->ns_t2col,
891 		    conv_cnote_pr_regname(state->ns_mach, w + 1,
892 		    CONV_FMT_DECIMAL, &inv_buf2),
893 		    fmt_num(state, &fdesc2, SL_FMT_NUM_ZHEX, buf2));
894 		fdesc1.slf_offset += 2 * fdesc1.slf_eltlen;
895 		w += 2;
896 	}
897 
898 	indent_exit(state);
899 }
900 
901 /*
902  * Output information from lwpstatus_t structure.
903  */
904 static void
905 dump_lwpstatus(note_state_t *state, const char *title)
906 {
907 	const sl_lwpstatus_layout_t	*layout = state->ns_arch->lwpstatus;
908 	Word		w, w2;
909 	int32_t		i;
910 	union {
911 		Conv_inv_buf_t			inv;
912 		Conv_cnote_pr_flags_buf_t	flags;
913 	} conv_buf;
914 
915 	indent_enter(state, title, &layout->pr_flags);
916 
917 	if (data_present(state, &layout->pr_flags)) {
918 		w = extract_as_word(state, &layout->pr_flags);
919 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAGS),
920 		    conv_cnote_pr_flags(w, 0, &conv_buf.flags));
921 	}
922 
923 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_LWPID), pr_lwpid);
924 
925 	if (data_present(state, &layout->pr_why)) {
926 		w = extract_as_word(state, &layout->pr_why);
927 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHY),
928 		    conv_cnote_pr_why(w, 0, &conv_buf.inv));
929 	}
930 
931 	if (data_present(state, &layout->pr_what)) {
932 		w2 = extract_as_word(state, &layout->pr_what);
933 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHAT),
934 		    conv_cnote_pr_what(w, w2, 0, &conv_buf.inv));
935 	}
936 
937 	if (data_present(state, &layout->pr_cursig)) {
938 		w = extract_as_word(state, &layout->pr_cursig);
939 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_CURSIG),
940 		    conv_cnote_signal(w, CONV_FMT_DECIMAL, &conv_buf.inv));
941 	}
942 
943 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_INFO), pr_info, dump_siginfo);
944 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWPPEND), pr_lwppend,
945 	    dump_sigset);
946 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWPHOLD), pr_lwphold,
947 	    dump_sigset);
948 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ACTION), pr_action,
949 	    dump_sigaction);
950 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ALTSTACK), pr_altstack,
951 	    dump_stack);
952 
953 	PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_PR_OLDCONTEXT), pr_oldcontext);
954 
955 	if (data_present(state, &layout->pr_syscall)) {
956 		w = extract_as_word(state, &layout->pr_syscall);
957 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
958 		    conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
959 	}
960 
961 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NSYSARG), pr_nsysarg);
962 
963 	if (data_present(state, &layout->pr_errno)) {
964 		w = extract_as_word(state, &layout->pr_errno);
965 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_ERRNO),
966 		    conv_cnote_errno(w, CONV_FMT_DECIMAL, &conv_buf.inv));
967 	}
968 
969 	if (data_present(state, &layout->pr_nsysarg)) {
970 		w2 = extract_as_word(state, &layout->pr_nsysarg);
971 		print_array(state, &layout->pr_sysarg, SL_FMT_NUM_ZHEX, w2, 1,
972 		    MSG_ORIG(MSG_CNOTE_T_PR_SYSARG));
973 	}
974 
975 	PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RVAL1), pr_rval1,
976 	    MSG_ORIG(MSG_CNOTE_T_PR_RVAL2), pr_rval2);
977 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
978 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TSTAMP), pr_tstamp,
979 	    dump_timestruc);
980 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_UTIME), pr_utime, dump_timestruc);
981 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_STIME), pr_stime, dump_timestruc);
982 
983 	if (data_present(state, &layout->pr_errpriv)) {
984 		i = extract_as_sword(state, &layout->pr_errpriv);
985 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_ERRPRIV),
986 		    conv_cnote_priv(i, CONV_FMT_DECIMAL, &conv_buf.inv));
987 	}
988 
989 	PRINT_ZHEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_USTACK), pr_ustack,
990 	    MSG_ORIG(MSG_CNOTE_T_PR_INSTR), pr_instr);
991 
992 	/*
993 	 * In order to line up all the values in a single column,
994 	 * we would have to set vcol to a very high value, which results
995 	 * in ugly looking output that runs off column 80. So, we use
996 	 * two levels of vcol, one for the contents so far, and a
997 	 * higher one for the pr_reg sub-struct.
998 	 */
999 	state->ns_vcol += 3;
1000 	state->ns_t2col += 3;
1001 	state->ns_v2col += 2;
1002 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_REG), pr_reg, dump_prgregset);
1003 	state->ns_vcol -= 3;
1004 	state->ns_t2col -= 3;
1005 	state->ns_v2col -= 2;
1006 
1007 	/*
1008 	 * The floating point register state is complex, and highly
1009 	 * platform dependent. For now, we simply display it as
1010 	 * a hex dump. This can be replaced if better information
1011 	 * is required.
1012 	 */
1013 	if (data_present(state, &layout->pr_fpreg)) {
1014 		indent_enter(state, MSG_ORIG(MSG_CNOTE_T_PR_FPREG),
1015 		    &layout->pr_fpreg);
1016 		dump_hex_bytes(layout->pr_fpreg.slf_offset + state->ns_data,
1017 		    layout->pr_fpreg.slf_eltlen, state->ns_indent, 4, 3);
1018 		indent_exit(state);
1019 	}
1020 
1021 	indent_exit(state);
1022 }
1023 
1024 
1025 /*
1026  * Output information from pstatus_t structure.
1027  */
1028 static void
1029 dump_pstatus(note_state_t *state, const char *title)
1030 {
1031 	const sl_pstatus_layout_t	*layout = state->ns_arch->pstatus;
1032 	Word				w;
1033 	union {
1034 		Conv_inv_buf_t			inv;
1035 		Conv_cnote_pr_flags_buf_t	flags;
1036 	} conv_buf;
1037 
1038 	indent_enter(state, title, &layout->pr_flags);
1039 
1040 	if (data_present(state, &layout->pr_flags)) {
1041 		w = extract_as_word(state, &layout->pr_flags);
1042 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAGS),
1043 		    conv_cnote_pr_flags(w, 0, &conv_buf.flags));
1044 	}
1045 
1046 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NLWP), pr_nlwp);
1047 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
1048 	    MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
1049 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGID), pr_pgid,
1050 	    MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
1051 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ASLWPID), pr_aslwpid,
1052 	    MSG_ORIG(MSG_CNOTE_T_PR_AGENTID), pr_agentid);
1053 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGPEND), pr_sigpend,
1054 	    dump_sigset);
1055 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_BRKBASE),
1056 	    &layout->pr_brkbase, SL_FMT_NUM_ZHEX,
1057 	    MSG_ORIG(MSG_CNOTE_T_PR_BRKSIZE),
1058 	    &layout->pr_brksize, SL_FMT_NUM_HEX);
1059 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_STKBASE),
1060 	    &layout->pr_stkbase, SL_FMT_NUM_ZHEX,
1061 	    MSG_ORIG(MSG_CNOTE_T_PR_STKSIZE),
1062 	    &layout->pr_stksize, SL_FMT_NUM_HEX);
1063 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_UTIME), pr_utime, dump_timestruc);
1064 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_STIME), pr_stime, dump_timestruc);
1065 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CUTIME), pr_cutime,
1066 	    dump_timestruc);
1067 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CSTIME), pr_cstime,
1068 	    dump_timestruc);
1069 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGTRACE), pr_sigtrace,
1070 	    dump_sigset);
1071 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_FLTTRACE), pr_flttrace,
1072 	    dump_fltset);
1073 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SYSENTRY), pr_sysentry,
1074 	    dump_sysset);
1075 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SYSEXIT), pr_sysexit,
1076 	    dump_sysset);
1077 
1078 	if (data_present(state, &layout->pr_dmodel)) {
1079 		w = extract_as_word(state, &layout->pr_dmodel);
1080 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_DMODEL),
1081 		    conv_cnote_pr_dmodel(w, 0, &conv_buf.inv));
1082 	}
1083 
1084 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_TASKID), pr_taskid,
1085 	    MSG_ORIG(MSG_CNOTE_T_PR_PROJID), pr_projid);
1086 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_NZOMB), pr_nzomb,
1087 	    MSG_ORIG(MSG_CNOTE_T_PR_ZONEID), pr_zoneid);
1088 
1089 	/*
1090 	 * In order to line up all the values in a single column,
1091 	 * we would have to set vcol to a very high value, which results
1092 	 * in ugly looking output that runs off column 80. So, we use
1093 	 * two levels of vcol, one for the contents so far, and a
1094 	 * higher one for the pr_lwp sub-struct.
1095 	 */
1096 	state->ns_vcol += 5;
1097 	state->ns_t2col += 5;
1098 	state->ns_v2col += 5;
1099 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWP), pr_lwp, dump_lwpstatus);
1100 	state->ns_vcol -= 5;
1101 	state->ns_t2col -= 5;
1102 	state->ns_v2col -= 5;
1103 
1104 	indent_exit(state);
1105 }
1106 
1107 
1108 /*
1109  * Output information from prstatus_t (<sys/old_procfs.h>) structure.
1110  */
1111 static void
1112 dump_prstatus(note_state_t *state, const char *title)
1113 {
1114 	const sl_prstatus_layout_t	*layout = state->ns_arch->prstatus;
1115 	Word				w, w2;
1116 	int				i;
1117 	union {
1118 		Conv_inv_buf_t			inv;
1119 		Conv_cnote_old_pr_flags_buf_t	flags;
1120 	} conv_buf;
1121 
1122 	indent_enter(state, title, &layout->pr_flags);
1123 
1124 	if (data_present(state, &layout->pr_flags)) {
1125 		w = extract_as_word(state, &layout->pr_flags);
1126 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAGS),
1127 		    conv_cnote_old_pr_flags(w, 0, &conv_buf.flags));
1128 	}
1129 
1130 	if (data_present(state, &layout->pr_why)) {
1131 		w = extract_as_word(state, &layout->pr_why);
1132 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHY),
1133 		    conv_cnote_pr_why(w, 0, &conv_buf.inv));
1134 	}
1135 
1136 	if (data_present(state, &layout->pr_what)) {
1137 		w2 = extract_as_word(state, &layout->pr_what);
1138 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_WHAT),
1139 		    conv_cnote_pr_what(w, w2, 0, &conv_buf.inv));
1140 	}
1141 
1142 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_INFO), pr_info, dump_siginfo);
1143 
1144 	if (data_present(state, &layout->pr_cursig)) {
1145 		w = extract_as_word(state, &layout->pr_cursig);
1146 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_CURSIG),
1147 		    conv_cnote_signal(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1148 	}
1149 
1150 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NLWP), pr_nlwp);
1151 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGPEND), pr_sigpend,
1152 	    dump_sigset);
1153 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGHOLD), pr_sighold,
1154 	    dump_sigset);
1155 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ALTSTACK), pr_altstack,
1156 	    dump_stack);
1157 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ACTION), pr_action,
1158 	    dump_sigaction);
1159 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
1160 	    MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
1161 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGRP), pr_pgrp,
1162 	    MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
1163 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_UTIME), pr_utime, dump_timestruc);
1164 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_STIME), pr_stime, dump_timestruc);
1165 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CUTIME), pr_cutime,
1166 	    dump_timestruc);
1167 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CSTIME), pr_cstime,
1168 	    dump_timestruc);
1169 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
1170 
1171 	if (data_present(state, &layout->pr_syscall)) {
1172 		w = extract_as_word(state, &layout->pr_syscall);
1173 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
1174 		    conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1175 	}
1176 
1177 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NSYSARG), pr_nsysarg);
1178 
1179 	if (data_present(state, &layout->pr_nsysarg)) {
1180 		w2 = extract_as_word(state, &layout->pr_nsysarg);
1181 		print_array(state, &layout->pr_sysarg, SL_FMT_NUM_ZHEX, w2, 1,
1182 		    MSG_ORIG(MSG_CNOTE_T_PR_SYSARG));
1183 	}
1184 
1185 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_WHO), pr_who);
1186 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWPPEND), pr_sigpend,
1187 	    dump_sigset);
1188 	PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_PR_OLDCONTEXT), pr_oldcontext);
1189 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_BRKBASE),
1190 	    &layout->pr_brkbase, SL_FMT_NUM_ZHEX,
1191 	    MSG_ORIG(MSG_CNOTE_T_PR_BRKSIZE),
1192 	    &layout->pr_brksize, SL_FMT_NUM_HEX);
1193 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_STKBASE),
1194 	    &layout->pr_stkbase, SL_FMT_NUM_ZHEX,
1195 	    MSG_ORIG(MSG_CNOTE_T_PR_STKSIZE),
1196 	    &layout->pr_stksize, SL_FMT_NUM_HEX);
1197 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_PROCESSOR), pr_processor);
1198 
1199 	if (data_present(state, &layout->pr_bind)) {
1200 		i = extract_as_sword(state, &layout->pr_bind);
1201 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_BIND),
1202 		    conv_cnote_psetid(i, CONV_FMT_DECIMAL, &conv_buf.inv));
1203 	}
1204 
1205 	PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_PR_INSTR), pr_instr);
1206 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_REG), pr_reg, dump_prgregset);
1207 
1208 	indent_exit(state);
1209 }
1210 
1211 
1212 /*
1213  * Print percent from 16-bit binary fraction [0 .. 1]
1214  * Round up .01 to .1 to indicate some small percentage (the 0x7000 below).
1215  *
1216  * Note: This routine was copied from ps(1) and then modified.
1217  */
1218 static const char *
1219 prtpct_value(note_state_t *state, const sl_field_t *fdesc,
1220     sl_fmtbuf_t buf)
1221 {
1222 	uint_t value;		/* need 32 bits to compute with */
1223 
1224 	value = extract_as_word(state, fdesc);
1225 	value = ((value * 1000) + 0x7000) >> 15;	/* [0 .. 1000] */
1226 	if (value >= 1000)
1227 		value = 999;
1228 
1229 	(void) snprintf(buf, sizeof (sl_fmtbuf_t),
1230 	    MSG_ORIG(MSG_CNOTE_FMT_PRTPCT), value / 10, value % 10);
1231 
1232 	return (buf);
1233 }
1234 
1235 
1236 
1237 /*
1238  * Version of prtpct() used for a 2-up display of two adjacent percentages.
1239  */
1240 static void
1241 prtpct_2up(note_state_t *state, const sl_field_t *fdesc1,
1242     const char *title1, const sl_field_t *fdesc2, const char *title2)
1243 {
1244 	sl_fmtbuf_t	buf1, buf2;
1245 
1246 	if (!(data_present(state, fdesc1) &&
1247 	    data_present(state, fdesc2)))
1248 		return;
1249 
1250 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
1251 	    state->ns_vcol - state->ns_indent, title1,
1252 	    state->ns_t2col - state->ns_vcol,
1253 	    prtpct_value(state, fdesc1, buf1),
1254 	    state->ns_v2col - state->ns_t2col, title2,
1255 	    prtpct_value(state, fdesc2, buf2));
1256 }
1257 
1258 
1259 /*
1260  * The psinfo_t and prpsinfo_t structs have pr_state and pr_sname
1261  * fields that we wish to print in a 2up format. The pr_state is
1262  * an integer, while pr_sname is a single character.
1263  */
1264 static void
1265 print_state_sname_2up(note_state_t *state,
1266     const sl_field_t *state_fdesc,
1267     const sl_field_t *sname_fdesc)
1268 {
1269 	sl_fmtbuf_t	buf1, buf2;
1270 	int		sname;
1271 
1272 	/*
1273 	 * If the field slf_offset and extent fall past the end of the
1274 	 * available data, then return without doing anything. That note
1275 	 * is from an older core file that doesn't have all the fields
1276 	 * that we know about.
1277 	 */
1278 	if (!(data_present(state, state_fdesc) &&
1279 	    data_present(state, sname_fdesc)))
1280 		return;
1281 
1282 	sname = extract_as_sword(state, sname_fdesc);
1283 	buf2[0] = sname;
1284 	buf2[1] = '\0';
1285 
1286 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
1287 	    state->ns_vcol - state->ns_indent, MSG_ORIG(MSG_CNOTE_T_PR_STATE),
1288 	    state->ns_t2col - state->ns_vcol,
1289 	    fmt_num(state, state_fdesc, SL_FMT_NUM_DEC, buf1),
1290 	    state->ns_v2col - state->ns_t2col, MSG_ORIG(MSG_CNOTE_T_PR_SNAME),
1291 	    buf2);
1292 }
1293 
1294 /*
1295  * Output information from lwpsinfo_t structure.
1296  */
1297 static void
1298 dump_lwpsinfo(note_state_t *state, const char *title)
1299 {
1300 	const sl_lwpsinfo_layout_t	*layout = state->ns_arch->lwpsinfo;
1301 	Word			w;
1302 	int32_t			i;
1303 	union {
1304 		Conv_cnote_proc_flag_buf_t	proc_flag;
1305 		Conv_inv_buf_t			inv;
1306 	} conv_buf;
1307 
1308 	indent_enter(state, title, &layout->pr_flag);
1309 
1310 	if (data_present(state, &layout->pr_flag)) {
1311 		w = extract_as_word(state, &layout->pr_flag);
1312 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAG),
1313 		    conv_cnote_proc_flag(w, 0, &conv_buf.proc_flag));
1314 	}
1315 
1316 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_LWPID), &layout->pr_lwpid,
1317 	    SL_FMT_NUM_DEC, MSG_ORIG(MSG_CNOTE_T_PR_ADDR), &layout->pr_addr,
1318 	    SL_FMT_NUM_ZHEX);
1319 	PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PR_WCHAN), pr_wchan);
1320 
1321 	if (data_present(state, &layout->pr_stype)) {
1322 		w = extract_as_word(state, &layout->pr_stype);
1323 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_STYPE),
1324 		    conv_cnote_pr_stype(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1325 	}
1326 
1327 	print_state_sname_2up(state, &layout->pr_state, &layout->pr_sname);
1328 
1329 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NICE), pr_nice);
1330 
1331 	if (data_present(state, &layout->pr_syscall)) {
1332 		w = extract_as_word(state, &layout->pr_syscall);
1333 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
1334 		    conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1335 	}
1336 
1337 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_OLDPRI), pr_oldpri,
1338 	    MSG_ORIG(MSG_CNOTE_T_PR_CPU), pr_cpu);
1339 
1340 	if (data_present(state, &layout->pr_pri) &&
1341 	    data_present(state, &layout->pr_pctcpu)) {
1342 		sl_fmtbuf_t	buf1, buf2;
1343 
1344 		dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
1345 		    state->ns_vcol - state->ns_indent,
1346 		    MSG_ORIG(MSG_CNOTE_T_PR_PRI),
1347 		    state->ns_t2col - state->ns_vcol,
1348 		    fmt_num(state, &layout->pr_pri, SL_FMT_NUM_DEC, buf1),
1349 		    state->ns_v2col - state->ns_t2col,
1350 		    MSG_ORIG(MSG_CNOTE_T_PR_PCTCPU),
1351 		    prtpct_value(state, &layout->pr_pctcpu, buf2));
1352 	}
1353 
1354 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_START), pr_start, dump_timestruc);
1355 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TIME), pr_time, dump_timestruc);
1356 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
1357 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_NAME), pr_name);
1358 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ONPRO), pr_onpro,
1359 	    MSG_ORIG(MSG_CNOTE_T_PR_BINDPRO), pr_bindpro);
1360 
1361 	if (data_present(state, &layout->pr_bindpset)) {
1362 		i = extract_as_sword(state, &layout->pr_bindpset);
1363 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_BINDPSET),
1364 		    conv_cnote_psetid(i, CONV_FMT_DECIMAL, &conv_buf.inv));
1365 	}
1366 
1367 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_LGRP), pr_lgrp);
1368 
1369 	indent_exit(state);
1370 }
1371 
1372 
1373 /*
1374  * Output information from psinfo_t structure.
1375  */
1376 static void
1377 dump_psinfo(note_state_t *state, const char *title)
1378 {
1379 	const sl_psinfo_layout_t	*layout = state->ns_arch->psinfo;
1380 	Word				w;
1381 	union {
1382 		Conv_cnote_proc_flag_buf_t	proc_flag;
1383 		Conv_inv_buf_t			inv;
1384 	} conv_buf;
1385 
1386 	indent_enter(state, title, &layout->pr_flag);
1387 
1388 	if (data_present(state, &layout->pr_flag)) {
1389 		w = extract_as_word(state, &layout->pr_flag);
1390 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAG),
1391 		    conv_cnote_proc_flag(w, 0, &conv_buf.proc_flag));
1392 	}
1393 
1394 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NLWP), pr_nlwp);
1395 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
1396 	    MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
1397 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGID), pr_pgid,
1398 	    MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
1399 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_UID), pr_uid,
1400 	    MSG_ORIG(MSG_CNOTE_T_PR_EUID), pr_euid);
1401 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_GID), pr_gid,
1402 	    MSG_ORIG(MSG_CNOTE_T_PR_EGID), pr_egid);
1403 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ADDR), &layout->pr_addr,
1404 	    SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_PR_SIZE), &layout->pr_size,
1405 	    SL_FMT_NUM_HEX);
1406 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_RSSIZE),
1407 	    &layout->pr_rssize, SL_FMT_NUM_HEX, MSG_ORIG(MSG_CNOTE_T_PR_TTYDEV),
1408 	    &layout->pr_ttydev, SL_FMT_NUM_DEC);
1409 	prtpct_2up(state, &layout->pr_pctcpu, MSG_ORIG(MSG_CNOTE_T_PR_PCTCPU),
1410 	    &layout->pr_pctmem, MSG_ORIG(MSG_CNOTE_T_PR_PCTMEM));
1411 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_START), pr_start, dump_timestruc);
1412 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TIME), pr_time, dump_timestruc);
1413 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CTIME), pr_ctime, dump_timestruc);
1414 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_FNAME), pr_fname);
1415 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_PSARGS), pr_psargs);
1416 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_WSTAT), &layout->pr_wstat,
1417 	    SL_FMT_NUM_HEX, MSG_ORIG(MSG_CNOTE_T_PR_ARGC), &layout->pr_argc,
1418 	    SL_FMT_NUM_DEC);
1419 	PRINT_ZHEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ARGV), pr_argv,
1420 	    MSG_ORIG(MSG_CNOTE_T_PR_ENVP), pr_envp);
1421 
1422 	if (data_present(state, &layout->pr_dmodel)) {
1423 		w = extract_as_word(state, &layout->pr_dmodel);
1424 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_DMODEL),
1425 		    conv_cnote_pr_dmodel(w, 0, &conv_buf.inv));
1426 	}
1427 
1428 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_TASKID), pr_taskid,
1429 	    MSG_ORIG(MSG_CNOTE_T_PR_PROJID), pr_projid);
1430 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_NZOMB), pr_nzomb,
1431 	    MSG_ORIG(MSG_CNOTE_T_PR_POOLID), pr_poolid);
1432 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ZONEID), pr_zoneid,
1433 	    MSG_ORIG(MSG_CNOTE_T_PR_CONTRACT), pr_contract);
1434 
1435 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWP), pr_lwp, dump_lwpsinfo);
1436 
1437 	indent_exit(state);
1438 }
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 
1854 	return (CORENOTE_R_BADTYPE);
1855 }
1856