FreeBSD/cddl/contrib/opensolaris/tools/ctf/cvt/ctf.c
/*
 * Resurrect the labels stored in the CTF data, returning the index associated
 * with a label provided by the caller.  There are several cases, outlined
 * below.  Note that, given two labels, the one associated with the lesser type
 * index is considered to be older than the other.
 *
 *  1. matchlbl == NULL - return the index of the most recent label.
 *  2. matchlbl == "BASE" - return the index of the oldest label.
 *  3. matchlbl != NULL, but doesn't match any labels in the section - warn
 *	the user, and proceed as if matchlbl == "BASE" (for safety).
 *  4. matchlbl != NULL, and matches one of the labels in the section - return
 *	the type index associated with the label.
 */
Resurrect the labels stored in the CTF data, returning the index associated
with a label provided by the caller.  There are several cases, outlined
below.  Note that, given two labels, the one associated with the lesser type
index is considered to be older than the other.

1. matchlbl == NULL - return the index of the most recent label.
2. matchlbl == "BASE" - return the index of the oldest label.
3. matchlbl != NULL, but doesn't match any labels in the section - warn
the user, and proceed as if matchlbl == "BASE" (for safety).
4. matchlbl != NULL, and matches one of the labels in the section - return
the type index associated with the label.
Resurrect the labels stored in the CTF data returning the index associated with a label provided by the caller . There are several cases outlined below . Note that given two labels the one associated with the lesser type index is considered to be older than the other . 1 . matchlbl == NULL - return the index of the most recent label . 2 . matchlbl == " BASE " - return the index of the oldest label . 3 . matchlbl ! = NULL but doesn ' t match any labels in the section - warn the user and proceed as if matchlbl == " BASE " ( for safety ) . 4 . matchlbl ! = NULL and matches one of the labels in the section - return the type index associated with the label .
static int
resurrect_labels(ctf_header_t *h, tdata_t *td, caddr_t ctfdata, char *matchlbl)
{
	caddr_t buf = ctfdata + h->cth_lbloff;
	caddr_t sbuf = ctfdata + h->cth_stroff;
	size_t bufsz = h->cth_objtoff - h->cth_lbloff;
	int lastidx = 0, baseidx = -1;
	char *baselabel = NULL;
	ctf_lblent_t *ctl;
	void *v = (void *) buf;
	for (ctl = v; (caddr_t)ctl < buf + bufsz; ctl++) {
		char *label = sbuf + ctl->ctl_label;
		lastidx = ctl->ctl_typeidx;
		debug(3, "Resurrected label %s type idx %d\n", label, lastidx);
		tdata_label_add(td, label, lastidx);
		if (baseidx == -1) {
			baseidx = lastidx;
			baselabel = label;
			if (matchlbl != NULL && streq(matchlbl, "BASE"))
				return (lastidx);
		}
		if (matchlbl != NULL && streq(label, matchlbl))
			return (lastidx);
	}
	if (matchlbl != NULL) {
		warning("%s: Cannot find label `%s' - using base (%s)\n",
		    curfile, matchlbl, (baselabel ? baselabel : "NONE"));
		tdata_label_free(td);
		tdata_label_add(td, baselabel, baseidx);
		return (baseidx);
	}
	return (lastidx);
}
static int resurrect_labels ( ctf_header_t * h , tdata_t * td , caddr_t ctfdata , char * matchlbl ) { caddr_t buf = ctfdata + h -> cth_lbloff ; caddr_t sbuf = ctfdata + h -> cth_stroff ; size_t bufsz = h -> cth_objtoff - h -> cth_lbloff ; int lastidx = 0 , baseidx = -1 ; char * baselabel = NULL ; ctf_lblent_t * ctl ; void * v = ( void * ) buf ; for ( ctl = v ; ( caddr_t ) ctl < buf + bufsz ; ctl ++ ) { char * label = sbuf + ctl -> ctl_label ; lastidx = ctl -> ctl_typeidx ; debug ( 3 , " \n " , label , lastidx ) ; tdata_label_add ( td , label , lastidx ) ; if ( baseidx == -1 ) { baseidx = lastidx ; baselabel = label ; if ( matchlbl != NULL && streq ( matchlbl , " " ) ) return ( lastidx ) ; } if ( matchlbl != NULL && streq ( label , matchlbl ) ) return ( lastidx ) ; } if ( matchlbl != NULL ) { warning ( " \n " , curfile , matchlbl , ( baselabel ? baselabel : " " ) ) ; tdata_label_free ( td ) ; tdata_label_add ( td , baselabel , baseidx ) ; return ( baseidx ) ; } return ( lastidx ) ; }
Resurrect the labels stored in the CTF data, returning the index associated
 with a label provided by the caller.
Resurrect the labels stored in the CTF data returning the index associated with a label provided by the caller .
/* User provided a label that didn't match */