--- /dev/null
+/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
+
+ D r . D e a m o n 6 4
+ for INTEL64(R), AMD64(R)
+
+ Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
+
+/* File Info -----------------------------------------------------------
+File: drd64_.c
+Function:
+Comment:
+----------------------------------------------------------------------*/
+
+#define DRD64_SRC_LIBGOBLIN_DWARF_LINE
+#include"drd64_libgoblin.h"
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+/*
+Byte *
+ LibGoblin_DwarfLine_Read_LineHeader_FileNameData(
+ LibGoblin_Dwarf_LineSection *pt_line,
+ Byte *pb_data,
+ QWord *pqw_remain,
+ int i_files )
+{
+ QWord qw_qword;
+ Byte b_byte;
+
+ // Read FileName ---
+ b_byte = *pb_data;
+ pt_line->t_filename[ i_files ].pstr_srcfilename
+ = (char *)(pb_data - 1);
+ while( ( 0 < *pqw_remain) && ('\0' != b_byte) ) {
+ (*pqw_remain)--;
+ b_byte = *pb_data++;
+ }
+
+ // Read Directory Index ---
+ pb_data = DWARF_Common_DecodeULEB128(
+ &qw_qword, pb_data, pqw_remain );
+ if( NULL == pb_data ) { return NULL; }
+ pt_line->t_filename[ i_files ].dw_dirindex = (DWord)qw_qword;
+
+ // Read File-Date ---
+ pb_data = DWARF_Common_DecodeULEB128(
+ &qw_qword, pb_data, pqw_remain );
+ if( NULL == pb_data ) { return NULL; }
+ pt_line->t_filename[ i_files ].qw_date = qw_qword;
+
+ // Read File-Size ---
+ pb_data = DWARF_Common_DecodeULEB128(
+ &qw_qword, pb_data, pqw_remain );
+ if( NULL == pb_data ) { return NULL; }
+ pt_line->t_filename[ i_files ].qw_filesize = qw_qword;
+
+ return pb_data;
+}
+*/
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+/*
+Byte *
+ LibGoblin_DwarfLine_Read_LineHeader_FileNames(
+ LibGoblin_Dwarf_LineSection *pt_line,
+ Byte *pb_data,
+ QWord *pqw_remain )
+{
+ int i_files;
+ Byte b_byte;
+
+ i_files = 0;
+
+ if( 1 > (*pqw_remain)-- ) { return NULL; }
+ b_byte = *pb_data++;
+
+ while( '\0' != b_byte) {
+ pb_data = LibGoblin_DwarfLine_Read_LineHeader_FileNameData(
+ pt_line, pb_data, pqw_remain, i_files );
+
+ if( 1 > (*pqw_remain)-- ) { return NULL; }
+ b_byte = *pb_data++;
+
+ i_files++;
+ }
+
+ pt_line->i_num_filename = i_files;
+
+ return pb_data;
+}
+*/
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+/*
+Byte *
+ LibGoblin_DwarfLine_Read_LineHeader_IncludePath(
+ LibGoblin_Dwarf_LineSection *pt_line,
+ Byte *pb_data,
+ QWord *qw_remain )
+{
+ int i_cnt;
+ Byte b_byte;
+
+ i_cnt = 0;
+
+ if( 1 > (*qw_remain)-- ) { return NULL; }
+ pt_line->pstr_includepath = (char *)pb_data;
+ b_byte = *pb_data++;
+
+ while( '\0' != b_byte ) {
+ if( 1 > (*qw_remain)-- ) { return NULL; }
+ b_byte = *pb_data++;
+
+ if( '\0' == b_byte ) {
+ if( 1 > (*qw_remain)-- ) { return NULL; }
+ b_byte = *pb_data++;
+ i_cnt++;
+ }
+ }
+ pt_line->i_num_includepath = i_cnt;
+
+ return pb_data;
+}
+*/
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+Byte *
+ DWARF_Line_Read_LineHeader(
+ LibGoblin_DWARF_Line_Header *pt_line,
+ Byte *pb_data,
+ QWord *pqw_size_linesec )
+{
+ int i_bitflag;
+ int i_cnt;
+ Byte b_byte;
+ DWord dw_dword;
+ QWord qw_qword;
+ QWord qw_remain;
+
+ assert( NULL != pt_line );
+ assert( NULL != pb_data );
+
+ i_bitflag = 32;
+ pt_line->b_bits = 32;
+ qw_remain = *pqw_size_linesec;
+
+ // Read unit_length (4Byte(32bit) or 8Byte(64bit)) ---
+ pb_data = DWARF_Common_Read_DWord( &dw_dword, pb_data, &qw_remain );
+ if( NULL == pb_data ) { return NULL; }
+
+ if( ((DWord)0xffffffff) == dw_dword ) {
+ pb_data = DWARF_Common_Read_QWord( &qw_qword, pb_data, &qw_remain );
+ if( NULL == pb_data ) { return NULL; }
+
+ i_bitflag = 64;
+ pt_line->b_bits = 64;
+ qw_remain = qw_qword;
+ }
+ else {
+ qw_remain = (QWord)dw_dword;
+ }
+
+ // Read version (2Byte) ---
+ pb_data = DWARF_Common_Read_Word( &(pt_line->w_version), pb_data, &qw_remain );
+ if( NULL == pb_data ) { return NULL; }
+
+ // Read Header Length (4Byte(32bit), 8Byte(64bit)) ---
+ if( 64 == i_bitflag ) {
+ pb_data = DWARF_Common_Read_QWord( &qw_qword, pb_data, &qw_remain );
+ if( NULL == pb_data ) { return NULL; }
+
+ pt_line->qw_headerlength = qw_qword;
+ }
+ else {
+ pb_data = DWARF_Common_Read_DWord( &dw_dword, pb_data, &qw_remain );
+ if( NULL == pb_data ) { return NULL; }
+
+ pt_line->qw_headerlength = (QWord)dw_dword;
+ }
+
+ // Read minimum Instruction Length (1Byte) ---
+ pb_data = DWARF_Common_Read_Byte(
+ &(pt_line->b_minimum_inst_length), pb_data, &qw_remain );
+ if( NULL == pb_data ) { return NULL; }
+
+ // Read default isStatement (1Byte) ---
+ pb_data = DWARF_Common_Read_Byte(
+ &(pt_line->b_default_is_stmt), pb_data, &qw_remain );
+ if( NULL == pb_data ) { return NULL; }
+
+ // Read LineBase (1Byte) ---
+ pb_data = DWARF_Common_Read_Byte( &b_byte, pb_data, &qw_remain );
+ if( NULL == pb_data ) { return NULL; }
+ pt_line->i_line_base = (INT)((char)b_byte);
+
+ // Read LineRange (1Byte) ---
+ pb_data = DWARF_Common_Read_Byte( &b_byte, pb_data, &qw_remain );
+ if( NULL == pb_data ) { return NULL; }
+ pt_line->i_line_range = (INT)((DWord)b_byte);
+
+ // Read Opcode Base (1Byte) ---
+ pb_data = DWARF_Common_Read_Byte(
+ &(pt_line->b_opcode_base), pb_data, &qw_remain );
+ if( NULL == pb_data ) { return NULL; }
+
+ // Read Operand length of the Standard Opecode ---
+ for( i_cnt = 1; i_cnt < (pt_line->b_opcode_base); i_cnt++) {
+ pb_data = DWARF_Common_DecodeULEB128( &qw_qword, pb_data, &qw_remain );
+ 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 );
+ printf(" min. Inst. length: %d\n", pt_line->b_minimum_inst_length );
+ printf(" default isStmt: %x\n", pt_line->b_default_is_stmt );
+ printf(" line_base: %d\n", pt_line->i_line_base );
+ 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 );
+ }
+*/
+ *pqw_size_linesec = qw_remain;
+
+ return pb_data;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBGOBLIN_DWARF_LINE_EXTERN
+int
+ DWARF_Line_ReadSrcFile(
+ LibGoblin_BinaryInfo *p_binfo,
+ DWord dw_offset )
+{
+ int i_pos;
+ int i_path;
+ int i_files;
+ Byte b_byte;
+ Byte *pb_line;
+ DWord dw_dirindex;
+ QWord qw_qword;
+ QWord qw_date;
+ QWord qw_filesize;
+ QWord qw_remain;
+ char str_filename[DRD64_MAX_PATH + 1];
+ LibGoblin_SectionInfo *psec_line;
+ LibGoblin_DWARF_Line_Header t_linehdr;
+
+ psec_line = Section_GetSectionInfo( p_binfo, LIBGOBLIN_SECTION_ID_DEBUG_LINE );
+ assert( NULL != psec_line );
+
+ 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 ===============
+ i_path = 0;
+
+ if( 1 > qw_remain-- ) { return NULL; }
+ b_byte = *pb_line++;
+
+ while( '\0' != b_byte ) {
+ if( 1 > qw_remain-- ) { return NULL; }
+ b_byte = *pb_line++;
+
+ if( '\0' == b_byte ) {
+ if( 1 > qw_remain-- ) { return NULL; }
+ b_byte = *pb_line++;
+ i_path++;
+ }
+ }
+ t_linehdr.i_path = i_path;
+ //printf(" path nums: %d\n", t_linehdr.i_path );
+
+
+ // (Phase3) Read FileName Section in .debug_line Header ===========
+ if( 1 > qw_remain-- ) { return NULL; }
+ b_byte = *pb_line++;
+
+ i_files = 0;
+ while( '\0' != b_byte) {
+ // Read FileName ---
+ i_pos = 0;
+ while( ( 0 < qw_remain) && ('\0' != b_byte) ) {
+ str_filename[i_pos++] = (char)b_byte;
+ b_byte = *pb_line++;
+ qw_remain--;
+ }
+ str_filename[i_pos++] = (char)b_byte;
+
+ // Read Directory Index ---
+ pb_line = DWARF_Common_DecodeULEB128( &qw_qword, pb_line, &qw_remain );
+ if( NULL == pb_line ) { return NULL; }
+ 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; }
+ qw_date = qw_qword;
+
+ // Read File-Size ---
+ pb_line = DWARF_Common_DecodeULEB128( &qw_qword, pb_line, &qw_remain );
+ if( NULL == pb_line ) { return NULL; }
+ 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 );
+
+ i_files++;
+
+ if( 1 > qw_remain-- ) { return NULL; }
+ b_byte = *pb_line++;
+ }
+
+ return 0x00;
+}
+
+
+/* EOF of drd64_.c ----------------------------------- */
--- /dev/null
+/*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
+
+ D r . D e a m o n 6 4
+ for INTEL64(R), AMD64(R)
+
+ Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
+
+/* File Info -----------------------------------------------------------
+File: drd64_.h
+Function: Header
+Comment:
+----------------------------------------------------------------------*/
+
+#ifndef DRD64_HEADER_LIBGOBLIN_DWARF_LINE
+#define DRD64_HEADER_LIBGOBLIN_DWARF_LINE
+
+#include"drd64_libgoblin.h"
+
+#ifdef DRD64_SRC_LIBGOBLIN_DWARF_LINE
+ #define LIBGOBLIN_DWARF_LINE_EXTERN
+#else
+ #define LIBGOBLIN_DWARF_LINE_EXTERN extern
+#endif
+
+LIBGOBLIN_DWARF_LINE_EXTERN
+ int DWARF_Line_ReadSrcFile( LibGoblin_BinaryInfo *p_binfo, DWord dw_offset );
+
+
+#endif /* DRD64_HEADER_LIBGOBLIN_DWARF_LINE */
+
+/* EOF of drd64_.h ----------------------------------- */