Update vendor-sys/illumos/dist to illumos-gate 13752:9f5f6c52ba19

(non-zfs part)

Obtained from:	ssh://anonhg@hg.illumos.org/illumos-gate
This commit is contained in:
Martin Matuska 2012-07-18 10:58:30 +00:00
parent 5b5bfb7422
commit 27385285a1

View File

@ -22,6 +22,10 @@
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 2012 Jason King. All rights reserved.
* Use is subject to license terms.
*/
/*
* DWARF to tdata conversion
@ -360,6 +364,37 @@ die_attr_form(dwarf_t *dw, Dwarf_Attribute attr)
return (0);
}
/*
* the following functions lookup the value of an attribute in a DIE:
*
* die_signed
* die_unsigned
* die_bool
* die_string
*
* They all take the same parameters (with the exception of valp which is
* a pointer to the type of the attribute we are looking up):
*
* dw - the dwarf object to look in
* die - the DIE we're interested in
* name - the name of the attribute to lookup
* valp - pointer to where the value of the attribute is placed
* req - if the value is required (0 / non-zero)
*
* If the attribute is not found, one of the following happens:
* - program terminates (req is non-zero)
* - function returns 0
*
* If the value is found, and in a form (class) we can handle, the function
* returns 1.
*
* Currently, we can only handle attribute values that are stored as
* constants (immediate value). If an attribute has a form we cannot
* handle (for example VLAs may store the dimensions of the array
* as a DWARF expression that can compute it at runtime by reading
* values off the stack or other locations in memory), it is treated
* the same as if the attribute does not exist.
*/
static int
die_signed(dwarf_t *dw, Dwarf_Die die, Dwarf_Half name, Dwarf_Signed *valp,
int req)
@ -371,6 +406,9 @@ die_signed(dwarf_t *dw, Dwarf_Die die, Dwarf_Half name, Dwarf_Signed *valp,
return (0); /* die_attr will terminate for us if necessary */
if (dwarf_formsdata(attr, &val, &dw->dw_err) != DW_DLV_OK) {
if (req == 0)
return (0);
terminate("die %llu: failed to get signed (form 0x%x)\n",
die_off(dw, die), die_attr_form(dw, attr));
}
@ -392,6 +430,9 @@ die_unsigned(dwarf_t *dw, Dwarf_Die die, Dwarf_Half name, Dwarf_Unsigned *valp,
return (0); /* die_attr will terminate for us if necessary */
if (dwarf_formudata(attr, &val, &dw->dw_err) != DW_DLV_OK) {
if (req == 0)
return (0);
terminate("die %llu: failed to get unsigned (form 0x%x)\n",
die_off(dw, die), die_attr_form(dw, attr));
}
@ -412,6 +453,9 @@ die_bool(dwarf_t *dw, Dwarf_Die die, Dwarf_Half name, Dwarf_Bool *valp, int req)
return (0); /* die_attr will terminate for us if necessary */
if (dwarf_formflag(attr, &val, &dw->dw_err) != DW_DLV_OK) {
if (req == 0)
return (0);
terminate("die %llu: failed to get bool (form 0x%x)\n",
die_off(dw, die), die_attr_form(dw, attr));
}
@ -432,6 +476,9 @@ die_string(dwarf_t *dw, Dwarf_Die die, Dwarf_Half name, char **strp, int req)
return (0); /* die_attr will terminate for us if necessary */
if (dwarf_formstring(attr, &str, &dw->dw_err) != DW_DLV_OK) {
if (req == 0)
return (0);
terminate("die %llu: failed to get string (form 0x%x)\n",
die_off(dw, die), die_attr_form(dw, attr));
}
@ -1791,6 +1838,27 @@ die_resolve(dwarf_t *dw)
} while (dw->dw_nunres != 0);
}
/*
* Any object containing at least one allocatable section of non-0 size is
* taken to be a file which should contain DWARF type information
*/
static boolean_t
should_have_dwarf(Elf *elf)
{
Elf_Scn *scn = NULL;
while ((scn = elf_nextscn(elf, scn)) != NULL) {
GElf_Shdr shdr;
gelf_getshdr(scn, &shdr);
if ((shdr.sh_flags & SHF_ALLOC) &&
(shdr.sh_size != 0))
return (B_TRUE);
}
return (B_FALSE);
}
/*ARGSUSED*/
int
dw_read(tdata_t *td, Elf *elf, const char *filename)
@ -1814,8 +1882,12 @@ dw_read(tdata_t *td, Elf *elf, const char *filename)
if ((rc = dwarf_elf_init(elf, DW_DLC_READ, NULL, NULL, &dw.dw_dw,
&dw.dw_err)) == DW_DLV_NO_ENTRY) {
errno = ENOENT;
return (-1);
if (should_have_dwarf(elf)) {
errno = ENOENT;
return (-1);
} else {
return (0);
}
} else if (rc != DW_DLV_OK) {
if (dwarf_errno(dw.dw_err) == DW_DLE_DEBUG_INFO_NULL) {
/*
@ -1834,10 +1906,18 @@ dw_read(tdata_t *td, Elf *elf, const char *filename)
terminate("file does not contain valid DWARF data: %s\n",
dwarf_errmsg(dw.dw_err));
/*
* Some compilers emit no DWARF for empty files, others emit an empty
* compilation unit.
*/
if ((cu = die_sibling(&dw, NULL)) == NULL ||
(child = die_child(&dw, cu)) == NULL)
((child = die_child(&dw, cu)) == NULL) &&
should_have_dwarf(elf)) {
terminate("file does not contain dwarf type data "
"(try compiling with -g)\n");
} else if (child == NULL) {
return (0);
}
dw.dw_maxoff = nxthdr - 1;