OSDN Git Service

2019/02/24(Sun) 18:41
[drdeamon64/drdeamon64.git] / libgoblin / drd64_libgoblin_debug_addrinfo.c
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
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.
16
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.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_.c
33 Function: 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #define DRD64_SRC_LIBGOBLIN_DEBUG_ADDRINFO
38 #include"drd64_libgoblin.h"
39
40
41 /*----------------------------------------------------------------------
42 ----------------------------------------------------------------------*/
43 LIBGOBLIN_DEBUG_ADDRINFO_EXTERN
44 int
45         LibGoblin_Debug_AddrInfo_PrintAddrTable(
46                         LibGoblin_BinaryInfo    *p_binfo,
47                         Byte            b_level )
48 {
49         Word                                    w_scope;
50         Word                                    w_type;
51         DWord                                   dw_cnt;
52         LibGoblin_AddressInfo   *p_addr;
53         LibGoblin_ProgramInfo   *p_pginfo;
54
55         assert( NULL != p_binfo );
56         p_pginfo        = ProgInfo_GetProgInfo( p_binfo->i_pginfo );
57
58         if( 0x00 < b_level )
59                 { puts("[DEBUG] Address Info. Table -------------------------------------------"); }
60
61         p_addr  = p_binfo->p_addrinfo;
62         if( NULL == p_addr )    {
63                 if( 0x00 < b_level )    { puts(" Not exist Address Table."); }
64                 return 0x01;
65         }
66
67         for( dw_cnt = 0; dw_cnt < p_binfo->dw_max_addrinfo; dw_cnt++, p_addr++ )        {
68                 if( 0x00 < b_level )    {
69                         printf("  %08lx - %08lx (%8d) ", p_addr->ptr_addr.value,
70                                                         p_addr->ptr_addr.value + p_addr->dw_size, p_addr->dw_size );
71
72                         // b_elf_flags
73                         w_scope = p_addr->b_elf_flags >> 4;
74                         if( STB_GLOBAL == w_scope )             { printf( "[Global:" ); }
75                         else if( STB_WEAK == w_scope )  { printf( "[Weak  :" ); }
76                         else if( STB_LOCAL == w_scope ) { printf( "[Local :" ); }
77                         else                                                    { printf( "[Other :" ); }
78
79                         w_type  = p_addr->b_elf_flags & 0x0f;
80                         switch( w_type )        {
81                                 case STT_NOTYPE:        printf( "No Type ] " ); break;
82                                 case STT_OBJECT:        printf( "Object  ] " ); break;
83                                 case STT_FUNC:          printf( "Function] " ); break;
84                                 case STT_SECTION:       printf( "Section ] " ); break;
85                                 case STT_FILE:          printf( "File    ] " ); break;
86                                 case STT_COMMON:        printf( "Common  ] " ); break;
87                                 case STT_TLS:           printf( "TLS     ] " ); break;
88                                 case STT_NUM:           printf( "Number  ] " ); break;
89                                 default:                        printf( "(Other) ] " ); break;
90                         }
91
92                         // pstr_name
93                         printf( "%30s ", p_addr->pstr_name );
94                         if( STT_SECTION == w_type )             {
95                                 printf("\n");
96                                 continue;
97                         }
98
99                         // dw_srcid
100                         // w_secid
101                         if( SHN_ABS  == p_addr->w_secid )                       { printf("(ABS)"); }
102                         else if( SHN_COMMON  == p_addr->w_secid )       { printf("(Common)"); }
103                         else if( SHN_XINDEX  == p_addr->w_secid )       { printf("(XIndex)"); }
104                         else if( SHN_UNDEF  == p_addr->w_secid )        { printf("(UNDEF)"); }
105                         else if( LIBGOBLIN_SECTION_ID_MAX > p_addr->w_secid )   {
106                                 printf("(%s)",
107                                         LibGoblin_Section_GetSectionName( p_pginfo, p_addr->w_secid ));
108                         }
109                         else    { printf("(NO SHNDX)%d", p_addr->w_secid); }
110                         // dw_next
111                         printf("\n");
112                 }
113         }
114
115         if( 0x00 < b_level )    {
116                 puts("-----------------------------------------------------------------------");
117                 puts("");
118         }
119
120         return 0x00;
121 }
122
123
124
125 /* EOF of drd64_.c ----------------------------------- */