/*-
* Copyright (c) 2009,2010 Kai Wang
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
if (!dbg->dbg_info_loaded) {
ret = _dwarf_info_load(dbg, 1, 1, error);
if (ret != DW_DLE_NONE)
goto fail_cleanup;
}
/* Find the referenced CU. */
STAILQ_FOREACH(cu, &dbg->dbg_cu, cu_next) {
if (cu->cu_offset == nt->nt_cu_offset)
break;
}
nt->nt_cu = cu; /* FIXME: Check if NULL here */
/* Add name pairs. */
while (offset < ds->ds_size) {
cuoff = dbg->read(ds->ds_data, &offset, dwarf_size);
if (cuoff == 0)
break;
if ((np = malloc(sizeof(struct _Dwarf_NamePair))) ==
NULL) {
ret = DW_DLE_MEMORY;
DWARF_SET_ERROR(dbg, error, ret);
goto fail_cleanup;
}
np->np_nt = nt;
np->np_offset = cuoff;
p = (char *) ds->ds_data;
np->np_name = &p[offset];
while (p[offset++] != '\0')
;
STAILQ_INSERT_TAIL(&nt->nt_nplist, np, np_next);
ns->ns_len++;
}
}
/* Build array of name pairs from all tables. */
if (ns->ns_len > 0) {
if ((ns->ns_array = malloc(sizeof(Dwarf_NamePair) *
ns->ns_len)) == NULL) {
ret = DW_DLE_MEMORY;
DWARF_SET_ERROR(dbg, error, ret);
goto fail_cleanup;
}