OSDN Git Service

(LibGoblin)
[drdeamon64/drdeamon64.git] / libgoblin / drd64_libgoblin_dwarf_abbrev.c
index 3528699..77e2479 100644 (file)
@@ -113,8 +113,7 @@ Byte *
        p_entry->dw_tag = (DWord)qw_temp;
 
        /* Read IsChildren */
-       pb_src  = LibGoblin_DwarfCommon_Read_Byte(
-                                       &(p_entry->b_children), pb_src, pqw_remain );
+       pb_src  = DWARF_Common_Read_Byte( &(p_entry->b_children), pb_src, pqw_remain );
        if( NULL == pb_src )    { return NULL; }
 
 /*
@@ -260,9 +259,12 @@ int
        DWARF_Abbrev_GetItems(
                int             *pi_filenum,
                int             *pi_abbrevs,
+               int             *pi_maxitems,
                QWord   *pqw_size,
                LibGoblin_BinaryInfo    *p_binfo )
 {
+       int             i_maxitems;
+       int             i_items;
        Byte    *pb_data;
        Byte    b_children;
        QWord   qw_temp;
@@ -288,6 +290,7 @@ int
        *pi_filenum     = 0;
        *pi_abbrevs     = 0;
 
+       i_maxitems      = 0;
        do      {
                (*pi_abbrevs)++;
 
@@ -306,7 +309,9 @@ int
                b_children      = *pb_data++;
                qw_size--;
 
+               i_items = -1;
                do      {
+                       i_items++;
                        /* Read Attribute */
                        pb_data = DWARF_Common_DecodeULEB128( &qw_temp, pb_data, &qw_size );
                        dw_attribute    = (DWord)qw_temp;
@@ -315,8 +320,9 @@ int
                        pb_data = DWARF_Common_DecodeULEB128( &qw_temp, pb_data, &qw_size );
                        dw_format       = (DWord)qw_temp;
 
-               }while((0x00 != dw_attribute) && (0x00 != dw_format)
-                                       && (qw_size > 0) );
+               }while((0x00 != dw_attribute) && (0x00 != dw_format) && (qw_size > 0) );
+
+               if( i_maxitems < i_items )      { i_maxitems    = i_items; }
 
                /* Skip Byte for Next Compile-Unit Abbrev. */
                if( 0x00 == *pb_data )  {
@@ -325,6 +331,8 @@ int
                }
 
        }while((qw_size > 0) && (dw_tag != 0x00));
+
+       *pi_maxitems    = i_maxitems;
        
        return 0x00;
 }
@@ -338,17 +346,19 @@ int
                LibGoblin_BinaryInfo    *p_binfo )
 {
        int             i_result;
+       int             i_maxitems      = 0;
        int             i_filenums      = 0;
        int             i_abbrevs       = 0;
        QWord   qw_size;
        DWARF_AbbrevEntry       *p_abbrev;
+       LibGoblin_DWARF_DIEValue        *p_dievalue;
        LibGoblin_BinaryFile    *p_bfile;
 
        p_bfile = BinaryFile_GetBinaryFile( p_binfo->i_binfile );
        assert( NULL != p_bfile );
        
        // Count Abbrevs ---
-       i_result        = DWARF_Abbrev_GetItems( &i_filenums, &i_abbrevs, &qw_size, p_binfo );
+       i_result        = DWARF_Abbrev_GetItems( &i_filenums, &i_abbrevs, &i_maxitems, &qw_size, p_binfo );
        if( 0x00 != i_result )  {
                return 0x01;
        }
@@ -363,7 +373,18 @@ int
        p_bfile->dwarf.i_abbrevs_max            = 0;
        p_bfile->dwarf.qw_abbrev_unreadsz       = qw_size;
 
-       p_bfile->dwarf.i_srcfiles                       = i_filenums;
+       p_bfile->dwarf.i_objfiles                       = i_filenums;
+
+       // Alloc Abbrev Memory ---
+       p_dievalue      = (LibGoblin_DWARF_DIEValue *)malloc(
+                                                               sizeof( LibGoblin_DWARF_DIEValue ) * i_maxitems );
+       if( NULL == p_dievalue )        {
+               return 0x03;
+       }
+       p_bfile->dwarf.i_maxvals        = i_maxitems;
+
+       p_binfo->dwarf.i_maxvals        = i_maxitems;
+       p_binfo->dwarf.p_infoval        = p_dievalue;
 
        return 0x00;
 }