1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
/*
Copyright 2014-2014 David Anderson. All rights reserved.
This program is free software; you can redistribute it and/or modify it
under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it would be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Further, this software is distributed without any warranty that it is
free of the rightful claim of any third person regarding infringement
or the like. Any license provided herein, whether implied or
otherwise, applies only to this software file. Patent licenses, if
any, provided herein do not apply to combinations of this program with
other software, or any other product whatsoever.
You should have received a copy of the GNU General Public License along
with this program; if not, write the Free Software Foundation, Inc., 51
Franklin Street - Fifth Floor, Boston MA 02110-1301, USA.
*/
#include "globals.h"
#include "naming.h"
#include "esb.h"
#include "sanitized.h"
#include "print_sections.h"
#define TRUE 1
#define FALSE 0
static int
hashval_zero(Dwarf_Sig8 *val)
{
unsigned u = 0;
for(u=0 ; u < sizeof(Dwarf_Sig8);++u) {
if (val->signature[u]) {
return FALSE;
}
}
return TRUE;
}
extern void
print_debugfission_index(Dwarf_Debug dbg,const char *type)
{
int res = 0;
Dwarf_Xu_Index_Header xuhdr = 0;
Dwarf_Unsigned version_number = 0;
Dwarf_Unsigned offsets_count = 0;
Dwarf_Unsigned units_count = 0;
Dwarf_Unsigned hash_slots_count = 0;
Dwarf_Error fierr = 0;
const char * section_name = 0;
const char * section_type2 = 0;
const char * section_name2 = 0;
int is_cu = !strcmp(type,"cu")?TRUE:FALSE;
res = dwarf_get_xu_index_header(dbg,
type,
&xuhdr,
&version_number,
&offsets_count,
&units_count,
&hash_slots_count,
§ion_name,
&fierr);
if (res == DW_DLV_NO_ENTRY) {
/* This applies to most object files. */
return;
}
if (res == DW_DLV_ERROR) {
/* Odd. FIXME */
return;
}
res = dwarf_get_xu_index_section_type(xuhdr,
§ion_type2,
§ion_name2,
&fierr);
if (res == DW_DLV_NO_ENTRY) {
/* Impossible. */
print_error(dbg,"dwarf_get_xu_index_section_type",
DW_DLE_XU_IMPOSSIBLE_ERROR,fierr);
dwarf_xu_header_free(xuhdr);
return;
}
if (res == DW_DLV_ERROR) {
/* Impossible. FIXME */
print_error(dbg,"dwarf_get_xu_index_section_type", res,fierr);
dwarf_xu_header_free(xuhdr);
return;
}
if (strcmp(section_type2,type)) {
print_error(dbg,"dwarf_get_xu_index_section_type",
DW_DLE_XU_IMPOSSIBLE_ERROR,fierr);
dwarf_xu_header_free(xuhdr);
return;
}
if(!section_name || !*section_name) {
section_name = (is_cu?".debug_cu_index":".debug_tu_index");
}
{
struct esb_s truename;
char buf[DWARF_SECNAME_BUFFER_SIZE];
esb_constructor_fixed(&truename,buf,sizeof(buf));
get_true_section_name(dbg,section_name,
&truename,TRUE);
printf("\n%s\n",sanitized(esb_get_string(&truename)));
esb_destructor(&truename);
}
printf(" Version: %" DW_PR_DUu "\n",
version_number);
printf(" Number of columns: %" DW_PR_DUu "\n",
offsets_count);
printf(" number of entries: %" DW_PR_DUu "\n",
units_count);
printf(" Number of slots: %" DW_PR_DUu "\n",
hash_slots_count);
if (hash_slots_count > 0) {
printf("\n");
printf(" hash index\n");
}
{
Dwarf_Unsigned h = 0;
for( h = 0; h < hash_slots_count; h++) {
Dwarf_Sig8 hashval;
Dwarf_Unsigned index = 0;
Dwarf_Unsigned col = 0;
struct esb_s hashhexstring;
esb_constructor(&hashhexstring);
memset(&hashval,0,sizeof(hashval));
res = dwarf_get_xu_hash_entry(xuhdr,h,
&hashval,&index,&fierr);
if (res == DW_DLV_ERROR) {
print_error(dbg,"dwarf_get_xu_hash_entry",res,fierr);
dwarf_xu_header_free(xuhdr);
esb_destructor(&hashhexstring);
return;
} else if (res == DW_DLV_NO_ENTRY) {
/* Impossible */
printf(" [%4" DW_PR_DUu "] "
"dwarf_get_xu_hash_entry impossible return code: "
"No entry?\n",
h);
dwarf_xu_header_free(xuhdr);
esb_destructor(&hashhexstring);
return;
} else if (hashval_zero(&hashval) && index == 0 ) {
/* An unused hash slot, we do not print them */
continue;
}
format_sig8_string(&hashval,&hashhexstring);
printf(" [%4" DW_PR_DUu "] %s"
" %8" DW_PR_DUu "\n",
h,
esb_get_string(&hashhexstring),
index);
esb_destructor(&hashhexstring);
printf(" col section "
"offset size\n");
for (col = 0; col < offsets_count; col++) {
Dwarf_Unsigned off = 0;
Dwarf_Unsigned len = 0;
const char * name = 0;
Dwarf_Unsigned num = 0;
res = dwarf_get_xu_section_names(xuhdr,
col,&num,&name,&fierr);
if (res != DW_DLV_OK) {
print_error(dbg,"dwarf_get_xu_section_names",res,fierr);
dwarf_xu_header_free(xuhdr);
return;
}
res = dwarf_get_xu_section_offset(xuhdr,
index,col,&off,&len,&fierr);
if (res != DW_DLV_OK) {
print_error(dbg,"dwarf_get_xu_section_offset",res,fierr);
dwarf_xu_header_free(xuhdr);
return;
}
printf(" [,%2" DW_PR_DUu "] %20s "
"0x%" DW_PR_XZEROS DW_PR_DUx
" (%8" DW_PR_DUu ") "
"0x%" DW_PR_XZEROS DW_PR_DUx
" (%8" DW_PR_DUu ")\n",
col,name,
off,off,
len,len);
}
}
}
dwarf_xu_header_free(xuhdr);
}
|