FreeBSD/cddl/contrib/opensolaris/lib/libdtrace/common/dt_print.c
/*
 * Print one member of a structure.  This callback is invoked from
 * ctf_type_visit() recursively.
 */
Print one member of a structure.  This callback is invoked from
ctf_type_visit() recursively.
Print one member of a structure . This callback is invoked from ctf_type_visit () recursively .
static int
dt_print_member(const char *name, ctf_id_t id, ulong_t off, int depth,
    void *data)
{
	char type[DT_TYPE_NAMELEN];
	int kind;
	dt_printarg_t *pap = data;
	FILE *fp = pap->pa_file;
	ctf_file_t *ctfp = pap->pa_ctfp;
	boolean_t arraymember;
	boolean_t brief;
	ctf_encoding_t e;
	ctf_id_t rtype;
	dt_print_trailing_braces(pap, depth);
	if (depth < pap->pa_depth)
		(void) fprintf(fp, "\n");
	pap->pa_depth = depth;
	if ((rtype = ctf_type_resolve(ctfp, id)) == CTF_ERR ||
	    (kind = ctf_type_kind(ctfp, rtype)) == CTF_ERR ||
	    kind < CTF_K_INTEGER || kind > CTF_K_FORWARD) {
		dt_print_indent(pap);
		(void) fprintf(fp, "%s = <invalid type %lu>", name, id);
		return (0);
	}
	dt_print_type_name(ctfp, id, type, sizeof (type));
	arraymember = (pap->pa_nest != 0 && depth == 0);
	brief = (arraymember && !CTF_IS_STRUCTLIKE(kind));
	if (!brief) {
		if (arraymember)
			(void) fprintf(fp, "\n");
		dt_print_indent(pap);
		(void) fprintf(fp, "%s", type);
		if (name[0] != '\0') {
			if (type[strlen(type) - 1] != '*' &&
			    type[strlen(type) -1] != ' ') {
				(void) fprintf(fp, " ");
			}
			(void) fprintf(fp, "%s", name);
			if (kind == CTF_K_INTEGER &&
			    ctf_type_encoding(ctfp, id, &e) == 0) {
				ulong_t bits = e.cte_bits;
				ulong_t size = bits / NBBY;
				if (bits % NBBY != 0 ||
				    off % NBBY != 0 ||
				    size > 8 ||
				    size != ctf_type_size(ctfp, id)) {
					(void) fprintf(fp, " :%lu", bits);
				}
			}
			(void) fprintf(fp, " =");
		}
		(void) fprintf(fp, " ");
	}
	dt_printfuncs[kind - 1](rtype, off, pap);
	if (!brief)
		(void) fprintf(fp, "\n");
	return (0);
}
static int dt_print_member ( const char * name , ctf_id_t id , ulong_t off , int depth , void * data ) { char type [ DT_TYPE_NAMELEN ] ; int kind ; dt_printarg_t * pap = data ; FILE * fp = pap -> pa_file ; ctf_file_t * ctfp = pap -> pa_ctfp ; boolean_t arraymember ; boolean_t brief ; ctf_encoding_t e ; ctf_id_t rtype ; dt_print_trailing_braces ( pap , depth ) ; if ( depth < pap -> pa_depth ) ( void ) fprintf ( fp , " \n " ) ; pap -> pa_depth = depth ; if ( ( rtype = ctf_type_resolve ( ctfp , id ) ) == CTF_ERR || ( kind = ctf_type_kind ( ctfp , rtype ) ) == CTF_ERR || kind < CTF_K_INTEGER || kind > CTF_K_FORWARD ) { dt_print_indent ( pap ) ; ( void ) fprintf ( fp , " " , name , id ) ; return ( 0 ) ; } dt_print_type_name ( ctfp , id , type , sizeof ( type ) ) ; arraymember = ( pap -> pa_nest != 0 && depth == 0 ) ; brief = ( arraymember && ! CTF_IS_STRUCTLIKE ( kind ) ) ; if ( ! brief ) { if ( arraymember ) ( void ) fprintf ( fp , " \n " ) ; dt_print_indent ( pap ) ; ( void ) fprintf ( fp , " " , type ) ; if ( name [ 0 ] != ' \0 ' ) { if ( type [ strlen ( type ) - 1 ] != ' ' && type [ strlen ( type ) - 1 ] != ' ' ) { ( void ) fprintf ( fp , " " ) ; } ( void ) fprintf ( fp , " " , name ) ; if ( kind == CTF_K_INTEGER && ctf_type_encoding ( ctfp , id , & e ) == 0 ) { ulong_t bits = e . cte_bits ; ulong_t size = bits / NBBY ; if ( bits % NBBY != 0 || off % NBBY != 0 || size > 8 || size != ctf_type_size ( ctfp , id ) ) { ( void ) fprintf ( fp , " " , bits ) ; } } ( void ) fprintf ( fp , " " ) ; } ( void ) fprintf ( fp , " " ) ; } dt_printfuncs [ kind - 1 ] ( rtype , off , pap ) ; if ( ! brief ) ( void ) fprintf ( fp , " \n " ) ; return ( 0 ) ; }
Print one member of a structure.
Print one member of a structure .
/*
	 * dt_print_trailing_braces() doesn't include the trailing newline; add
	 * it here if necessary.
	 */ /*
		 * If this is a direct array member and a struct (otherwise
		 * brief would be true), then print a trailing newline, as the
		 * array printing code doesn't include it because it might be a
		 * simple type.
		 */ /* always print the type */ /*
			 * For aesthetics, we don't include a space between the
			 * type name and member name if the type is a pointer.
			 * This will give us "void *foo =" instead of "void *
			 * foo =".  Unions also have the odd behavior that the
			 * type name is returned as "union ", with a trailing
			 * space, so we also avoid printing a space if the type
			 * name already ends with a space.
			 */ /*
			 * If this looks like a bitfield, or is an integer not
			 * aligned on a byte boundary, print the number of
			 * bits after the name.
			 */ /* direct simple array members are not separated by newlines */