diff options
Diffstat (limited to 'usr/src/tools/ctf/dwarf/common/dwarf_abbrev.c')
| -rw-r--r-- | usr/src/tools/ctf/dwarf/common/dwarf_abbrev.c | 195 |
1 files changed, 103 insertions, 92 deletions
diff --git a/usr/src/tools/ctf/dwarf/common/dwarf_abbrev.c b/usr/src/tools/ctf/dwarf/common/dwarf_abbrev.c index da051e6225..c2ae361f33 100644 --- a/usr/src/tools/ctf/dwarf/common/dwarf_abbrev.c +++ b/usr/src/tools/ctf/dwarf/common/dwarf_abbrev.c @@ -1,6 +1,7 @@ /* - Copyright (C) 2000,2001 Silicon Graphics, Inc. All Rights Reserved. + Copyright (C) 2000-2005 Silicon Graphics, Inc. All Rights Reserved. + Portions Copyright (C) 2009-2010 David Anderson. 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 @@ -32,6 +33,12 @@ http://oss.sgi.com/projects/GenInfo/NoticeExplan */ +/* The address of the Free Software Foundation is + Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + Boston, MA 02110-1301, USA. + SGI has moved from the above address. +*/ + @@ -42,68 +49,69 @@ int dwarf_get_abbrev(Dwarf_Debug dbg, - Dwarf_Unsigned offset, - Dwarf_Abbrev * returned_abbrev, - Dwarf_Unsigned * length, - Dwarf_Unsigned * abbr_count, Dwarf_Error * error) + Dwarf_Unsigned offset, + Dwarf_Abbrev * returned_abbrev, + Dwarf_Unsigned * length, + Dwarf_Unsigned * abbr_count, Dwarf_Error * error) { - Dwarf_Small *abbrev_ptr; - Dwarf_Small *abbrev_section_end; - Dwarf_Half attr; - Dwarf_Half attr_form; - Dwarf_Abbrev ret_abbrev; + Dwarf_Small *abbrev_ptr = 0; + Dwarf_Small *abbrev_section_end = 0; + Dwarf_Half attr = 0; + Dwarf_Half attr_form = 0; + Dwarf_Abbrev ret_abbrev = 0; Dwarf_Unsigned labbr_count = 0; - Dwarf_Unsigned utmp; + Dwarf_Unsigned utmp = 0; if (dbg == NULL) { - _dwarf_error(NULL, error, DW_DLE_DBG_NULL); - return (DW_DLV_ERROR); + _dwarf_error(NULL, error, DW_DLE_DBG_NULL); + return (DW_DLV_ERROR); } - if (dbg->de_debug_abbrev == 0) { - /* Loads abbrev section (and .debug_info as we do those - together). */ - int res = _dwarf_load_debug_info(dbg, error); - - if (res != DW_DLV_OK) { - return res; - } + if (dbg->de_debug_abbrev.dss_data == 0) { + /* Loads abbrev section (and .debug_info as we do those + together). */ + int res = _dwarf_load_debug_info(dbg, error); + + if (res != DW_DLV_OK) { + return res; + } } - if (offset >= dbg->de_debug_abbrev_size) { - return (DW_DLV_NO_ENTRY); + if (offset >= dbg->de_debug_abbrev.dss_size) { + return (DW_DLV_NO_ENTRY); } ret_abbrev = (Dwarf_Abbrev) _dwarf_get_alloc(dbg, DW_DLA_ABBREV, 1); if (ret_abbrev == NULL) { - _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); - return (DW_DLV_ERROR); + _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); + return (DW_DLV_ERROR); } ret_abbrev->ab_dbg = dbg; if (returned_abbrev == 0 || abbr_count == 0) { - _dwarf_error(dbg, error, DW_DLE_DWARF_ABBREV_NULL); - return (DW_DLV_ERROR); + dwarf_dealloc(dbg, ret_abbrev, DW_DLA_ABBREV); + _dwarf_error(dbg, error, DW_DLE_DWARF_ABBREV_NULL); + return (DW_DLV_ERROR); } *abbr_count = 0; if (length != NULL) - *length = 1; + *length = 1; - abbrev_ptr = dbg->de_debug_abbrev + offset; + abbrev_ptr = dbg->de_debug_abbrev.dss_data + offset; abbrev_section_end = - dbg->de_debug_abbrev + dbg->de_debug_abbrev_size; + dbg->de_debug_abbrev.dss_data + dbg->de_debug_abbrev.dss_size; DECODE_LEB128_UWORD(abbrev_ptr, utmp); ret_abbrev->ab_code = (Dwarf_Word) utmp; if (ret_abbrev->ab_code == 0) { - *returned_abbrev = ret_abbrev; - *abbr_count = 0; - if (length) { - *length = 1; - } - return (DW_DLV_OK); + *returned_abbrev = ret_abbrev; + *abbr_count = 0; + if (length) { + *length = 1; + } + return (DW_DLV_OK); } DECODE_LEB128_UWORD(abbrev_ptr, utmp); @@ -112,26 +120,27 @@ dwarf_get_abbrev(Dwarf_Debug dbg, ret_abbrev->ab_abbrev_ptr = abbrev_ptr; do { - Dwarf_Unsigned utmp2; + Dwarf_Unsigned utmp2; - DECODE_LEB128_UWORD(abbrev_ptr, utmp2) - attr = (Dwarf_Half) utmp2; - DECODE_LEB128_UWORD(abbrev_ptr, utmp2) - attr_form = (Dwarf_Half) utmp2; + DECODE_LEB128_UWORD(abbrev_ptr, utmp2); + attr = (Dwarf_Half) utmp2; + DECODE_LEB128_UWORD(abbrev_ptr, utmp2); + attr_form = (Dwarf_Half) utmp2; - if (attr != 0) - (labbr_count)++; + if (attr != 0) + (labbr_count)++; } while (abbrev_ptr < abbrev_section_end && - (attr != 0 || attr_form != 0)); + (attr != 0 || attr_form != 0)); if (abbrev_ptr > abbrev_section_end) { - _dwarf_error(dbg, error, DW_DLE_ABBREV_DECODE_ERROR); - return (DW_DLV_ERROR); + dwarf_dealloc(dbg, ret_abbrev, DW_DLA_ABBREV); + _dwarf_error(dbg, error, DW_DLE_ABBREV_DECODE_ERROR); + return (DW_DLV_ERROR); } if (length != NULL) - *length = abbrev_ptr - dbg->de_debug_abbrev - offset; + *length = abbrev_ptr - dbg->de_debug_abbrev.dss_data - offset; *returned_abbrev = ret_abbrev; *abbr_count = labbr_count; @@ -140,25 +149,27 @@ dwarf_get_abbrev(Dwarf_Debug dbg, int dwarf_get_abbrev_code(Dwarf_Abbrev abbrev, - Dwarf_Unsigned * returned_code, - Dwarf_Error * error) + Dwarf_Unsigned * returned_code, + Dwarf_Error * error) { if (abbrev == NULL) { - _dwarf_error(NULL, error, DW_DLE_DWARF_ABBREV_NULL); - return (DW_DLV_ERROR); + _dwarf_error(NULL, error, DW_DLE_DWARF_ABBREV_NULL); + return (DW_DLV_ERROR); } *returned_code = abbrev->ab_code; return (DW_DLV_OK); } +/* DWARF defines DW_TAG_hi_user as 0xffff so no tag should be + over 16 bits. */ int dwarf_get_abbrev_tag(Dwarf_Abbrev abbrev, - Dwarf_Half * returned_tag, Dwarf_Error * error) + Dwarf_Half * returned_tag, Dwarf_Error * error) { if (abbrev == NULL) { - _dwarf_error(NULL, error, DW_DLE_DWARF_ABBREV_NULL); - return (DW_DLV_ERROR); + _dwarf_error(NULL, error, DW_DLE_DWARF_ABBREV_NULL); + return (DW_DLV_ERROR); } *returned_tag = abbrev->ab_tag; @@ -168,12 +179,12 @@ dwarf_get_abbrev_tag(Dwarf_Abbrev abbrev, int dwarf_get_abbrev_children_flag(Dwarf_Abbrev abbrev, - Dwarf_Signed * returned_flag, - Dwarf_Error * error) + Dwarf_Signed * returned_flag, + Dwarf_Error * error) { if (abbrev == NULL) { - _dwarf_error(NULL, error, DW_DLE_DWARF_ABBREV_NULL); - return (DW_DLV_ERROR); + _dwarf_error(NULL, error, DW_DLE_DWARF_ABBREV_NULL); + return (DW_DLV_ERROR); } *returned_flag = abbrev->ab_has_child; @@ -183,65 +194,65 @@ dwarf_get_abbrev_children_flag(Dwarf_Abbrev abbrev, int dwarf_get_abbrev_entry(Dwarf_Abbrev abbrev, - Dwarf_Signed index, - Dwarf_Half * returned_attr_num, - Dwarf_Signed * form, - Dwarf_Off * offset, Dwarf_Error * error) + Dwarf_Signed index, + Dwarf_Half * returned_attr_num, + Dwarf_Signed * form, + Dwarf_Off * offset, Dwarf_Error * error) { - Dwarf_Byte_Ptr abbrev_ptr; - Dwarf_Byte_Ptr abbrev_end; - Dwarf_Byte_Ptr mark_abbrev_ptr; - Dwarf_Half attr; - Dwarf_Half attr_form; + Dwarf_Byte_Ptr abbrev_ptr = 0; + Dwarf_Byte_Ptr abbrev_end = 0; + Dwarf_Byte_Ptr mark_abbrev_ptr = 0; + Dwarf_Half attr = 0; + Dwarf_Half attr_form = 0; if (index < 0) - return (DW_DLV_NO_ENTRY); + return (DW_DLV_NO_ENTRY); if (abbrev == NULL) { - _dwarf_error(NULL, error, DW_DLE_DWARF_ABBREV_NULL); - return (DW_DLV_ERROR); + _dwarf_error(NULL, error, DW_DLE_DWARF_ABBREV_NULL); + return (DW_DLV_ERROR); } if (abbrev->ab_code == 0) { - return (DW_DLV_NO_ENTRY); + return (DW_DLV_NO_ENTRY); } if (abbrev->ab_dbg == NULL) { - _dwarf_error(NULL, error, DW_DLE_DBG_NULL); - return (DW_DLV_ERROR); + _dwarf_error(NULL, error, DW_DLE_DBG_NULL); + return (DW_DLV_ERROR); } abbrev_ptr = abbrev->ab_abbrev_ptr; abbrev_end = - abbrev->ab_dbg->de_debug_abbrev + - abbrev->ab_dbg->de_debug_abbrev_size; + abbrev->ab_dbg->de_debug_abbrev.dss_data + + abbrev->ab_dbg->de_debug_abbrev.dss_size; for (attr = 1, attr_form = 1; - index >= 0 && abbrev_ptr < abbrev_end && (attr != 0 || - attr_form != 0); - index--) { - Dwarf_Unsigned utmp4; - - mark_abbrev_ptr = abbrev_ptr; - DECODE_LEB128_UWORD(abbrev_ptr, utmp4) - attr = (Dwarf_Half) utmp4; - DECODE_LEB128_UWORD(abbrev_ptr, utmp4) - attr_form = (Dwarf_Half) utmp4; + index >= 0 && abbrev_ptr < abbrev_end && (attr != 0 || + attr_form != 0); + index--) { + Dwarf_Unsigned utmp4; + + mark_abbrev_ptr = abbrev_ptr; + DECODE_LEB128_UWORD(abbrev_ptr, utmp4); + attr = (Dwarf_Half) utmp4; + DECODE_LEB128_UWORD(abbrev_ptr, utmp4); + attr_form = (Dwarf_Half) utmp4; } if (abbrev_ptr >= abbrev_end) { - _dwarf_error(abbrev->ab_dbg, error, DW_DLE_ABBREV_DECODE_ERROR); - return (DW_DLV_ERROR); + _dwarf_error(abbrev->ab_dbg, error, DW_DLE_ABBREV_DECODE_ERROR); + return (DW_DLV_ERROR); } if (index >= 0) { - return (DW_DLV_NO_ENTRY); + return (DW_DLV_NO_ENTRY); } if (form != NULL) - *form = attr_form; + *form = attr_form; if (offset != NULL) - *offset = mark_abbrev_ptr - abbrev->ab_dbg->de_debug_abbrev; + *offset = mark_abbrev_ptr - abbrev->ab_dbg->de_debug_abbrev.dss_data; *returned_attr_num = (attr); return DW_DLV_OK; |
