diff options
Diffstat (limited to 'usr/src/tools/ctf/dwarf/common/pro_die.c')
-rw-r--r-- | usr/src/tools/ctf/dwarf/common/pro_die.c | 310 |
1 files changed, 181 insertions, 129 deletions
diff --git a/usr/src/tools/ctf/dwarf/common/pro_die.c b/usr/src/tools/ctf/dwarf/common/pro_die.c index f4129884e4..948b641146 100644 --- a/usr/src/tools/ctf/dwarf/common/pro_die.c +++ b/usr/src/tools/ctf/dwarf/common/pro_die.c @@ -1,6 +1,7 @@ /* - Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. + Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved. + Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License @@ -19,10 +20,10 @@ You should have received a copy of the GNU Lesser General Public License along with this program; if not, write the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301, USA. - Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, + Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, Mountain View, CA 94043, or: http://www.sgi.com @@ -50,121 +51,170 @@ void _dwarf_pro_add_at_to_die(Dwarf_P_Die die, Dwarf_P_Attribute attr); /*---------------------------------------------------------------------------- - This function creates a new die. - tag: tag of the new die to be created - parent,child,left,right: specify neighbors of the new die. Only - one of these may be non-null + This function creates a new die. + tag: tag of the new die to be created + parent,child,left,right: specify neighbors of the new die. Only + one of these may be non-null -----------------------------------------------------------------------------*/ Dwarf_P_Die dwarf_new_die(Dwarf_P_Debug dbg, - Dwarf_Tag tag, - Dwarf_P_Die parent, - Dwarf_P_Die child, - Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error * error) + Dwarf_Tag tag, + Dwarf_P_Die parent, + Dwarf_P_Die child, + Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error * error) { - Dwarf_P_Die new_die, ret_die; + Dwarf_P_Die ret_die = 0; - new_die = (Dwarf_P_Die) - _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Die_s)); + Dwarf_P_Die new_die = (Dwarf_P_Die) + _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Die_s)); if (new_die == NULL) { - DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_ALLOC, - (Dwarf_P_Die) DW_DLV_BADADDR); + DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_ALLOC, + (Dwarf_P_Die) DW_DLV_BADADDR); } new_die->di_parent = NULL; new_die->di_left = NULL; new_die->di_right = NULL; new_die->di_child = NULL; + new_die->di_last_child = NULL; new_die->di_tag = tag; - ret_die = - dwarf_die_link(new_die, parent, child, left, right, error); + new_die->di_dbg = dbg; + new_die->di_marker = 0; + ret_die = + dwarf_die_link(new_die, parent, child, left, right, error); return ret_die; } /*---------------------------------------------------------------------------- - This function links up a die to specified neighbors - parent,child,left,right: specify neighbors of the new die. Only - one of these may be non-null + This function links up a die to specified neighbors + parent,child,left,right: specify neighbors of the new die. Only + one of these may be non-null -----------------------------------------------------------------------------*/ Dwarf_P_Die dwarf_die_link(Dwarf_P_Die new_die, - Dwarf_P_Die parent, - Dwarf_P_Die child, - Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error * error) + Dwarf_P_Die parent, + Dwarf_P_Die child, + Dwarf_P_Die left, Dwarf_P_Die right, Dwarf_Error * error) { - int n_nulls; /* to count # of non null neighbors */ + /* Count the # of non null neighbors. */ + int n_nulls = 0; - n_nulls = 0; if (parent != NULL) { - n_nulls++; - new_die->di_parent = parent; - if (parent->di_child) { /* got to traverse the child's siblings - */ - Dwarf_P_Die curdie; - - curdie = parent->di_child; - while (curdie->di_right) - curdie = curdie->di_right; - curdie->di_right = new_die; /* attach to sibling list */ - new_die->di_left = curdie; /* back pointer */ - } else - parent->di_child = new_die; + n_nulls++; + if (new_die->di_parent != NULL) { + DWARF_P_DBG_ERROR(NULL, DW_DLE_LINK_LOOP, + (Dwarf_P_Die) DW_DLV_BADADDR); + } + new_die->di_parent = parent; + if (parent->di_child) { + + /* di_last_child identifies the last sibling, the + die we want to attach new_die to. */ + /* ASSERT: if di_child is set so is di_last_child. */ + Dwarf_P_Die former_lastchild = parent->di_last_child; + parent->di_last_child = new_die; + /* Attach to the new die to end of the sibling list. */ + former_lastchild->di_right = new_die; + new_die->di_left = former_lastchild; + } else { + parent->di_child = new_die; + parent->di_last_child = new_die; + } } if (child != NULL) { - n_nulls++; - new_die->di_child = child; - if (child->di_parent) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS, - (Dwarf_P_Die) DW_DLV_BADADDR); - } else - child->di_parent = new_die; + n_nulls++; + new_die->di_child = child; + new_die->di_last_child = child; + if (child->di_parent) { + DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS, + (Dwarf_P_Die) DW_DLV_BADADDR); + } else { + child->di_parent = new_die; + } } if (left != NULL) { - n_nulls++; - new_die->di_left = left; - if (left->di_right) /* there's already a right sibl, lets - insert */ - new_die->di_right = left->di_right; - left->di_right = new_die; - /* add parent pointer */ - if (new_die->di_parent) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS, - (Dwarf_P_Die) DW_DLV_BADADDR); - } else - new_die->di_parent = left->di_parent; + n_nulls++; + new_die->di_left = left; + if (left->di_right) { + /* There's already a right sibling of left, + insert the new die in the list. */ + new_die->di_right = left->di_right; + left->di_right->di_left = new_die; + } + left->di_right = new_die; + if (new_die->di_parent) { + DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS, + (Dwarf_P_Die) DW_DLV_BADADDR); + } else { + new_die->di_parent = left->di_parent; + } } if (right != NULL) { - n_nulls++; - new_die->di_right = right; - if (right->di_left) /* left sibl exists, try inserting */ - new_die->di_left = right->di_left; - right->di_left = new_die; - if (new_die->di_parent) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS, - (Dwarf_P_Die) DW_DLV_BADADDR); - } else - new_die->di_parent = right->di_parent; + n_nulls++; + new_die->di_right = right; + if (right->di_left) { + /* There is already a left sibling of the right die, + insert the new die in the list. */ + new_die->di_left = right->di_left; + right->di_left->di_right = new_die; + } + right->di_left = new_die; + if (new_die->di_parent) { + DWARF_P_DBG_ERROR(NULL, DW_DLE_PARENT_EXISTS, + (Dwarf_P_Die) DW_DLV_BADADDR); + } else { + new_die->di_parent = right->di_parent; + } } - if (n_nulls > 1) { /* multiple neighbors, error */ - DWARF_P_DBG_ERROR(NULL, DW_DLE_EXTRA_NEIGHBORS, - (Dwarf_P_Die) DW_DLV_BADADDR); + if (n_nulls > 1) { + /* Multiple neighbors! error! */ + DWARF_P_DBG_ERROR(NULL, DW_DLE_EXTRA_NEIGHBORS, + (Dwarf_P_Die) DW_DLV_BADADDR); } return new_die; } +Dwarf_Unsigned +dwarf_add_die_marker(Dwarf_P_Debug dbg, + Dwarf_P_Die die, + Dwarf_Unsigned marker, + Dwarf_Error * error) +{ + if (die == NULL) { + DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_NULL, DW_DLV_NOCOUNT); + } + die->di_marker = marker; + return 0; +} + + +Dwarf_Unsigned +dwarf_get_die_marker(Dwarf_P_Debug dbg, + Dwarf_P_Die die, + Dwarf_Unsigned * marker, + Dwarf_Error * error) +{ + if (die == NULL) { + DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_NULL, DW_DLV_NOCOUNT); + } + *marker = die->di_marker; + return 0; +} + + /*---------------------------------------------------------------------------- - This function adds a die to dbg struct. It should be called using - the root of all the dies. + This function adds a die to dbg struct. It should be called using + the root of all the dies. -----------------------------------------------------------------------------*/ Dwarf_Unsigned dwarf_add_die_to_debug(Dwarf_P_Debug dbg, - Dwarf_P_Die first_die, Dwarf_Error * error) + Dwarf_P_Die first_die, Dwarf_Error * error) { if (first_die == NULL) { - DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_NULL, DW_DLV_NOCOUNT); + DWARF_P_DBG_ERROR(dbg, DW_DLE_DIE_NULL, DW_DLV_NOCOUNT); } if (first_die->di_tag != DW_TAG_compile_unit) { - DWARF_P_DBG_ERROR(dbg, DW_DLE_WRONG_TAG, DW_DLV_NOCOUNT); + DWARF_P_DBG_ERROR(dbg, DW_DLE_WRONG_TAG, DW_DLV_NOCOUNT); } dbg->de_dies = first_die; return 0; @@ -172,16 +222,16 @@ dwarf_add_die_to_debug(Dwarf_P_Debug dbg, int _dwarf_pro_add_AT_stmt_list(Dwarf_P_Debug dbg, - Dwarf_P_Die first_die, Dwarf_Error * error) + Dwarf_P_Die first_die, Dwarf_Error * error) { Dwarf_P_Attribute new_attr; int uwordb_size = dbg->de_offset_size; /* Add AT_stmt_list attribute */ new_attr = (Dwarf_P_Attribute) - _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s)); + _dwarf_p_get_alloc(dbg, sizeof(struct Dwarf_P_Attribute_s)); if (new_attr == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, DW_DLV_NOCOUNT); + DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, DW_DLV_NOCOUNT); } new_attr->ar_attribute = DW_AT_stmt_list; @@ -192,15 +242,15 @@ _dwarf_pro_add_AT_stmt_list(Dwarf_P_Debug dbg, new_attr->ar_next = NULL; new_attr->ar_reloc_len = uwordb_size; new_attr->ar_data = (char *) - _dwarf_p_get_alloc(NULL, uwordb_size); + _dwarf_p_get_alloc(dbg, uwordb_size); if (new_attr->ar_data == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_ADDR_ALLOC, DW_DLV_NOCOUNT); + DWARF_P_DBG_ERROR(NULL, DW_DLE_ADDR_ALLOC, DW_DLV_NOCOUNT); } { - Dwarf_Unsigned du = 0; + Dwarf_Unsigned du = 0; - WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data, - (const void *) &du, sizeof(du), uwordb_size); + WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data, + (const void *) &du, sizeof(du), uwordb_size); } _dwarf_pro_add_at_to_die(first_die, new_attr); @@ -208,7 +258,7 @@ _dwarf_pro_add_AT_stmt_list(Dwarf_P_Debug dbg, } /*----------------------------------------------------------------------------- - Add AT_name attribute to die + Add AT_name attribute to die ------------------------------------------------------------------------------*/ Dwarf_P_Attribute dwarf_add_AT_name(Dwarf_P_Die die, char *name, Dwarf_Error * error) @@ -216,14 +266,14 @@ dwarf_add_AT_name(Dwarf_P_Die die, char *name, Dwarf_Error * error) Dwarf_P_Attribute new_attr; if (die == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, - (Dwarf_P_Attribute) DW_DLV_BADADDR); + DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, + (Dwarf_P_Attribute) DW_DLV_BADADDR); } new_attr = (Dwarf_P_Attribute) - _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s)); + _dwarf_p_get_alloc(die->di_dbg,sizeof(struct Dwarf_P_Attribute_s)); if (new_attr == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, - (Dwarf_P_Attribute) DW_DLV_BADADDR); + DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, + (Dwarf_P_Attribute) DW_DLV_BADADDR); } /* fill in the information */ @@ -234,10 +284,10 @@ dwarf_add_AT_name(Dwarf_P_Die die, char *name, Dwarf_Error * error) new_attr->ar_next = NULL; new_attr->ar_reloc_len = 0; new_attr->ar_data = (char *) - _dwarf_p_get_alloc(NULL, strlen(name) + 1); + _dwarf_p_get_alloc(die->di_dbg, strlen(name)+1); if (new_attr->ar_data == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_STRING_ALLOC, - (Dwarf_P_Attribute) DW_DLV_BADADDR); + DWARF_P_DBG_ERROR(NULL, DW_DLE_STRING_ALLOC, + (Dwarf_P_Attribute) DW_DLV_BADADDR); } strcpy(new_attr->ar_data, name); @@ -250,24 +300,25 @@ dwarf_add_AT_name(Dwarf_P_Die die, char *name, Dwarf_Error * error) /*----------------------------------------------------------------------------- - Add AT_comp_dir attribute to die + Add AT_comp_dir attribute to die ------------------------------------------------------------------------------*/ Dwarf_P_Attribute dwarf_add_AT_comp_dir(Dwarf_P_Die ownerdie, - char *current_working_directory, - Dwarf_Error * error) + char *current_working_directory, + Dwarf_Error * error) { Dwarf_P_Attribute new_attr; if (ownerdie == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, - (Dwarf_P_Attribute) DW_DLV_BADADDR); + DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, + (Dwarf_P_Attribute) DW_DLV_BADADDR); } new_attr = (Dwarf_P_Attribute) - _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s)); + _dwarf_p_get_alloc(ownerdie->di_dbg, + sizeof(struct Dwarf_P_Attribute_s)); if (new_attr == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, - (Dwarf_P_Attribute) DW_DLV_BADADDR); + DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, + (Dwarf_P_Attribute) DW_DLV_BADADDR); } /* fill in the information */ @@ -278,10 +329,11 @@ dwarf_add_AT_comp_dir(Dwarf_P_Die ownerdie, new_attr->ar_next = NULL; new_attr->ar_reloc_len = 0; new_attr->ar_data = (char *) - _dwarf_p_get_alloc(NULL, strlen(current_working_directory) + 1); + _dwarf_p_get_alloc(ownerdie->di_dbg, + strlen(current_working_directory)+1); if (new_attr->ar_data == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_STRING_ALLOC, - (Dwarf_P_Attribute) DW_DLV_BADADDR); + DWARF_P_DBG_ERROR(NULL, DW_DLE_STRING_ALLOC, + (Dwarf_P_Attribute) DW_DLV_BADADDR); } strcpy(new_attr->ar_data, current_working_directory); @@ -294,19 +346,19 @@ dwarf_add_AT_comp_dir(Dwarf_P_Die ownerdie, int _dwarf_pro_add_AT_fde(Dwarf_P_Debug dbg, - Dwarf_P_Die die, - Dwarf_Unsigned offset, Dwarf_Error * error) + Dwarf_P_Die die, + Dwarf_Unsigned offset, Dwarf_Error * error) { Dwarf_P_Attribute new_attr; int uwordb_size = dbg->de_offset_size; if (die == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, -1); + DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, -1); } new_attr = (Dwarf_P_Attribute) - _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s)); + _dwarf_p_get_alloc(dbg,sizeof(struct Dwarf_P_Attribute_s)); if (new_attr == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, -1); + DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, -1); } /* fill in the information */ @@ -317,15 +369,15 @@ _dwarf_pro_add_AT_fde(Dwarf_P_Debug dbg, new_attr->ar_next = NULL; new_attr->ar_reloc_len = uwordb_size; new_attr->ar_data = (char *) - _dwarf_p_get_alloc(NULL, uwordb_size); + _dwarf_p_get_alloc(dbg, uwordb_size); if (new_attr->ar_data == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_ADDR_ALLOC, DW_DLV_NOCOUNT); + DWARF_P_DBG_ERROR(NULL, DW_DLE_ADDR_ALLOC, DW_DLV_NOCOUNT); } { - Dwarf_Unsigned du = offset; + Dwarf_Unsigned du = offset; - WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data, - (const void *) &du, sizeof(du), uwordb_size); + WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data, + (const void *) &du, sizeof(du), uwordb_size); } _dwarf_pro_add_at_to_die(die, new_attr); @@ -335,19 +387,19 @@ _dwarf_pro_add_AT_fde(Dwarf_P_Debug dbg, int _dwarf_pro_add_AT_macro_info(Dwarf_P_Debug dbg, - Dwarf_P_Die die, - Dwarf_Unsigned offset, Dwarf_Error * error) + Dwarf_P_Die die, + Dwarf_Unsigned offset, Dwarf_Error * error) { Dwarf_P_Attribute new_attr; int uwordb_size = dbg->de_offset_size; if (die == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, -1); + DWARF_P_DBG_ERROR(NULL, DW_DLE_DIE_NULL, -1); } new_attr = (Dwarf_P_Attribute) - _dwarf_p_get_alloc(NULL, sizeof(struct Dwarf_P_Attribute_s)); + _dwarf_p_get_alloc(dbg,sizeof(struct Dwarf_P_Attribute_s)); if (new_attr == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, -1); + DWARF_P_DBG_ERROR(NULL, DW_DLE_ATTR_ALLOC, -1); } /* fill in the information */ @@ -359,15 +411,15 @@ _dwarf_pro_add_AT_macro_info(Dwarf_P_Debug dbg, new_attr->ar_next = NULL; new_attr->ar_reloc_len = uwordb_size; new_attr->ar_data = (char *) - _dwarf_p_get_alloc(NULL, uwordb_size); + _dwarf_p_get_alloc(dbg, uwordb_size); if (new_attr->ar_data == NULL) { - DWARF_P_DBG_ERROR(NULL, DW_DLE_ADDR_ALLOC, DW_DLV_NOCOUNT); + DWARF_P_DBG_ERROR(NULL, DW_DLE_ADDR_ALLOC, DW_DLV_NOCOUNT); } { - Dwarf_Unsigned du = offset; + Dwarf_Unsigned du = offset; - WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data, - (const void *) &du, sizeof(du), uwordb_size); + WRITE_UNALIGNED(dbg, (void *) new_attr->ar_data, + (const void *) &du, sizeof(du), uwordb_size); } _dwarf_pro_add_at_to_die(die, new_attr); @@ -380,11 +432,11 @@ void _dwarf_pro_add_at_to_die(Dwarf_P_Die die, Dwarf_P_Attribute attr) { if (die->di_last_attr) { - die->di_last_attr->ar_next = attr; - die->di_last_attr = attr; - die->di_n_attr++; + die->di_last_attr->ar_next = attr; + die->di_last_attr = attr; + die->di_n_attr++; } else { - die->di_n_attr = 1; - die->di_attrs = die->di_last_attr = attr; + die->di_n_attr = 1; + die->di_attrs = die->di_last_attr = attr; } } |