Comment:
----------------------------------------------------------------------*/
-#define DRD64_SRC_LIBGOBLIN_DWARF_ABBREV
+#define DRD64_SRC_LIBGOBLIN_DWARF_INFO
#include"drd64_libgoblin.h"
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
Byte *
- LibGoblin_DwarfInfo_ReadFormat_Ref_inCU(
- LibGoblin_Dwarf_DIEValue *p_dievalue,
+ DWARF_Info_ReadFormat_Ref_inCU(
+ LibGoblin_DWARF_DIEValue *p_val,
Byte *pb_src,
QWord *pqw_remain,
- Byte *pb_type,
- int i_sizebytes,
+ Byte b_bytes,
Byte *pb_custart )
{
Byte *pb_link;
QWord qw_size;
assert( NULL != pb_src );
- assert( NULL != p_dievalue );
+ assert( NULL != p_val );
- if( 1 == i_sizebytes ) {
- pb_src = LibGoblin_DwarfCommon_Read_Byte(
- &b_size, pb_src, pqw_remain );
+ if( 1 == b_bytes ) {
+ pb_src = DWARF_Common_Read_Byte( &b_size, pb_src, pqw_remain );
qw_size = (QWord)b_size;
}
- else if( 2 == i_sizebytes ) {
- pb_src = LibGoblin_DwarfCommon_Read_Word(
- &w_size, pb_src, pqw_remain );
+ else if( 2 == b_bytes ) {
+ pb_src = DWARF_Common_Read_Word( &w_size, pb_src, pqw_remain );
qw_size = (QWord)w_size;
}
- else if( 4 == i_sizebytes ) {
- pb_src = LibGoblin_DwarfCommon_Read_DWord(
- &dw_size, pb_src, pqw_remain );
+ else if( 4 == b_bytes ) {
+ pb_src = DWARF_Common_Read_DWord( &dw_size, pb_src, pqw_remain );
qw_size = (QWord)dw_size;
}
- else if( 8 == i_sizebytes ) {
- pb_src = LibGoblin_DwarfCommon_Read_QWord(
- &qw_size, pb_src, pqw_remain );
+ else if( 8 == b_bytes ) {
+ pb_src = DWARF_Common_Read_QWord( &qw_size, pb_src, pqw_remain );
}
else {
- pb_src = DWARF_Common_DecodeULEB128(
- &qw_size, pb_src, pqw_remain );
+ pb_src = DWARF_Common_DecodeULEB128( &qw_size, pb_src, pqw_remain );
}
if( NULL == pb_src ) { return NULL; }
- pb_link = pb_custart + qw_size;
- p_dievalue->pb_link = pb_link;
- *pb_type = LIBGOBLIN_DWARF_INFO_TYPE_LINK;
+ p_val->value.pb_link = pb_custart + qw_size;
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_LINK;
+ p_val->qw_size = (QWord)b_bytes;
return pb_src;
}
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
Byte *
- LibGoblin_DwarfInfo_ReadFormat_Block(
- LibGoblin_Dwarf_DIEValue *p_dievalue,
+ DWARF_Info_ReadFormat_Block(
+ LibGoblin_DWARF_DIEValue *p_val,
Byte *pb_src,
QWord *pqw_remain,
- Byte *pb_type,
int i_sizebytes )
{
Byte b_size;
Word w_size;
DWord dw_size;
QWord qw_size;
+
assert( NULL != pb_src );
- assert( NULL != p_dievalue );
+ assert( NULL != p_val );
if( 1 == i_sizebytes ) {
- pb_src = LibGoblin_DwarfCommon_Read_Byte(
- &b_size, pb_src, pqw_remain );
+ pb_src = DWARF_Common_Read_Byte( &b_size, pb_src, pqw_remain );
qw_size = (QWord)b_size;
}
else if( 2 == i_sizebytes ) {
- pb_src = LibGoblin_DwarfCommon_Read_Word(
- &w_size, pb_src, pqw_remain );
+ pb_src = DWARF_Common_Read_Word( &w_size, pb_src, pqw_remain );
qw_size = (QWord)w_size;
}
else if( 4 == i_sizebytes ) {
- pb_src = LibGoblin_DwarfCommon_Read_DWord(
- &dw_size, pb_src, pqw_remain );
+ pb_src = DWARF_Common_Read_DWord( &dw_size, pb_src, pqw_remain );
qw_size = (QWord)dw_size;
}
else if( 8 == i_sizebytes ) {
- pb_src = LibGoblin_DwarfCommon_Read_QWord(
- &qw_size, pb_src, pqw_remain );
+ pb_src = DWARF_Common_Read_QWord( &qw_size, pb_src, pqw_remain );
}
else {
- pb_src = DWARF_Common_DecodeULEB128(
- &qw_size, pb_src, pqw_remain );
+ pb_src = DWARF_Common_DecodeULEB128( &qw_size, pb_src, pqw_remain );
}
- if( NULL == pb_src ) { return NULL; }
-
-
if( *pqw_remain >= qw_size ) {
- p_dievalue->t_value.qw_size = qw_size;
- p_dievalue->t_value.pb_data = pb_src;
- *pb_type = LIBGOBLIN_DWARF_INFO_TYPE_BLOCK;
- pb_src += qw_size;
- *pqw_remain -= qw_size;
+ p_val->qw_size = qw_size;
+ p_val->value.pb_data = pb_src;
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_BLOCK;
+ pb_src += qw_size;
+ *pqw_remain -= qw_size;
}
+ else { pb_src = NULL; }
return pb_src;
}
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
Byte *
- LibGoblin_DwarfInfo_ReadFormat_Strp(
- LibGoblin_Dwarf_DIEValue *p_dievalue,
+ DWARF_Info_ReadFormat_Strp(
+ LibGoblin_DWARF_DIEValue *p_val,
Byte *pb_src,
QWord *pqw_remain,
- Byte *pb_type,
+ LibGoblin_BinaryInfo *p_binfo,
Byte b_bits )
{
+ Byte *pb_string = NULL;
+ QWord qw_offset;
+ DWord dw_offset;
+ LibGoblin_SectionInfo *psec_dbgstr;
+
assert( NULL != pb_src );
- assert( NULL != p_dievalue );
+ assert( NULL != p_val );
- if( 64 == b_bits ) {
- pb_src = LibGoblin_DwarfCommon_Read_QWord(
- &(p_dievalue->qw_value), pb_src, pqw_remain );
- *pb_type = LIBGOBLIN_DWARF_INFO_TYPE_QWORD;
+ psec_dbgstr = Section_GetSectionInfo( p_binfo, LIBGOBLIN_SECTION_ID_DEBUG_STR );
+ assert( NULL != psec_dbgstr );
+ assert( NULL != psec_dbgstr->pb_data );
+
+ if( 8 == b_bits ) {
+ pb_src = DWARF_Common_Read_QWord( &qw_offset, pb_src, pqw_remain );
+ pb_string = psec_dbgstr->pb_data + qw_offset;
}
- else if( 32 == b_bits ) {
- pb_src = LibGoblin_DwarfCommon_Read_DWord(
- &(p_dievalue->dw_value), pb_src, pqw_remain );
- *pb_type = LIBGOBLIN_DWARF_INFO_TYPE_DWORD;
+ else if( 4 == b_bits ) {
+ pb_src = DWARF_Common_Read_DWord( &dw_offset, pb_src, pqw_remain );
+ pb_string = psec_dbgstr->pb_data + dw_offset;
}
+ p_val->value.pstr_value = (char *)pb_string;
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_STRING;
+ p_val->qw_size = 0;
+
return pb_src;
}
+
+
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
Byte *
- LibGoblin_DwarfInfo_ReadFormat_String(
- LibGoblin_Dwarf_DIEValue *p_dievalue,
+ DWARF_Info_ReadFormat_String(
+ LibGoblin_DWARF_DIEValue *p_val,
Byte *pb_src,
- QWord *pqw_remain,
- Byte *pb_type )
+ QWord *pqw_remain )
{
Byte *pb_now;
+ QWord qw_size = 0;
assert( NULL != pb_src );
- assert( NULL != p_dievalue );
+ assert( NULL != p_val );
pb_now = pb_src;
while( (0 < *pqw_remain) && ('\0' != *pb_now) ) {
pb_now++;
+ qw_size++;
(*pqw_remain)--;
}
if( 0 < *pqw_remain ) {
- p_dievalue->str_value = (char *)pb_src;
- *pb_type = LIBGOBLIN_DWARF_INFO_TYPE_STRING;
+ p_val->value.pstr_value = (char *)pb_src;
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_STRING;
+ p_val->qw_size = qw_size;
pb_now++;
(*pqw_remain)--;
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
Byte *
- LibGoblin_DwarfInfo_ReadFormat_Address(
- LibGoblin_Dwarf_DIEValue *p_dievalue,
+ DWARF_Info_ReadFormat_Address(
+ LibGoblin_DWARF_DIEValue *p_val,
Byte *pb_src,
QWord *pqw_remain,
- Byte *pb_type,
- int i_pointersize )
+ Byte b_pointersize )
{
assert( NULL != pb_src );
- assert( NULL != p_dievalue );
+ assert( NULL != p_val );
- if( 8 == i_pointersize ) {
- pb_src = LibGoblin_DwarfCommon_Read_QWord(
- &(p_dievalue->qw_value), pb_src, pqw_remain );
- *pb_type = LIBGOBLIN_DWARF_INFO_TYPE_QWORD;
+ if( 8 == b_pointersize ) {
+ pb_src = DWARF_Common_Read_QWord(
+ &(p_val->value.qw_value), pb_src, pqw_remain );
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_QWORD;
+ p_val->qw_size = 8;
}
- else if( 4 == i_pointersize ) {
- pb_src = LibGoblin_DwarfCommon_Read_DWord(
- &(p_dievalue->dw_value), pb_src, pqw_remain );
- *pb_type = LIBGOBLIN_DWARF_INFO_TYPE_DWORD;
+ else if( 4 == b_pointersize ) {
+ pb_src = DWARF_Common_Read_DWord(
+ &(p_val->value.dw_value), pb_src, pqw_remain );
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_DWORD;
+ p_val->qw_size = 4;
}
- else if( 2 == i_pointersize ) {
- pb_src = LibGoblin_DwarfCommon_Read_Word(
- &(p_dievalue->w_value), pb_src, pqw_remain );
- *pb_type = LIBGOBLIN_DWARF_INFO_TYPE_WORD;
+ else if( 2 == b_pointersize ) {
+ pb_src = DWARF_Common_Read_Word(
+ &(p_val->value.w_value), pb_src, pqw_remain );
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_WORD;
+ p_val->qw_size = 2;
}
- if( NULL == pb_src )
- { *pb_type = LIBGOBLIN_DWARF_INFO_TYPE_NONE; }
-
return pb_src;
}
-
/*----------------------------------------------------------------------
----------------------------------------------------------------------*/
Byte *
- LibGoblin_DwarfInfo_ReadDIE(
- LibGoblin_Dwarf_DIE *p_die,
- Byte *pb_src,
+ DWARF_Info_ReadFormat_InDirect(
+ LibGoblin_DWARF_DIEValue *p_val,
+ Byte *pb_info,
QWord *pqw_remains,
- LibGoblin_Dwarf_SourceFile *pt_srcfile,
- LibGoblin_DwarfCommon_CUHeader *p_cuheader )
+ LibGoblin_BinaryInfo *p_binfo,
+ LibGoblin_DWARF_Info_CUHeader *p_cuheader )
{
- int i_cnt;
- Byte *pb_abb;
- Byte b_type;
- DWord dw_abbrev;
- DWord dw_attribute;
- DWord dw_format;
QWord qw_size;
- QWord qw_temp;
- LibGoblin_Dwarf_AbbrevInfo *p_abbrev;
- LibGoblin_Dwarf_AbbrevEntry t_abbentry;
-
- //printf(" pnt: %p ", pb_src);
- // Read Reference Abbrev-ID
- pb_src = DWARF_Common_DecodeULEB128(
- &qw_temp, pb_src, pqw_remains );
- dw_abbrev = (DWord)qw_temp;
-
- //printf(" abbrev: %ld\n", dw_abbrev);
-
- if( 0x00000000 == dw_abbrev ) { return pb_src; }
-
- // Set Reference Abbrev
- p_abbrev = (pt_srcfile->p_abbrev_info) + (dw_abbrev - 1 );
- if( NULL == p_abbrev ) { return NULL; }
-
- pb_abb = p_abbrev->pb_pos;
- assert( NULL != pb_abb );
-
- qw_size = (QWord)p_abbrev->w_size;
- pb_abb = LibGoblin_DwarfAbbrev_ReadEntry( &t_abbentry, pb_abb, &qw_size);
- if( NULL == pb_abb ) { return NULL; }
-
- p_die->dw_tag = t_abbentry.dw_tag;
- p_die->dw_abbrev = t_abbentry.dw_id;
- p_die->i_items = t_abbentry.i_items;
-
- for( i_cnt = 0; i_cnt < p_die->i_items; i_cnt++ ) {
- dw_attribute = t_abbentry.dw_attribute[ i_cnt ];
- dw_format = t_abbentry.dw_format[ i_cnt ];
-
- p_die->dw_attribute[ i_cnt ] = dw_attribute;
- p_die->dw_format[ i_cnt ] = dw_format;
-
- switch( dw_format ) {
- case DW_FORM_addr: // 0x01: address
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Address(
- &(p_die->t_value[i_cnt]), pb_src, pqw_remains,
- &b_type, (int)(p_cuheader->b_pointersize) );
- break;
- case DW_FORM_block2: // 0x03: block
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Block(
- &(p_die->t_value[i_cnt]),
- pb_src, pqw_remains, &b_type, 2);
- break;
- case DW_FORM_block4: // 0x04: block
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Block(
- &(p_die->t_value[i_cnt]),
- pb_src, pqw_remains, &b_type, 4);
- break;
- case DW_FORM_data2: // 0x05: const.
- pb_src = LibGoblin_DwarfCommon_Read_Word(
- &(p_die->t_value[i_cnt].w_value),
- pb_src, pqw_remains );
- b_type = LIBGOBLIN_DWARF_INFO_TYPE_WORD;
- break;
- case DW_FORM_data4: // 0x06: const. line/loc/mac/rng-ptr
- pb_src = LibGoblin_DwarfCommon_Read_DWord(
- &(p_die->t_value[i_cnt].dw_value),
- pb_src, pqw_remains );
- b_type = LIBGOBLIN_DWARF_INFO_TYPE_DWORD;
- break;
- case DW_FORM_data8: // 0x07: const. line/loc/mac/rng-ptr
- pb_src = LibGoblin_DwarfCommon_Read_QWord(
- &(p_die->t_value[i_cnt].qw_value),
- pb_src, pqw_remains );
- b_type = LIBGOBLIN_DWARF_INFO_TYPE_QWORD;
- break;
- case DW_FORM_string: // 0x08: string
- pb_src = LibGoblin_DwarfInfo_ReadFormat_String(
- &(p_die->t_value[i_cnt]),
- pb_src, pqw_remains, &b_type);
- break;
- case DW_FORM_block: // 0x09: block
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Block(
- &(p_die->t_value[i_cnt]),
- pb_src, pqw_remains, &b_type, -1);
- break;
- case DW_FORM_block1: // 0x0a: block
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Block(
- &(p_die->t_value[i_cnt]),
- pb_src, pqw_remains, &b_type, 1);
- break;
- case DW_FORM_data1: // 0x0b: const.
- pb_src = LibGoblin_DwarfCommon_Read_Byte(
- &(p_die->t_value[i_cnt].b_value),
- pb_src, pqw_remains );
- b_type = LIBGOBLIN_DWARF_INFO_TYPE_BYTE;
- break;
- case DW_FORM_flag: // 0x0c: flag
- pb_src = LibGoblin_DwarfCommon_Read_Byte(
- &(p_die->t_value[i_cnt].b_value),
- pb_src, pqw_remains );
- b_type = LIBGOBLIN_DWARF_INFO_TYPE_BYTE;
- break;
- case DW_FORM_sdata: // 0x0d: sdata
- pb_src = DWARF_Common_DecodeLEB128(
- &(p_die->t_value[i_cnt].ii_value),
- pb_src, pqw_remains );
- b_type = LIBGOBLIN_DWARF_INFO_TYPE_INT64;
- break;
- case DW_FORM_strp: // 0x0e: string
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Strp(
- &(p_die->t_value[i_cnt]),
- pb_src, pqw_remains, &b_type,
- p_cuheader->b_bits );
- // XXX reference for .debug_str
- break;
- case DW_FORM_udata: // 0x0f: const.
- pb_src = DWARF_Common_DecodeULEB128(
- &(p_die->t_value[i_cnt].qw_value),
- pb_src, pqw_remains );
- b_type = LIBGOBLIN_DWARF_INFO_TYPE_QWORD;
- break;
- case DW_FORM_ref_addr: // 0x10: ref.
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Address(
- &(p_die->t_value[i_cnt]),pb_src, pqw_remains,
- &b_type, (int)(p_cuheader->b_pointersize) );
- break;
- case DW_FORM_ref1: // 0x11: ref.
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Ref_inCU(
- &(p_die->t_value[i_cnt]),
- pb_src, pqw_remains, &b_type, 1,
- pt_srcfile->t_infosec.pb_pos );
- break;
- case DW_FORM_ref2: // 0x12: ref.
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Ref_inCU(
- &(p_die->t_value[i_cnt]),
- pb_src, pqw_remains, &b_type, 2,
- pt_srcfile->t_infosec.pb_pos );
- break;
- case DW_FORM_ref4: // 0x13: ref.
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Ref_inCU(
- &(p_die->t_value[i_cnt]),
- pb_src, pqw_remains, &b_type, 4,
- pt_srcfile->t_infosec.pb_pos );
- break;
- case DW_FORM_ref8: // 0x14: ref.
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Ref_inCU(
- &(p_die->t_value[i_cnt]),
- pb_src, pqw_remains, &b_type, 8,
- pt_srcfile->t_infosec.pb_pos );
- break;
- case DW_FORM_ref_udata: // 0x15: ref.
- pb_src = LibGoblin_DwarfInfo_ReadFormat_Ref_inCU(
- &(p_die->t_value[i_cnt]),
- pb_src, pqw_remains, &b_type, -1,
- pt_srcfile->t_infosec.pb_pos );
- break;
- case DW_FORM_indirect: // 0x16: ref.
- puts("a");
- break;
- default:
- break;
- }
+ DWord dw_form;
+
+ // Get InDirect DW_FORM_*** value. ---
+ pb_info = DWARF_Common_DecodeULEB128( &qw_size, pb_info, pqw_remains );
+ dw_form = (DWord)qw_size;
+
+ // Re-Call Read FormatData Function ---
+ pb_info = DWARF_Info_ReadFormat_Data(
+ p_val, pb_info, pqw_remains, dw_form, p_binfo, p_cuheader );
+
+ return pb_info;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+Byte *
+ DWARF_Info_ReadFormat_Data(
+ LibGoblin_DWARF_DIEValue *p_val,
+ Byte *pb_info,
+ QWord *pqw_remains,
+ DWord dw_format,
+ LibGoblin_BinaryInfo *p_binfo,
+ LibGoblin_DWARF_Info_CUHeader *p_cuheader )
+{
+
+ switch( dw_format ) {
+ case DW_FORM_addr: // 0x01: address
+ pb_info = DWARF_Info_ReadFormat_Address(
+ p_val, pb_info, pqw_remains, p_cuheader->b_pointersize );
+ break;
+ case DW_FORM_block2: // 0x03: block
+ pb_info = DWARF_Info_ReadFormat_Block( p_val, pb_info, pqw_remains, 2);
+ break;
+ case DW_FORM_block4: // 0x04: block
+ pb_info = DWARF_Info_ReadFormat_Block( p_val, pb_info, pqw_remains, 4);
+ break;
+ case DW_FORM_data2: // 0x05: const.
+ pb_info = DWARF_Common_Read_Word( &(p_val->value.w_value), pb_info, pqw_remains );
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_WORD;
+ p_val->qw_size = 2;
+ break;
+ case DW_FORM_data4: // 0x06: const. line/loc/mac/rng-ptr
+ pb_info = DWARF_Common_Read_DWord( &(p_val->value.dw_value), pb_info, pqw_remains );
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_DWORD;
+ p_val->qw_size = 4;
+ break;
+ case DW_FORM_data8: // 0x07: const. line/loc/mac/rng-ptr
+ pb_info = DWARF_Common_Read_QWord( &(p_val->value.qw_value), pb_info, pqw_remains );
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_QWORD;
+ p_val->qw_size = 4;
+ break;
+ case DW_FORM_string: // 0x08: string
+ pb_info = DWARF_Info_ReadFormat_String( p_val, pb_info, pqw_remains );
+ break;
+ case DW_FORM_block: // 0x09: block
+ pb_info = DWARF_Info_ReadFormat_Block( p_val, pb_info, pqw_remains, -1);
+ break;
+ case DW_FORM_block1: // 0x0a: block
+ pb_info = DWARF_Info_ReadFormat_Block( p_val, pb_info, pqw_remains, 1);
+ break;
+ case DW_FORM_data1: // 0x0b: const.
+ pb_info = DWARF_Common_Read_Byte( &(p_val->value.b_value), pb_info, pqw_remains );
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_BYTE;
+ p_val->qw_size = 1;
+ break;
+ case DW_FORM_flag: // 0x0c: flag
+ pb_info = DWARF_Common_Read_Byte( &(p_val->value.b_value), pb_info, pqw_remains );
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_BYTE;
+ p_val->qw_size = 1;
+ break;
+ case DW_FORM_sdata: // 0x0d: sdata
+ pb_info = DWARF_Common_DecodeLEB128( &(p_val->value.ii_value), pb_info, pqw_remains );
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_INT64;
+ p_val->qw_size = 8;
+ break;
+ case DW_FORM_strp: // 0x0e: string (in .debug_str section)
+ pb_info = DWARF_Info_ReadFormat_Strp(
+ p_val, pb_info, pqw_remains, p_binfo, p_cuheader->b_offsetsize );
+ break;
+ case DW_FORM_udata: // 0x0f: const.
+ pb_info = DWARF_Common_DecodeULEB128( &(p_val->value.qw_value), pb_info, pqw_remains );
+ p_val->b_type = LIBGOBLIN_DWARF_INFO_TYPE_QWORD;
+ p_val->qw_size = 8;
+ break;
+ case DW_FORM_ref_addr: // 0x10: ref.
+ pb_info = DWARF_Info_ReadFormat_Address(
+ p_val, pb_info, pqw_remains, p_cuheader->b_pointersize );
+ break;
+ case DW_FORM_ref1: // 0x11: ref.
+ pb_info = DWARF_Info_ReadFormat_Ref_inCU(
+ p_val, pb_info, pqw_remains, 1, p_cuheader->pb_custart );
+ break;
+ case DW_FORM_ref2: // 0x12: ref.
+ pb_info = DWARF_Info_ReadFormat_Ref_inCU(
+ p_val, pb_info, pqw_remains, 2, p_cuheader->pb_custart );
+ break;
+ case DW_FORM_ref4: // 0x13: ref.
+ pb_info = DWARF_Info_ReadFormat_Ref_inCU(
+ p_val, pb_info, pqw_remains, 4, p_cuheader->pb_custart );
+ break;
+ case DW_FORM_ref8: // 0x14: ref.
+ pb_info = DWARF_Info_ReadFormat_Ref_inCU(
+ p_val, pb_info, pqw_remains, 8, p_cuheader->pb_custart );
+ break;
+ case DW_FORM_ref_udata: // 0x15: ref.
+ pb_info = DWARF_Info_ReadFormat_Ref_inCU(
+ p_val, pb_info, pqw_remains, -1, p_cuheader->pb_custart );
+ break;
+ case DW_FORM_indirect: // 0x16: ref.
+ pb_info = DWARF_Info_ReadFormat_InDirect(
+ p_val, pb_info, pqw_remains, p_binfo, p_cuheader );
+ break;
+ default:
+ break;
}
-
- return pb_src;
+ switch( p_val->b_type ) {
+ case LIBGOBLIN_DWARF_INFO_TYPE_STRING:
+ printf( "[Str] %s\n", p_val->value.pstr_value );
+ break;
+ default:
+ break;
+ }
+
+ return pb_info;
}
----------------------------------------------------------------------*/
Byte *
DWARF_Info_ReadCUHeader(
- LibGoblin_DwarfCommon_CUHeader *p_cuhead,
+ LibGoblin_DWARF_Info_CUHeader *p_cuhead,
Byte *pb_info,
QWord *pqw_size_info )
{
i_bitflag = 32;
// Read unit_length (4Byte + 8Byte(64bit)) ---
- pb_info = LibGoblin_DwarfCommon_Read_DWord(
- &dw_dword, pb_info, pqw_size_info );
+ pb_info = DWARF_Common_Read_DWord( &dw_dword, pb_info, pqw_size_info );
if( NULL == pb_info ) { return NULL; }
// 64bit - First 4Byte = 0xffffffff
if( ((DWord)0xffffffff) == dw_dword ) {
- pb_info = LibGoblin_DwarfCommon_Read_QWord(
- &qw_qword, pb_info, pqw_size_info );
+ pb_info = DWARF_Common_Read_QWord( &qw_qword, pb_info, pqw_size_info );
if( NULL == pb_info ) { return NULL; }
p_cuhead->qw_unitsize = (QWord)qw_qword;
i_bitflag = 64;
p_cuhead->b_bits = 64;
+ p_cuhead->b_offsetsize = 8;
}
// 32bit - First 4Byte = value.
else {
p_cuhead->qw_unitsize = (QWord)dw_dword;
p_cuhead->b_bits = 32;
+ p_cuhead->b_offsetsize = 4;
}
// Read version (2Byte) ---
- pb_info = LibGoblin_DwarfCommon_Read_Word(
- &(p_cuhead->w_version), pb_info, pqw_size_info );
+ pb_info = DWARF_Common_Read_Word( &(p_cuhead->w_version), pb_info, pqw_size_info );
if( NULL == pb_info ) { return NULL; }
i_readbytes = 2;
// Read abbrev_offset (4Byte(32bit), 8Byte(64bit)) ---
if( 64 == i_bitflag ) {
- pb_info = LibGoblin_DwarfCommon_Read_QWord(
- &qw_qword, pb_info, pqw_size_info );
+ pb_info = DWARF_Common_Read_QWord( &qw_qword, pb_info, pqw_size_info );
if( NULL == pb_info ) { return NULL; }
i_readbytes += 8;
p_cuhead->qw_abbrev_offset = qw_qword;
}
else {
- pb_info = LibGoblin_DwarfCommon_Read_DWord(
- &dw_dword, pb_info, pqw_size_info );
+ pb_info = DWARF_Common_Read_DWord( &dw_dword, pb_info, pqw_size_info );
if( NULL == pb_info ) { return NULL; }
i_readbytes += 4;
}
// Read address_size (1Byte) ---
- pb_info = LibGoblin_DwarfCommon_Read_Byte(
- &(p_cuhead->b_pointersize), pb_info, pqw_size_info);
+ pb_info = DWARF_Common_Read_Byte( &(p_cuhead->b_pointersize), pb_info, pqw_size_info);
if( NULL == pb_info ) { return NULL; }
i_readbytes += 1;
{
int i_result;
int i_srcfiles;
+ int i_abbrevs;
+ int i_cnt;
Byte *pb_info;
- Byte *pb_abbrev;
+ Byte *pb_custart;
DWord dw_arvid;
+ DWord dw_attribute;
+ DWord dw_format;
QWord qw_temp;
QWord qw_size_cu;
QWord qw_size_info;
LibGoblin_SectionInfo *psec_info;
- LibGoblin_SectionInfo *psec_abbrev;
LibGoblin_BinaryFile *p_bfile;
- LibGoblin_DwarfCommon_CUHeader t_cuheader;
- LibGoblin_Dwarf_DIE t_die;
DWARF_AbbrevEntry *p_abbrev;
DWARF_AbbrevEntry *p_arvnow;
- int i_abbrevs;
+ LibGoblin_DWARF_DIEValue *p_infoval;
+ LibGoblin_DWARF_DIEValue *p_val;
+ LibGoblin_DWARF_Info_CUHeader t_cuheader;
assert( NULL != p_binfo );
i_srcfiles = p_bfile->dwarf.i_srcfiles;
+ p_infoval = p_bfile->dwarf.p_infoval;
+
// Get section Info ---
psec_info = Section_GetSectionInfo( p_binfo, LIBGOBLIN_SECTION_ID_DEBUG_INFO );
assert( NULL != psec_info );
//do {
// Read Compile Unit Header ---
+ pb_custart = pb_info;
pb_info = DWARF_Info_ReadCUHeader( &t_cuheader, pb_info, &qw_size_info );
- if( NULL == pb_info ) { return NULL; }
+ if( NULL == pb_info ) {
+ return 0x02;
+ }
- qw_size_cu = t_cuheader.qw_unitsize;
+ 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 ---
i_result = DWARF_Abbrev_ReadAbbrevEntry(
dw_arvid = (DWord)qw_temp;
//assert( 0 < dw_arvid );
p_arvnow = p_abbrev + (dw_arvid - 1);
+printf(" [AbbrevID = %d] TAG=%02xh\n", dw_arvid, p_arvnow->dw_tag );
+
+ // Read Debug Information Entry (DIE) ---
+ memset( p_infoval, 0x00, sizeof( LibGoblin_DWARF_DIEValue ) * p_arvnow->i_items );
+ p_val = p_infoval;
+ for( i_cnt = 0; i_cnt < p_arvnow->i_items; i_cnt++, p_val++ ) {
+ dw_attribute = p_arvnow->dw_attribute[ i_cnt ];
+ dw_format = p_arvnow->dw_format[ i_cnt ];
+printf(" Attr=%02xh, FORM=%02xh : ", dw_attribute, dw_format );
- // Read Debug Information Entry (DIE)
- //pb_data = LibGoblin_DwarfInfo_ReadDIE( &t_die, pb_data, &qw_size_cu, p_src, &t_cuheader );
+ pb_info = DWARF_Info_ReadFormat_Data(
+ p_val, pb_info, &qw_size_cu, dw_format, p_binfo, &t_cuheader );
+ }
// Dispatch for generate Rapid-Access Table by DIE-tag