dwarf_pro_die.c revision 261246
1238423Sjhb/*- 2238423Sjhb * Copyright (c) 2009 Kai Wang 3238423Sjhb * All rights reserved. 4238423Sjhb * 5238423Sjhb * Redistribution and use in source and binary forms, with or without 6238423Sjhb * modification, are permitted provided that the following conditions 7238423Sjhb * are met: 8238423Sjhb * 1. Redistributions of source code must retain the above copyright 9238423Sjhb * notice, this list of conditions and the following disclaimer. 10238423Sjhb * 2. Redistributions in binary form must reproduce the above copyright 11238423Sjhb * notice, this list of conditions and the following disclaimer in the 12238423Sjhb * documentation and/or other materials provided with the distribution. 13238423Sjhb * 14238423Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15238423Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16238423Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17238423Sjhb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18238423Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19238423Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20238423Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21238423Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22238423Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23238423Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24238423Sjhb * SUCH DAMAGE. 25238423Sjhb */ 26238423Sjhb 27238423Sjhb#include "_libdwarf.h" 28238423Sjhb 29238423SjhbELFTC_VCSID("$Id: dwarf_pro_die.c 2074 2011-10-27 03:34:33Z jkoshy $"); 30238423Sjhb 31238423SjhbDwarf_Unsigned 32263221Sjmmvdwarf_add_die_to_debug(Dwarf_P_Debug dbg, Dwarf_P_Die first_die, 33238423Sjhb Dwarf_Error *error) 34238423Sjhb{ 35238423Sjhb 36238423Sjhb if (dbg == NULL || first_die == NULL) { 37258063Sjhb DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 38238423Sjhb return (DW_DLV_NOCOUNT); 39238423Sjhb } 40238423Sjhb 41258063Sjhb dbg->dbgp_root_die = first_die; 42258063Sjhb 43258063Sjhb return (DW_DLV_OK); 44238423Sjhb} 45258063Sjhb 46258063SjhbDwarf_P_Die 47258063Sjhbdwarf_new_die(Dwarf_P_Debug dbg, Dwarf_Tag new_tag, 48238423Sjhb Dwarf_P_Die parent, Dwarf_P_Die child, Dwarf_P_Die left_sibling, 49238423Sjhb Dwarf_P_Die right_sibling, Dwarf_Error *error) 50238423Sjhb{ 51238423Sjhb Dwarf_P_Die die; 52238423Sjhb int count; 53238423Sjhb 54238423Sjhb if (dbg == NULL) { 55238423Sjhb DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 56238423Sjhb return (DW_DLV_BADADDR); 57238423Sjhb } 58238423Sjhb 59238423Sjhb count = _dwarf_die_count_links(parent, child, left_sibling, 60238423Sjhb right_sibling); 61238423Sjhb 62238423Sjhb if (count > 1) { 63238423Sjhb DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 64238423Sjhb return (DW_DLV_BADADDR); 65238423Sjhb } 66238423Sjhb 67238423Sjhb if (_dwarf_die_alloc(dbg, &die, error) != DW_DLE_NONE) 68238423Sjhb return (DW_DLV_BADADDR); 69238423Sjhb 70238423Sjhb die->die_dbg = dbg; 71238423Sjhb die->die_tag = new_tag; 72238423Sjhb 73238423Sjhb STAILQ_INSERT_TAIL(&dbg->dbgp_dielist, die, die_pro_next); 74238423Sjhb 75238423Sjhb if (count == 0) 76238423Sjhb return (die); 77238423Sjhb 78238423Sjhb _dwarf_die_link(die, parent, child, left_sibling, right_sibling); 79238423Sjhb 80238423Sjhb return (die); 81238423Sjhb} 82238423Sjhb 83238423SjhbDwarf_P_Die 84238423Sjhbdwarf_die_link(Dwarf_P_Die die, Dwarf_P_Die parent, 85238423Sjhb Dwarf_P_Die child, Dwarf_P_Die left_sibling, Dwarf_P_Die right_sibling, 86238423Sjhb Dwarf_Error *error) 87238423Sjhb{ 88238423Sjhb Dwarf_Debug dbg; 89238423Sjhb int count; 90238423Sjhb 91238423Sjhb 92238423Sjhb if (die == NULL) { 93238423Sjhb DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT); 94238423Sjhb return (DW_DLV_BADADDR); 95238423Sjhb } 96238423Sjhb 97238423Sjhb dbg = die->die_dbg; 98238423Sjhb count = _dwarf_die_count_links(parent, child, left_sibling, 99238423Sjhb right_sibling); 100238423Sjhb 101238423Sjhb if (count > 1) { 102238423Sjhb DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT); 103263221Sjmmv return (DW_DLV_BADADDR); 104238423Sjhb } else if (count == 0) 105238423Sjhb return (die); 106238423Sjhb 107238423Sjhb _dwarf_die_link(die, parent, child, left_sibling, right_sibling); 108238423Sjhb 109238423Sjhb return (die); 110238423Sjhb} 111238423Sjhb