1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
4 for INTEL64(R), AMD64(R)
6 Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
31 /* File Info -----------------------------------------------------------
35 ----------------------------------------------------------------------*/
37 #define DRD64_SRC_LIBGOBLIN_DEBUG_OBJINFO
38 #include"drd64_libgoblin.h"
40 static char gstr_type[256][9] = {
58 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
59 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
60 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
61 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
62 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
63 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
64 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
67 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
68 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
69 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
70 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
71 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
72 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
73 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
74 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
77 /*====================================================================*/
78 /*--------------------------------------------------------------------*/
80 Debug_ObjectInfo_Print_SymbolCommon(
81 LibGoblin_ObjectInfo *p_obj,
87 char str_visibility[32];
88 LibGoblin_BinaryInfo *p_binfo_origin;
90 printf(" %s\t\t[OBJINFO] Addr.Link(%3d <-> %3d) File{ Offset=%8p, Size=%8ld, BinFileID=%d }\n",
92 p_obj->addrlink.i_prev_id, p_obj->addrlink.i_next_id,
93 p_obj->file.pv_offset, p_obj->file.qw_size, p_obj->file.i_binfile );
95 // Symbol type - ELFNN_ST_TYPE - st_info
96 switch( p_obj->info.symbol.b_type ) {
97 case STT_NOTYPE: // 0 - Unspecified type.
98 strcpy( str_type, "NoType" );
100 case STT_OBJECT: // 1 - Data object.
101 strcpy( str_type, "Data Object" );
103 case STT_FUNC: // 2 - Function.
104 strcpy( str_type, "Function" );
106 case STT_SECTION: // 3 - Section.
107 strcpy( str_type, "Section" );
109 case STT_FILE: // 4 - Source file.
110 strcpy( str_type, "Source File" );
112 case STT_COMMON: // 5 - Uninitialized common block.
113 strcpy( str_type, "UnInit. CommonBlock" );
115 case STT_TLS: // 6 - TLS object.
116 strcpy( str_type, "TLS Object" );
119 strcpy( str_type, "Num" );
122 strcpy( str_type, "GNU IFunc" );
125 snprintf( str_type, 31, "(%02xh)", p_obj->info.symbol.b_type );
129 // Symbol Binding - ELFNN_ST_BIND - st_info
130 switch( p_obj->info.symbol.b_binding ) {
131 case STB_LOCAL: // 0 - Local symbol
132 strcpy( str_binding, "Local" );
134 case STB_GLOBAL: // 1 - Global symbol
135 strcpy( str_binding, "Global" );
137 case STB_WEAK: // 2 - like global - lower precedence
138 strcpy( str_binding, "WEAK" );
140 case STB_GNU_UNIQUE: // 10 - Unique symbol (GNU)
141 strcpy( str_binding, "GNU Unique" );
144 snprintf( str_binding, 31, "(%02xh)", p_obj->info.symbol.b_binding );
149 // Symbol visibility - ELFNN_ST_VISIBILITY - st_other
150 switch( p_obj->info.symbol.b_visibility ) {
151 case STV_DEFAULT: // 0x00 - Default visibility (see binding).
152 strcpy( str_visibility, "Default" );
154 case STV_INTERNAL: // 0x01 - Special meaning in relocatable objects.
155 strcpy( str_visibility, "INTERNAL" );
157 case STV_HIDDEN: // 0x02 - Not visible.
158 strcpy( str_visibility, "HIDDEN" );
160 case STV_PROTECTED: // 0x03 - Visible but not preemptible.
161 strcpy( str_visibility, "PROTECTED" );
164 strcpy( str_visibility, "EXPORTED" );
167 strcpy( str_visibility, "SINGLETON" );
170 strcpy( str_visibility, "ELIMINATE" );
173 snprintf( str_binding, 31, "(%02xh)", p_obj->info.symbol.b_binding );
177 printf(" %s\t\t[SYMBOL] Type: %s, Binding: %s, Visibility: %s\n",
178 pstr_space, str_type, str_binding, str_visibility );
181 if( OBJINFO_STATUS_DYNAMIC & p_obj->dw_status ) {
182 p_binfo_origin = BinaryInfo_GetBinInfo( p_obj->dynamic.i_binfo_origin );
184 printf(" %s\t\t[DYNAMIC] Lib.Name: %s (binfo id= %d), .dynsym index= %d\n",
186 ((NULL != p_binfo_origin) ? p_binfo_origin->str_filename : "--NULL--"),
187 p_obj->dynamic.i_binfo_origin, p_obj->dynamic.i_dynsym_index );
194 /*--------------------------------------------------------------------*/
196 Debug_ObjectInfo_Print_Function(
197 LibGoblin_ObjectInfo *p_obj,
201 Debug_ObjectInfo_Print_SymbolCommon( p_obj, pstr_space, b_level );
205 /*--------------------------------------------------------------------*/
207 Debug_ObjectInfo_Print_Object(
208 LibGoblin_ObjectInfo *p_obj,
212 Debug_ObjectInfo_Print_SymbolCommon( p_obj, pstr_space, b_level );
216 /*--------------------------------------------------------------------*/
218 Debug_ObjectInfo_Print_Common(
219 LibGoblin_ObjectInfo *p_obj,
223 Debug_ObjectInfo_Print_SymbolCommon( p_obj, pstr_space, b_level );
227 /*--------------------------------------------------------------------*/
229 Debug_ObjectInfo_Print_TLS(
230 LibGoblin_ObjectInfo *p_obj,
234 Debug_ObjectInfo_Print_SymbolCommon( p_obj, pstr_space, b_level );
238 /*--------------------------------------------------------------------*/
240 Debug_ObjectInfo_Print_Rel(
241 LibGoblin_ObjectInfo *p_obj,
245 //Debug_ObjectInfo_Print_SymbolCommon( p_obj, pstr_space, b_level );
249 /*--------------------------------------------------------------------*/
251 Debug_ObjectInfo_Print_Section(
252 LibGoblin_ObjectInfo *p_obj,
260 printf(" %s\t\t[OBJINFO] Addr.Link(%3d <-> %3d) File{ Offset=%8p, Size=%8ld, BinFileID=%d }\n",
262 p_obj->addrlink.i_prev_id, p_obj->addrlink.i_next_id,
263 p_obj->file.pv_offset, p_obj->file.qw_size, p_obj->file.i_binfile );
266 switch( p_obj->info.section.dw_type ) {
269 strncpy( str_type, "NULL", 31 );
271 /* 1 - program defined information */
273 strncpy( str_type, "PROGBITS", 31 );
275 /* 2 - symbol table section */
277 strncpy( str_type, "SYMTAB", 31 );
279 /* 3 - string table section */
281 strncpy( str_type, "STRTAB", 31 );
283 /* 4 - relocation section with addends */
285 strncpy( str_type, "RELA", 31 );
287 /* 5 - symbol hash table section */
289 strncpy( str_type, "HASH", 31 );
291 /* 6 - dynamic section */
293 strncpy( str_type, "DYNAMIC", 31 );
295 /* 7 - note section */
297 strncpy( str_type, "NOTE", 31 );
299 /* 8 - no space section */
301 strncpy( str_type, "NOBITS", 31 );
303 /* 9 - relocation section - no addends */
305 strncpy( str_type, "REL", 31 );
307 /* 10 - reserved - purpose unknown */
309 strncpy( str_type, "SHLIB", 31 );
311 /* 11 - dynamic symbol table section */
313 strncpy( str_type, "DYNSYM", 31 );
315 /* 14 - Initialization function pointers. */
317 strncpy( str_type, "INIT_ARRAY", 31 );
319 /* 15 - Termination function pointers. */
321 strncpy( str_type, "FINI_ARRAY", 31 );
323 /* 16 - Pre-initialization function ptrs. */
324 case SHT_PREINIT_ARRAY:
325 strncpy( str_type, "PREINIT_ARRAY", 31 );
327 /* 17 - Section group. */
329 strncpy( str_type, "GROUP", 31 );
331 /* 18 - Section indexes (see SHN_XINDEX). */
332 case SHT_SYMTAB_SHNDX:
333 strncpy( str_type, "SYMTAB_SHNDX", 31 );
337 snprintf( str_type, 31, "(%8x)", p_obj->info.section.dw_type );
341 qw_flag = p_obj->info.section.qw_flag;
343 /* SHF_WRITE 0x1: Section contains writable data. */
344 if( SHF_WRITE & qw_flag ) { strcat( str_flag, "Write " ); }
345 /* SHF_ALLOC 0x2: Section occupies memory. */
346 if( SHF_ALLOC & qw_flag ) { strcat( str_flag, "Alloc " ); }
347 /* SHF_EXECINSTR 0x4: Section contains instructions. */
348 if( SHF_EXECINSTR & qw_flag ) { strcat( str_flag, "Exec " ); }
349 /* SHF_MERGE 0x10: Section may be merged. */
350 if( SHF_MERGE & qw_flag ) { strcat( str_flag, "Merged " ); }
351 /* SHF_STRINGS 0x20: Section contains strings. */
352 if( SHF_STRINGS & qw_flag ) { strcat( str_flag, "Strings " ); }
353 /* SHF_INFO_LINK 0x40: sh_info holds section index. */
354 if( SHF_INFO_LINK & qw_flag ) { strcat( str_flag, "InfoLink " ); }
355 /* SHF_LINK_ORDER 0x80: Special ordering requirements. */
356 if( SHF_LINK_ORDER & qw_flag ) { strcat( str_flag, "LinkOrder " ); }
357 /* SHF_OS_NONCONFORMING 0x100: OS-specific processing required. */
358 if( SHF_OS_NONCONFORMING & qw_flag ) { strcat( str_flag, "OSspecific " ); }
359 /* SHF_GROUP 0x200: Member of section group. */
360 if( SHF_GROUP & qw_flag ) { strcat( str_flag, "Group " ); }
361 /* SHF_TLS 0x400: Section contains TLS data. */
362 if( SHF_TLS & qw_flag ) { strcat( str_flag, "TLS " ); }
363 /* SHF_COMPRESSED 0x800: Section contains compressed data. */
364 if( SHF_COMPRESSED & qw_flag ) { strcat( str_flag, "Compressed " ); }
366 printf(" %s\t\t[SECTION] Type: %s, Align= %ld, Flag[ %s]\n",
367 pstr_space, str_type, p_obj->info.section.qw_align, str_flag );
368 printf(" %s\t\t[SECTION] EntSize= %ld, Link(Related Section)= %d, Info(Depends Section Type)= %xh\n",
369 pstr_space, p_obj->info.section.qw_entsize,
370 p_obj->info.section.dw_link, p_obj->info.section.dw_info );
375 /*--------------------------------------------------------------------*/
377 Debug_ObjectInfo_Print_ProgramHeader(
378 LibGoblin_ObjectInfo *p_obj,
386 printf(" %s\t\t[OBJINFO] Addr.Link(%3d <-> %3d) File{ Offset=%8p, Size=%8ld, BinFileID=%d }\n",
388 p_obj->addrlink.i_prev_id, p_obj->addrlink.i_next_id,
389 p_obj->file.pv_offset, p_obj->file.qw_size, p_obj->file.i_binfile );
391 switch( p_obj->info.proghdr.dw_type ) {
393 strncpy( str_type, "NULL", 31 );
396 strncpy( str_type, "LOAD", 31 );
399 strncpy( str_type, "DYNAMIC", 31 );
402 strncpy( str_type, "INTERP", 31 );
405 strncpy( str_type, "NOTE", 31 );
408 strncpy( str_type, "SHLIB", 31 );
411 strncpy( str_type, "PHDR", 31 );
414 strncpy( str_type, "TLS", 31 );
417 snprintf( str_type, 31, "(%8x)", p_obj->info.proghdr.dw_type );
421 dw_flag = p_obj->info.proghdr.dw_flags;
422 snprintf( str_flag, 7, "%c%c%c%c%c",
423 ((PF_R & dw_flag) ? 'R' : ' '),
424 ((PF_W & dw_flag) ? 'W' : ' '),
425 ((PF_X & dw_flag) ? 'X' : ' '),
426 ((PF_MASKOS & dw_flag) ? 'O': ' '),
427 ((PF_MASKPROC & dw_flag) ? 'P': ' ') );
429 printf(" %s\t\t[PROGHDR] Flag[%5s] Type: %s, align= %ld\n",
430 pstr_space, str_flag, str_type, p_obj->info.proghdr.qw_align );
435 /*--------------------------------------------------------------------*/
437 Debug_ObjectInfo_Print_ProgramFile(
438 LibGoblin_ObjectInfo *p_obj,
442 printf(" %s\t\t[OBJINFO] Addr.Link(%3d <-> %3d)\n",
443 pstr_space, p_obj->addrlink.i_prev_id, p_obj->addrlink.i_next_id );
445 printf(" %s\t\t[PROGRAM] BinaryInfo ID= %d\n",
446 pstr_space, p_obj->info.program.i_binfo_id );
451 /*--------------------------------------------------------------------*/
453 Debug_ObjectInfo_Print_ObjectFile(
454 LibGoblin_ObjectInfo *p_obj,
458 printf(" %s\t\t[OBJINFO] Addr.Link(%3d <-> %3d)\n",
459 pstr_space, p_obj->addrlink.i_prev_id, p_obj->addrlink.i_next_id );
460 printf(" %s\t\t[OBJFILE] Abbrev Nums=%3d (%8ph) CU Header: size=%ld, ver=%d, pointer size=%d\n",
461 pstr_space, p_obj->info.objfile.i_abbrevs, p_obj->info.objfile.p_abbrev,
462 p_obj->info.objfile.t_cuheader.qw_unitsize,
463 p_obj->info.objfile.t_cuheader.w_version,
464 p_obj->info.objfile.t_cuheader.b_pointersize );
470 /*====================================================================*/
471 /*--------------------------------------------------------------------*/
473 Debug_ObjectInfo_PrintInfo(
474 LibGoblin_ObjectInfo *p_obj,
481 // Set Space String ---
483 *(pstr_space + i_len - 2) = '+';
484 *(pstr_space + i_len - 1) = '-';
486 printf(" %sOBJINFO[%4d] (%-8s)\t%16lxh - %16lxh (Size: %16lxh) : %s\n",
487 pstr_space, p_obj->i_id,
488 gstr_type[ p_obj->b_type ],
489 p_obj->addr.ptr_addr.value,
490 (( 0 < p_obj->addr.qw_size )
491 ? (p_obj->addr.ptr_addr.value + p_obj->addr.qw_size - 1)
492 : p_obj->addr.ptr_addr.value),
497 if( NO_OBJINFO != p_obj->grplink.i_next_id )
498 { *(pstr_space + i_len - 2) = '|'; }
499 else { *(pstr_space + i_len - 2) = ' '; }
500 *(pstr_space + i_len - 1) = ' ';
503 if( NO_OBJINFO != p_obj->grplink.i_child_topid )
504 { strcat( pstr_space, " | " ); }
505 else { strcat( pstr_space, " " ); }
507 switch( p_obj->b_type ) {
508 case OBJINFO_TYPE_PROGRAM:
509 Debug_ObjectInfo_Print_ProgramFile( p_obj, pstr_space, b_level );
512 case OBJINFO_TYPE_PROGHDR:
513 Debug_ObjectInfo_Print_ProgramHeader( p_obj, pstr_space, b_level );
516 case OBJINFO_TYPE_SECTION:
517 Debug_ObjectInfo_Print_Section( p_obj, pstr_space, b_level );
520 case OBJINFO_TYPE_OBJFILE:
521 Debug_ObjectInfo_Print_ObjectFile( p_obj, pstr_space, b_level );
524 case OBJINFO_TYPE_FUNCTION:
525 Debug_ObjectInfo_Print_Function( p_obj, pstr_space, b_level );
528 case OBJINFO_TYPE_OBJECT:
529 Debug_ObjectInfo_Print_Object( p_obj, pstr_space, b_level );
532 case OBJINFO_TYPE_COMMON:
533 Debug_ObjectInfo_Print_Common( p_obj, pstr_space, b_level );
536 case OBJINFO_TYPE_TLS:
537 Debug_ObjectInfo_Print_TLS( p_obj, pstr_space, b_level );
540 case OBJINFO_TYPE_REL:
541 Debug_ObjectInfo_Print_Rel( p_obj, pstr_space, b_level );
547 printf(" %s\n", pstr_space );
549 *(pstr_space + i_len) = '\0';
555 /*====================================================================*/
556 /*--------------------------------------------------------------------*/
557 LIBGOBLIN_DEBUG_OBJINFO_EXTERN
559 Debug_ObjectInfo_Print_AllAddrLink(
560 LibGoblin_ProgramInfo *p_pginfo,
563 //LibGoblin_ObjectInfo *p_objinfo;
566 { puts("[DEBUG] ObjectInfo - Addr.Link --------------------------------------"); }
571 if( 0x00 < b_level ) {
572 puts("-----------------------------------------------------------------------");
579 /*====================================================================*/
580 /*--------------------------------------------------------------------*/
582 Debug_ObjectInfo_Print_GroupLink(
583 LibGoblin_ProgramInfo *p_pginfo,
584 LibGoblin_ObjectInfo *p_objstart,
590 LibGoblin_ObjectInfo *p_objinfo;
592 i_len = strnlen( pstr_space, 384 );
593 if( 0 < i_depth ) { strcat( pstr_space, " | " ); }
595 if( NULL == p_objstart ) { return; }
596 p_objinfo = p_objstart;
599 Debug_ObjectInfo_PrintInfo( p_objinfo, i_depth, pstr_space,
600 (i_len + ((0 < i_depth) ? 3 : 0)), b_level );
603 if( NO_OBJINFO != p_objinfo->grplink.i_child_topid ) {
604 Debug_ObjectInfo_Print_GroupLink(
606 OBJINFO( p_pginfo, p_objinfo->grplink.i_child_topid ),
607 (i_depth + 1), pstr_space, b_level );
610 // Set Next ObjectInfo ---
611 p_objinfo = ((NO_OBJINFO == p_objinfo->grplink.i_next_id)
612 ? NULL : OBJINFO( p_pginfo, p_objinfo->grplink.i_next_id ));
613 } while( NULL != p_objinfo );
615 *(pstr_space + i_len) = '\0';
621 /*--------------------------------------------------------------------*/
622 LIBGOBLIN_DEBUG_OBJINFO_EXTERN
624 Debug_ObjectInfo_Print_AllGroupLink(
625 LibGoblin_ProgramInfo *p_pginfo,
629 //LibGoblin_ObjectInfo *p_objinfo;
634 { puts("[DEBUG] ObjectInfo - GroupLink --------------------------------------"); }
637 Debug_ObjectInfo_Print_GroupLink( p_pginfo, p_pginfo->objinfo.p_objinfo, 0, str_space, b_level );
639 if( 0x00 < b_level ) {
640 puts("-----------------------------------------------------------------------");
648 /* EOF of drd64_.c ----------------------------------- */