From 96219d1d1cb403c8468b56c8754ed4d73622c5c5 Mon Sep 17 00:00:00 2001 From: "Koine Yuusuke(koinec)" Date: Fri, 24 May 2019 05:37:31 +0900 Subject: [PATCH] (LibGoblin) * WorkBackup --- libgoblin/drd64_libgoblin_debug_dwarf_str.c | 89 ++++++++++++ libgoblin/drd64_libgoblin_debug_dwarf_str.h | 209 ++++++++++++++++------------ libgoblin/drd64_libgoblin_dwarf_info.c | 5 +- 3 files changed, 210 insertions(+), 93 deletions(-) diff --git a/libgoblin/drd64_libgoblin_debug_dwarf_str.c b/libgoblin/drd64_libgoblin_debug_dwarf_str.c index 5efee3b..7e30cb5 100644 --- a/libgoblin/drd64_libgoblin_debug_dwarf_str.c +++ b/libgoblin/drd64_libgoblin_debug_dwarf_str.c @@ -37,13 +37,102 @@ Comment: #define DRD64_SRC_LIBGOBLIN_DEBUG_DWARF_STR #include"drd64_libgoblin.h" + /*---------------------------------------------------------------------- ----------------------------------------------------------------------*/ +LIBGOBLIN_DEBUG_DWARF_STR_EXTERN +char * + Debug_DWARF_GetTAGname( + DWord dw_tag ) +{ + int i_cnt; + char *pstr_name = NULL; + + if( DEBUG_DWARF_STR_TAG_MAX >= dw_tag ) { + pstr_name = gpstr_dwarf_tag_name[ dw_tag ]; + goto goto_Debug_DWARF_GetTAGname_post; + } + + for( i_cnt = 0; i_cnt < DEBUG_DWARF_STR_TAG_EXT_MAX; i_cnt++ ) { + if( dw_tag == gt_dwarf_str_tag_ext[ i_cnt ].dw_tag ) { + pstr_name = gt_dwarf_str_tag_ext[ i_cnt ].pstr_tagname; + break; + } + } + + if( NULL == pstr_name ) { + snprintf( gstr_dwarf_tag, sizeof( gstr_dwarf_tag ), "none_TAG: 0x%02x", dw_tag ); + pstr_name = gstr_dwarf_tag; + } + +goto_Debug_DWARF_GetTAGname_post: + return pstr_name; +} /*---------------------------------------------------------------------- ----------------------------------------------------------------------*/ +LIBGOBLIN_DEBUG_DWARF_STR_EXTERN +char * + Debug_DWARF_GetAttributeName( + DWord dw_attr ) +{ + int i_cnt; + char *pstr_name = NULL; + + if( DEBUG_DWARF_STR_AT_MAX >= dw_attr ) { + pstr_name = gpstr_dwarf_attribute_name[ dw_attr ]; + goto goto_Debug_DWARF_GetAttributeName_post; + } + + for( i_cnt = 0; i_cnt < DEBUG_DWARF_STR_AT_EXT_MAX; i_cnt++ ) { + if( dw_attr == gt_dwarf_str_at_ext[ i_cnt ].dw_at ) { + pstr_name = gt_dwarf_str_at_ext[ i_cnt ].pstr_atname; + break; + } + } + + if( NULL == pstr_name ) { + snprintf( gstr_dwarf_attribute, sizeof( gstr_dwarf_attribute ), "none_AT: 0x%02x", dw_attr ); + pstr_name = gstr_dwarf_attribute; + } + +goto_Debug_DWARF_GetAttributeName_post: + return pstr_name; +} + + +/*---------------------------------------------------------------------- +----------------------------------------------------------------------*/ +LIBGOBLIN_DEBUG_DWARF_STR_EXTERN +char * + Debug_DWARF_GetFormName( + DWord dw_form ) +{ + int i_cnt; + char *pstr_name = NULL; + + if( DEBUG_DWARF_STR_FORM_MAX >= dw_form ) { + pstr_name = gpstr_dwarf_form_name[ dw_form ]; + goto goto_Debug_DWARF_GetFormName_post; + } + + switch( dw_form ) { + case DW_FORM_GNU_ref_alt: // 0x1f20 + pstr_name = "DW_FORM_GNU_ref_alt"; + break; + case DW_FORM_GNU_strp_alt: // 0x1f21 + pstr_name = "DW_FORM_GNU_strp_alt"; + break; + default: + snprintf( gstr_dwarf_form, sizeof( gstr_dwarf_form ), "none_FORM: 0x%02x", dw_form ); + pstr_name = gstr_dwarf_form; + break; + } +goto_Debug_DWARF_GetFormName_post: + return pstr_name; +} /* EOF of drd64_.c ----------------------------------- */ diff --git a/libgoblin/drd64_libgoblin_debug_dwarf_str.h b/libgoblin/drd64_libgoblin_debug_dwarf_str.h index 30b94b7..730c310 100644 --- a/libgoblin/drd64_libgoblin_debug_dwarf_str.h +++ b/libgoblin/drd64_libgoblin_debug_dwarf_str.h @@ -45,14 +45,34 @@ Comment: #define LIBGOBLIN_DEBUG_DWARF_STR_EXTERN extern #endif +LIBGOBLIN_DEBUG_DWARF_STR_EXTERN + char *Debug_DWARF_GetTAGname( DWord dw_tag ); +LIBGOBLIN_DEBUG_DWARF_STR_EXTERN + char *Debug_DWARF_GetAttributeName( DWord dw_attr ); +LIBGOBLIN_DEBUG_DWARF_STR_EXTERN + char *Debug_DWARF_GetFormName( DWord dw_form ); + #define DEBUG_DWARF_STR_TAG_MAX 0x4f -#define DEBUG_DWARF_STR_AT_MAX 0x6f +#define DEBUG_DWARF_STR_TAG_EXT_MAX 10 + +typedef struct { + DWord dw_tag; + char *pstr_tagname; +} LibGoblin_Debug_DWARF_Str_TagExtension; + #ifndef DRD64_SRC_LIBGOBLIN_DEBUG_DWARF_STR - extern char *gstr_dwarf_tag_name[DEBUG_DWARF_STR_TAG_MAX+1]; + extern char gstr_dwarf_tag[ 64 ]; + + extern char *gpstr_dwarf_tag_name[DEBUG_DWARF_STR_TAG_MAX + 1]; + extern LibGoblin_Debug_DWARF_Str_TagExtension + gt_dwarf_str_tag_ext[ DEBUG_DWARF_STR_TAG_EXT_MAX + 1]; + #else - char *gstr_dwarf_tag_name[DEBUG_DWARF_STR_TAG_MAX+1] = { + char gstr_dwarf_tag[ 64 ]; + + char *gpstr_dwarf_tag_name[DEBUG_DWARF_STR_TAG_MAX + 1] = { "noe_TAG(ENDorERROR)", /* 0x00 */ "DW_TAG_array_type", /* 0x01 */ "DW_TAG_class_type", /* 0x02 */ @@ -138,35 +158,44 @@ Comment: "none_TAG: 0x4e", /* 0x4e */ "none_TAG: 0x4f" /* 0x4f */ }; -#endif -typedef struct { - DWord dw_tag; - char *pstr_tagname; +// #define DW_TAG_lo_user 0x4080 +// #define DW_TAG_hi_user 0xffff +LibGoblin_Debug_DWARF_Str_TagExtension gt_dwarf_str_tag_ext[ DEBUG_DWARF_STR_TAG_EXT_MAX + 1] = { + { 0x4101, "DW_TAG_format_label" }, + { 0x4102, "DW_TAG_function_template" }, + { 0x4103, "DW_TAG_class_template" }, + { 0x4104, "DW_TAG_GNU_BINCL" }, + { 0x4105, "DW_TAG_GNU_EINCL" }, + { 0x4106, "DW_TAG_GNU_template_template_parameter" }, // = DW_TAG_GNU_template_template_param + { 0x4107, "DW_TAG_GNU_template_parameter_pack" }, + { 0x4108, "DW_TAG_GNU_formal_parameter_pack" }, + { 0x4109, "DW_TAG_GNU_call_site" }, + { 0x410a, "DW_TAG_GNU_call_site_parameter" } }; +#endif -// #define DW_TAG_lo_user 0x4080 -// #define DW_TAG_hi_user 0xffff -// GNU extensions. -// #define DW_TAG_format_label 0x4101 -// #define DW_TAG_function_template 0x4102 -// #define DW_TAG_class_template 0x4103 -// #define DW_TAG_GNU_BINCL 0x4104 -// #define DW_TAG_GNU_EINCL 0x4105 -// #define DW_TAG_GNU_template_template_parameter 0x4106 -// #define DW_TAG_GNU_template_template_param 0x4106 -// #define DW_TAG_GNU_template_parameter_pack 0x4107 -// #define DW_TAG_GNU_formal_parameter_pack 0x4108 -// #define DW_TAG_GNU_call_site 0x4109 -// #define DW_TAG_GNU_call_site_parameter 0x410a +typedef struct { + char *pstr_atname; + DWord dw_at; +} LibGoblin_Debug_DWARF_Str_ATExtension; +#define DEBUG_DWARF_STR_AT_MAX 0x6f +#define DEBUG_DWARF_STR_AT_EXT_MAX 53 #ifndef DRD64_SRC_LIBGOBLIN_DEBUG_DWARF_STR - extern char *gstr_dwarf_attribute_name[DEBUG_DWARF_STR_AT_MAX+1]; + extern char gstr_dwarf_attribute[ 64 ]; + + extern LibGoblin_Debug_DWARF_Str_ATExtension + gt_dwarf_str_at_ext[ DEBUG_DWARF_STR_AT_EXT_MAX + 1 ]; + extern char *gpstr_dwarf_attribute_name[ DEBUG_DWARF_STR_AT_MAX + 1 ]; + #else - char *gstr_dwarf_attribute_name[DEBUG_DWARF_STR_AT_MAX+1] = { + char gstr_dwarf_attribute[ 64 ]; + + char *gpstr_dwarf_attribute_name[ DEBUG_DWARF_STR_AT_MAX + 1 ] = { "none_AT(ENDorERROR)", /* 0x00 */ "DW_AT_sibling", /* 0x01 */ "DW_AT_location", /* 0x02 */ @@ -285,83 +314,81 @@ typedef struct { "DW_AT_linkage_name" /* 0x6e - DWARF4? */ "none_AT: 0x6f", /* 0x6f */ }; -#endif -/* -#define DW_AT_lo_user 0x2000 -#define DW_AT_hi_user 0x3fff - -// SGI/MIPS extensions. -#define DW_AT_MIPS_fde 0x2001 -#define DW_AT_MIPS_loop_begin 0x2002 -#define DW_AT_MIPS_tail_loop_begin 0x2003 -#define DW_AT_MIPS_epilog_begin 0x2004 -#define DW_AT_MIPS_loop_unroll_factor 0x2005 -#define DW_AT_MIPS_software_pipeline_depth 0x2006 -#define DW_AT_MIPS_linkage_name 0x2007 -#define DW_AT_MIPS_stride 0x2008 -#define DW_AT_MIPS_abstract_name 0x2009 -#define DW_AT_MIPS_clone_origin 0x200a -#define DW_AT_MIPS_has_inlines 0x200b -#define DW_AT_MIPS_stride_byte 0x200c -#define DW_AT_MIPS_stride_elem 0x200d -#define DW_AT_MIPS_ptr_dopetype 0x200e -#define DW_AT_MIPS_allocatable_dopetype 0x200f -#define DW_AT_MIPS_assumed_shape_dopetype 0x2010 -#define DW_AT_MIPS_assumed_size 0x2011 +// #define DW_AT_lo_user 0x2000 +// #define DW_AT_hi_user 0x3fff +LibGoblin_Debug_DWARF_Str_ATExtension + gt_dwarf_str_at_ext[ DEBUG_DWARF_STR_AT_EXT_MAX + 1 ] = { + { "DW_AT_sf_names", 0x2101 }, // GNU extensions. + { "DW_AT_src_info", 0x2102 }, // GNU extensions. + { "DW_AT_mac_info", 0x2103 }, // GNU extensions. + { "DW_AT_src_coords", 0x2104 }, // GNU extensions. + { "DW_AT_body_begin", 0x2105 }, // GNU extensions. + { "DW_AT_body_end", 0x2106 }, // GNU extensions. + { "DW_AT_GNU_vector", 0x2107 }, // GNU extensions. + { "DW_AT_GNU_guarded_by", 0x2108 }, // GNU extensions. + { "DW_AT_GNU_pt_guarded_by", 0x2109 }, // GNU extensions. + { "DW_AT_GNU_guarded", 0x210a }, // GNU extensions. + { "DW_AT_GNU_pt_guarded", 0x210b }, // GNU extensions. + { "DW_AT_GNU_locks_excluded", 0x210c }, // GNU extensions. + { "DW_AT_GNU_exclusive_locks_required", 0x210d }, // GNU extensions. + { "DW_AT_GNU_shared_locks_required", 0x210e }, // GNU extensions. + { "DW_AT_GNU_odr_signature", 0x210f }, // GNU extensions. + { "DW_AT_GNU_template_name", 0x2110 }, // GNU extensions. + { "DW_AT_GNU_call_site_value", 0x2111 }, // GNU extensions. + { "DW_AT_GNU_call_site_data_value", 0x2112 }, // GNU extensions. + { "DW_AT_GNU_call_site_target", 0x2113 }, // GNU extensions. + { "DW_AT_GNU_call_site_target_clobbered", 0x2114 }, // GNU extensions. + { "DW_AT_GNU_tail_call", 0x2115 }, // GNU extensions. + { "DW_AT_GNU_all_tail_call_sites", 0x2116 }, // GNU extensions. + { "DW_AT_GNU_all_call_sites", 0x2117 }, // GNU extensions. + { "DW_AT_GNU_all_source_call_sites", 0x2118 }, // GNU extensions. + { "DW_AT_MIPS_fde", 0x2001 }, // SGI/MIPS extensions. + { "DW_AT_MIPS_loop_begin", 0x2002 }, // SGI/MIPS extensions. + { "DW_AT_MIPS_tail_loop_begin", 0x2003 }, // SGI/MIPS extensions. + { "DW_AT_MIPS_epilog_begin", 0x2004 }, // SGI/MIPS extensions. + { "DW_AT_MIPS_loop_unroll_factor", 0x2005 }, // SGI/MIPS extensions. + { "DW_AT_MIPS_software_pipeline_depth", 0x2006 }, // SGI/MIPS extensions. + { "DW_AT_MIPS_linkage_name", 0x2007 }, // SGI/MIPS extensions. + { "DW_AT_MIPS_stride", 0x2008 }, // SGI/MIPS extensions. + { "DW_AT_MIPS_abstract_name", 0x2009 }, // SGI/MIPS extensions. + { "DW_AT_MIPS_clone_origin", 0x200a }, // SGI/MIPS extensions. + { "DW_AT_MIPS_has_inlines", 0x200b }, // SGI/MIPS extensions. + { "DW_AT_MIPS_stride_byte", 0x200c }, // SGI/MIPS extensions. + { "DW_AT_MIPS_stride_elem", 0x200d }, // SGI/MIPS extensions. + { "DW_AT_MIPS_ptr_dopetype", 0x200e }, // SGI/MIPS extensions. + { "DW_AT_MIPS_allocatable_dopetype", 0x200f }, // SGI/MIPS extensions. + { "DW_AT_MIPS_assumed_shape_dopetype", 0x2010 }, // SGI/MIPS extensions. + { "DW_AT_MIPS_assumed_size", 0x2011 }, // SGI/MIPS extensions. + { "DW_AT_APPLE_optimized", 0x3fe1 }, // Apple extensions. + { "DW_AT_APPLE_flags", 0x3fe2 }, // Apple extensions. + { "DW_AT_APPLE_isa", 0x3fe3 }, // Apple extensions. + { "DW_AT_APPLE_block", 0x3fe4 }, // Apple extensions. + { "DW_AT_APPLE_major_runtime_vers", 0x3fe5 }, // Apple extensions. + { "DW_AT_APPLE_runtime_class", 0x3fe6 }, // Apple extensions. + { "DW_AT_APPLE_omit_frame_ptr", 0x3fe7 }, // Apple extensions. + { "DW_AT_APPLE_property_name", 0x3fe8 }, // Apple extensions. + { "DW_AT_APPLE_property_getter", 0x3fe9 }, // Apple extensions. + { "DW_AT_APPLE_property_setter", 0x3fea }, // Apple extensions. + { "DW_AT_APPLE_property_attribute", 0x3feb }, // Apple extensions. + { "DW_AT_APPLE_objc_complete_type", 0x3fec }, // Apple extensions. + { "DW_AT_APPLE_property", 0x3fed }, // Apple extensions. +}; +#endif -// GNU extensions. -#define DW_AT_sf_names 0x2101 -#define DW_AT_src_info 0x2102 -#define DW_AT_mac_info 0x2103 -#define DW_AT_src_coords 0x2104 -#define DW_AT_body_begin 0x2105 -#define DW_AT_body_end 0x2106 -#define DW_AT_GNU_vector 0x2107 -#define DW_AT_GNU_guarded_by 0x2108 -#define DW_AT_GNU_pt_guarded_by 0x2109 -#define DW_AT_GNU_guarded 0x210a -#define DW_AT_GNU_pt_guarded 0x210b -#define DW_AT_GNU_locks_excluded 0x210c -#define DW_AT_GNU_exclusive_locks_required 0x210d -#define DW_AT_GNU_shared_locks_required 0x210e -#define DW_AT_GNU_odr_signature 0x210f -#define DW_AT_GNU_template_name 0x2110 -#define DW_AT_GNU_call_site_value 0x2111 -#define DW_AT_GNU_call_site_data_value 0x2112 -#define DW_AT_GNU_call_site_target 0x2113 -#define DW_AT_GNU_call_site_target_clobbered 0x2114 -#define DW_AT_GNU_tail_call 0x2115 -#define DW_AT_GNU_all_tail_call_sites 0x2116 -#define DW_AT_GNU_all_call_sites 0x2117 -#define DW_AT_GNU_all_source_call_sites 0x2118 - -// Apple extensions. -#define DW_AT_APPLE_optimized 0x3fe1 -#define DW_AT_APPLE_flags 0x3fe2 -#define DW_AT_APPLE_isa 0x3fe3 -#define DW_AT_APPLE_block 0x3fe4 -#define DW_AT_APPLE_major_runtime_vers 0x3fe5 -#define DW_AT_APPLE_runtime_class 0x3fe6 -#define DW_AT_APPLE_omit_frame_ptr 0x3fe7 -#define DW_AT_APPLE_property_name 0x3fe8 -#define DW_AT_APPLE_property_getter 0x3fe9 -#define DW_AT_APPLE_property_setter 0x3fea -#define DW_AT_APPLE_property_attribute 0x3feb -#define DW_AT_APPLE_objc_complete_type 0x3fec -#define DW_AT_APPLE_property 0x3fed -*/ #define DEBUG_DWARF_STR_FORM_MAX 0x21 #ifndef DRD64_SRC_LIBGOBLIN_DEBUG_DWARF_STR - extern char *gstr_dwarf_form_name[DEBUG_DWARF_STR_FORM_MAX+1]; + extern char *gstr_dwarf_form[ 32 ]; + extern char *gpstr_dwarf_form_name[DEBUG_DWARF_STR_FORM_MAX + 1]; #else - char *gstr_dwarf_form_name[DEBUG_DWARF_STR_FORM_MAX+1] = { - "noe_FORM(0x00)", // 0x00 + char *gstr_dwarf_form[ 32 ]; + char *gpstr_dwarf_form_name[DEBUG_DWARF_STR_FORM_MAX + 1] = { + "none_FORM: 0x00", // 0x00 "DW_FORM_addr", // 0x01 - "noe_FORM(0x02)", // 0x02 + "none_FORM: 0x02", // 0x02 "DW_FORM_block2", // 0x03 "DW_FORM_block4", // 0x04 "DW_FORM_data2", // 0x05 diff --git a/libgoblin/drd64_libgoblin_dwarf_info.c b/libgoblin/drd64_libgoblin_dwarf_info.c index e53f7a3..1748eeb 100644 --- a/libgoblin/drd64_libgoblin_dwarf_info.c +++ b/libgoblin/drd64_libgoblin_dwarf_info.c @@ -556,7 +556,7 @@ int } p_arvnow = p_abbrev + (dw_arvid - 1); -printf(" [AbbrevID = %d] TAG=%02xh\n", dw_arvid, p_arvnow->dw_tag ); +printf(" [AbbrevID = %d] %s (%02xh)\n", dw_arvid, Debug_DWARF_GetTAGname(p_arvnow->dw_tag), p_arvnow->dw_tag ); // Read Debug Information Entry (DIE) --- memset( p_infoval, 0x00, sizeof( LibGoblin_DWARF_DIEValue ) * p_arvnow->i_items ); @@ -565,7 +565,8 @@ printf(" [AbbrevID = %d] TAG=%02xh\n", dw_arvid, p_arvnow->dw_tag ); 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 ); +printf(" %-24s, %-24s : ", Debug_DWARF_GetAttributeName( dw_attribute ), + Debug_DWARF_GetFormName( dw_format ) ); pb_info = DWARF_Info_ReadFormat_Data( p_val, pb_info, &qw_size_cu, dw_format, p_binfo, &t_cuheader ); -- 2.11.0