Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Oct 2007 05:31:51 GMT
From:      John Birrell <jb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 127665 for review
Message-ID:  <200710180531.l9I5VpUr007413@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=127665

Change 127665 by jb@jb_freebsd1 on 2007/10/18 05:31:15

	Fix compiler warnings for WARNS=6.
	
	Update to reflect the new BSD libdwarf which doesn't return
	objects in malloced memory. Our libdwarf API doesn't require
	looking up an Attribute for a DIE and then going back to
	trundle trough to get the value. Instead, given a DIE, the
	attribute value can be obtained directly since the library
	resolved the AttributeValue (as opposed to the Attribute which
	is part of the Abbrev) when the DWARF data was initialised.

Affected files ...

.. //depot/projects/dtrace/src/contrib/opensolaris/tools/ctf/cvt/dwarf.c#8 edit

Differences ...

==== //depot/projects/dtrace/src/contrib/opensolaris/tools/ctf/cvt/dwarf.c#8 (text) ====

@@ -129,7 +129,7 @@
 typedef struct dwarf {
 	Dwarf_Debug dw_dw;		/* for libdwarf */
 	Dwarf_Error dw_err;		/* for libdwarf */
-	Dwarf_Unsigned dw_maxoff;	/* highest legal offset in this cu */
+	Dwarf_Off dw_maxoff;		/* highest legal offset in this cu */
 	tdata_t *dw_td;			/* root of the tdesc/iidesc tree */
 	hash_t *dw_tidhash;		/* hash of tdescs by t_id */
 	hash_t *dw_fwdhash;		/* hash of fwd decls by name */
@@ -272,7 +272,7 @@
 		return (off);
 
 	terminate("failed to get offset for die: %s\n",
-	    dwarf_errmsg(dw->dw_err));
+	    dwarf_errmsg(&dw->dw_err));
 	/*NOTREACHED*/
 	return (0);
 }
@@ -290,7 +290,7 @@
 		return (NULL);
 
 	terminate("die %llu: failed to find type sibling: %s\n",
-	    die_off(dw, die), dwarf_errmsg(dw->dw_err));
+	    die_off(dw, die), dwarf_errmsg(&dw->dw_err));
 	/*NOTREACHED*/
 	return (NULL);
 }
@@ -307,7 +307,7 @@
 		return (NULL);
 
 	terminate("die %llu: failed to find type child: %s\n",
-	    die_off(dw, die), dwarf_errmsg(dw->dw_err));
+	    die_off(dw, die), dwarf_errmsg(&dw->dw_err));
 	/*NOTREACHED*/
 	return (NULL);
 }
@@ -321,7 +321,7 @@
 		return (tag);
 
 	terminate("die %llu: failed to get tag for type: %s\n",
-	    die_off(dw, die), dwarf_errmsg(dw->dw_err));
+	    die_off(dw, die), dwarf_errmsg(&dw->dw_err));
 	/*NOTREACHED*/
 	return (0);
 }
@@ -344,43 +344,21 @@
 	}
 
 	terminate("die %llu: failed to get attribute for type: %s\n",
-	    die_off(dw, die), dwarf_errmsg(dw->dw_err));
+	    die_off(dw, die), dwarf_errmsg(&dw->dw_err));
 	/*NOTREACHED*/
 	return (NULL);
 }
 
