| 1 |
/* |
| 2 |
Copyright (C) 2021 David Anderson. All Rights Reserved. |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of version 2 of the GNU General |
| 6 |
Public License as published by the Free Software Foundation. |
| 7 |
|
| 8 |
This program is distributed in the hope that it would be |
| 9 |
useful, but WITHOUT ANY WARRANTY; without even the implied |
| 10 |
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 11 |
PURPOSE. |
| 12 |
|
| 13 |
Further, this software is distributed without any warranty |
| 14 |
that it is free of the rightful claim of any third person |
| 15 |
regarding infringement or the like. Any license provided |
| 16 |
herein, whether implied or otherwise, applies only to this |
| 17 |
software file. Patent licenses, if any, provided herein |
| 18 |
do not apply to combinations of this program with other |
| 19 |
software, or any other product whatsoever. |
| 20 |
|
| 21 |
You should have received a copy of the GNU General Public |
| 22 |
License along with this program; if not, write the Free |
| 23 |
Software Foundation, Inc., 51 Franklin Street - Fifth Floor, |
| 24 |
Boston MA 02110-1301, USA. |
| 25 |
*/ |
| 26 |
|
| 27 |
#include <config.h> |
| 28 |
|
| 29 |
#include <stdio.h> /* printf() */ |
| 30 |
#include <stdlib.h> /* calloc() free() malloc() */ |
| 31 |
|
| 32 |
/* Windows specific header files */ |
| 33 |
#if defined(_WIN32) && defined(HAVE_STDAFX_H) |
| 34 |
#include "stdafx.h" |
| 35 |
#endif /* HAVE_STDAFX_H */ |
| 36 |
|
| 37 |
#include "dwarf.h" |
| 38 |
#include "libdwarf.h" |
| 39 |
#include "libdwarf_private.h" |
| 40 |
#include "dd_defined_types.h" |
| 41 |
#include "dd_checkutil.h" |
| 42 |
#include "dd_glflags.h" |
| 43 |
#include "dd_globals.h" |
| 44 |
#include "dd_tsearchbal.h" |
| 45 |
#include "dd_naming.h" |
| 46 |
#include "dd_attr_form.h" |
| 47 |
#include "dwarfdump-af-table-std.h" |
| 48 |
#include "dwarfdump-af-table-ext.h" |
| 49 |
#include "dwarfdump-ta-table.h" |
| 50 |
#include "dwarfdump-ta-ext-table.h" |
| 51 |
#include "dwarfdump-tt-table.h" |
| 52 |
#include "dwarfdump-tt-ext-table.h" |
| 53 |
|
| 54 |
/* Here we have code to read the generated header files |
| 55 |
with the relationship data so we can print the data. |
| 56 |
This also prints the attr-form tables. |
| 57 |
See also print_tag_attributes_usage.c as that is |
| 58 |
where tag-tag and tag-attr tree is printed. */ |
| 59 |
|
| 60 |
#if 0 |
| 61 |
static void |
| 62 |
print_3key_record(const char *msg,int num,Three_Key_Entry *e) |
| 63 |
{ |
| 64 |
printf("3key %s %d 0x%x 0x%x 0x%x st %d ct %lu\n", |
| 65 |
msg,num,e->key1,e->key2,e->key3, |
| 66 |
e->from_tables, |
| 67 |
(unsigned long)e->count); |
| 68 |
} |
| 69 |
#endif /* 0 */ |
| 70 |
|
| 71 |
void * threekey_tag_tag_base; /* tag-tree recording */ |
| 72 |
void * threekey_tag_attr_base; /* for tag_attr recording */ |
| 73 |
void * threekey_attr_form_base; /* for attr/class/form recording */ |
| 74 |
void * threekey_tag_use_base; /* for simple tag counting */ |
| 75 |
|
| 76 |
int |
| 77 |
make_3key(Dwarf_Half k1, |
| 78 |
Dwarf_Half k2, |
| 79 |
Dwarf_Half k3, |
| 80 |
Dwarf_Small std_or_exten, |
| 81 |
Dwarf_Small reserved, |
| 82 |
Dwarf_Unsigned count, |
| 83 |
Three_Key_Entry ** out) |
| 84 |
{ |
| 85 |
Three_Key_Entry *e = |
| 86 |
(Three_Key_Entry *)malloc(sizeof(Three_Key_Entry)); |
| 87 |
if (!e) { |
| 88 |
return DW_DLV_ERROR; /* out of memory */ |
| 89 |
} |
| 90 |
e->key1 = k1; |
| 91 |
e->key2 = k2; |
| 92 |
e->key3 = k3; |
| 93 |
e->from_tables = std_or_exten; |
| 94 |
e->reserved = reserved; |
| 95 |
e->count = count; |
| 96 |
*out = e; |
| 97 |
return DW_DLV_OK; |
| 98 |
} |
| 99 |
|
| 100 |
void |
| 101 |
free_func_3key_entry(void *keystructptr) |
| 102 |
{ |
| 103 |
Three_Key_Entry *e = keystructptr; |
| 104 |
if (e->from_tables) { |
| 105 |
/* Points into static AF_STD or |
| 106 |
AF_EXTEN array. do not free */ |
| 107 |
return; |
| 108 |
} |
| 109 |
free(e); |
| 110 |
} |
| 111 |
|
| 112 |
int |
| 113 |
std_compare_3key_entry(const void *l_in, const void *r_in) |
| 114 |
{ |
| 115 |
const Three_Key_Entry *l = l_in; |
| 116 |
const Three_Key_Entry *r = r_in; |
| 117 |
if (l->key1 < r->key1) { |
| 118 |
return -1; |
| 119 |
} |
| 120 |
if (l->key1 > r->key1) { |
| 121 |
return 1; |
| 122 |
} |
| 123 |
if (l->key2 < r->key2) { |
| 124 |
return -1; |
| 125 |
} |
| 126 |
if (l->key2 > r->key2) { |
| 127 |
return 1; |
| 128 |
} |
| 129 |
if (l->key3 < r->key3) { |
| 130 |
return -1; |
| 131 |
} |
| 132 |
if (l->key3 > r->key3) { |
| 133 |
return 1; |
| 134 |
} |
| 135 |
return 0; |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
static Dwarf_Unsigned counting_global; |
| 140 |
static void |
| 141 |
count_3key_entry(const void * vptr, |
| 142 |
DW_VISIT x, |
| 143 |
int level) |
| 144 |
{ |
| 145 |
(void)vptr; |
| 146 |
(void)level; |
| 147 |
if (x == dwarf_preorder || x == dwarf_leaf) { |
| 148 |
++counting_global; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
/* Tree argument expected is threekey_attr_form_base for example */ |
| 153 |
Dwarf_Unsigned |
| 154 |
three_key_entry_count(void *base) |
| 155 |
{ |
| 156 |
Dwarf_Unsigned count = 0; |
| 157 |
|
| 158 |
counting_global = 0; |
| 159 |
dwarf_twalk(base,count_3key_entry); |
| 160 |
count = counting_global; |
| 161 |
counting_global = 0; |
| 162 |
return count; |
| 163 |
} |
| 164 |
|
| 165 |
/* Used for base table creation */ |
| 166 |
static int |
| 167 |
dd_insert_table_entry(void *tree, |
| 168 |
Three_Key_Entry *e, |
| 169 |
int *errnum) |
| 170 |
{ |
| 171 |
Three_Key_Entry *re = 0; |
| 172 |
void *ret = dwarf_tsearch(e,tree,std_compare_3key_entry); |
| 173 |
if (!ret) { |
| 174 |
*errnum = DW_DLE_ALLOC_FAIL; |
| 175 |
return DW_DLV_ERROR; |
| 176 |
} |
| 177 |
re = *(Three_Key_Entry **)ret; |
| 178 |
if (re == e) { |
| 179 |
/* Normal. Added. */ |
| 180 |
return DW_DLV_OK; |
| 181 |
} |
| 182 |
/* A full duplicate in the table. Oops. |
| 183 |
Not a great choice of error code. */ |
| 184 |
*errnum = DW_DLE_ATTR_FORM_BAD; |
| 185 |
return DW_DLV_ERROR; |
| 186 |
} |
| 187 |
|
| 188 |
static int |
| 189 |
dd_common_build_base_tree(void *tree_base, |
| 190 |
Three_Key_Entry *std, |
| 191 |
Three_Key_Entry *ext, |
| 192 |
int *errnum) |
| 193 |
{ |
| 194 |
struct Three_Key_Entry_s *key = 0; |
| 195 |
int res = 0; |
| 196 |
int t = 0; |
| 197 |
void *tree = tree_base; |
| 198 |
struct Three_Key_Entry_s * stdext [3] = {std,ext,0}; |
| 199 |
|
| 200 |
for (key = stdext[t]; key ; ++t, key = stdext[t]) { |
| 201 |
for ( ; ; ++key) { |
| 202 |
if (!(key->key1 | key->key1 | key->key3)){ |
| 203 |
break; |
| 204 |
} |
| 205 |
res = dd_insert_table_entry(tree,key,errnum); |
| 206 |
if (res != DW_DLV_OK) { |
| 207 |
if (res == DW_DLV_ERROR) { |
| 208 |
return res; |
| 209 |
} |
| 210 |
*errnum = DW_DLE_ALLOC_FAIL; |
| 211 |
return res; |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
return DW_DLV_OK; |
| 216 |
} |
| 217 |
|
| 218 |
int |
| 219 |
dd_build_tag_attr_form_base_trees(int*errnum) |
| 220 |
{ |
| 221 |
int res = 0; |
| 222 |
|
| 223 |
res = dd_common_build_base_tree(&threekey_attr_form_base, |
| 224 |
dd_threekey_af_table_std,dd_threekey_af_table_ext, |
| 225 |
errnum); |
| 226 |
if (res != DW_DLV_OK){ |
| 227 |
return res; |
| 228 |
} |
| 229 |
res = dd_common_build_base_tree(&threekey_tag_attr_base, |
| 230 |
dd_threekey_ta_std,dd_threekey_ta_ext, |
| 231 |
errnum); |
| 232 |
if (res != DW_DLV_OK){ |
| 233 |
return res; |
| 234 |
} |
| 235 |
res = dd_common_build_base_tree(&threekey_tag_tag_base, |
| 236 |
dd_threekey_tt_std,dd_threekey_tt_ext, |
| 237 |
errnum); |
| 238 |
if (res != DW_DLV_OK){ |
| 239 |
return res; |
| 240 |
} |
| 241 |
/* No need to initialize the tag_use tree, the |
| 242 |
initial run-time dwarf_tsearch call will do that. |
| 243 |
All entries are run-time-only. */ |
| 244 |
return DW_DLV_OK; |
| 245 |
} |
| 246 |
|
| 247 |
void |
| 248 |
dd_destroy_tag_use_base_tree(void) |
| 249 |
{ |
| 250 |
if (!threekey_tag_use_base) { |
| 251 |
return; |
| 252 |
} |
| 253 |
dwarf_tdestroy(threekey_tag_use_base, |
| 254 |
free_func_3key_entry); |
| 255 |
threekey_tag_use_base = 0; |
| 256 |
} |
| 257 |
static void |
| 258 |
dd_destroy_attr_form_tree(void) |
| 259 |
{ |
| 260 |
if (!threekey_attr_form_base) { |
| 261 |
return; |
| 262 |
} |
| 263 |
dwarf_tdestroy(threekey_attr_form_base, |
| 264 |
free_func_3key_entry); |
| 265 |
threekey_attr_form_base = 0; |
| 266 |
} |
| 267 |
static void |
| 268 |
dd_destroy_tag_attr_tree(void) |
| 269 |
{ |
| 270 |
if (!threekey_tag_attr_base) { |
| 271 |
return; |
| 272 |
} |
| 273 |
dwarf_tdestroy(threekey_tag_attr_base, |
| 274 |
free_func_3key_entry); |
| 275 |
threekey_tag_attr_base = 0; |
| 276 |
} |
| 277 |
static void |
| 278 |
dd_destroy_tag_tag_tree(void) |
| 279 |
{ |
| 280 |
if (!threekey_tag_tag_base) { |
| 281 |
return; |
| 282 |
} |
| 283 |
dwarf_tdestroy(threekey_tag_tag_base, |
| 284 |
free_func_3key_entry); |
| 285 |
threekey_tag_tag_base = 0; |
| 286 |
} |
| 287 |
|
| 288 |
void |
| 289 |
dd_destroy_tag_attr_form_trees(void) |
| 290 |
{ |
| 291 |
dd_destroy_attr_form_tree(); |
| 292 |
dd_destroy_tag_attr_tree(); |
| 293 |
dd_destroy_tag_tag_tree(); |
| 294 |
dd_destroy_tag_use_base_tree(); |
| 295 |
} |
| 296 |
|
| 297 |
/* SKIP_AF_CHECK defined means this is in scripts/ddbuild.sh |
| 298 |
and this checking makes no sense and will not compile. */ |
| 299 |
#ifndef SKIP_AF_CHECK |
| 300 |
static Dwarf_Bool |
| 301 |
legal_attr_formclass_combination(Dwarf_Half attr, |
| 302 |
Dwarf_Half fc) |
| 303 |
{ |
| 304 |
Three_Key_Entry *e = 0; |
| 305 |
Three_Key_Entry *re = 0; |
| 306 |
void *ret = 0; |
| 307 |
int res = 0; |
| 308 |
|
| 309 |
res = make_3key(attr,fc,0,0,0,0,&e); |
| 310 |
if (res!= DW_DLV_OK) { |
| 311 |
/* Hiding some sort of botch/malloc issue */ |
| 312 |
return TRUE; |
| 313 |
} |
| 314 |
ret = dwarf_tfind(e,&threekey_attr_form_base, |
| 315 |
std_compare_3key_entry); |
| 316 |
if (!ret) { |
| 317 |
/* Surprising combo. */ |
| 318 |
free(e); |
| 319 |
return FALSE; |
| 320 |
} |
| 321 |
re = *(Three_Key_Entry **)ret; |
| 322 |
if (!glflags.gf_suppress_check_extensions_tables) { |
| 323 |
free(e); |
| 324 |
return TRUE; |
| 325 |
} |
| 326 |
if (re->from_tables == AF_STD) { |
| 327 |
free(e); |
| 328 |
return TRUE; |
| 329 |
} |
| 330 |
free(e); |
| 331 |
return FALSE; |
| 332 |
} |
| 333 |
|
| 334 |
static void |
| 335 |
check_attr_formclass_combination(Dwarf_Debug dbg, |
| 336 |
Dwarf_Half tag, |
| 337 |
Dwarf_Half attrnum, |
| 338 |
Dwarf_Half fc, |
| 339 |
int pd_dwarf_names_print_on_error, |
| 340 |
int die_stack_indent_level) |
| 341 |
{ |
| 342 |
const char *tagname = "<AT invalid>"; |
| 343 |
const char *formclassname = "<FORM_CLASS invalid>"; |
| 344 |
DWARF_CHECK_COUNT(attr_formclass_result,1); |
| 345 |
if (legal_attr_formclass_combination(attrnum,fc)) { |
| 346 |
/* OK */ |
| 347 |
} else { |
| 348 |
/* Report errors only if tag-attr check is on */ |
| 349 |
if (glflags.gf_check_tag_attr) { |
| 350 |
tagname = get_AT_name(attrnum, |
| 351 |
pd_dwarf_names_print_on_error); |
| 352 |
tag_specific_globals_setup(dbg,tag, |
| 353 |
die_stack_indent_level); |
| 354 |
formclassname = get_FORM_CLASS_name(fc, |
| 355 |
pd_dwarf_names_print_on_error); |
| 356 |
|
| 357 |
DWARF_CHECK_ERROR3(attr_formclass_result,tagname, |
| 358 |
formclassname, |
| 359 |
"check the attr-formclass combination"); |
| 360 |
} else { /* Nothing to do. */ } |
| 361 |
} |
| 362 |
} |
| 363 |
#endif /* SKIP_AF_CHECK */ |
| 364 |
|
| 365 |
void |
| 366 |
record_attr_form_use( |
| 367 |
Dwarf_Debug dbg, |
| 368 |
Dwarf_Half tag, |
| 369 |
Dwarf_Half attr, |
| 370 |
Dwarf_Half fclass, |
| 371 |
Dwarf_Half form, |
| 372 |
int die_stack_indent_level) |
| 373 |
{ |
| 374 |
/* SKIP_AF_CHECK defined means this is in scripts/ddbuild.sh |
| 375 |
and checking/recording makes no sense and will not compile. */ |
| 376 |
#ifdef SKIP_AF_CHECK |
| 377 |
(void)dbg; |
| 378 |
(void)tag; |
| 379 |
(void)attr; |
| 380 |
(void)fclass; |
| 381 |
(void)form; |
| 382 |
(void)die_stack_indent_level;; |
| 383 |
return; |
| 384 |
#else |
| 385 |
Three_Key_Entry *e = 0; |
| 386 |
Three_Key_Entry *re = 0; |
| 387 |
void *ret = 0; |
| 388 |
int res = 0; |
| 389 |
|
| 390 |
/* SKIP_AF_CHECK defined means this is in scripts/ddbuild.sh |
| 391 |
and this checking makes no sense and will not compile. */ |
| 392 |
check_attr_formclass_combination(dbg, |
| 393 |
tag,attr,fclass,1, |
| 394 |
die_stack_indent_level); |
| 395 |
res = make_3key(attr,fclass,form,0,0,1,&e); |
| 396 |
if (res!= DW_DLV_OK) { |
| 397 |
/* Could print something */ |
| 398 |
return; |
| 399 |
} |
| 400 |
ret = dwarf_tsearch(e,&threekey_attr_form_base, |
| 401 |
std_compare_3key_entry); |
| 402 |
if (!ret) { |
| 403 |
free_func_3key_entry(e); |
| 404 |
/* Could print something */ |
| 405 |
return; |
| 406 |
} |
| 407 |
re = *(Three_Key_Entry **)ret; |
| 408 |
if (re == e) { |
| 409 |
/* Brand new entry. Done. |
| 410 |
local malloc is in the tree. */ |
| 411 |
return; |
| 412 |
} |
| 413 |
/* Was already entered.*/ |
| 414 |
re->count++; |
| 415 |
/* Clean out the local malloc */ |
| 416 |
free_func_3key_entry(e); |
| 417 |
return; |
| 418 |
#endif /* SKIP_AF_CHECK */ |
| 419 |
} |
| 420 |
|
| 421 |
static Dwarf_Unsigned recordcount = 0; |
| 422 |
static Dwarf_Unsigned recordmax = 0; |
| 423 |
static Three_Key_Entry * tkarray = 0; |
| 424 |
static void |
| 425 |
extract_3key_entry(const void * vptr, |
| 426 |
DW_VISIT x, |
| 427 |
int level) |
| 428 |
{ |
| 429 |
(void)level; |
| 430 |
if (x == dwarf_preorder || x == dwarf_leaf) { |
| 431 |
Three_Key_Entry *m = *(Three_Key_Entry **)vptr; |
| 432 |
if (recordcount >= recordmax) { |
| 433 |
/* Should never happen */ |
| 434 |
return; |
| 435 |
} |
| 436 |
tkarray[recordcount] = *m; |
| 437 |
++recordcount; |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
static int |
| 442 |
qsortformclass(const void * e1in, const void * e2in) |
| 443 |
{ |
| 444 |
Three_Key_Entry *e1 = (Three_Key_Entry *)e1in; |
| 445 |
Three_Key_Entry *e2 = (Three_Key_Entry *)e2in; |
| 446 |
|
| 447 |
if (e1->key2 < e2->key2) { |
| 448 |
return -1; |
| 449 |
} |
| 450 |
if (e1->key2 > e2->key2) { |
| 451 |
return 1; |
| 452 |
} |
| 453 |
return 0; |
| 454 |
} |
| 455 |
|
| 456 |
static int |
| 457 |
qsortform(const void * e1in, const void * e2in) |
| 458 |
{ |
| 459 |
Three_Key_Entry *e1 = (Three_Key_Entry *)e1in; |
| 460 |
Three_Key_Entry *e2 = (Three_Key_Entry *)e2in; |
| 461 |
|
| 462 |
if (e1->key3 < e2->key3) { |
| 463 |
return -1; |
| 464 |
} |
| 465 |
if (e1->key3 > e2->key3) { |
| 466 |
return 1; |
| 467 |
} |
| 468 |
return 0; |
| 469 |
} |
| 470 |
|
| 471 |
static int |
| 472 |
qsortcountattr(const void * e1in, const void * e2in) |
| 473 |
{ |
| 474 |
Three_Key_Entry *e1 = (Three_Key_Entry *)e1in; |
| 475 |
Three_Key_Entry *e2 = (Three_Key_Entry *)e2in; |
| 476 |
|
| 477 |
if (e1->count < e2->count) { |
| 478 |
return 1; |
| 479 |
} |
| 480 |
if (e1->count > e2->count) { |
| 481 |
return -1; |
| 482 |
} |
| 483 |
if (e1->key1 < e2->key1) { |
| 484 |
return -1; |
| 485 |
} |
| 486 |
if (e1->key1 > e2->key1) { |
| 487 |
return 1; |
| 488 |
} |
| 489 |
if (e1->key3 < e2->key3) { |
| 490 |
return -1; |
| 491 |
} |
| 492 |
if (e1->key3 > e2->key3) { |
| 493 |
return 1; |
| 494 |
} |
| 495 |
if (e1->key2 < e2->key2) { |
| 496 |
return -1; |
| 497 |
} |
| 498 |
if (e1->key2 > e2->key2) { |
| 499 |
return 1; |
| 500 |
} |
| 501 |
return 0; |
| 502 |
} |
| 503 |
|
| 504 |
static int |
| 505 |
qsortk1k2(const void * e1in, const void * e2in) |
| 506 |
{ |
| 507 |
Three_Key_Entry *e1 = (Three_Key_Entry *)e1in; |
| 508 |
Three_Key_Entry *e2 = (Three_Key_Entry *)e2in; |
| 509 |
|
| 510 |
if (e1->key1 < e2->key1) { |
| 511 |
return -1; |
| 512 |
} |
| 513 |
if (e1->key1 > e2->key1) { |
| 514 |
return 1; |
| 515 |
} |
| 516 |
if (e1->key2 < e2->key2) { |
| 517 |
return -1; |
| 518 |
} |
| 519 |
if (e1->key2 > e2->key2) { |
| 520 |
return 1; |
| 521 |
} |
| 522 |
return 0; |
| 523 |
} |
| 524 |
|
| 525 |
void |
| 526 |
print_attr_form_usage(void) |
| 527 |
{ |
| 528 |
Three_Key_Entry *tk_l = 0; |
| 529 |
Dwarf_Unsigned i = 0; |
| 530 |
unsigned curform = 0; |
| 531 |
Dwarf_Unsigned formtotal = 0; |
| 532 |
unsigned curattr = 0; |
| 533 |
Dwarf_Unsigned attrtotal = 0; |
| 534 |
Dwarf_Unsigned j = 0; |
| 535 |
float total = 0.0f; |
| 536 |
float pct = 0.0f; |
| 537 |
Dwarf_Bool startnoted = FALSE; |
| 538 |
const char * localformat= NULL; |
| 539 |
Dwarf_Unsigned localsum = 0; |
| 540 |
/* These are file static and must be carefully aligned |
| 541 |
with our table reading. |
| 542 |
Dwarf_Unsigned recordcount = 0; |
| 543 |
Dwarf_Unsigned recordmax = 0; |
| 544 |
Three_Key_Entry * tkarray = 0; |
| 545 |
*/ |
| 546 |
|
| 547 |
recordmax = three_key_entry_count(threekey_attr_form_base); |
| 548 |
if (!recordmax) { |
| 549 |
return; |
| 550 |
} |
| 551 |
tk_l = (Three_Key_Entry *)calloc(recordmax+1, |
| 552 |
sizeof(Three_Key_Entry)); |
| 553 |
tkarray=tk_l; |
| 554 |
if (!tk_l) { |
| 555 |
printf("ERROR: unable to malloc attr/form array " |
| 556 |
" for a summary report \n"); |
| 557 |
glflags.gf_count_major_errors++; |
| 558 |
return; |
| 559 |
} |
| 560 |
/* Reset the file-global! */ |
| 561 |
recordcount = 0; |
| 562 |
dwarf_twalk(threekey_attr_form_base,extract_3key_entry); |
| 563 |
if (recordcount != recordmax) { |
| 564 |
printf("ERROR: unable to fill in attr/form array " |
| 565 |
" for a summary report, count %lu != walk %lu \n", |
| 566 |
(unsigned long)recordcount, |
| 567 |
(unsigned long)recordmax); |
| 568 |
glflags.gf_count_major_errors++; |
| 569 |
free(tk_l); |
| 570 |
tkarray = 0; |
| 571 |
return; |
| 572 |
} |
| 573 |
for (i = 0; i < recordmax; ++i) { |
| 574 |
Three_Key_Entry * tke = tk_l+i; |
| 575 |
|
| 576 |
if (!tke->key3) { |
| 577 |
/* Skip table building data */ |
| 578 |
continue; |
| 579 |
} |
| 580 |
total += (float)tke->count; |
| 581 |
} |
| 582 |
qsort(tk_l,recordmax,sizeof(Three_Key_Entry), |
| 583 |
qsortcountattr); |
| 584 |
printf("\n*** ATTRIBUTES AND FORMS USAGE ***\n"); |
| 585 |
printf("Full record count : %8" DW_PR_DUu "\n", |
| 586 |
recordmax); |
| 587 |
printf("Total number of objectfile attributes: %8.0f\n", total); |
| 588 |
printf("[] " |
| 589 |
" found rate\n"); |
| 590 |
localformat="[%3u] %-30s %-20s %7" DW_PR_DUu " %.0f%%\n"; |
| 591 |
localsum = 0; |
| 592 |
for (i = 0; i < recordmax; ++i) { |
| 593 |
Three_Key_Entry * tke = tk_l+i; |
| 594 |
|
| 595 |
if (!tke->key3) { |
| 596 |
/* Skip table building data */ |
| 597 |
continue; |
| 598 |
} |
| 599 |
pct = ( (float)tke->count / total)*100.0f; |
| 600 |
printf(localformat, |
| 601 |
(unsigned)i, |
| 602 |
get_AT_name(tke->key1,1), |
| 603 |
get_FORM_name(tke->key3,1), |
| 604 |
tke->count,pct); |
| 605 |
localsum += tke->count; |
| 606 |
} |
| 607 |
printf(localformat, (unsigned)(recordmax), |
| 608 |
"Sum found:","",localsum,100.0f); |
| 609 |
|
| 610 |
qsort(tk_l,recordmax,sizeof(Three_Key_Entry), |
| 611 |
qsortformclass); |
| 612 |
j = 0; |
| 613 |
/* Re-using the following two */ |
| 614 |
curform = 0; |
| 615 |
formtotal = 0; |
| 616 |
startnoted = FALSE; |
| 617 |
printf("\n*** COUNT BY FORMCLASS ***\n"); |
| 618 |
printf("[] found rate\n"); |
| 619 |
localsum = 0; |
| 620 |
localformat="[%2u] %-28s %6" DW_PR_DUu " %.0f%%\n"; |
| 621 |
for (i = 0; i < recordmax; ++i) { |
| 622 |
Three_Key_Entry * tke = tk_l+i; |
| 623 |
|
| 624 |
if (!tke->key3) { |
| 625 |
/* Skip table building data */ |
| 626 |
continue; |
| 627 |
} |
| 628 |
if (!startnoted) { |
| 629 |
curform = tke->key2; |
| 630 |
formtotal = tke->count; |
| 631 |
startnoted = TRUE; |
| 632 |
continue; |
| 633 |
} |
| 634 |
if (curform != tke->key2) { |
| 635 |
pct = ( (float)formtotal / total)*100.0f; |
| 636 |
printf(localformat, |
| 637 |
(unsigned)j, |
| 638 |
get_FORM_CLASS_name(curform,1), |
| 639 |
formtotal,pct); |
| 640 |
localsum += formtotal; |
| 641 |
curform = tke->key2; |
| 642 |
formtotal = tke->count; |
| 643 |
++j; |
| 644 |
continue; |
| 645 |
} |
| 646 |
formtotal += tke->count; |
| 647 |
} |
| 648 |
if (formtotal) { |
| 649 |
pct = ( (float)formtotal / total)*100.0f; |
| 650 |
printf(localformat, |
| 651 |
(unsigned)j, |
| 652 |
get_FORM_CLASS_name(curform,1), |
| 653 |
formtotal,pct); |
| 654 |
localsum += formtotal; |
| 655 |
} |
| 656 |
printf(localformat, (unsigned)(j+1), |
| 657 |
"Sum found:",localsum,100.0f); |
| 658 |
|
| 659 |
/* Re-using the following two */ |
| 660 |
curform = 0; |
| 661 |
formtotal = 0; |
| 662 |
startnoted = FALSE; |
| 663 |
qsort(tk_l,recordmax,sizeof(Three_Key_Entry), |
| 664 |
qsortform); |
| 665 |
j = 0; |
| 666 |
printf("\n*** COUNT BY FORM ***\n"); |
| 667 |
printf("[] found rate\n"); |
| 668 |
localformat="[%2u] %-20s %6" DW_PR_DUu " %.0f%%\n"; |
| 669 |
localsum = 0; |
| 670 |
for (i = 0; i < recordmax; ++i) { |
| 671 |
Three_Key_Entry * tke = tk_l+i; |
| 672 |
|
| 673 |
if (!tke->key3) { |
| 674 |
/* Skip table building data */ |
| 675 |
continue; |
| 676 |
} |
| 677 |
if (!startnoted) { |
| 678 |
curform = tke->key3; |
| 679 |
formtotal = tke->count; |
| 680 |
startnoted = TRUE; |
| 681 |
continue; |
| 682 |
} |
| 683 |
if (curform != tke->key3) { |
| 684 |
pct = ( (float)formtotal / total)*100.0f; |
| 685 |
printf(localformat, |
| 686 |
(unsigned)j, |
| 687 |
get_FORM_name(curform,1), |
| 688 |
formtotal,pct); |
| 689 |
localsum += formtotal; |
| 690 |
curform = tke->key3; |
| 691 |
formtotal = tke->count; |
| 692 |
++j; |
| 693 |
continue; |
| 694 |
} |
| 695 |
formtotal += tke->count; |
| 696 |
} |
| 697 |
if (formtotal) { |
| 698 |
pct = ( (float)formtotal / total)*100.0f; |
| 699 |
printf(localformat, |
| 700 |
(unsigned)j, |
| 701 |
get_FORM_name(curform,1), |
| 702 |
formtotal,pct); |
| 703 |
localsum += formtotal; |
| 704 |
} |
| 705 |
printf(localformat, (unsigned)(j+1), |
| 706 |
"Sum found:",localsum,100.0f); |
| 707 |
|
| 708 |
j = 0; |
| 709 |
curattr = 0; |
| 710 |
attrtotal = 0; |
| 711 |
startnoted = FALSE; |
| 712 |
printf("\n*** COUNT BY ATTRIBUTE ***\n"); |
| 713 |
printf("[] found rate\n"); |
| 714 |
localsum = 0; |
| 715 |
localformat="[%2u] %-30s %6" DW_PR_DUu " %.0f%%\n"; |
| 716 |
for (i = 0; i < recordmax; ++i) { |
| 717 |
Three_Key_Entry * tke = tk_l+i; |
| 718 |
|
| 719 |
if (!tke->key3) { |
| 720 |
/* Skip table building data */ |
| 721 |
continue; |
| 722 |
} |
| 723 |
if (!startnoted) { |
| 724 |
curattr = tke->key1; |
| 725 |
attrtotal = tke->count; |
| 726 |
startnoted = TRUE; |
| 727 |
continue; |
| 728 |
} |
| 729 |
if (curattr != tke->key1) { |
| 730 |
pct = ( (float)attrtotal / total)*100.0f; |
| 731 |
printf(localformat, |
| 732 |
(unsigned)j, |
| 733 |
get_AT_name(curattr,1), |
| 734 |
attrtotal,pct); |
| 735 |
localsum += attrtotal; |
| 736 |
curattr = tke->key1; |
| 737 |
attrtotal = tke->count; |
| 738 |
++j; |
| 739 |
continue; |
| 740 |
} |
| 741 |
formtotal += tke->count; |
| 742 |
} |
| 743 |
if (attrtotal) { |
| 744 |
pct = ( (float)attrtotal / total)*100.0f; |
| 745 |
printf(localformat, |
| 746 |
(unsigned)j, |
| 747 |
get_AT_name(curattr,1), |
| 748 |
attrtotal,pct); |
| 749 |
localsum += attrtotal; |
| 750 |
} |
| 751 |
printf(localformat, (unsigned)(j+1), |
| 752 |
"Sum found:",localsum,100.0f); |
| 753 |
free(tk_l); |
| 754 |
tkarray = 0; |
| 755 |
} |
| 756 |
|
| 757 |
/* extract all tag_tree records |
| 758 |
(also called tag_tag sometimes) to an array, |
| 759 |
sort by tag number and child tag number. |
| 760 |
|
| 761 |
Loop the list, printing tag (and name) |
| 762 |
and within that a line for each child tag and count. |
| 763 |
*/ |
| 764 |
static const char * |
| 765 |
gettablename(unsigned t) |
| 766 |
{ |
| 767 |
switch(t) { |
| 768 |
case AF_STD: |
| 769 |
return "Standard "; |
| 770 |
case AF_EXTEN: |
| 771 |
return "Extended "; |
| 772 |
case AF_UNKNOWN: |
| 773 |
return "Unknown "; |
| 774 |
default: |
| 775 |
break; |
| 776 |
} |
| 777 |
return "Impossible"; |
| 778 |
} |
| 779 |
|
| 780 |
void |
| 781 |
dd_print_tag_tree_results(Dwarf_Unsigned tag_tag_count) |
| 782 |
{ |
| 783 |
Three_Key_Entry *tk_l = 0; |
| 784 |
Dwarf_Unsigned i = 0; |
| 785 |
Dwarf_Half curparent = 0; |
| 786 |
/* These are file static and must be carefully aligned |
| 787 |
with our table reading. |
| 788 |
Dwarf_Unsigned recordcount = 0; |
| 789 |
Dwarf_Unsigned recordmax = 0; |
| 790 |
Three_Key_Entry * tkarray = 0; |
| 791 |
*/ |
| 792 |
|
| 793 |
recordmax = tag_tag_count; |
| 794 |
printf("\nNumber of tag-parent/tag-child records %7" |
| 795 |
DW_PR_DUu "\n", tag_tag_count); |
| 796 |
if (!tag_tag_count) { |
| 797 |
return; |
| 798 |
} |
| 799 |
tkarray = 0; |
| 800 |
tk_l = (Three_Key_Entry *)calloc(tag_tag_count+1, |
| 801 |
sizeof(Three_Key_Entry)); |
| 802 |
tkarray=tk_l; |
| 803 |
if (!tk_l) { |
| 804 |
printf("ERROR: unable to malloc tag-parent/tag-child array " |
| 805 |
" for a summary report \n"); |
| 806 |
glflags.gf_count_major_errors++; |
| 807 |
return; |
| 808 |
} |
| 809 |
/* Reset the file-global! */ |
| 810 |
recordcount = 0; |
| 811 |
dwarf_twalk(threekey_tag_tag_base,extract_3key_entry); |
| 812 |
if (recordcount != tag_tag_count) { |
| 813 |
printf("ERROR: unable to fill in tag-paraent/tag-child array " |
| 814 |
" for a summary report, count %lu != walk %lu \n", |
| 815 |
(unsigned long)tag_tag_count, |
| 816 |
(unsigned long)recordcount); |
| 817 |
glflags.gf_count_major_errors++; |
| 818 |
free(tk_l); |
| 819 |
tkarray = 0; |
| 820 |
return; |
| 821 |
} |
| 822 |
qsort(tk_l,recordcount,sizeof(Three_Key_Entry), |
| 823 |
qsortk1k2); |
| 824 |
|
| 825 |
for (i = 0; i < recordmax; ++i) { |
| 826 |
Three_Key_Entry * tke = tk_l+i; |
| 827 |
|
| 828 |
/* In checking mode verbose is automatically 1 */ |
| 829 |
if (glflags.verbose < 2) { |
| 830 |
if (!tke->count) { |
| 831 |
/* Skip this */ |
| 832 |
continue; |
| 833 |
} |
| 834 |
} |
| 835 |
if (tke->key1 != curparent) { |
| 836 |
printf("[ %4" DW_PR_DUu "] 0x%04x %-38s" |
| 837 |
" table count\n", |
| 838 |
i,tke->key1,get_TAG_name(tke->key1,1)); |
| 839 |
curparent = tke->key1; |
| 840 |
} |
| 841 |
printf(" 0x%04x %-38s %s %7" DW_PR_DUu "\n", |
| 842 |
tke->key2, get_TAG_name(tke->key2,1), |
| 843 |
gettablename(tke->from_tables), |
| 844 |
tke->count); |
| 845 |
} |
| 846 |
free(tk_l); |
| 847 |
} |
| 848 |
void |
| 849 |
dd_print_tag_attr_results(Dwarf_Unsigned tag_attr_count) |
| 850 |
{ |
| 851 |
|
| 852 |
Three_Key_Entry *tk_l = 0; |
| 853 |
Dwarf_Unsigned i = 0; |
| 854 |
Dwarf_Half curparent = 0; |
| 855 |
/* These are file static and must be carefully aligned |
| 856 |
with our table reading. |
| 857 |
Dwarf_Unsigned recordcount = 0; |
| 858 |
Dwarf_Unsigned recordmax = 0; |
| 859 |
Three_Key_Entry * tkarray = 0; |
| 860 |
*/ |
| 861 |
Dwarf_Unsigned attrs_unknown = 0; /* meaning not in tables */ |
| 862 |
Dwarf_Unsigned attrs_extended = 0; |
| 863 |
Dwarf_Unsigned attrs_std = 0; |
| 864 |
Dwarf_Unsigned count_attr_instances = 0; |
| 865 |
|
| 866 |
recordmax = tag_attr_count; |
| 867 |
printf("\nNumber of tag/attr records %7" |
| 868 |
DW_PR_DUu "\n", |
| 869 |
tag_attr_count); |
| 870 |
if (!tag_attr_count) { |
| 871 |
return; |
| 872 |
} |
| 873 |
tkarray = 0; |
| 874 |
tk_l = (Three_Key_Entry *)calloc(tag_attr_count+1, |
| 875 |
sizeof(Three_Key_Entry)); |
| 876 |
tkarray=tk_l; |
| 877 |
if (!tk_l) { |
| 878 |
printf("ERROR: unable to malloc tag/attr array " |
| 879 |
" for a summary report \n"); |
| 880 |
glflags.gf_count_major_errors++; |
| 881 |
return; |
| 882 |
} |
| 883 |
/* Reset the file-global! */ |
| 884 |
recordcount = 0; |
| 885 |
dwarf_twalk(threekey_tag_attr_base,extract_3key_entry); |
| 886 |
if (recordcount != tag_attr_count) { |
| 887 |
printf("ERROR: unable to fill in tag/attr array " |
| 888 |
" for a summary report, count %lu != walk %lu \n", |
| 889 |
(unsigned long)tag_attr_count, |
| 890 |
(unsigned long)recordcount); |
| 891 |
glflags.gf_count_major_errors++; |
| 892 |
free(tk_l); |
| 893 |
tkarray = 0; |
| 894 |
return; |
| 895 |
} |
| 896 |
qsort(tk_l,recordcount,sizeof(Three_Key_Entry), |
| 897 |
qsortk1k2); |
| 898 |
|
| 899 |
for (i = 0; i < recordmax; ++i) { |
| 900 |
Three_Key_Entry * tke = tk_l+i; |
| 901 |
|
| 902 |
count_attr_instances += tke->count; |
| 903 |
} |
| 904 |
|
| 905 |
for (i = 0; i < recordmax; ++i) { |
| 906 |
Three_Key_Entry * tke = tk_l+i; |
| 907 |
double pct = 0.0; |
| 908 |
|
| 909 |
/* In checking mode verbose is automatically 1 */ |
| 910 |
if (glflags.verbose < 2) { |
| 911 |
if (!tke->count) { |
| 912 |
/* Skip this */ |
| 913 |
continue; |
| 914 |
} |
| 915 |
} |
| 916 |
if (tke->key1 != curparent) { |
| 917 |
printf("[ %4" DW_PR_DUu "] 0x%04x %-38s" |
| 918 |
" table count percent\n", |
| 919 |
i,tke->key1,get_TAG_name(tke->key1,1)); |
| 920 |
curparent = tke->key1; |
| 921 |
} |
| 922 |
switch(tke->from_tables) { |
| 923 |
case AF_STD: |
| 924 |
attrs_std += tke->count; |
| 925 |
break; |
| 926 |
case AF_EXTEN: |
| 927 |
attrs_extended += tke->count; |
| 928 |
break; |
| 929 |
case AF_UNKNOWN: |
| 930 |
default: |
| 931 |
attrs_unknown += tke->count; |
| 932 |
break; |
| 933 |
} |
| 934 |
if (count_attr_instances) { |
| 935 |
pct = ((double)tke->count/(double)count_attr_instances)* |
| 936 |
100.0; |
| 937 |
} |
| 938 |
printf(" 0x%04x %-38s %s %7" DW_PR_DUu |
| 939 |
" %4.1f\n", |
| 940 |
tke->key2, get_AT_name(tke->key2,1), |
| 941 |
gettablename(tke->from_tables), |
| 942 |
tke->count,pct); |
| 943 |
} |
| 944 |
printf("Number of attribute instances : %7" DW_PR_DUu "\n", |
| 945 |
count_attr_instances); |
| 946 |
printf("Number of standard table entries: %7" DW_PR_DUu "\n", |
| 947 |
attrs_std); |
| 948 |
printf("Number of extended table entries: %7" DW_PR_DUu "\n", |
| 949 |
attrs_extended); |
| 950 |
printf("Number of unknown table entries: %7" DW_PR_DUu "\n", |
| 951 |
attrs_unknown); |
| 952 |
free(tk_l); |
| 953 |
#if 0 |
| 954 |
FIXME |
| 955 |
#endif |
| 956 |
} |
| 957 |
|
| 958 |
void |
| 959 |
dd_print_tag_use_results(Dwarf_Unsigned tag_count) |
| 960 |
{ |
| 961 |
Three_Key_Entry *tk_l = 0; |
| 962 |
Dwarf_Unsigned i = 0; |
| 963 |
Dwarf_Unsigned sum_of_uses = 0; |
| 964 |
/* These are file static and must be carefully aligned |
| 965 |
with our table reading. |
| 966 |
Dwarf_Unsigned recordcount = 0; |
| 967 |
Dwarf_Unsigned recordmax = 0; |
| 968 |
Three_Key_Entry * tkarray = 0; |
| 969 |
*/ |
| 970 |
|
| 971 |
recordmax = tag_count; |
| 972 |
printf("\nNumber of TAG records %7" DW_PR_DUu "\n", |
| 973 |
tag_count); |
| 974 |
if (!tag_count) { |
| 975 |
return; |
| 976 |
} |
| 977 |
tkarray = 0; |
| 978 |
tk_l = (Three_Key_Entry *)calloc(tag_count+1, |
| 979 |
sizeof(Three_Key_Entry)); |
| 980 |
tkarray=tk_l; |
| 981 |
if (!tk_l) { |
| 982 |
printf("ERROR: unable to malloc tag array " |
| 983 |
" for a summary report \n"); |
| 984 |
glflags.gf_count_major_errors++; |
| 985 |
return; |
| 986 |
} |
| 987 |
/* Reset the file-global! */ |
| 988 |
recordcount = 0; |
| 989 |
dwarf_twalk(threekey_tag_use_base,extract_3key_entry); |
| 990 |
if (recordcount != tag_count) { |
| 991 |
printf("ERROR: unable to fill in tag/attr array " |
| 992 |
" for a summary report, count %lu != walk %lu \n", |
| 993 |
(unsigned long)tag_count, |
| 994 |
(unsigned long)recordcount); |
| 995 |
glflags.gf_count_major_errors++; |
| 996 |
free(tk_l); |
| 997 |
tkarray = 0; |
| 998 |
return; |
| 999 |
} |
| 1000 |
qsort(tk_l,recordcount,sizeof(Three_Key_Entry), |
| 1001 |
qsortk1k2); |
| 1002 |
|
| 1003 |
for (i = 0; i < recordmax; ++i) { |
| 1004 |
Three_Key_Entry * tke = tk_l+i; |
| 1005 |
sum_of_uses += tke->count; |
| 1006 |
} |
| 1007 |
printf("Number of distinct TAGs in object %7" DW_PR_DUu "\n", |
| 1008 |
sum_of_uses); |
| 1009 |
|
| 1010 |
printf("[ ] TAG " |
| 1011 |
" use-count percent\n"); |
| 1012 |
|
| 1013 |
for (i = 0; i < recordmax; ++i) { |
| 1014 |
Three_Key_Entry * tke = tk_l+i; |
| 1015 |
double pct = 0.0; |
| 1016 |
|
| 1017 |
/* In checking mode verbose is automatically 1 */ |
| 1018 |
if (glflags.verbose < 2) { |
| 1019 |
if (!tke->count) { |
| 1020 |
/* Skip this */ |
| 1021 |
continue; |
| 1022 |
} |
| 1023 |
} |
| 1024 |
if (sum_of_uses) { |
| 1025 |
pct = ((double)tke->count/(double)sum_of_uses)* 100.0; |
| 1026 |
} |
| 1027 |
printf("[ %4" DW_PR_DUu "] 0x%04x %-38s %7" |
| 1028 |
DW_PR_DUu " %3.1f\n", |
| 1029 |
i,tke->key1,get_TAG_name(tke->key1,1), |
| 1030 |
tke->count,pct); |
| 1031 |
} |
| 1032 |
free(tk_l); |
| 1033 |
tkarray = 0; |
| 1034 |
} |