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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
|
/*
Copyright (C) 2006 Silicon Graphics, Inc. All Rights Reserved.
Portions Copyright 2011-2019 David Anderson. All Rights Reserved.
Portions Copyright 2012 SN Systems Ltd. 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 "config.h"
#include "globals.h"
#include "esb.h"
/* Windows specific header files */
#if defined(_WIN32) && defined(HAVE_STDAFX_H)
#include "stdafx.h"
#endif /* HAVE_STDAFX_H */
#if defined(_WIN32) && defined(HAVE_WINDOWS_H)
#include <windows.h>
#define BOOLEAN_TYPEDEFED 1
#endif /* HAVE_WINDOWS_H */
#include "globals.h"
#include "dwarf.h"
#include "libdwarf.h"
#include <ctype.h>
#include "dwconf.h"
#include "makename.h"
/* The nesting level is arbitrary, 2 should suffice.
But at least this prevents an infinite loop.
*/
#define MAX_NEST_LEVEL 3
struct token_s {
unsigned tk_len;
char *tk_data;
};
enum linetype_e {
LT_ERROR,
LT_COMMENT,
LT_BLANK,
LT_BEGINABI,
LT_REG,
LT_FRAME_INTERFACE,
LT_CFA_REG,
LT_INITIAL_REG_VALUE,
LT_SAME_VAL_REG,
LT_UNDEFINED_VAL_REG,
LT_REG_TABLE_SIZE,
LT_ADDRESS_SIZE,
LT_INCLUDEABI,
LT_ENDABI,
LT_OPTION
};
struct comtable_s {
enum linetype_e type;
char *name;
size_t namelen;
};
static int errcount = 0; /* Count errors found in this scan of
the configuration file. */
static char name_begin_abi[] = "beginabi:";
static char name_reg[] = "reg:";
static char name_frame_interface[] = "frame_interface:";
static char name_cfa_reg[] = "cfa_reg:";
static char name_initial_reg_value[] = "initial_reg_value:";
static char name_same_val_reg[] = "same_val_reg:";
static char name_undefined_val_reg[] = "undefined_val_reg:";
static char name_reg_table_size[] = "reg_table_size:";
static char name_address_size[] = "address_size:";
static char name_includeabi[] = "includeabi:";
static char name_endabi[] = "endabi:";
static char name_option[] = "option:";
/* The namelen field is filled in at runtime with
the correct value. Filling in a fake '1' avoids
a compiler warning. */
static struct comtable_s comtable[] = {
{LT_BEGINABI, name_begin_abi,1},
{LT_REG, name_reg,1},
{LT_FRAME_INTERFACE, name_frame_interface,1},
{LT_CFA_REG, name_cfa_reg,1},
{LT_INITIAL_REG_VALUE, name_initial_reg_value,1},
{LT_SAME_VAL_REG, name_same_val_reg,1},
{LT_UNDEFINED_VAL_REG, name_undefined_val_reg,1},
{LT_REG_TABLE_SIZE, name_reg_table_size,1},
{LT_ADDRESS_SIZE, name_address_size,1},
{LT_INCLUDEABI, name_includeabi,1},
{LT_ENDABI, name_endabi,1},
{LT_OPTION, name_option,1},
};
struct conf_internal_s {
unsigned long beginabi_lineno;
unsigned long frame_interface_lineno;
unsigned long initial_reg_value_lineno;
unsigned long reg_table_size_lineno;
unsigned long address_size_lineno;
unsigned long same_val_reg_lineno;
unsigned long undefined_val_reg_lineno;
unsigned long cfa_reg_lineno;
unsigned long regcount;
struct dwconf_s * conf_out;
const char * conf_name_used;
char ** conf_defaults;
};
static void
init_conf_internal(struct conf_internal_s *s,
struct dwconf_s * conf_out)
{
s->beginabi_lineno = 0;
s->frame_interface_lineno = 0;
s->initial_reg_value_lineno = 0;
s->reg_table_size_lineno = 0;
s->address_size_lineno = 0;
s->same_val_reg_lineno = 0;
s->undefined_val_reg_lineno = 0;
s->cfa_reg_lineno = 0;
s->cfa_reg_lineno = 0;
s->conf_name_used = 0;
s->conf_defaults = 0;
s->regcount = 0;
s->conf_out = conf_out;
}
static unsigned size_of_comtable = sizeof(comtable) /
sizeof(comtable[0]);
static FILE *find_a_file(const char *named_file, char **defaults,
const char** name_used);
static int find_abi_start(FILE * stream, const char *abi_name,
long *offset,
unsigned long *lineno_out);
static int parse_abi(FILE * stream, const char *fname,
const char *abiname,
struct conf_internal_s *out, unsigned long lineno,
unsigned nest_level);
static char *get_token(char *cp, struct token_s *outtok);
/* This finds a dwarfdump.conf file and
then parses it. It updates
conf_out as appropriate.
This finds the first file (looking in a set of places)
with that name. It then looks for the right ABI entry.
If the first file it finds does not have that ABI entry it
gives up.
It would also be reasonable to search every
'dwarfdump.conf'
it finds for the abi.
But we stop at the first dwarfdump.conf
we find.
This is the internal call to get the
conf data to implement
a crude 'includeabi' feature.
Each call here starts at offset 0 of
a new stream.
Returns 0 if no errors found, else returns > 0.
*/
static int
find_conf_file_and_read_config_inner(const char *named_file,
const char *named_abi,
struct conf_internal_s *conf_internal,
unsigned nest_level)
{
FILE *conf_stream = 0;
const char *name_used = 0;
long offset = 0;
int res = FALSE;
unsigned long lineno = 0;
errcount = 0;
conf_stream = find_a_file(named_file,
conf_internal->conf_defaults,
&name_used);
if (!conf_stream) {
++errcount;
printf("dwarfdump found no file %s!\n",
named_file ? named_file : "readable for configuration. "
"(add options -v -v to see what file names tried)\n");
return FOUND_ERROR;
}
if (glflags.verbose > 6) {
printf("dwarfdump using configuration file %s\n", name_used);
}
conf_internal->conf_name_used = name_used;
/* And option: lines must come before any abi data. */
res = find_abi_start(conf_stream, named_abi, &offset, &lineno);
if (res == FOUND_DONE ||res == FOUND_OPTION) {
/* nothing more to do */
fclose(conf_stream);
return FOUND_DONE;
}
if (res == FOUND_ERROR) {
++errcount;
fclose(conf_stream);
printf("dwarfdump found no usable abi %s in file %s.\n",
named_abi?named_abi:"<not looking for abi>",
name_used);
return FOUND_ERROR;
}
/* res == FOUND_ABI_START */
res = fseek(conf_stream, offset, SEEK_SET);
if (res != 0) {
++errcount;
fclose(conf_stream);
printf("dwarfdump seek to %ld offset in %s failed!\n",
offset, name_used);
return FOUND_ERROR;
}
parse_abi(conf_stream, name_used, named_abi,
conf_internal, lineno,
nest_level);
fclose(conf_stream);
if (errcount) {
return FOUND_ERROR;
}
return FOUND_ABI_START;
}
/* This is the external-facing call to get the conf data. */
int
find_conf_file_and_read_config(const char *named_file,
const char *named_abi, char **defaults,
struct dwconf_s *conf_out)
{
int res = 0;
struct conf_internal_s conf_internal;
init_conf_file_data(conf_out);
init_conf_internal(&conf_internal,conf_out);
conf_internal.conf_defaults = defaults;
res = find_conf_file_and_read_config_inner(named_file,
named_abi,
&conf_internal,0);
return res;
}
/* Given path strings, attempt to make a canonical file name:
that is, avoid superfluous '/' so that no
'//' (or worse) is created in the output. The path components
are to be separated so at least one '/'
is to appear between the two 'input strings' when
creating the output.
*/
#if defined(BUILD_FOR_TEST) || !defined(_WIN32)
static char *
canonical_append(char *target, unsigned int target_size,
const char *first_string, const char *second_string)
{
size_t firstlen = strlen(first_string);
/* +1 +1: Leave room for added "/" and final NUL, though that is
overkill, as we drop a NUL byte too. */
if ((firstlen + strlen(second_string) + 1 + 1) >= target_size) {
/* Not enough space. */
return NULL;
}
for (; *second_string == '/'; ++second_string) {
}
for (; firstlen > 0 && first_string[firstlen - 1] == '/';
--firstlen) {
}
target[0] = 0;
if (firstlen > 0) {
strncpy(target, first_string, firstlen);
target[firstlen + 1] = 0;
}
target[firstlen] = '/';
firstlen++;
target[firstlen] = 0;
strcat(target, second_string);
return target;
}
#endif /* defined(BUILD_FOR_TEST) || !defined(_WIN32) */
#ifdef BUILD_FOR_TEST
#define CANBUF 25
struct canap_s {
char *res_exp;
char *first;
char *second;
} canap[] = {
{
"ab/c", "ab", "c"}, {
"ab/c", "ab/", "c"}, {
"ab/c", "ab", "/c"}, {
"ab/c", "ab////", "/////c"}, {
"ab/", "ab", ""}, {
"ab/", "ab////", ""}, {
"ab/", "ab////", ""}, {
"/a", "", "a"}, {
0, "/abcdefgbijkl", "pqrstuvwxyzabcd"}, {
0, 0, 0}
};
static void
test_canonical_append(void)
{
/* Make buf big, this is test code, so be safe. */
char lbuf[1000];
unsigned i;
unsigned failcount = 0;
printf("Entry test_canonical_append\n");
for (i = 0;; ++i) {
char *res = 0;
if (canap[i].first == 0 && canap[i].second == 0)
break;
res = canonical_append(lbuf, CANBUF, canap[i].first,
canap[i].second);
if (res == 0) {
if (canap[i].res_exp == 0) {
/* GOOD */
printf("PASS %u\n", i);
} else {
++failcount;
printf("FAIL: entry %u wrong, expected %s, got NULL\n",
i, canap[i].res_exp);
}
} else {
if (canap[i].res_exp == 0) {
++failcount;
printf("FAIL: entry %u wrong, got %s expected NULL\n",
i, res);
} else {
if (strcmp(res, canap[i].res_exp) == 0) {
printf("PASS %u\n", i);
/* GOOD */
} else {
++failcount;
printf("FAIL: entry %u wrong, expected %s got %s\n",
i, canap[i].res_exp, res);
}
}
}
}
printf("FAIL count %u\n", failcount);
}
#endif /* BUILD_FOR_TEST */
/* Try to find a file as named and open for read.
We treat each name as a full name, we are not
combining separate name and path components.
This is an arbitrary choice...
The defaults are listed in command_options.c in the array
config_file_defaults[].
Since named_file comes from an esb_get_string, lname
may be non-null but pointing to empty string to mean
no-name.
*/
static FILE *
find_a_file(const char *named_file, char **defaults, const char ** name_used)
{
FILE *fin = 0;
const char *lname = named_file;
const char *type = "r";
int i = 0;
#ifdef BUILD_FOR_TEST
test_canonical_append();
#endif /* BUILD_FOR_TEST */
if (lname && (strlen(lname) > 0)) {
/* Name given, just assume it is fully correct,
try no other. */
#ifdef BUILD_FOR_TEST
#endif /* BUILD_FOR_TEST */
printf("dwarfdump looking for"
" configuration as %s\n", lname);
#if 0
if (glflags.verbose > 1) {
}
#endif
fin = fopen(lname, type);
if (fin) {
*name_used = lname;
return fin;
}
return 0;
}
/* No name given, find a default, if we can. */
for (i = 0; defaults[i]; ++i) {
lname = defaults[i];
#ifdef _WIN32
/* Open the configuration file, located
in the directory where the tool is loaded from */
{
static char szPath[MAX_PATH];
if (GetModuleFileName(NULL,szPath,MAX_PATH)) {
char *pDir = strrchr(szPath,'/');
size_t len = 0;
if (!pDir) {
pDir = strrchr(szPath,'\\');
if (!pDir) {
/* No file was found */
return 0;
}
}
/* Add the configuration name to the pathname */
++pDir;
len = pDir - szPath;
safe_strcpy(pDir,sizeof(szPath)-len,"dwarfdump.conf",14);
lname = szPath;
}
}
#else /* non-Win */
if (strncmp(lname, "HOME/", 5) == 0) {
/* arbitrary size */
char buf[2000];
char *homedir = getenv("HOME");
if (homedir) {
char *cp = canonical_append(buf, sizeof(buf),
homedir, lname + 5);
if (!cp) {
/* OOps, ignore this one. */
continue;
}
lname = makename(buf);
}
}
#endif /* _WIN32 */
#ifdef BUILD_FOR_TEST
printf("dwarfdump looking for"
" configuration as %s\n", lname);
#endif /* BUILD_FOR_TEST */
#if 0
if (glflags.verbose > 1) {
}
#endif
fin = fopen(lname, type);
if (fin) {
*name_used = lname;
return fin;
}
}
return 0;
}
/* Start at a token begin, see how long it is,
return length. */
static unsigned
find_token_len(char *cp)
{
unsigned len = 0;
for (; *cp; ++cp) {
if (isspace(*cp)) {
return len;
}
if (*cp == '#') {
return len; /* begins comment */
}
++len;
}
return len;
}
/*
Skip past all whitespace: the only code that even knows
what whitespace is.
*/
static char *
skipwhite(char *cp)
{
for (; *cp; ++cp) {
if (!isspace(*cp)) {
return cp;
}
}
return cp;
}
/* Return TRUE if ok. FALSE if find more tokens.
Emit error message if error.
*/
static int
ensure_has_no_more_tokens(char *cp, const char *fname, unsigned long lineno)
{
struct token_s tok;
get_token(cp, &tok);
if (tok.tk_len > 0) {
printf("dwarfdump.conf error: "
"extra characters after command operands, found "
"\"%s\" in %s line %lu\n", tok.tk_data, fname, lineno);
++errcount;
return FALSE;
}
return TRUE;
}
/* There may be many beginabi: lines in a dwarfdump.conf file,
find the one we want and return its file offset.
*/
static int
find_abi_start(FILE * stream, const char *abi_name,
long *offset, unsigned long *lineno_out)
{
char buf[100];
unsigned long lineno = 0;
for (; !feof(stream);) {
struct token_s tok;
char *line = 0;
long loffset = ftell(stream);
line = fgets(buf, sizeof(buf), stream);
++lineno;
if (!line) {
if (!abi_name) {
return FOUND_DONE;
}
++errcount;
return FOUND_ERROR;
}
line = get_token(buf, &tok);
if (!strcmp(tok.tk_data, "option:")) {
get_token(line, &tok);
if (tok.tk_data && !strcmp(tok.tk_data,
"--format-expr-ops-joined")) {
/* print expr ops joined onto one line:
matching historical behavior. */
glflags.gf_expr_ops_joined = TRUE;
} else {
printf("ERROR: option command %s is not understood"
" giving up\n",tok.tk_data);
++errcount;
return FOUND_ERROR;
}
continue;
}
if (strcmp(tok.tk_data, "beginabi:")) {
continue;
}
/* Is beginabi: */
if (!abi_name) {
continue;
}
get_token(line, &tok);
if (strcmp(tok.tk_data, abi_name)) {
continue;
}
*offset = loffset;
*lineno_out = lineno;
return FOUND_ABI_START;
}
if (!abi_name) {
/* All is ok */
return FOUND_DONE;
}
++errcount;
return FALSE;
}
/* Turn a non-delimited
input char array into a NUL-terminated C string
(with the help of makename() to get a permanent
address for the result ing string).
*/
static char *
build_string(unsigned tlen, char *cp)
{
struct esb_s x;
char buffer[32];
char *ret = 0;
esb_constructor_fixed(&x,buffer,sizeof(buffer));
esb_appendn(&x,cp,tlen);
ret = makename(esb_get_string(&x));
esb_destructor(&x);
return ret;
}
/* The tokenizer for our simple parser.
*/
static char *
get_token(char *cp, struct token_s *outtok)
{
char *lcp = skipwhite(cp);
unsigned tlen = find_token_len(lcp);
outtok->tk_len = tlen;
if (tlen > 0) {
outtok->tk_data = build_string(tlen, lcp);
} else {
outtok->tk_data = "";
}
return lcp + tlen;
}
/*
We can't get all the field set up statically very easily,
so we get the command string length set here.
*/
static void
finish_comtable_setup(void)
{
unsigned i;
for (i = 0; i < size_of_comtable; ++i) {
comtable[i].namelen = strlen(comtable[i].name);
}
}
/*
Given a line of the table, determine if it is a command
or not, and if a command, which one is it.
Return LT_ERROR if it's not recognized.
*/
static enum linetype_e
which_command(char *cp, struct comtable_s **tableentry)
{
unsigned i = 0;
struct token_s tok;
if (*cp == '#')
return LT_COMMENT;
if (!*cp)
return LT_BLANK;
get_token(cp, &tok);
for (i = 0; i < size_of_comtable; ++i) {
if (tok.tk_len == comtable[i].namelen &&
strcmp(comtable[i].name, tok.tk_data) == 0) {
*tableentry = &comtable[i];
return comtable[i].type;
}
}
return LT_ERROR;
}
static int
parseoption(char *cp, const char *fname,unsigned long lineno,
struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
struct token_s tok;
cp = cp + clen + 1;
cp = skipwhite(cp);
get_token(cp, &tok);
if (!tok.tk_data) {
printf("ERROR: empty option: command is ignored");
return FALSE;
}
ensure_has_no_more_tokens(cp + tok.tk_len, fname, lineno);
if (!strcmp(tok.tk_data,"--format-expr-ops-joined")) {
glflags.gf_expr_ops_joined = TRUE;
} else {
printf("ERROR: option command %s is not understood"
" and is ignored",tok.tk_data);
return FALSE;
}
return TRUE;
}
/* We are promised it's an abiname: command
find the name on the line.
*/
static int
parsebeginabi(char *cp, const char *fname, const char *abiname,
unsigned long lineno, struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
size_t abinamelen = strlen(abiname);
struct token_s tok;
cp = cp + clen + 1;
cp = skipwhite(cp);
get_token(cp, &tok);
if (tok.tk_len != abinamelen ||
strncmp(cp, abiname, abinamelen)) {
printf("dwarfdump internal error: "
"mismatch \"%s\" with \"%s\" \"%s\" line %lu\n",
cp, tok.tk_data, fname, lineno);
++errcount;
return FALSE;
}
ensure_has_no_more_tokens(cp + tok.tk_len, fname, lineno);
return TRUE;
}
/* This expands register names as required, but does not
ensure no names duplicated.
*/
#define CONF_TABLE_OVERSIZE 100
static void
add_to_reg_table(struct dwconf_s *conf,
char *rname, unsigned long rval, const char *fname,
unsigned long lineno)
{
if (conf->cf_regs_malloced == 0) {
conf->cf_regs = 0;
conf->cf_named_regs_table_size = 0;
}
if (rval >= conf->cf_named_regs_table_size) {
char **newregs = 0;
unsigned long newtablen = rval + CONF_TABLE_OVERSIZE;
unsigned long newtabsize = newtablen * sizeof(char *);
unsigned long oldtabsize =
conf->cf_named_regs_table_size * sizeof(char *);
newregs = realloc(conf->cf_regs, newtabsize);
if (!newregs) {
printf("dwarfdump: unable to malloc table %lu bytes. "
" %s line %lu\n", newtabsize, fname, lineno);
exit(1);
}
/* Zero out the new entries. */
memset((char *) newregs + (oldtabsize), 0,
(newtabsize - oldtabsize));
conf->cf_named_regs_table_size = (unsigned long) newtablen;
conf->cf_regs = newregs;
conf->cf_regs_malloced = 1;
}
conf->cf_regs[rval] = rname;
return;
}
/* Our input is supposed to be a number.
Determine the value (and return it) or generate an error message.
*/
static int
make_a_number(char *cmd, const char *filename, unsigned long
lineno, struct token_s *tok, unsigned long *val_out)
{
char *endnum = 0;
unsigned long val = 0;
val = strtoul(tok->tk_data, &endnum, 0);
if (val == 0 && endnum == (tok->tk_data)) {
printf("dwarfdump.conf error: "
"%s missing register number (\"%s\" not valid) %s line %lu\n",
cmd, tok->tk_data, filename, lineno);
++errcount;
return FALSE;
}
if (endnum != (tok->tk_data + tok->tk_len)) {
printf("dwarfdump.conf error: "
"%s Missing register number (\"%s\" not valid) %s line %lu\n",
cmd, tok->tk_data, filename, lineno);
++errcount;
return FALSE;
}
*val_out = val;
return TRUE;
}
/* We are guaranteed it's a reg: command, so parse that command
and record the interesting data.
*/
static int
parsereg(char *cp, const char *fname, unsigned long lineno,
struct conf_internal_s *conf, struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
struct token_s regnum;
struct token_s tokreg;
unsigned long val = 0;
int ok = FALSE;
int res = FALSE;
cp = cp + clen + 1;
cp = get_token(cp, &tokreg);
cp = get_token(cp, ®num);
if (tokreg.tk_len == 0) {
printf("dwarfdump.conf error: "
"reg: missing register name %s line %lu",
fname, lineno);
++errcount;
return FALSE;
}
if (regnum.tk_len == 0) {
printf("dwarfdump.conf error: "
"reg: missing register number %s line %lu",
fname, lineno);
++errcount;
return FALSE;
}
ok = make_a_number(comtab->name, fname, lineno, ®num, &val);
if (!ok) {
++errcount;
return FALSE;
}
add_to_reg_table(conf->conf_out, tokreg.tk_data, val, fname, lineno);
res = ensure_has_no_more_tokens(cp, fname, lineno);
return res;
}
/*
We are guaranteed it's an frame_interface: command.
Parse it and record the value data.
*/
static int
parseframe_interface(char *cp, const char *fname, unsigned long lineno,
struct conf_internal_s *conf, struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
struct token_s tok;
unsigned long val = 0;
int ok = FALSE;
int res = FALSE;
cp = cp + clen + 1;
cp = get_token(cp, &tok);
if (tok.tk_len == 0) {
printf("dwarfdump.conf error: "
"%s missing interface number %s line %lu",
comtab->name, fname, lineno);
++errcount;
return FALSE;
}
ok = make_a_number(comtab->name, fname, lineno, &tok, &val);
if (!ok) {
++errcount;
return FALSE;
}
if (val != 2 && val != 3) {
printf("dwarfdump.conf error: "
"%s only interface numbers 2 or 3 are allowed, "
" not %lu. %s line %lu",
comtab->name, val, fname, lineno);
++errcount;
return FALSE;
}
conf->conf_out->cf_interface_number = (int) val;
res = ensure_has_no_more_tokens(cp, fname, lineno);
return res;
}
/*
We are guaranteed it's a cfa_reg: command. Parse it
and record the important data.
*/
static int
parsecfa_reg(char *cp, const char *fname, unsigned long lineno,
struct conf_internal_s *conf, struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
struct token_s tok;
unsigned long val = 0;
int ok = FALSE;
int res = FALSE;
cp = cp + clen + 1;
cp = get_token(cp, &tok);
if (tok.tk_len == 0) {
printf("dwarfdump.conf error: "
"%s missing cfa_reg number %s line %lu",
comtab->name, fname, lineno);
++errcount;
return FALSE;
}
ok = make_a_number(comtab->name, fname, lineno, &tok, &val);
if (!ok) {
++errcount;
return FALSE;
}
conf->conf_out->cf_cfa_reg = (int) val;
res = ensure_has_no_more_tokens(cp, fname, lineno);
return res;
}
/* We are guaranteed it's an initial_reg_value: command,
parse it and put the reg value where it will be remembered.
*/
static int
parseinitial_reg_value(char *cp, const char *fname,
unsigned long lineno,
struct conf_internal_s *conf, struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
struct token_s tok;
unsigned long val = 0;
int ok = FALSE;
int res = FALSE;
cp = cp + clen + 1;
cp = get_token(cp, &tok);
if (tok.tk_len == 0) {
printf("dwarfdump.conf error: "
"%s missing initial reg value %s line %lu",
comtab->name, fname, lineno);
++errcount;
return FALSE;
}
ok = make_a_number(comtab->name, fname, lineno, &tok, &val);
if (!ok) {
++errcount;
return FALSE;
}
conf->conf_out->cf_initial_rule_value = (int) val;
res = ensure_has_no_more_tokens(cp, fname, lineno);
return res;
}
static int
parsesame_val_reg(char *cp, const char *fname,
unsigned long lineno,
struct conf_internal_s *conf, struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
struct token_s tok;
unsigned long val = 0;
int ok = FALSE;
int res = FALSE;
cp = cp + clen + 1;
cp = get_token(cp, &tok);
if (tok.tk_len == 0) {
printf("dwarfdump.conf error: "
"%s missing same_reg value %s line %lu",
comtab->name, fname, lineno);
++errcount;
return FALSE;
}
ok = make_a_number(comtab->name, fname, lineno, &tok, &val);
if (!ok) {
++errcount;
return FALSE;
}
conf->conf_out->cf_same_val = val;
res = ensure_has_no_more_tokens(cp, fname, lineno);
return res;
}
static int
parseundefined_val_reg(char *cp, const char *fname,
unsigned long lineno,
struct conf_internal_s *conf, struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
struct token_s tok;
unsigned long val = 0;
int ok = FALSE;
int res = FALSE;
cp = cp + clen + 1;
cp = get_token(cp, &tok);
if (tok.tk_len == 0) {
printf("dwarfdump.conf error: "
"%s missing undefined_reg value %s line %lu",
comtab->name, fname, lineno);
++errcount;
return FALSE;
}
ok = make_a_number(comtab->name, fname, lineno, &tok, &val);
if (!ok) {
++errcount;
return FALSE;
}
conf->conf_out->cf_undefined_val = (int) val;
res = ensure_has_no_more_tokens(cp, fname, lineno);
return res;
}
/* We are guaranteed it's a table size command, parse it
and record the table size.
*/
static int
parsereg_table_size(char *cp, const char *fname, unsigned long lineno,
struct conf_internal_s *conf, struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
struct token_s tok;
unsigned long val = 0;
int ok = FALSE;
int res = FALSE;
cp = cp + clen + 1;
cp = get_token(cp, &tok);
if (tok.tk_len == 0) {
printf("dwarfdump.conf error: "
"%s missing reg table size value %s line %lu",
comtab->name, fname, lineno);
++errcount;
return FALSE;
}
ok = make_a_number(comtab->name, fname, lineno, &tok, &val);
if (!ok) {
++errcount;
return FALSE;
}
conf->conf_out->cf_table_entry_count = (unsigned long) val;
res = ensure_has_no_more_tokens(cp, fname, lineno);
return res;
}
/* We are guaranteed it's a table size command, parse it
and record the table size.
*/
static int
parseaddress_size(char *cp, const char *fname, unsigned long lineno,
struct conf_internal_s *conf, struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
struct token_s tok;
unsigned long val = 0;
int ok = FALSE;
int res = FALSE;
cp = cp + clen + 1;
cp = get_token(cp, &tok);
if (tok.tk_len == 0) {
printf("dwarfdump.conf error: "
"%s missing address size value %s line %lu",
comtab->name, fname, lineno);
++errcount;
return FALSE;
}
ok = make_a_number(comtab->name, fname, lineno, &tok, &val);
if (!ok) {
++errcount;
return FALSE;
}
conf->conf_out->cf_address_size = (unsigned long) val;
res = ensure_has_no_more_tokens(cp, fname, lineno);
return res;
}
/* We are guaranteed it's an endabi: command, parse it and
check we have the right abi.
*/
static int
parseendabi(char *cp, const char *fname,
const char *abiname, unsigned long lineno,
struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
struct token_s tok;
int res = 0;
cp = cp + clen + 1;
cp = get_token(cp, &tok);
if (strcmp(abiname, tok.tk_data) != 0) {
printf("%s error: "
"mismatch abi name %s (here) vs. %s (beginabi:) %s line %lu\n",
comtab->name, tok.tk_data, abiname, fname, lineno);
++errcount;
return FALSE;
}
res = ensure_has_no_more_tokens(cp, fname, lineno);
return res;
}
static int
parseincludeabi(char *cp, const char *fname, unsigned long lineno,
char **abiname_out,
struct comtable_s *comtab)
{
size_t clen = comtab->namelen;
struct token_s tok;
char *name = 0;
int res = FALSE;
cp = cp + clen + 1;
cp = get_token(cp, &tok);
name = makename(tok.tk_data);
*abiname_out = name;
res = ensure_has_no_more_tokens(cp, fname, lineno);
return res;
}
/* Return TRUE if we succeeded and filed in *out.
Return FALSE if we failed (and fill in nothing).
beginabi: <abiname>
reg: <regname> <dwarf regnumber>
frame_interface: <integer value 2 or 3>
cfa_reg: <number>
initial_reg_value: <number: normally 1034 or 1035 >
reg_table_size: <size of table>
endabi: <abiname>
We are positioned at the start of a beginabi: line when
called.
*/
static int
parse_abi(FILE * stream, const char *fname, const char *abiname,
struct conf_internal_s *conf_internal,
unsigned long lineno,
unsigned int nest_level)
{
struct dwconf_s *localconf = conf_internal->conf_out;
char buf[1000];
int comtype = 0;
static int first_time_done = 0;
struct comtable_s *comtabp = 0;
int inourabi = FALSE;
if (nest_level > MAX_NEST_LEVEL) {
++errcount;
printf("dwarfdump.conf: includeabi nest "
"too deep in %s at line %lu\n",
fname, lineno);
return FALSE;
}
if (first_time_done == 0) {
finish_comtable_setup();
first_time_done = 1;
}
for (; !feof(stream);) {
char *line = 0;
/* long loffset = ftell(stream); */
line = fgets(buf, sizeof(buf), stream);
if (!line) {
++errcount;
printf("dwarfdump: end of file or error"
" before endabi: in %s, line %lu\n",
fname, lineno);
return FALSE;
}
++lineno;
line = skipwhite(line);
comtype = which_command(line, &comtabp);
switch (comtype) {
case LT_OPTION:
if (!inourabi) break;
parseoption(line, fname, lineno,comtabp);
break;
case LT_ERROR:
++errcount;
printf
("dwarfdump: Unknown text in %s is \"%s\" at line %lu\n",
fname, line, lineno);
break;
case LT_COMMENT:
break;
case LT_BLANK:
break;
case LT_BEGINABI:
if (conf_internal->beginabi_lineno > 0) {
++errcount;
printf
("dwarfdump: Encountered beginabi: when not expected. "
"%s line %lu previous beginabi line %lu\n", fname,
lineno, conf_internal->beginabi_lineno);
}
conf_internal->beginabi_lineno = lineno;
inourabi = parsebeginabi(line, fname,
abiname, lineno, comtabp);
break;
case LT_REG:
if (!inourabi) break;
parsereg(line, fname, lineno, conf_internal, comtabp);
conf_internal->regcount++;
break;
case LT_FRAME_INTERFACE:
if (!inourabi) break;
if (conf_internal->frame_interface_lineno > 0) {
++errcount;
printf
("dwarfdump: Encountered duplicate frame_interface: "
"%s line %lu previous frame_interface: line %lu\n",
fname, lineno, conf_internal->frame_interface_lineno);
}
conf_internal->frame_interface_lineno = lineno;
parseframe_interface(line, fname,
lineno, conf_internal, comtabp);
break;
case LT_CFA_REG:
if (!inourabi) break;
if (conf_internal->cfa_reg_lineno > 0) {
printf("dwarfdump: Encountered duplicate cfa_reg: "
"%s line %lu previous cfa_reg line %lu\n",
fname, lineno, conf_internal->cfa_reg_lineno);
++errcount;
}
conf_internal->cfa_reg_lineno = lineno;
parsecfa_reg(line, fname, lineno, conf_internal, comtabp);
break;
case LT_INITIAL_REG_VALUE:
if (!inourabi) break;
if (conf_internal->initial_reg_value_lineno > 0) {
printf
("dwarfdump: Encountered duplicate initial_reg_value: "
"%s line %lu previous initial_reg_value: line %lu\n",
fname, lineno, conf_internal->initial_reg_value_lineno);
++errcount;
}
conf_internal->initial_reg_value_lineno = lineno;
parseinitial_reg_value(line, fname,
lineno, conf_internal, comtabp);
break;
case LT_SAME_VAL_REG:
if (!inourabi) break;
if (conf_internal->same_val_reg_lineno > 0) {
++errcount;
printf
("dwarfdump: Encountered duplicate same_val_reg: "
"%s line %lu previous initial_reg_value: line %lu\n",
fname, lineno, conf_internal->initial_reg_value_lineno);
}
conf_internal->same_val_reg_lineno = lineno;
parsesame_val_reg(line, fname,
lineno, conf_internal, comtabp);
break;
case LT_UNDEFINED_VAL_REG:
if (!inourabi) break;
if (conf_internal->undefined_val_reg_lineno > 0) {
++errcount;
printf
("dwarfdump: Encountered duplicate undefined_val_reg: "
"%s line %lu previous initial_reg_value: line %lu\n",
fname, lineno, conf_internal->initial_reg_value_lineno);
}
if (!inourabi) break;
conf_internal->undefined_val_reg_lineno = lineno;
parseundefined_val_reg(line, fname,
lineno, conf_internal, comtabp);
break;
case LT_REG_TABLE_SIZE:
if (!inourabi) break;
if (conf_internal->reg_table_size_lineno > 0) {
printf("dwarfdump: duplicate reg_table_size: "
"%s line %lu previous reg_table_size: line %lu\n",
fname, lineno, conf_internal->reg_table_size_lineno);
++errcount;
}
conf_internal->reg_table_size_lineno = lineno;
parsereg_table_size(line, fname,
lineno, conf_internal, comtabp);
break;
case LT_ENDABI:
if (!inourabi) break;
parseendabi(line, fname, abiname, lineno, comtabp);
if (conf_internal->regcount >
localconf->cf_table_entry_count) {
printf("dwarfdump: more registers named than "
" in %s ( %lu named vs %s %lu)"
" %s line %lu\n",
abiname, (unsigned long) conf_internal->regcount,
name_reg_table_size,
(unsigned long) localconf->cf_table_entry_count,
fname, (unsigned long) lineno);
++errcount;
}
inourabi = FALSE;
return TRUE;
case LT_ADDRESS_SIZE:
if (!inourabi) break;
if (conf_internal->address_size_lineno > 0) {
printf("dwarfdump: duplicate address_size: "
"%s line %lu previous address_size:"
" line %lu\n",
fname, lineno,
conf_internal->address_size_lineno);
++errcount;
}
conf_internal->address_size_lineno = lineno;
parseaddress_size(line, fname,
lineno, conf_internal, comtabp);
break;
case LT_INCLUDEABI: {
char *abiname_inner = 0;
unsigned long abilno = conf_internal->beginabi_lineno;
int ires = 0;
if (!inourabi) break;
ires = parseincludeabi(line,fname,lineno,
&abiname_inner,comtabp);
if (ires == FALSE) {
return FALSE;
}
/* For the nested abi read, the abi line
number must be set as if not-yet-read
and then restored. */
conf_internal->beginabi_lineno = 0;
ires = find_conf_file_and_read_config_inner(
conf_internal->conf_name_used,
abiname_inner, conf_internal,nest_level+1);
if (ires == FOUND_ERROR) {
return ires;
}
conf_internal->beginabi_lineno = abilno;
}
break;
default:
printf("dwarfdump internal error,"
" impossible line type %d %s %lu \n",
(int) comtype, fname, lineno);
exit(1);
}
}
++errcount;
printf("End of file, no endabi: found. %s, line %lu\n",
fname, lineno);
return FALSE;
}
/* MIPS/IRIX frame register names.
For alternate name sets, use dwarfdump.conf or
revise dwarf.h and libdwarf.h and this table.
*/
static char *regnames[] = {
"cfa",
"r1/at", "r2/v0", "r3/v1",
"r4/a0", "r5/a1", "r6/a2", "r7/a3",
"r8/t0", "r9/t1", "r10/t2", "r11/t3",
"r12/t4", "r13/t5", "r14/t6", "r15/t7",
"r16/s0", "r17/s1", "r18/s2", "r19/s3",
"r20/s4", "r21/s5", "r22/s6", "r23/s7",
"r24/t8", "r25/t9", "r26/k0", "r27/k1",
"r28/gp", "r29/sp", "r30/s8", "r31",
"$f0", "$f1",
"$f2", "$f3",
"$f4", "$f5",
"$f6", "$f7",
"$f8", "$f9",
"$f10", "$f11",
"$f12", "$f13",
"$f14", "$f15",
"$f16", "$f17",
"$f18", "$f19",
"$f20", "$f21",
"$f22", "$f23",
"$f24", "$f25",
"$f26", "$f27",
"$f28", "$f29",
"$f30", "$f31",
"ra", "slk",
};
/* Naming a few registers makes printing these just
a little bit faster.
*/
static char *genericregnames[] = {
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
"r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",
"r20"
};
/* This is a simple generic set of registers. The
table entry count is pretty arbitrary.
*/
void
init_conf_file_data(struct dwconf_s *config_file_data)
{
unsigned generic_table_count;
config_file_data->cf_abi_name = "";
config_file_data->cf_config_file_path = "";
config_file_data->cf_interface_number = 3;
config_file_data->cf_table_entry_count = 100;
#if 0
printf("dadebug init generic 100 table entries\n");
#endif
config_file_data->cf_initial_rule_value = DW_FRAME_UNDEFINED_VAL;
config_file_data->cf_cfa_reg = DW_FRAME_CFA_COL3;
config_file_data->cf_address_size = 0;
config_file_data->cf_same_val = DW_FRAME_SAME_VAL;
config_file_data->cf_undefined_val = DW_FRAME_UNDEFINED_VAL;
config_file_data->cf_regs = genericregnames;
generic_table_count =
sizeof(genericregnames) / sizeof(genericregnames[0]);
config_file_data->cf_named_regs_table_size = generic_table_count;
config_file_data->cf_regs_malloced = 0;
}
/* These defaults match MIPS/IRIX ABI defaults, but this
function is not actually used.
For a 'generic' ABI, see -R or init_conf_file_data().
To really get the old MIPS, use '-x abi=mips'.
For other ABIs, see -x abi=<whatever>
to configure dwarfdump (and libdwarf) frame
data reporting at runtime.
*/
void
init_mips_conf_file_data(struct dwconf_s *config_file_data)
{
unsigned long base_table_count =
sizeof(regnames) / sizeof(regnames[0]);
memset(config_file_data, 0, sizeof(*config_file_data));
/* Interface 2 is deprecated, but for testing purposes
is acceptable. */
config_file_data->cf_interface_number = 2;
config_file_data->cf_table_entry_count = DW_REG_TABLE_SIZE;
config_file_data->cf_initial_rule_value =
DW_FRAME_REG_INITIAL_VALUE;
config_file_data->cf_cfa_reg = DW_FRAME_CFA_COL;
config_file_data->cf_address_size = 0;
config_file_data->cf_same_val = DW_FRAME_SAME_VAL;
config_file_data->cf_undefined_val = DW_FRAME_UNDEFINED_VAL;
config_file_data->cf_regs = regnames;
config_file_data->cf_named_regs_table_size = base_table_count;
config_file_data->cf_regs_malloced = 0;
if (config_file_data->cf_table_entry_count != base_table_count) {
printf("dwarfdump: improper base table initization, "
"header files wrong: "
"DW_REG_TABLE_SIZE %u != string table size %lu\n",
(unsigned) DW_REG_TABLE_SIZE,
(unsigned long) base_table_count);
exit(1);
}
return;
}
/* A 'generic' ABI. For up to 1200 registers.
Perhaps cf_initial_rule_value should be d
UNDEFINED VALUE (1034) instead, but for the purposes of
getting the dwarfdump output correct
either will work.
*/
void
init_generic_config_1200_regs(struct dwconf_s *config_file_data)
{
unsigned long generic_table_count =
sizeof(genericregnames) / sizeof(genericregnames[0]);
config_file_data->cf_interface_number = 3;
config_file_data->cf_table_entry_count = 1200;
/* There is no defined name for cf_initial_rule_value,
cf_same_val, or cf_undefined_val in libdwarf.h,
these must just be high enough to be higher than
any real register number.
DW_FRAME_CFA_COL3 must also be higher than any
real register number. */
config_file_data->cf_initial_rule_value = 1235; /* SAME VALUE */
config_file_data->cf_cfa_reg = DW_FRAME_CFA_COL3;
config_file_data->cf_address_size = 0;
config_file_data->cf_same_val = 1235;
config_file_data->cf_undefined_val = 1234;
config_file_data->cf_regs = genericregnames;
config_file_data->cf_named_regs_table_size = generic_table_count;
config_file_data->cf_regs_malloced = 0;
}
/* Print the 'right' string for the register we are given.
Deal sensibly with the special regs as well as numbers
we know and those we have not been told about.
We are not allowing negative register numbers.
*/
void
print_reg_from_config_data(Dwarf_Unsigned reg,
struct dwconf_s *config_data)
{
char *name = 0;
if (reg == config_data->cf_cfa_reg) {
fputs("cfa",stdout);
return;
}
if (reg == config_data->cf_undefined_val) {
fputs("u",stdout);
return;
}
if (reg == config_data->cf_same_val) {
fputs("s",stdout);
return;
}
if (config_data->cf_regs == 0 ||
reg >= config_data->cf_named_regs_table_size) {
printf("r%" DW_PR_DUu "",reg);
return;
}
name = config_data->cf_regs[reg];
if (!name) {
/* Can happen, the reg names table can be sparse. */
printf("r%" DW_PR_DUu "", reg);
return;
}
fputs(name,stdout);
return;
}
void
free_all_dwconf(struct dwconf_s *conf)
{
if (conf->cf_regs_malloced) {
free(conf->cf_regs);
}
conf->cf_regs = 0;
conf->cf_named_regs_table_size =0;
conf->cf_regs_malloced = 0;
}
|