-static Dwarf_Half
-die_attr_form(dwarf_t *dw, Dwarf_Attribute attr)
-{
-	Dwarf_Half form;
-
-	if (dwarf_whatform(attr, &form, &dw->dw_err) == DW_DLV_OK)
-		return (form);
-
-	terminate("failed to get attribute form for type: %s\n",
-	    dwarf_errmsg(dw->dw_err));
-	/*NOTREACHED*/
-	return (0);
-}
-
 static int
 die_signed(dwarf_t *dw, Dwarf_Die die, Dwarf_Half name, Dwarf_Signed *valp,
     int req)
 {
-	Dwarf_Attribute attr;
-	Dwarf_Signed val;
-
-	if ((attr = die_attr(dw, die, name, req)) == NULL)
-		return (0); /* die_attr will terminate for us if necessary */
-
-	if (dwarf_formsdata(attr, &val, &dw->dw_err) != DW_DLV_OK) {
-		terminate("die %llu: failed to get signed (form 0x%x)\n",
-		    die_off(dw, die), die_attr_form(dw, attr));
+	if (dwarf_attrval_signed(die, name, valp, &dw->dw_err) != DWARF_E_NONE) {
+		if (req) 
+			terminate("die %llu: failed to get unsigned: %s\n",
+			    die_off(dw, die), dwarf_errmsg(&dw->dw_err));
 	}
 
-	dwarf_dealloc(dw->dw_dw, attr, DW_DLA_ATTR);
-
-	*valp = val;
 	return (1);
 }
 
@@ -388,78 +366,55 @@
 die_unsigned(dwarf_t *dw, Dwarf_Die die, Dwarf_Half name, Dwarf_Unsigned *valp,
     int req)
 {
-	Dwarf_Attribute attr;
-	Dwarf_Unsigned val;
-
-	if ((attr = die_attr(dw, die, name, req)) == NULL)
-		return (0); /* die_attr will terminate for us if necessary */
-
-	if (dwarf_formudata(attr, &val, &dw->dw_err) != DW_DLV_OK) {
-		terminate("die %llu: failed to get unsigned (form 0x%x)\n",
-		    die_off(dw, die), die_attr_form(dw, attr));
+	if (dwarf_attrval_unsigned(die, name, valp, &dw->dw_err) != DWARF_E_NONE) {
+		if (req) 
+			terminate("die %llu: failed to get unsigned: %s\n",
+			    die_off(dw, die), dwarf_errmsg(&dw->dw_err));
 	}
 
-	dwarf_dealloc(dw->dw_dw, attr, DW_DLA_ATTR);
-
-	*valp = val;
 	return (1);
 }
 
 static int
 die_bool(dwarf_t *dw, Dwarf_Die die, Dwarf_Half name, Dwarf_Bool *valp, int req)
 {
-	Dwarf_Attribute attr;
-	Dwarf_Bool val;
-
-	if ((attr = die_attr(dw, die, name, req)) == NULL)
-		return (0); /* die_attr will terminate for us if necessary */
-
-	if (dwarf_formflag(attr, &val, &dw->dw_err) != DW_DLV_OK) {
-		terminate("die %llu: failed to get bool (form 0x%x)\n",
-		    die_off(dw, die), die_attr_form(dw, attr));
+	if (dwarf_attrval_flag(die, name, valp, &dw->dw_err) != DWARF_E_NONE) {
+		if (req) 
+			terminate("die %llu: failed to get flag: %s\n",
+			    die_off(dw, die), dwarf_errmsg(&dw->dw_err));
 	}
 
-	dwarf_dealloc(dw->dw_dw, attr, DW_DLA_ATTR);
-
-	*valp = val;
 	return (1);
 }
 
 static int
 die_string(dwarf_t *dw, Dwarf_Die die, Dwarf_Half name, char **strp, int req)
 {
-	Dwarf_Attribute attr;
-	char *str;
+	const char *str = NULL;
 
-	if ((attr = die_attr(dw, die, name, req)) == NULL)
-		return (0); /* die_attr will terminate for us if necessary */
-
-	if (dwarf_formstring(attr, &str, &dw->dw_err) != DW_DLV_OK) {
-		terminate("die %llu: failed to get string (form 0x%x)\n",
-		    die_off(dw, die), die_attr_form(dw, attr));
-	}
+	if (dwarf_attrval_string(die, name, &str, &dw->dw_err) != DWARF_E_NONE ||
+	    str == NULL) {
+		if (req) 
+			terminate("die %llu: failed to get string: %s\n",
+			    die_off(dw, die), dwarf_errmsg(&dw->dw_err));
+		else
+			*strp = NULL;
+	} else
+		*strp = xstrdup(str);
 
-	*strp = xstrdup(str);
-	dwarf_dealloc(dw->dw_dw, str, DW_DLA_STRING);
-
 	return (1);
 }
 
 static Dwarf_Off
 die_attr_ref(dwarf_t *dw, Dwarf_Die die, Dwarf_Half name)
 {
-	Dwarf_Attribute attr;
 	Dwarf_Off off;
 
-	attr = die_attr(dw, die, name, DW_ATTR_REQ);
-
-	if (dwarf_formref(attr, &off, &dw->dw_err) != DW_DLV_OK) {
-		terminate("die %llu: failed to get ref (form 0x%x)\n",
-		    die_off(dw, die), die_attr_form(dw, attr));
+	if (dwarf_attrval_unsigned(die, name, &off, &dw->dw_err) != DWARF_E_NONE) {
+		terminate("die %llu: failed to get ref: %s\n",
+		    die_off(dw, die), dwarf_errmsg(&dw->dw_err));
 	}
 
-	dwarf_dealloc(dw->dw_dw, attr, DW_DLA_ATTR);
-
 	return (off);
 }
 
@@ -523,21 +478,13 @@
 
 static int
 die_mem_offset(dwarf_t *dw, Dwarf_Die die, Dwarf_Half name,
-    Dwarf_Unsigned *valp, int req)
+    Dwarf_Unsigned *valp, int req __unused)
 {
-	Dwarf_Attribute attr;
-	Dwarf_Locdesc *loc;
-	Dwarf_Signed locnum;
+	Dwarf_Locdesc *loc = NULL;
+	Dwarf_Signed locnum = 0;
 
-	if ((attr = die_attr(dw, die, name, req)) == NULL)
-		return (0); /* die_attr will terminate for us if necessary */
-
-	if (dwarf_loclist(attr, &loc, &locnum, &dw->dw_err) != DW_DLV_OK) {
-		terminate("die %llu: failed to get mem offset location list\n",
-		    die_off(dw, die));
-	}
-
-	dwarf_dealloc(dw->dw_dw, attr, DW_DLA_ATTR);
+	if (dwarf_locdesc(die, name, &loc, &locnum, &dw->dw_err) != DW_DLV_OK)
+		return (0);
 
 	if (locnum != 1 || loc->ld_s->lr_atom != DW_OP_plus_uconst) {
 		terminate("die %llu: cannot parse member offset\n",
@@ -546,8 +493,10 @@
 
 	*valp = loc->ld_s->lr_number;
 
-	dwarf_dealloc(dw->dw_dw, loc->ld_s, DW_DLA_LOC_BLOCK);
-	dwarf_dealloc(dw->dw_dw, loc, DW_DLA_LOCDESC);
+	if (loc != NULL)
+		if (dwarf_locdesc_free(loc, &dw->dw_err) != DW_DLV_OK)
+			terminate("die %llu: cannot free location descriptor: %s\n",
+			    die_off(dw, die), dwarf_errmsg(&dw->dw_err));
 
 	return (1);
 }
@@ -641,7 +590,7 @@
 {
 	Dwarf_Unsigned uval;
 	Dwarf_Signed sval;
-	tdesc_t *ctdp;
+	tdesc_t *ctdp = NULL;
 	Dwarf_Die dim2;
 	ardef_t *ar;
 
@@ -741,7 +690,7 @@
 
 /*ARGSUSED1*/
 static int
-die_array_resolve(tdesc_t *tdp, tdesc_t **tdpp, void *private)
+die_array_resolve(tdesc_t *tdp, tdesc_t **tdpp __unused, void *private)
 {
 	dwarf_t *dw = private;
 	size_t sz;
@@ -771,7 +720,7 @@
 
 /*ARGSUSED1*/
 static int
-die_array_failed(tdesc_t *tdp, tdesc_t **tdpp, void *private)
+die_array_failed(tdesc_t *tdp, tdesc_t **tdpp __unused, void *private __unused)
 {
 	tdesc_t *cont = tdp->t_ardef->ad_contents;
 
@@ -867,7 +816,7 @@
 
 /*ARGSUSED1*/
 static int
-die_enum_resolve(tdesc_t *tdp, tdesc_t **tdpp, void *private)
+die_enum_resolve(tdesc_t *tdp, tdesc_t **tdpp __unused, void *private)
 {
 	dwarf_t *dw = private;
 	tdesc_t *full = NULL;
@@ -939,8 +888,9 @@
 	/*
 	 * GCC allows empty SOUs as an extension.
 	 */
-	if ((mem = die_child(dw, str)) == NULL)
+	if ((mem = die_child(dw, str)) == NULL) {
 		goto out;
+	}
 
 	mlastp = &tdp->t_members;
 
@@ -967,7 +917,7 @@
 		 * bug 11816).
 		 */
 		if ((ml->ml_name = die_name(dw, mem)) == NULL)
-			ml->ml_name = "";
+			ml->ml_name = NULL;
 
 		ml->ml_type = die_lookup_pass1(dw, mem, DW_AT_type);
 
@@ -984,7 +934,7 @@
 			ml->ml_size = tdesc_bitsize(ml->ml_type);
 
 		if (die_unsigned(dw, mem, DW_AT_bit_offset, &bitoff, 0)) {
-#ifdef	_BIG_ENDIAN
+#ifdef	FROGFACE_BIG_ENDIAN
 			ml->ml_offset += bitoff;
 #else
 			ml->ml_offset += tdesc_bitsize(ml->ml_type) - bitoff -
@@ -1058,7 +1008,7 @@
 
 /*ARGSUSED1*/
 static int
-die_sou_resolve(tdesc_t *tdp, tdesc_t **tdpp, void *private)
+die_sou_resolve(tdesc_t *tdp, tdesc_t **tdpp __unused, void *private)
 {
 	dwarf_t *dw = private;
 	mlist_t *ml;
@@ -1117,7 +1067,7 @@
 
 /*ARGSUSED1*/
 static int
-die_sou_failed(tdesc_t *tdp, tdesc_t **tdpp, void *private)
+die_sou_failed(tdesc_t *tdp, tdesc_t **tdpp __unused, void *private __unused)
 {
 	const char *typename = (tdp->t_type == STRUCT ? "struct" : "union");
 	mlist_t *ml;
@@ -1146,7 +1096,7 @@
 	fndef_t *fn;
 	int i;
 
-	debug(3, "die %llu: creating function pointer\n", off);
+	debug(3, "die %llu <%llx>: creating function pointer\n", off, off);
 
 	/*
 	 * We'll begin by processing any type definition nodes that may be
@@ -1176,7 +1126,6 @@
 	tdp->t_type = FUNCTION;
 
 	if ((attr = die_attr(dw, die, DW_AT_type, 0)) != NULL) {
-		dwarf_dealloc(dw->dw_dw, attr, DW_DLA_ATTR);
 		fn->fn_ret = die_lookup_pass1(dw, die, DW_AT_type);
 	} else {
 		fn->fn_ret = tdesc_intr_void(dw);
@@ -1200,7 +1149,7 @@
 
 		fn->fn_args = xcalloc(sizeof (tdesc_t *) * fn->fn_nargs);
 		for (i = 0, arg = die_child(dw, die);
-		    arg != NULL && i < fn->fn_nargs;
+		    arg != NULL && i < (int) fn->fn_nargs;
 		    arg = die_sibling(dw, arg)) {
 			if (die_tag(dw, arg) != DW_TAG_formal_parameter)
 				continue;
@@ -1225,7 +1174,8 @@
 die_base_name_parse(const char *name, char **newp)
 {
 	char buf[100];
-	char *base, *c;
+	char const *base;
+	char *c;
 	int nlong = 0, nshort = 0, nchar = 0, nint = 0;
 	int sign = 1;
 	char fmt = '\0';
@@ -1309,7 +1259,7 @@
 #else
 	{ { 12, 16 }, { CTF_FP_LDOUBLE, CTF_FP_LDCPLX, CTF_FP_LDIMAGRY } },
 #endif
-	{ { 0, 0 } }
+	{ { 0, 0 }, { 0, 0, 0 } }
 };
 
 static uint_t
@@ -1410,8 +1360,13 @@
 	 */
 	(void) die_unsigned(dw, base, DW_AT_byte_size, &sz, DW_ATTR_REQ);
 
-	if (tdp->t_name == NULL)
-		terminate("die %llu: base type without name\n", off);
+	if (tdp->t_name == NULL) {
+		/* terminate("die %llu: base type without name\n", off); */
+		char dummy_name[64];
+		snprintf(dummy_name, sizeof(dummy_name), "die%lx", (u_long) off);
+		debug(1, "die %llu: has no name. Using a dummy one: '%s'\n", off, dummy_name);
+		tdp->t_name = xstrdup(dummy_name);
+	}
 
 	/* XXX make a name parser for float too */
 	if ((intr = die_base_name_parse(tdp->t_name, &new)) != NULL) {
@@ -1452,7 +1407,6 @@
 	tdp->t_type = type;
 
 	if ((attr = die_attr(dw, die, DW_AT_type, 0)) != NULL) {
-		dwarf_dealloc(dw->dw_dw, attr, DW_DLA_ATTR);
 		tdp->t_tdesc = die_lookup_pass1(dw, die, DW_AT_type);
 	} else {
 		tdp->t_tdesc = tdesc_intr_void(dw);
@@ -1505,14 +1459,14 @@
 
 /*ARGSUSED3*/
 static void
-die_function_create(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off, tdesc_t *tdp)
+die_function_create(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off, tdesc_t *tdp __unused)
 {
 	Dwarf_Die arg;
 	Dwarf_Half tag;
 	iidesc_t *ii;
 	char *name;
 
-	debug(3, "die %llu: creating function definition\n", off);
+	debug(3, "die %llu: creating function definition '%s'\n", off);
 
 	/*
 	 * We'll begin by processing any type definition nodes that may be
@@ -1551,7 +1505,7 @@
 
 	for (arg = die_child(dw, die); arg != NULL;
 	    arg = die_sibling(dw, arg)) {
-		char *name;
+		char *name1;
 
 		debug(3, "die %llu: looking at sub member at %llu\n",
 		    off, die_off(dw, die));
@@ -1559,13 +1513,13 @@
 		if (die_tag(dw, arg) != DW_TAG_formal_parameter)
 			continue;
 
-		if ((name = die_name(dw, arg)) == NULL) {
+		if ((name1 = die_name(dw, arg)) == NULL) {
 			terminate("die %llu: func arg %d has no name\n",
 			    off, ii->ii_nargs + 1);
 		}
 
-		if (strcmp(name, "...") == 0) {
-			free(name);
+		if (strcmp(name1, "...") == 0) {
+			free(name1);
 			ii->ii_vargs = 1;
 			continue;
 		}
@@ -1597,7 +1551,7 @@
 
 /*ARGSUSED3*/
 static void
-die_variable_create(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off, tdesc_t *tdp)
+die_variable_create(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off, tdesc_t *tdp __unused)
 {
 	iidesc_t *ii;
 	char *name;
@@ -1619,7 +1573,7 @@
 
 /*ARGSUSED2*/
 static int
-die_fwd_resolve(tdesc_t *fwd, tdesc_t **fwdp, void *private)
+die_fwd_resolve(tdesc_t *fwd, tdesc_t **fwdp, void *private __unused)
 {
 	if (fwd->t_flags & TDESC_F_RESOLVED)
 		return (1);
@@ -1637,7 +1591,7 @@
 
 /*ARGSUSED*/
 static void
-die_lexblk_descend(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off, tdesc_t *tdp)
+die_lexblk_descend(dwarf_t *dw, Dwarf_Die die, Dwarf_Off off __unused, tdesc_t *tdp __unused)
 {
 	Dwarf_Die child = die_child(dw, die);
 
@@ -1720,8 +1674,14 @@
 		tdesc_add(dw, tdp);
 	}
 
-	if (tdp != NULL)
+	if (tdp != NULL) {
 		tdp->t_name = die_name(dw, die);
+		if (tdp->t_name == NULL) {
+			char dummy_name[64];
+			snprintf(dummy_name, sizeof(dummy_name), "die%lx", (u_long) off);
+			tdp->t_name = xstrdup(dummy_name);
+		}
+	}
 
 	dc->dc_create(dw, die, off, tdp);
 }
@@ -1783,7 +1743,7 @@
 
 		debug(3, "resolve: pass %d, %u left\n", pass, dw->dw_nunres);
 
-		if (dw->dw_nunres == last) {
+		if ((int) dw->dw_nunres == last) {
 			fprintf(stderr, "%s: failed to resolve the following "
 			    "types:\n", progname);
 
@@ -1801,11 +1761,12 @@
 
 /*ARGSUSED*/
 int
-dw_read(tdata_t *td, Elf *elf, const char *filename)
+dw_read(tdata_t *td, Elf *elf, char *filename __unused)
 {
 	Dwarf_Unsigned abboff, hdrlen, nxthdr;
 	Dwarf_Half vers, addrsz;
-	Dwarf_Die cu, child;
+	Dwarf_Die cu = 0;
+	Dwarf_Die child = 0;
 	dwarf_t dw;
 	char *prod = NULL;
 	int rc;
@@ -1820,12 +1781,12 @@
 	dw.dw_enumhash = hash_new(TDESC_HASH_BUCKETS, tdesc_namehash,
 	    tdesc_namecmp);
 
-	if ((rc = dwarf_elf_init(elf, DW_DLC_READ, NULL, NULL, &dw.dw_dw,
+	if ((rc = dwarf_elf_init(elf, DW_DLC_READ, &dw.dw_dw,
 	    &dw.dw_err)) == DW_DLV_NO_ENTRY) {
 		errno = ENOENT;
 		return (-1);
 	} else if (rc != DW_DLV_OK) {
-		if (dwarf_errno(dw.dw_err) == DW_DLE_DEBUG_INFO_NULL) {
+		if (dwarf_errno(&dw.dw_err) == DW_DLE_DEBUG_INFO_NULL) {
 			/*
 			 * There's no type data in the DWARF section, but
 			 * libdwarf is too clever to handle that properly.
@@ -1834,13 +1795,14 @@
 		}
 
 		terminate("failed to initialize DWARF: %s\n",
-		    dwarf_errmsg(dw.dw_err));
+		    dwarf_errmsg(&dw.dw_err));
 	}
 
 	if ((rc = dwarf_next_cu_header(dw.dw_dw, &hdrlen, &vers, &abboff,
-	    &addrsz, &nxthdr, &dw.dw_err)) != DW_DLV_OK ||
-	    (cu = die_sibling(&dw, NULL)) == NULL ||
-	    (child = die_child(&dw, cu)) == NULL)
+	    &addrsz, &nxthdr, &dw.dw_err)) != DW_DLV_OK)
+		terminate("rc = %d %s\n", rc, dwarf_errmsg(&dw.dw_err));
+
+	if ((cu = die_sibling(&dw, NULL)) == NULL)
 		terminate("file does not contain dwarf type data "
 		    "(try compiling with -g)\n");
 
@@ -1868,13 +1830,14 @@
 		debug(1, "CU name: %s\n", dw.dw_cuname);
 	}
 
-	die_create(&dw, child);
+	if ((child = die_child(&dw, cu)) != NULL)
+		die_create(&dw, child);
 
 	if ((rc = dwarf_next_cu_header(dw.dw_dw, &hdrlen, &vers, &abboff,
 	    &addrsz, &nxthdr, &dw.dw_err)) != DW_DLV_NO_ENTRY)
 		terminate("multiple compilation units not supported\n");
 
-	(void) dwarf_finish(dw.dw_dw, &dw.dw_err);
+	(void) dwarf_finish(&dw.dw_dw, &dw.dw_err);
 
 	die_resolve(&dw);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200710180531.l9I5VpUr007413>