From f076e157d9aa8247b6183d087daedad344a9303c Mon Sep 17 00:00:00 2001 From: "Koine Yuusuke(koinec)" Date: Wed, 21 Aug 2019 12:05:25 +0900 Subject: [PATCH] (LibGoblin) * WorkBackup --- libgoblin/drd64_libgoblin_dwarf_line.c | 98 +++++++++++++++------------------- 1 file changed, 44 insertions(+), 54 deletions(-) diff --git a/libgoblin/drd64_libgoblin_dwarf_line.c b/libgoblin/drd64_libgoblin_dwarf_line.c index 2f2d6e0..b74f3cd 100644 --- a/libgoblin/drd64_libgoblin_dwarf_line.c +++ b/libgoblin/drd64_libgoblin_dwarf_line.c @@ -117,37 +117,32 @@ Byte * /*---------------------------------------------------------------------- ----------------------------------------------------------------------*/ -/* -Byte * - LibGoblin_DwarfLine_Read_LineHeader_IncludePath( - LibGoblin_Dwarf_LineSection *pt_line, - Byte *pb_data, - QWord *qw_remain ) +char * + DWARF_Line_GetPath_fromLineHeader( + Byte *pb_path, + DWord dw_dirindex ) { - int i_cnt; - Byte b_byte; - - i_cnt = 0; + char *pstr_path; + DWord dw_cnt; - if( 1 > (*qw_remain)-- ) { return NULL; } - pt_line->pstr_includepath = (char *)pb_data; - b_byte = *pb_data++; + if( 0 == dw_dirindex ) + { return NULL; } - while( '\0' != b_byte ) { - if( 1 > (*qw_remain)-- ) { return NULL; } - b_byte = *pb_data++; + dw_dirindex--; + pstr_path = pb_path; - if( '\0' == b_byte ) { - if( 1 > (*qw_remain)-- ) { return NULL; } - b_byte = *pb_data++; - i_cnt++; - } + while(( '\0' != *pb_path ) && ( 0 < dw_dirindex )) { + while( '\0' != *pb_path++ ); + pstr_path = pb_path; + dw_dirindex--; } - pt_line->i_num_includepath = i_cnt; - return pb_data; + if( '\0' == *pb_path ) + { pstr_path = NULL; } + + return pstr_path; } -*/ + /*---------------------------------------------------------------------- ----------------------------------------------------------------------*/ @@ -236,13 +231,7 @@ Byte * pt_line->dw_stdoperand_length[i_cnt] = (int)((DWord)qw_qword); } - // Read FileNames --- /* - pb_data = LibGoblin_DwarfLine_Read_LineHeader_FileNames( - pt_line, pb_data, &qw_remain ); - if( NULL == pb_data ) { return NULL; } -*/ - printf(" Length: %ld \n", qw_remain ); printf(" version: %d \n", pt_line->w_version ); printf(" header length: %ld\n", pt_line->qw_headerlength ); @@ -252,21 +241,10 @@ Byte * printf(" line_range: %d\n", pt_line->i_line_range ); printf(" opcode_base: %d\n", pt_line->b_opcode_base ); for( i_cnt = 1; i_cnt < pt_line->b_opcode_base; i_cnt++ ) { - printf(" Std.Operand(%x) : %d \n", i_cnt, - pt_line->dw_stdoperand_length[i_cnt] ); - } -/* - printf(" include path nums: %d\n", pt_line->i_num_includepath ); - printf(" include file nums: %d\n", pt_line->i_num_filename ); - for( i_cnt = 0; i_cnt < pt_line->i_num_filename; i_cnt++ ) { - printf(" SrcFile[%d] filename: %s Dir.Index: %d Date: %ld Size: %ld \n", - i_cnt, - pt_line->t_filename[i_cnt].pstr_srcfilename, - pt_line->t_filename[i_cnt].dw_dirindex, - pt_line->t_filename[i_cnt].qw_date, - pt_line->t_filename[i_cnt].qw_date ); + printf(" Std.Operand(%x) : %d \n", i_cnt, pt_line->dw_stdoperand_length[i_cnt] ); } */ + *pqw_size_linesec = qw_remain; return pb_data; @@ -291,33 +269,38 @@ int QWord qw_date; QWord qw_filesize; QWord qw_remain; + char *pstr_path; char str_filename[DRD64_MAX_PATH + 1]; LibGoblin_SectionInfo *psec_line; LibGoblin_DWARF_Line_Header t_linehdr; + LibGoblin_BinaryFile *p_bfile; psec_line = Section_GetSectionInfo( p_binfo, LIBGOBLIN_SECTION_ID_DEBUG_LINE ); assert( NULL != psec_line ); + p_bfile = BinaryFile_GetBinaryFile( p_binfo->i_binfile ); + assert( NULL != p_bfile ); + pb_line = psec_line->pb_data + dw_offset; qw_remain = psec_line->qw_size - dw_offset; // (Phase1) Read .debug_line Header =============================== pb_line = DWARF_Line_Read_LineHeader( &t_linehdr, pb_line, &qw_remain ); - t_linehdr.pb_path = pb_line; // (Phase2) Skip Path Section in .debug_line Header =============== + t_linehdr.pb_path = pb_line; i_path = 0; - if( 1 > qw_remain-- ) { return NULL; } + if( 1 > qw_remain-- ) { return -0x01; } b_byte = *pb_line++; while( '\0' != b_byte ) { - if( 1 > qw_remain-- ) { return NULL; } + if( 1 > qw_remain-- ) { return -0x01; } b_byte = *pb_line++; if( '\0' == b_byte ) { - if( 1 > qw_remain-- ) { return NULL; } + if( 1 > qw_remain-- ) { return -0x01; } b_byte = *pb_line++; i_path++; } @@ -327,7 +310,7 @@ int // (Phase3) Read FileName Section in .debug_line Header =========== - if( 1 > qw_remain-- ) { return NULL; } + if( 1 > qw_remain-- ) { return -0x01; } b_byte = *pb_line++; i_files = 0; @@ -343,25 +326,32 @@ int // Read Directory Index --- pb_line = DWARF_Common_DecodeULEB128( &qw_qword, pb_line, &qw_remain ); - if( NULL == pb_line ) { return NULL; } + if( NULL == pb_line ) { return -0x01; } dw_dirindex = (DWord)qw_qword; // Read File-Date --- pb_line = DWARF_Common_DecodeULEB128( &qw_qword, pb_line, &qw_remain ); - if( NULL == pb_line ) { return NULL; } + if( NULL == pb_line ) { return -0x01; } qw_date = qw_qword; // Read File-Size --- pb_line = DWARF_Common_DecodeULEB128( &qw_qword, pb_line, &qw_remain ); - if( NULL == pb_line ) { return NULL; } + if( NULL == pb_line ) { return -0x01; } qw_filesize = qw_qword; - printf(" SrcFile[%2d] %30s Dir.Index: %d Date: %ld Size: %ld \n", - i_files, str_filename, dw_dirindex, qw_date, qw_filesize ); + if( 0 == dw_dirindex ) + { pstr_path = p_bfile->str_remotepath; } + else + { pstr_path = DWARF_Line_GetPath_fromLineHeader( t_linehdr.pb_path, dw_dirindex ); } + +/* + printf(" SrcFile[%2d] %30s Dir.Index: %d Date: %ld Size: %ld Path: %s\n", + i_files, str_filename, dw_dirindex, qw_date, qw_filesize, pstr_path ); +*/ i_files++; - if( 1 > qw_remain-- ) { return NULL; } + if( 1 > qw_remain-- ) { return -0x01; } b_byte = *pb_line++; } -- 2.11.0