home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / libdwarf / dwarf_abbrev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.1 KB  |  184 lines

  1. /*
  2.     dwarf_abbrev.c
  3.  
  4.     $Revision: 1.13 $        $Date: 1994/06/17 02:38:55 $
  5. */
  6.  
  7. #include <stdio.h>
  8. #include "dwarf_incl.h"
  9. #include "dwarf_abbrev.h"
  10.  
  11. int
  12. dwarf_get_abbrev (
  13.     Dwarf_Debug        dbg,
  14.     Dwarf_Unsigned    offset,
  15.     Dwarf_Abbrev        *returned_abbrev,
  16.     Dwarf_Unsigned    *length,
  17.     Dwarf_Unsigned    *abbr_count,
  18.     Dwarf_Error        *error
  19. )
  20. {
  21.     Dwarf_Small        *abbrev_ptr;
  22.     Dwarf_Small        *abbrev_section_end;
  23.     Dwarf_Half        attr;
  24.     Dwarf_Half        attr_form;
  25.     Dwarf_Abbrev    ret_abbrev;
  26.     Dwarf_Unsigned     labbr_count = 0;
  27.  
  28.  
  29.     if (dbg == NULL) {
  30.     _dwarf_error(NULL, error, DW_DLE_DBG_NULL); 
  31.     return(DW_DLV_ERROR);
  32.     }
  33.  
  34.     if (offset >= dbg->de_debug_abbrev_size)  {
  35.     return(DW_DLV_NO_ENTRY);
  36.     }
  37.  
  38.     ret_abbrev = (Dwarf_Abbrev)_dwarf_get_alloc(dbg, DW_DLA_ABBREV, 1);
  39.     if (ret_abbrev == NULL) {
  40.         _dwarf_error(dbg, error, DW_DLE_ALLOC_FAIL); 
  41.         return(DW_DLV_ERROR);
  42.     }
  43.     ret_abbrev->ab_dbg = dbg;
  44.     if(returned_abbrev == 0 || abbr_count == 0 ) {
  45.     _dwarf_error(dbg, error, DW_DLE_DEBUG_ABBREV_NULL);
  46.         return(DW_DLV_ERROR);
  47.     }
  48.  
  49.  
  50.     *abbr_count = 0;
  51.     if (length != NULL) *length = 1;
  52.  
  53.     abbrev_ptr = dbg->de_debug_abbrev + offset;
  54.     abbrev_section_end = dbg->de_debug_abbrev + dbg->de_debug_abbrev_size;
  55.  
  56.     DECODE_LEB128_UWORD(abbrev_ptr, ret_abbrev->ab_code)
  57.     if (ret_abbrev->ab_code == 0) {
  58.     *returned_abbrev = ret_abbrev;
  59.         *abbr_count = 0;
  60.     return(DW_DLV_OK);
  61.     }
  62.  
  63.     DECODE_LEB128_UWORD(abbrev_ptr, ret_abbrev->ab_tag)
  64.     ret_abbrev->ab_has_child = *(abbrev_ptr++);
  65.     ret_abbrev->ab_abbrev_ptr = abbrev_ptr;
  66.  
  67.     do {
  68.         DECODE_LEB128_UWORD(abbrev_ptr, attr)
  69.         DECODE_LEB128_UWORD(abbrev_ptr, attr_form)
  70.  
  71.     if ( attr != 0) (labbr_count)++;
  72.  
  73.     } while (abbrev_ptr < abbrev_section_end && (attr != 0 || attr_form != 0));
  74.  
  75.     if (abbrev_ptr > abbrev_section_end) {
  76.     _dwarf_error(dbg, error, DW_DLE_ABBREV_DECODE_ERROR); 
  77.     return(DW_DLV_ERROR);
  78.     }
  79.  
  80.     if (length != NULL) 
  81.     *length = abbrev_ptr - dbg->de_debug_abbrev - offset;
  82.  
  83.     *returned_abbrev = ret_abbrev;
  84.     *abbr_count = labbr_count;
  85.     return(DW_DLV_OK);
  86. }
  87.  
  88.  
  89. int
  90. dwarf_get_abbrev_tag (
  91.     Dwarf_Abbrev    abbrev,
  92.     Dwarf_Half         *returned_tag,
  93.     Dwarf_Error        *error
  94. )
  95. {
  96.     if (abbrev == NULL) {
  97.     _dwarf_error(NULL, error, DW_DLE_DWARF_ABBREV_NULL); 
  98.     return(DW_DLV_ERROR);
  99.     }
  100.     
  101.     *returned_tag = abbrev->ab_tag;
  102.     return(DW_DLV_OK);
  103. }
  104.  
  105.  
  106. int
  107. dwarf_get_abbrev_children_flag (
  108.     Dwarf_Abbrev    abbrev,
  109.     Dwarf_Signed       *returned_flag,
  110.     Dwarf_Error        *error
  111. )
  112. {
  113.     if (abbrev == NULL) {
  114.     _dwarf_error(NULL, error, DW_DLE_DWARF_ABBREV_NULL); 
  115.     return(DW_DLV_ERROR);
  116.     }
  117.     
  118.     *returned_flag = abbrev->ab_has_child;
  119.     return(DW_DLV_OK);
  120. }
  121.  
  122.  
  123. int
  124. dwarf_get_abbrev_entry (
  125.     Dwarf_Abbrev    abbrev,
  126.     Dwarf_Signed    index,
  127.     Dwarf_Half         *returned_attr_num,
  128.     Dwarf_Signed    *form,
  129.     Dwarf_Off        *offset,
  130.     Dwarf_Error        *error
  131. )
  132. {
  133.     Dwarf_Byte_Ptr    abbrev_ptr;
  134.     Dwarf_Byte_Ptr    abbrev_end;
  135.     Dwarf_Byte_Ptr    mark_abbrev_ptr;
  136.     Dwarf_Half        attr;
  137.     Dwarf_Half        attr_form;
  138.  
  139.     if (index < 0)
  140.     return(DW_DLV_NO_ENTRY);
  141.  
  142.     if (abbrev == NULL) {
  143.     _dwarf_error(NULL, error, DW_DLE_DWARF_ABBREV_NULL); 
  144.     return(DW_DLV_ERROR);
  145.     }
  146.     
  147.     if (abbrev->ab_code == 0) {
  148.     return(DW_DLV_NO_ENTRY);
  149.     }
  150.  
  151.     if (abbrev->ab_dbg == NULL) {
  152.     _dwarf_error(NULL, error, DW_DLE_DBG_NULL);
  153.     return(DW_DLV_ERROR);
  154.     }
  155.  
  156.     abbrev_ptr = abbrev->ab_abbrev_ptr;
  157.     abbrev_end = 
  158.     abbrev->ab_dbg->de_debug_abbrev + abbrev->ab_dbg->de_debug_abbrev_size;
  159.  
  160.     for (attr = 1,attr_form=1 ; 
  161.     index >= 0 && abbrev_ptr < abbrev_end && (attr != 0 || attr_form != 0); 
  162.     index--) {
  163.     mark_abbrev_ptr = abbrev_ptr;
  164.         DECODE_LEB128_UWORD(abbrev_ptr, attr)
  165.         DECODE_LEB128_UWORD(abbrev_ptr, attr_form)
  166.     } 
  167.  
  168.     if (abbrev_ptr >= abbrev_end) {
  169.     _dwarf_error(abbrev->ab_dbg, error, DW_DLE_ABBREV_DECODE_ERROR);
  170.     return(DW_DLV_ERROR);
  171.     }
  172.  
  173.     if (index >=  0) {
  174.     return(DW_DLV_NO_ENTRY);
  175.     }
  176.  
  177.     if (form != NULL) *form = attr_form;
  178.     if (offset != NULL) 
  179.     *offset = mark_abbrev_ptr - abbrev->ab_dbg->de_debug_abbrev;
  180.  
  181.     *returned_attr_num = (attr);
  182.     return DW_DLV_OK;
  183. }
  184.