xref: /titanic_44/usr/src/cmd/sgs/elfdump/common/corenote.c (revision 3f3aaf4e95972f6d6393cbff0a4652f4ee2c0dbf)
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 *
safe_str(const char * str,size_t n)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
extract_as_word(note_state_t * state,const sl_field_t * fdesc)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
extract_as_lword(note_state_t * state,const sl_field_t * fdesc)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
extract_as_sword(note_state_t * state,const sl_field_t * fdesc)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 *
fmt_num(note_state_t * state,const sl_field_t * fdesc,sl_fmt_num_t fmt_type,sl_fmtbuf_t buf)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
data_present(note_state_t * state,const sl_field_t * fdesc)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
indent_enter(note_state_t * state,const char * title,const sl_field_t * first_fdesc)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
indent_exit(note_state_t * state)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
print_num(note_state_t * state,const char * title,const sl_field_t * fdesc,sl_fmt_num_t fmt_type)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
print_num_2up(note_state_t * state,const char * title1,const sl_field_t * fdesc1,sl_fmt_num_t fmt_type1,const char * title2,const sl_field_t * fdesc2,sl_fmt_num_t fmt_type2)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
print_strbuf(note_state_t * state,const char * title,const sl_field_t * fdesc)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
print_str(note_state_t * state,const char * title,const char * str)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
print_subtype(note_state_t * state,const char * title,const sl_field_t * fdesc,dump_func_t dump_func)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
print_array(note_state_t * state,const sl_field_t * base_desc,sl_fmt_num_t fmt_type,int nelts,int check_nelts,const char * title)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
dump_auxv(note_state_t * state,const char * title)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
dump_fltset(note_state_t * state,const char * title)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
dump_sigset(note_state_t * state,const char * title)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
dump_sigaction(note_state_t * state,const char * title)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
dump_siginfo(note_state_t * state,const char * title)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
dump_stack(note_state_t * state,const char * title)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
dump_sysset(note_state_t * state,const char * title)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
dump_timestruc(note_state_t * state,const char * title)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
dump_utsname(note_state_t * state,const char * title)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
dump_prgregset(note_state_t * state,const char * title)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 	fdesc1 = fdesc2 = state->ns_arch->prgregset->elt0;
863 	indent_enter(state, title, &fdesc1);
864 
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
dump_lwpstatus(note_state_t * state,const char * title)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 		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 
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
dump_pstatus(note_state_t * state,const char * title)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
dump_prstatus(note_state_t * state,const char * title)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 
1144 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_INFO), pr_info, dump_siginfo);
1145 
1146 	if (data_present(state, &layout->pr_cursig)) {
1147 		w = extract_as_word(state, &layout->pr_cursig);
1148 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_CURSIG),
1149 		    conv_cnote_signal(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1150 	}
1151 
1152 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NLWP), pr_nlwp);
1153 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGPEND), pr_sigpend,
1154 	    dump_sigset);
1155 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_SIGHOLD), pr_sighold,
1156 	    dump_sigset);
1157 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ALTSTACK), pr_altstack,
1158 	    dump_stack);
1159 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_ACTION), pr_action,
1160 	    dump_sigaction);
1161 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
1162 	    MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
1163 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGRP), pr_pgrp,
1164 	    MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
1165 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_UTIME), pr_utime, dump_timestruc);
1166 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_STIME), pr_stime, dump_timestruc);
1167 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CUTIME), pr_cutime,
1168 	    dump_timestruc);
1169 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CSTIME), pr_cstime,
1170 	    dump_timestruc);
1171 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
1172 
1173 	if (data_present(state, &layout->pr_syscall)) {
1174 		w = extract_as_word(state, &layout->pr_syscall);
1175 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
1176 		    conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1177 	}
1178 
1179 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NSYSARG), pr_nsysarg);
1180 
1181 	if (data_present(state, &layout->pr_nsysarg)) {
1182 		w2 = extract_as_word(state, &layout->pr_nsysarg);
1183 		print_array(state, &layout->pr_sysarg, SL_FMT_NUM_ZHEX, w2, 1,
1184 		    MSG_ORIG(MSG_CNOTE_T_PR_SYSARG));
1185 	}
1186 
1187 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_WHO), pr_who);
1188 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWPPEND), pr_sigpend,
1189 	    dump_sigset);
1190 	PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_PR_OLDCONTEXT), pr_oldcontext);
1191 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_BRKBASE),
1192 	    &layout->pr_brkbase, SL_FMT_NUM_ZHEX,
1193 	    MSG_ORIG(MSG_CNOTE_T_PR_BRKSIZE),
1194 	    &layout->pr_brksize, SL_FMT_NUM_HEX);
1195 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_STKBASE),
1196 	    &layout->pr_stkbase, SL_FMT_NUM_ZHEX,
1197 	    MSG_ORIG(MSG_CNOTE_T_PR_STKSIZE),
1198 	    &layout->pr_stksize, SL_FMT_NUM_HEX);
1199 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_PROCESSOR), pr_processor);
1200 
1201 	if (data_present(state, &layout->pr_bind)) {
1202 		i = extract_as_sword(state, &layout->pr_bind);
1203 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_BIND),
1204 		    conv_cnote_psetid(i, CONV_FMT_DECIMAL, &conv_buf.inv));
1205 	}
1206 
1207 	PRINT_ZHEX(MSG_ORIG(MSG_CNOTE_T_PR_INSTR), pr_instr);
1208 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_REG), pr_reg, dump_prgregset);
1209 
1210 	indent_exit(state);
1211 }
1212 
1213 
1214 /*
1215  * Print percent from 16-bit binary fraction [0 .. 1]
1216  * Round up .01 to .1 to indicate some small percentage (the 0x7000 below).
1217  *
1218  * Note: This routine was copied from ps(1) and then modified.
1219  */
1220 static const char *
prtpct_value(note_state_t * state,const sl_field_t * fdesc,sl_fmtbuf_t buf)1221 prtpct_value(note_state_t *state, const sl_field_t *fdesc,
1222     sl_fmtbuf_t buf)
1223 {
1224 	uint_t value;		/* need 32 bits to compute with */
1225 
1226 	value = extract_as_word(state, fdesc);
1227 	value = ((value * 1000) + 0x7000) >> 15;	/* [0 .. 1000] */
1228 	if (value >= 1000)
1229 		value = 999;
1230 
1231 	(void) snprintf(buf, sizeof (sl_fmtbuf_t),
1232 	    MSG_ORIG(MSG_CNOTE_FMT_PRTPCT), value / 10, value % 10);
1233 
1234 	return (buf);
1235 }
1236 
1237 
1238 
1239 /*
1240  * Version of prtpct() used for a 2-up display of two adjacent percentages.
1241  */
1242 static void
prtpct_2up(note_state_t * state,const sl_field_t * fdesc1,const char * title1,const sl_field_t * fdesc2,const char * title2)1243 prtpct_2up(note_state_t *state, const sl_field_t *fdesc1,
1244     const char *title1, const sl_field_t *fdesc2, const char *title2)
1245 {
1246 	sl_fmtbuf_t	buf1, buf2;
1247 
1248 	if (!(data_present(state, fdesc1) &&
1249 	    data_present(state, fdesc2)))
1250 		return;
1251 
1252 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
1253 	    state->ns_vcol - state->ns_indent, title1,
1254 	    state->ns_t2col - state->ns_vcol,
1255 	    prtpct_value(state, fdesc1, buf1),
1256 	    state->ns_v2col - state->ns_t2col, title2,
1257 	    prtpct_value(state, fdesc2, buf2));
1258 }
1259 
1260 
1261 /*
1262  * The psinfo_t and prpsinfo_t structs have pr_state and pr_sname
1263  * fields that we wish to print in a 2up format. The pr_state is
1264  * an integer, while pr_sname is a single character.
1265  */
1266 static void
print_state_sname_2up(note_state_t * state,const sl_field_t * state_fdesc,const sl_field_t * sname_fdesc)1267 print_state_sname_2up(note_state_t *state,
1268     const sl_field_t *state_fdesc,
1269     const sl_field_t *sname_fdesc)
1270 {
1271 	sl_fmtbuf_t	buf1, buf2;
1272 	int		sname;
1273 
1274 	/*
1275 	 * If the field slf_offset and extent fall past the end of the
1276 	 * available data, then return without doing anything. That note
1277 	 * is from an older core file that doesn't have all the fields
1278 	 * that we know about.
1279 	 */
1280 	if (!(data_present(state, state_fdesc) &&
1281 	    data_present(state, sname_fdesc)))
1282 		return;
1283 
1284 	sname = extract_as_sword(state, sname_fdesc);
1285 	buf2[0] = sname;
1286 	buf2[1] = '\0';
1287 
1288 	dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
1289 	    state->ns_vcol - state->ns_indent, MSG_ORIG(MSG_CNOTE_T_PR_STATE),
1290 	    state->ns_t2col - state->ns_vcol,
1291 	    fmt_num(state, state_fdesc, SL_FMT_NUM_DEC, buf1),
1292 	    state->ns_v2col - state->ns_t2col, MSG_ORIG(MSG_CNOTE_T_PR_SNAME),
1293 	    buf2);
1294 }
1295 
1296 /*
1297  * Output information from lwpsinfo_t structure.
1298  */
1299 static void
dump_lwpsinfo(note_state_t * state,const char * title)1300 dump_lwpsinfo(note_state_t *state, const char *title)
1301 {
1302 	const sl_lwpsinfo_layout_t	*layout = state->ns_arch->lwpsinfo;
1303 	Word			w;
1304 	int32_t			i;
1305 	union {
1306 		Conv_cnote_proc_flag_buf_t	proc_flag;
1307 		Conv_inv_buf_t			inv;
1308 	} conv_buf;
1309 
1310 	indent_enter(state, title, &layout->pr_flag);
1311 
1312 	if (data_present(state, &layout->pr_flag)) {
1313 		w = extract_as_word(state, &layout->pr_flag);
1314 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAG),
1315 		    conv_cnote_proc_flag(w, 0, &conv_buf.proc_flag));
1316 	}
1317 
1318 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_LWPID), &layout->pr_lwpid,
1319 	    SL_FMT_NUM_DEC, MSG_ORIG(MSG_CNOTE_T_PR_ADDR), &layout->pr_addr,
1320 	    SL_FMT_NUM_ZHEX);
1321 	PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PR_WCHAN), pr_wchan);
1322 
1323 	if (data_present(state, &layout->pr_stype)) {
1324 		w = extract_as_word(state, &layout->pr_stype);
1325 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_STYPE),
1326 		    conv_cnote_pr_stype(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1327 	}
1328 
1329 	print_state_sname_2up(state, &layout->pr_state, &layout->pr_sname);
1330 
1331 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NICE), pr_nice);
1332 
1333 	if (data_present(state, &layout->pr_syscall)) {
1334 		w = extract_as_word(state, &layout->pr_syscall);
1335 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
1336 		    conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1337 	}
1338 
1339 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_OLDPRI), pr_oldpri,
1340 	    MSG_ORIG(MSG_CNOTE_T_PR_CPU), pr_cpu);
1341 
1342 	if (data_present(state, &layout->pr_pri) &&
1343 	    data_present(state, &layout->pr_pctcpu)) {
1344 		sl_fmtbuf_t	buf1, buf2;
1345 
1346 		dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
1347 		    state->ns_vcol - state->ns_indent,
1348 		    MSG_ORIG(MSG_CNOTE_T_PR_PRI),
1349 		    state->ns_t2col - state->ns_vcol,
1350 		    fmt_num(state, &layout->pr_pri, SL_FMT_NUM_DEC, buf1),
1351 		    state->ns_v2col - state->ns_t2col,
1352 		    MSG_ORIG(MSG_CNOTE_T_PR_PCTCPU),
1353 		    prtpct_value(state, &layout->pr_pctcpu, buf2));
1354 	}
1355 
1356 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_START), pr_start, dump_timestruc);
1357 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TIME), pr_time, dump_timestruc);
1358 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
1359 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_NAME), pr_name);
1360 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ONPRO), pr_onpro,
1361 	    MSG_ORIG(MSG_CNOTE_T_PR_BINDPRO), pr_bindpro);
1362 
1363 	if (data_present(state, &layout->pr_bindpset)) {
1364 		i = extract_as_sword(state, &layout->pr_bindpset);
1365 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_BINDPSET),
1366 		    conv_cnote_psetid(i, CONV_FMT_DECIMAL, &conv_buf.inv));
1367 	}
1368 
1369 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_LGRP), pr_lgrp);
1370 
1371 	indent_exit(state);
1372 }
1373 
1374 
1375 /*
1376  * Output information from psinfo_t structure.
1377  */
1378 static void
dump_psinfo(note_state_t * state,const char * title)1379 dump_psinfo(note_state_t *state, const char *title)
1380 {
1381 	const sl_psinfo_layout_t	*layout = state->ns_arch->psinfo;
1382 	Word				w;
1383 	union {
1384 		Conv_cnote_proc_flag_buf_t	proc_flag;
1385 		Conv_inv_buf_t			inv;
1386 	} conv_buf;
1387 
1388 	indent_enter(state, title, &layout->pr_flag);
1389 
1390 	if (data_present(state, &layout->pr_flag)) {
1391 		w = extract_as_word(state, &layout->pr_flag);
1392 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAG),
1393 		    conv_cnote_proc_flag(w, 0, &conv_buf.proc_flag));
1394 	}
1395 
1396 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NLWP), pr_nlwp);
1397 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
1398 	    MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
1399 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGID), pr_pgid,
1400 	    MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
1401 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_UID), pr_uid,
1402 	    MSG_ORIG(MSG_CNOTE_T_PR_EUID), pr_euid);
1403 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_GID), pr_gid,
1404 	    MSG_ORIG(MSG_CNOTE_T_PR_EGID), pr_egid);
1405 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ADDR), &layout->pr_addr,
1406 	    SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_PR_SIZE), &layout->pr_size,
1407 	    SL_FMT_NUM_HEX);
1408 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_RSSIZE),
1409 	    &layout->pr_rssize, SL_FMT_NUM_HEX, MSG_ORIG(MSG_CNOTE_T_PR_TTYDEV),
1410 	    &layout->pr_ttydev, SL_FMT_NUM_DEC);
1411 	prtpct_2up(state, &layout->pr_pctcpu, MSG_ORIG(MSG_CNOTE_T_PR_PCTCPU),
1412 	    &layout->pr_pctmem, MSG_ORIG(MSG_CNOTE_T_PR_PCTMEM));
1413 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_START), pr_start, dump_timestruc);
1414 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TIME), pr_time, dump_timestruc);
1415 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CTIME), pr_ctime, dump_timestruc);
1416 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_FNAME), pr_fname);
1417 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_PSARGS), pr_psargs);
1418 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_WSTAT), &layout->pr_wstat,
1419 	    SL_FMT_NUM_HEX, MSG_ORIG(MSG_CNOTE_T_PR_ARGC), &layout->pr_argc,
1420 	    SL_FMT_NUM_DEC);
1421 	PRINT_ZHEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ARGV), pr_argv,
1422 	    MSG_ORIG(MSG_CNOTE_T_PR_ENVP), pr_envp);
1423 
1424 	if (data_present(state, &layout->pr_dmodel)) {
1425 		w = extract_as_word(state, &layout->pr_dmodel);
1426 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_DMODEL),
1427 		    conv_cnote_pr_dmodel(w, 0, &conv_buf.inv));
1428 	}
1429 
1430 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_TASKID), pr_taskid,
1431 	    MSG_ORIG(MSG_CNOTE_T_PR_PROJID), pr_projid);
1432 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_NZOMB), pr_nzomb,
1433 	    MSG_ORIG(MSG_CNOTE_T_PR_POOLID), pr_poolid);
1434 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ZONEID), pr_zoneid,
1435 	    MSG_ORIG(MSG_CNOTE_T_PR_CONTRACT), pr_contract);
1436 
1437 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_LWP), pr_lwp, dump_lwpsinfo);
1438 
1439 	indent_exit(state);
1440 }
1441 
1442 /*
1443  * Output information from prpsinfo_t structure.
1444  */
1445 static void
dump_prpsinfo(note_state_t * state,const char * title)1446 dump_prpsinfo(note_state_t *state, const char *title)
1447 {
1448 	const sl_prpsinfo_layout_t	*layout = state->ns_arch->prpsinfo;
1449 	Word				w;
1450 	union {
1451 		Conv_cnote_proc_flag_buf_t	proc_flag;
1452 		Conv_inv_buf_t			inv;
1453 	} conv_buf;
1454 
1455 	indent_enter(state, title, &layout->pr_state);
1456 
1457 	print_state_sname_2up(state, &layout->pr_state, &layout->pr_sname);
1458 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_ZOMB), pr_zomb,
1459 	    MSG_ORIG(MSG_CNOTE_T_PR_NICE), pr_nice);
1460 
1461 	if (data_present(state, &layout->pr_flag)) {
1462 		w = extract_as_word(state, &layout->pr_flag);
1463 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FLAG),
1464 		    conv_cnote_proc_flag(w, 0, &conv_buf.proc_flag));
1465 	}
1466 
1467 
1468 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_UID), pr_uid,
1469 	    MSG_ORIG(MSG_CNOTE_T_PR_GID), pr_gid);
1470 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PID), pr_pid,
1471 	    MSG_ORIG(MSG_CNOTE_T_PR_PPID), pr_ppid);
1472 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PGRP), pr_pgrp,
1473 	    MSG_ORIG(MSG_CNOTE_T_PR_SID), pr_sid);
1474 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ADDR), &layout->pr_addr,
1475 	    SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_PR_SIZE), &layout->pr_size,
1476 	    SL_FMT_NUM_HEX);
1477 	PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RSSIZE), pr_rssize,
1478 	    MSG_ORIG(MSG_CNOTE_T_PR_WCHAN), pr_wchan);
1479 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_START), pr_start, dump_timestruc);
1480 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_TIME), pr_time, dump_timestruc);
1481 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_PRI), pr_pri,
1482 	    MSG_ORIG(MSG_CNOTE_T_PR_OLDPRI), pr_oldpri);
1483 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_CPU), pr_cpu);
1484 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_OTTYDEV), pr_ottydev,
1485 	    MSG_ORIG(MSG_CNOTE_T_PR_LTTYDEV), pr_lttydev);
1486 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_CLNAME), pr_clname);
1487 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_FNAME), pr_fname);
1488 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_PSARGS), pr_psargs);
1489 
1490 	if (data_present(state, &layout->pr_syscall)) {
1491 		w = extract_as_word(state, &layout->pr_syscall);
1492 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_SYSCALL),
1493 		    conv_cnote_syscall(w, CONV_FMT_DECIMAL, &conv_buf.inv));
1494 	}
1495 
1496 	PRINT_SUBTYPE(MSG_ORIG(MSG_CNOTE_T_PR_CTIME), pr_ctime, dump_timestruc);
1497 	PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PR_BYSIZE), pr_bysize,
1498 	    MSG_ORIG(MSG_CNOTE_T_PR_BYRSSIZE), pr_byrssize);
1499 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ARGC), &layout->pr_argc,
1500 	    SL_FMT_NUM_DEC, MSG_ORIG(MSG_CNOTE_T_PR_ARGV), &layout->pr_argv,
1501 	    SL_FMT_NUM_ZHEX);
1502 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PR_ENVP), &layout->pr_envp,
1503 	    SL_FMT_NUM_ZHEX, MSG_ORIG(MSG_CNOTE_T_PR_WSTAT), &layout->pr_wstat,
1504 	    SL_FMT_NUM_HEX);
1505 	prtpct_2up(state, &layout->pr_pctcpu, MSG_ORIG(MSG_CNOTE_T_PR_PCTCPU),
1506 	    &layout->pr_pctmem, MSG_ORIG(MSG_CNOTE_T_PR_PCTMEM));
1507 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_EUID), pr_euid,
1508 	    MSG_ORIG(MSG_CNOTE_T_PR_EGID), pr_egid);
1509 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_ASLWPID), pr_aslwpid);
1510 
1511 	if (data_present(state, &layout->pr_dmodel)) {
1512 		w = extract_as_word(state, &layout->pr_dmodel);
1513 		print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_DMODEL),
1514 		    conv_cnote_pr_dmodel(w, 0, &conv_buf.inv));
1515 	}
1516 
1517 	indent_exit(state);
1518 }
1519 
1520 
1521 /*
1522  * Output information from prcred_t structure.
1523  */
1524 static void
dump_prcred(note_state_t * state,const char * title)1525 dump_prcred(note_state_t *state, const char *title)
1526 {
1527 	const sl_prcred_layout_t *layout = state->ns_arch->prcred;
1528 	Word		ngroups;
1529 
1530 	indent_enter(state, title, &layout->pr_euid);
1531 
1532 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_EUID), pr_euid,
1533 	    MSG_ORIG(MSG_CNOTE_T_PR_RUID), pr_ruid);
1534 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_SUID), pr_suid,
1535 	    MSG_ORIG(MSG_CNOTE_T_PR_EGID), pr_egid);
1536 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RGID), pr_rgid,
1537 	    MSG_ORIG(MSG_CNOTE_T_PR_SGID), pr_sgid);
1538 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NGROUPS), pr_ngroups);
1539 
1540 	if (data_present(state, &layout->pr_ngroups)) {
1541 		ngroups = extract_as_word(state, &layout->pr_ngroups);
1542 		print_array(state, &layout->pr_groups, SL_FMT_NUM_DEC, ngroups,
1543 		    0, MSG_ORIG(MSG_CNOTE_T_PR_GROUPS));
1544 	}
1545 
1546 	indent_exit(state);
1547 }
1548 
1549 
1550 /*
1551  * Output information from prpriv_t structure.
1552  */
1553 static void
dump_prpriv(note_state_t * state,const char * title)1554 dump_prpriv(note_state_t *state, const char *title)
1555 {
1556 	const sl_prpriv_layout_t *layout = state->ns_arch->prpriv;
1557 	Word		nsets;
1558 
1559 	indent_enter(state, title, &layout->pr_nsets);
1560 
1561 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_NSETS), pr_nsets);
1562 	PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PR_SETSIZE), pr_setsize);
1563 	PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PR_INFOSIZE), pr_infosize);
1564 
1565 	if (data_present(state, &layout->pr_nsets)) {
1566 		nsets = extract_as_word(state, &layout->pr_nsets);
1567 		print_array(state, &layout->pr_sets, SL_FMT_NUM_ZHEX, nsets,
1568 		    0, MSG_ORIG(MSG_CNOTE_T_PR_SETS));
1569 	}
1570 
1571 	indent_exit(state);
1572 }
1573 
1574 static void
dump_prfdinfo(note_state_t * state,const char * title)1575 dump_prfdinfo(note_state_t *state, const char *title)
1576 {
1577 	const sl_prfdinfo_layout_t *layout = state->ns_arch->prfdinfo;
1578 	char buf[1024];
1579 	uint32_t fileflags, mode;
1580 
1581 	indent_enter(state, title, &layout->pr_fd);
1582 
1583 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_FD), pr_fd);
1584 	mode = extract_as_word(state, &layout->pr_mode);
1585 
1586 	print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_MODE),
1587 	    conv_cnote_filemode(mode, 0, buf, sizeof (buf)));
1588 
1589 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_UID), pr_uid,
1590 	    MSG_ORIG(MSG_CNOTE_T_PR_GID), pr_gid);
1591 
1592 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_MAJOR), pr_major,
1593 	    MSG_ORIG(MSG_CNOTE_T_PR_MINOR), pr_minor);
1594 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_RMAJOR), pr_rmajor,
1595 	    MSG_ORIG(MSG_CNOTE_T_PR_RMINOR), pr_rminor);
1596 
1597 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_INO), pr_ino);
1598 
1599 	PRINT_DEC_2UP(MSG_ORIG(MSG_CNOTE_T_PR_SIZE), pr_size,
1600 	    MSG_ORIG(MSG_CNOTE_T_PR_OFFSET), pr_offset);
1601 
1602 	fileflags = extract_as_word(state, &layout->pr_fileflags);
1603 
1604 	print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FILEFLAGS),
1605 	    conv_cnote_fileflags(fileflags, 0, buf, sizeof (buf)));
1606 
1607 	PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_FDFLAGS), pr_fdflags);
1608 
1609 	PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_PATH), pr_path);
1610 
1611 	indent_exit(state);
1612 }
1613 
1614 /*
1615  * Output information from priv_impl_info_t structure.
1616  */
1617 static void
dump_priv_impl_info(note_state_t * state,const char * title)1618 dump_priv_impl_info(note_state_t *state, const char *title)
1619 {
1620 	const sl_priv_impl_info_layout_t *layout;
1621 
1622 	layout = state->ns_arch->priv_impl_info;
1623 	indent_enter(state, title, &layout->priv_headersize);
1624 
1625 	PRINT_HEX_2UP(MSG_ORIG(MSG_CNOTE_T_PRIV_HEADERSIZE), priv_headersize,
1626 	    MSG_ORIG(MSG_CNOTE_T_PRIV_FLAGS), priv_flags);
1627 
1628 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PRIV_NSETS),
1629 	    &layout->priv_nsets, SL_FMT_NUM_DEC,
1630 	    MSG_ORIG(MSG_CNOTE_T_PRIV_SETSIZE), &layout->priv_setsize,
1631 	    SL_FMT_NUM_HEX);
1632 	print_num_2up(state, MSG_ORIG(MSG_CNOTE_T_PRIV_MAX), &layout->priv_max,
1633 	    SL_FMT_NUM_DEC, MSG_ORIG(MSG_CNOTE_T_PRIV_INFOSIZE),
1634 	    &layout->priv_infosize, SL_FMT_NUM_HEX);
1635 	PRINT_HEX(MSG_ORIG(MSG_CNOTE_T_PRIV_GLOBALINFOSIZE),
1636 	    priv_globalinfosize);
1637 
1638 	indent_exit(state);
1639 }
1640 
1641 
1642 /*
1643  * Dump information from an asrset_t array. This data
1644  * structure is specific to sparcv9, and does not appear
1645  * on any other platform.
1646  *
1647  * asrset_t is a simple array, defined in <sys/regset.h> as
1648  *	typedef	int64_t	asrset_t[16];	 %asr16 - > %asr31
1649  *
1650  * As such, we do not make use of the struct_layout facilities
1651  * for this routine.
1652  */
1653 static void
dump_asrset(note_state_t * state,const char * title)1654 dump_asrset(note_state_t *state, const char *title)
1655 {
1656 	static const sl_field_t ftemplate = { 0, sizeof (int64_t), 16, 0 };
1657 	sl_field_t	fdesc1, fdesc2;
1658 	sl_fmtbuf_t	buf1, buf2;
1659 	char		index1[MAXNDXSIZE * 2], index2[MAXNDXSIZE * 2];
1660 	Word		w, nelts;
1661 
1662 	fdesc1 = fdesc2 =  ftemplate;
1663 
1664 	/* We expect 16 values, but will print whatever is actually there */
1665 	nelts = state->ns_len / ftemplate.slf_eltlen;
1666 	if (nelts == 0)
1667 		return;
1668 
1669 	indent_enter(state, title, &fdesc1);
1670 
1671 	for (w = 0; w < nelts; ) {
1672 		(void) snprintf(index1, sizeof (index1),
1673 		    MSG_ORIG(MSG_FMT_ASRINDEX), w + 16);
1674 
1675 		if (w == (nelts - 1)) {
1676 			/* One last register is left */
1677 			dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE),
1678 			    INDENT, state->ns_vcol - state->ns_indent, index1,
1679 			    fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1));
1680 			fdesc1.slf_offset += fdesc1.slf_eltlen;
1681 			w++;
1682 			continue;
1683 		}
1684 
1685 		/* There are at least 2 more registers left. Show 2 up */
1686 		(void) snprintf(index2, sizeof (index2),
1687 		    MSG_ORIG(MSG_FMT_ASRINDEX), w + 17);
1688 
1689 		fdesc2.slf_offset = fdesc1.slf_offset + fdesc1.slf_eltlen;
1690 		dbg_print(0, MSG_ORIG(MSG_CNOTE_FMT_LINE_2UP), INDENT,
1691 		    state->ns_vcol - state->ns_indent, index1,
1692 		    state->ns_t2col - state->ns_vcol,
1693 		    fmt_num(state, &fdesc1, SL_FMT_NUM_ZHEX, buf1),
1694 		    state->ns_v2col - state->ns_t2col, index2,
1695 		    fmt_num(state, &fdesc2, SL_FMT_NUM_ZHEX, buf2));
1696 		fdesc1.slf_offset += 2 * fdesc1.slf_eltlen;
1697 		w += 2;
1698 	}
1699 
1700 	indent_exit(state);
1701 }
1702 
1703 corenote_ret_t
corenote(Half mach,int do_swap,Word type,const char * desc,Word descsz)1704 corenote(Half mach, int do_swap, Word type,
1705     const char *desc, Word descsz)
1706 {
1707 	note_state_t		state;
1708 
1709 	/*
1710 	 * Get the per-architecture layout definition
1711 	 */
1712 	state.ns_mach = mach;
1713 	state.ns_arch = sl_mach(state.ns_mach);
1714 	if (sl_mach(state.ns_mach) == NULL)
1715 		return (CORENOTE_R_BADARCH);
1716 
1717 	state.ns_swap = do_swap;
1718 	state.ns_indent = 4;
1719 	state.ns_t2col = state.ns_v2col = 0;
1720 	state.ns_data = desc;
1721 	state.ns_len = descsz;
1722 
1723 	switch (type) {
1724 	case NT_PRSTATUS:		/* prstatus_t <sys/old_procfs.h> */
1725 		state.ns_vcol = 26;
1726 		state.ns_t2col = 46;
1727 		state.ns_v2col = 60;
1728 		dump_prstatus(&state, MSG_ORIG(MSG_CNOTE_DESC_PRSTATUS_T));
1729 		return (CORENOTE_R_OK);
1730 
1731 	case NT_PRFPREG:		/* prfpregset_t	<sys/procfs_isa.h> */
1732 		return (CORENOTE_R_OK_DUMP);
1733 
1734 	case NT_PRPSINFO:		/* prpsinfo_t	<sys/old_procfs.h> */
1735 		state.ns_vcol = 20;
1736 		state.ns_t2col = 41;
1737 		state.ns_v2col = 54;
1738 		dump_prpsinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PRPSINFO_T));
1739 		return (CORENOTE_R_OK);
1740 
1741 	case NT_PRXREG:			/* prxregset_t <sys/procfs_isa.h> */
1742 		return (CORENOTE_R_OK_DUMP);
1743 
1744 	case NT_PLATFORM:		/* string from sysinfo(SI_PLATFORM) */
1745 		dbg_print(0, MSG_ORIG(MSG_NOTE_DESC));
1746 		dbg_print(0, MSG_ORIG(MSG_FMT_INDENT), safe_str(desc, descsz));
1747 		return (CORENOTE_R_OK);
1748 
1749 	case NT_AUXV:			/* auxv_t array	<sys/auxv.h> */
1750 		state.ns_vcol = 18;
1751 		dump_auxv(&state, MSG_ORIG(MSG_CNOTE_DESC_AUXV_T));
1752 		return (CORENOTE_R_OK);
1753 
1754 	case NT_GWINDOWS:		/* gwindows_t SPARC only */
1755 		return (CORENOTE_R_OK_DUMP);
1756 
1757 	case NT_ASRS:			/* asrset_t <sys/regset> sparcv9 only */
1758 		state.ns_vcol = 18;
1759 		state.ns_t2col = 38;
1760 		state.ns_v2col = 46;
1761 		dump_asrset(&state, MSG_ORIG(MSG_CNOTE_DESC_ASRSET_T));
1762 		return (CORENOTE_R_OK);
1763 
1764 	case NT_LDT:			/* ssd array <sys/sysi86.h> IA32 only */
1765 		return (CORENOTE_R_OK_DUMP);
1766 
1767 	case NT_PSTATUS:		/* pstatus_t <sys/procfs.h> */
1768 		state.ns_vcol = 22;
1769 		state.ns_t2col = 42;
1770 		state.ns_v2col = 54;
1771 		dump_pstatus(&state, MSG_ORIG(MSG_CNOTE_DESC_PSTATUS_T));
1772 		return (CORENOTE_R_OK);
1773 
1774 	case NT_PSINFO:			/* psinfo_t <sys/procfs.h> */
1775 		state.ns_vcol = 25;
1776 		state.ns_t2col = 45;
1777 		state.ns_v2col = 58;
1778 		dump_psinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PSINFO_T));
1779 		return (CORENOTE_R_OK);
1780 
1781 	case NT_PRCRED:			/* prcred_t <sys/procfs.h> */
1782 		state.ns_vcol = 20;
1783 		state.ns_t2col = 34;
1784 		state.ns_v2col = 44;
1785 		dump_prcred(&state, MSG_ORIG(MSG_CNOTE_DESC_PRCRED_T));
1786 		return (CORENOTE_R_OK);
1787 
1788 	case NT_UTSNAME:		/* struct utsname <sys/utsname.h> */
1789 		state.ns_vcol = 18;
1790 		dump_utsname(&state, MSG_ORIG(MSG_CNOTE_DESC_STRUCT_UTSNAME));
1791 		return (CORENOTE_R_OK);
1792 
1793 	case NT_LWPSTATUS:		/* lwpstatus_t <sys/procfs.h> */
1794 		state.ns_vcol = 24;
1795 		state.ns_t2col = 44;
1796 		state.ns_v2col = 54;
1797 		dump_lwpstatus(&state, MSG_ORIG(MSG_CNOTE_DESC_LWPSTATUS_T));
1798 		return (CORENOTE_R_OK);
1799 
1800 	case NT_LWPSINFO:		/* lwpsinfo_t <sys/procfs.h> */
1801 		state.ns_vcol = 22;
1802 		state.ns_t2col = 42;
1803 		state.ns_v2col = 54;
1804 		dump_lwpsinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_LWPSINFO_T));
1805 		return (CORENOTE_R_OK);
1806 
1807 	case NT_PRPRIV:			/* prpriv_t <sys/procfs.h> */
1808 		state.ns_vcol = 21;
1809 		state.ns_t2col = 34;
1810 		state.ns_v2col = 38;
1811 		dump_prpriv(&state, MSG_ORIG(MSG_CNOTE_DESC_PRPRIV_T));
1812 		return (CORENOTE_R_OK);
1813 
1814 	case NT_PRPRIVINFO:		/* priv_impl_info_t <sys/priv.h> */
1815 		state.ns_vcol = 29;
1816 		state.ns_t2col = 41;
1817 		state.ns_v2col = 56;
1818 		dump_priv_impl_info(&state,
1819 		    MSG_ORIG(MSG_CNOTE_DESC_PRIV_IMPL_INFO_T));
1820 		return (CORENOTE_R_OK);
1821 
1822 	case NT_CONTENT:		/* core_content_t <sys/corectl.h> */
1823 		if (sizeof (core_content_t) > descsz)
1824 			return (CORENOTE_R_BADDATA);
1825 		{
1826 			static sl_field_t fdesc = { 0, 8, 0, 0 };
1827 			Conv_cnote_cc_content_buf_t conv_buf;
1828 			core_content_t content;
1829 
1830 			state.ns_vcol = 8;
1831 			indent_enter(&state,
1832 			    MSG_ORIG(MSG_CNOTE_DESC_CORE_CONTENT_T),
1833 			    &fdesc);
1834 			content = extract_as_lword(&state, &fdesc);
1835 			print_str(&state, MSG_ORIG(MSG_STR_EMPTY),
1836 			    conv_cnote_cc_content(content, 0, &conv_buf));
1837 			indent_exit(&state);
1838 		}
1839 		return (CORENOTE_R_OK);
1840 
1841 	case NT_ZONENAME:		/* string from getzonenamebyid(3C) */
1842 		dbg_print(0, MSG_ORIG(MSG_NOTE_DESC));
1843 		dbg_print(0, MSG_ORIG(MSG_FMT_INDENT), safe_str(desc, descsz));
1844 		return (CORENOTE_R_OK);
1845 
1846 
1847 	case NT_FDINFO:
1848 		state.ns_vcol = 22;
1849 		state.ns_t2col = 41;
1850 		state.ns_v2col = 54;
1851 		dump_prfdinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PRFDINFO_T));
1852 		return (CORENOTE_R_OK);
1853 
1854 	case NT_SPYMASTER:
1855 		state.ns_vcol = 25;
1856 		state.ns_t2col = 45;
1857 		state.ns_v2col = 58;
1858 		dump_psinfo(&state, MSG_ORIG(MSG_CNOTE_DESC_PSINFO_T));
1859 		return (CORENOTE_R_OK);
1860 	}
1861 
1862 	return (CORENOTE_R_BADTYPE);
1863 }
1864