OSDN Git Service

(LibGoblin)
authorKoine Yuusuke(koinec) <koinec@users.osdn.me>
Tue, 4 Jun 2019 20:35:05 +0000 (05:35 +0900)
committerKoine Yuusuke(koinec) <koinec@users.osdn.me>
Tue, 4 Jun 2019 20:35:05 +0000 (05:35 +0900)
  * WorkBackup

libgoblin/drd64_libgoblin_dwarf_info.c

index a73ae0b..98f7665 100644 (file)
@@ -530,7 +530,7 @@ Byte *
 
 /*----------------------------------------------------------------------
 ----------------------------------------------------------------------*/
-int
+LibGoblin_SrcFile *
        DWARF_Info_RegistSrcFile_fromTagCompileUnit(
                LibGoblin_BinaryInfo    *p_binfo,
                LibGoblin_BinaryFile    *p_bfile,
@@ -541,6 +541,8 @@ int
 {
        int                                                     i_childlv;
        int                                                     i_cnt;
+       char                                            *pstr_srcpath   = NULL;
+       char                                            str_temp[DRD64_MAX_PATH+1];
        DWord                                           dw_arvid;
        DWord                                           dw_attribute;
        DWord                                           dw_format;
@@ -548,6 +550,7 @@ int
        DWARF_AbbrevEntry                       *p_arvnow;
        LibGoblin_DWARF_DIEValue        *p_infoval;
        LibGoblin_DWARF_DIEValue        *p_val;
+       LibGoblin_SrcFile                       *p_srcfile;
 
        assert( NULL != p_binfo );
        assert( NULL != p_bfile );
@@ -585,9 +588,31 @@ int
 
        }while( 0 != qw_size_cu ); 
 
-       if( DW_TAG_compile_unit != p_arvnow->dw_tag )   { return -0x01; }
+       if( DW_TAG_compile_unit != p_arvnow->dw_tag )   {
+               return NULL;
+       }
 
-       return 0;
+       p_val   = p_bfile->dwarf.p_infoval;
+       for( i_cnt = 0; i_cnt < p_arvnow->i_items; i_cnt++, p_val++ )   {
+               if( DW_AT_name == p_arvnow->dw_attribute[ i_cnt ] )     {
+                       pstr_srcpath    = p_val->value.pstr_value;
+                       break;
+               }
+       }
+
+       if( NULL == pstr_srcpath )      {
+               return NULL;            
+       }
+
+       strncpy( str_temp, pstr_srcpath, DRD64_MAX_PATH );
+       p_srcfile       = SrcFile_DispenseSrcFile( p_bfile, basename( str_temp ) );
+       if( NULL == p_srcfile ) {
+               return NULL;
+       }
+
+       strncpy( p_srcfile->str_srcpath, dirname( str_temp ), DRD64_MAX_PATH );
+
+       return p_srcfile;
 }
 
 
@@ -601,7 +626,6 @@ int
        int                                                     i_childlv;
        int                                                     i_result;
        int                                                     i_srcfiles;
-       int                                                     i_srcid;
        int                                                     i_abbrevs;
        int                                                     i_cnt;
        Byte                                            *pb_info;
@@ -619,6 +643,7 @@ int
        LibGoblin_DWARF_DIEValue        *p_infoval;
        LibGoblin_DWARF_DIEValue        *p_val;
        LibGoblin_DWARF_Info_CUHeader   t_cuheader;
+       LibGoblin_SrcFile                       *p_srcfile;
 
        assert( NULL != p_binfo );
 
@@ -638,7 +663,7 @@ int
        pb_info                 = psec_info->pb_data;
        qw_size_info    = psec_info->qw_size;
 
-       //do    {
+       do      {
                // Read Compile Unit Header ---
                pb_custart      = pb_info;
                pb_info = DWARF_Info_ReadCUHeader( &t_cuheader, pb_info, &qw_size_info );
@@ -649,20 +674,30 @@ int
                t_cuheader.pb_custart   = pb_custart;
                qw_size_cu                              = t_cuheader.qw_unitsize;
 
-               printf( "size: %ld, ver:%d, abbrev off.:%ld, addr.size: %d\n",
-                       t_cuheader.qw_unitsize,
-                       t_cuheader.w_version,
-                       t_cuheader.qw_abbrev_offset,
-                       t_cuheader.b_pointersize);
-
-               // Read Abbrev ---
+               // Read Abbrev for the now compile unit ---
                i_result        = DWARF_Abbrev_ReadAbbrevEntry(
                                                                &p_abbrev, &i_abbrevs,
                                                                p_binfo, p_bfile, t_cuheader.qw_abbrev_offset );
 
-               i_srcid = DWARF_Info_RegistSrcFile_fromTagCompileUnit(
+               // Read DW_TAG_compile_unit & Regist SrcFile struct. ---
+               p_srcfile       = DWARF_Info_RegistSrcFile_fromTagCompileUnit(
                                                                p_binfo, p_bfile, pb_info, p_abbrev, qw_size_cu, &t_cuheader );
+               if( NULL != p_srcfile ) {
+                       p_srcfile->dwarf.i_abbrevs      = i_abbrevs;
+                       p_srcfile->dwarf.p_abbrev       = p_abbrev;
 
+                       printf( "\n SrcFile: %s,  Orig.Path: %s\n",
+                                                               p_srcfile->str_filename, p_srcfile->str_srcpath );
+               }
+
+               printf( "    size: %ld, ver:%d, abbrev off.:%ld, addr.size: %d\n",
+                       t_cuheader.qw_unitsize,
+                       t_cuheader.w_version,
+                       t_cuheader.qw_abbrev_offset,
+                       t_cuheader.b_pointersize);
+
+
+               // Read & Process DWARF info TAG ---
                i_childlv       = 0;
                do      {
                        // Read Reference Abbrev-ID ---
@@ -697,10 +732,9 @@ int
                }while( 0 != qw_size_cu ); 
                qw_size_info    -= t_cuheader.qw_unitsize;
 
-       //}while((qw_size_info > 0) && (i_srcfiles > 0));
+       }while((qw_size_info > 0) && (i_srcfiles > 0));
 
        
-       
        return 0x00;
 }