Changes in external/tcl/tclExecute.c [adeddd8:d7d2da3] in git
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
external/tcl/tclExecute.c
radeddd8 rd7d2da3 51 51 52 52 /* 53 * Variable that controls whether execution tracing is enabled and, if so, 54 * what level of tracing is desired: 55 * 0: no execution tracing 56 * 1: trace invocations of Tcl procs only 57 * 2: trace invocations of all (not compiled away) commands 58 * 3: display each instruction executed 59 * This variable is linked to the Tcl variable "tcl_traceExec". 60 */ 61 62 int tclTraceExec = 0; 63 64 /* 53 65 * The following global variable is use to signal matherr that Tcl 54 66 * is responsible for the arithmetic, so errors can be handled in a … … 90 102 }; 91 103 104 /* 105 * Mapping from Tcl result codes to strings; used for error and debugging 106 * messages. 107 */ 108 109 #ifdef TCL_COMPILE_DEBUG 110 static char *resultStrings[] = { 111 "TCL_OK", "TCL_ERROR", "TCL_RETURN", "TCL_BREAK", "TCL_CONTINUE" 112 }; 113 #endif /* TCL_COMPILE_DEBUG */ 114 115 /* 116 * The following are statistics-related variables that record information 117 * about the bytecode compiler and interpreter's operation. This includes 118 * an array that records for each instruction how often it is executed. 119 */ 120 121 #ifdef TCL_COMPILE_STATS 122 static long numExecutions = 0; 123 static int instructionCount[256]; 124 #endif /* TCL_COMPILE_STATS */ 125 92 126 /* 93 127 * Macros for testing floating-point values for certain special cases. Test … … 153 187 #define POP_OBJECT() \ 154 188 (stackPtr[stackTop--].o) 189 190 /* 191 * Macros used to trace instruction execution. The macros TRACE, 192 * TRACE_WITH_OBJ, and O2S are only used inside TclExecuteByteCode. 193 * O2S is only used in TRACE* calls to get a string from an object. 194 * 195 * NOTE THAT CLIENTS OF O2S ARE LIKELY TO FAIL IF THE OBJECT'S 196 * STRING REP CONTAINS NULLS. 197 */ 198 199 #ifdef TCL_COMPILE_DEBUG 200 201 #define O2S(objPtr) \ 202 Tcl_GetStringFromObj((objPtr), &length) 203 204 #ifdef TCL_COMPILE_STATS 205 #define TRACE(a) \ 206 if (traceInstructions) { \ 207 fprintf(stdout, "%d: %d,%ld (%u) ", iPtr->numLevels, \ 208 stackTop, (tclObjsAlloced - tclObjsFreed), \ 209 (unsigned int)(pc - codePtr->codeStart)); \ 210 printf a; \ 211 fflush(stdout); \ 212 } 213 #define TRACE_WITH_OBJ(a, objPtr) \ 214 if (traceInstructions) { \ 215 fprintf(stdout, "%d: %d,%ld (%u) ", iPtr->numLevels, \ 216 stackTop, (tclObjsAlloced - tclObjsFreed), \ 217 (unsigned int)(pc - codePtr->codeStart)); \ 218 printf a; \ 219 bytes = Tcl_GetStringFromObj((objPtr), &length); \ 220 TclPrintSource(stdout, bytes, TclMin(length, 30)); \ 221 fprintf(stdout, "\n"); \ 222 fflush(stdout); \ 223 } 224 #else /* not TCL_COMPILE_STATS */ 225 #define TRACE(a) \ 226 if (traceInstructions) { \ 227 fprintf(stdout, "%d: %d (%u) ", iPtr->numLevels, stackTop, \ 228 (unsigned int)(pc - codePtr->codeStart)); \ 229 printf a; \ 230 fflush(stdout); \ 231 } 232 #define TRACE_WITH_OBJ(a, objPtr) \ 233 if (traceInstructions) { \ 234 fprintf(stdout, "%d: %d (%u) ", iPtr->numLevels, stackTop, \ 235 (unsigned int)(pc - codePtr->codeStart)); \ 236 printf a; \ 237 bytes = Tcl_GetStringFromObj((objPtr), &length); \ 238 TclPrintSource(stdout, bytes, TclMin(length, 30)); \ 239 fprintf(stdout, "\n"); \ 240 fflush(stdout); \ 241 } 242 #endif /* TCL_COMPILE_STATS */ 243 244 #else /* not TCL_COMPILE_DEBUG */ 245 246 #define TRACE(a) 247 #define TRACE_WITH_OBJ(a, objPtr) 248 #define O2S(objPtr) 249 250 #endif /* TCL_COMPILE_DEBUG */ 155 251 156 252 /* … … 178 274 static int ExprUnaryFunc _ANSI_ARGS_((Tcl_Interp *interp, 179 275 ExecEnv *eePtr, ClientData clientData)); 276 #ifdef TCL_COMPILE_STATS 277 static int EvalStatsCmd _ANSI_ARGS_((ClientData clientData, 278 Tcl_Interp *interp, int argc, char **argv)); 279 #endif /* TCL_COMPILE_STATS */ 180 280 static void FreeCmdNameInternalRep _ANSI_ARGS_(( 181 281 Tcl_Obj *objPtr)); … … 193 293 static int SetCmdNameFromAny _ANSI_ARGS_((Tcl_Interp *interp, 194 294 Tcl_Obj *objPtr)); 295 #ifdef TCL_COMPILE_DEBUG 296 static char * StringForResultCode _ANSI_ARGS_((int result)); 297 #endif /* TCL_COMPILE_DEBUG */ 195 298 static void UpdateStringOfCmdName _ANSI_ARGS_((Tcl_Obj *objPtr)); 299 #ifdef TCL_COMPILE_DEBUG 300 static void ValidatePcAndStackTop _ANSI_ARGS_(( 301 ByteCode *codePtr, unsigned char *pc, 302 int stackTop, int stackLowerBound, 303 int stackUpperBound)); 304 #endif /* TCL_COMPILE_DEBUG */ 196 305 197 306 /* … … 259 368 * 260 369 * Side effects: 261 * This procedure initializes the array of instruction names. 370 * This procedure initializes the array of instruction names. If 371 * compiling with the TCL_COMPILE_STATS flag, it initializes the 372 * array that counts the executions of each instruction and it 373 * creates the "evalstats" command. It also registers the command name 374 * Tcl_ObjType. It also establishes the link between the Tcl 375 * "tcl_traceExec" and C "tclTraceExec" variables. 262 376 * 263 377 *---------------------------------------------------------------------- … … 277 391 for (i = 0; instructionTable[i].name != NULL; i++) { 278 392 opName[i] = instructionTable[i].name; 393 } 394 395 #ifdef TCL_COMPILE_STATS 396 (VOID *) memset(instructionCount, 0, sizeof(instructionCount)); 397 (VOID *) memset(tclByteCodeCount, 0, sizeof(tclByteCodeCount)); 398 (VOID *) memset(tclSourceCount, 0, sizeof(tclSourceCount)); 399 400 Tcl_CreateCommand(interp, "evalstats", EvalStatsCmd, 401 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); 402 #endif /* TCL_COMPILE_STATS */ 403 404 if (Tcl_LinkVar(interp, "tcl_traceExec", (char *) &tclTraceExec, 405 TCL_LINK_INT) != TCL_OK) { 406 panic("InitByteCodeExecution: can't create link for tcl_traceExec variable"); 279 407 } 280 408 } … … 470 598 * process break, continue, and errors. */ 471 599 int result = TCL_OK; /* Return code returned after execution. */ 600 int traceInstructions = (tclTraceExec == 3); 472 601 Tcl_Obj *valuePtr, *value2Ptr, *namePtr, *objPtr; 473 602 char *bytes; 474 603 int length; 475 604 long i; 605 Tcl_DString command; /* Used for debugging. If tclTraceExec >= 2 606 * holds a string representing the last 607 * command invoked. */ 476 608 477 609 /* … … 488 620 489 621 /* 622 * THIS PROC FAILS IF AN OBJECT'S STRING REP HAS A NULL BYTE. 623 */ 624 625 if (tclTraceExec >= 2) { 626 PrintByteCodeInfo(codePtr); 627 #ifdef TCL_COMPILE_STATS 628 fprintf(stdout, " Starting stack top=%d, system objects=%ld\n", 629 eePtr->stackTop, (tclObjsAlloced - tclObjsFreed)); 630 #else 631 fprintf(stdout, " Starting stack top=%d\n", eePtr->stackTop); 632 #endif /* TCL_COMPILE_STATS */ 633 fflush(stdout); 634 } 635 636 #ifdef TCL_COMPILE_STATS 637 numExecutions++; 638 #endif /* TCL_COMPILE_STATS */ 639 640 /* 490 641 * Make sure the catch stack is large enough to hold the maximum number 491 642 * of catch commands that could ever be executing at the same time. This … … 508 659 509 660 /* 661 * Initialize the buffer that holds a string containing the name and 662 * arguments for the last invoked command. 663 */ 664 665 Tcl_DStringInit(&command); 666 667 /* 510 668 * Loop executing instructions until a "done" instruction, a TCL_RETURN, 511 669 * or some error. … … 513 671 514 672 for (;;) { 673 #ifdef TCL_COMPILE_DEBUG 674 ValidatePcAndStackTop(codePtr, pc, stackTop, initStackTop, 675 eePtr->stackEnd); 676 #else /* not TCL_COMPILE_DEBUG */ 677 if (traceInstructions) { 678 #ifdef TCL_COMPILE_STATS 679 fprintf(stdout, "%d: %d,%ld ", iPtr->numLevels, stackTop, 680 (tclObjsAlloced - tclObjsFreed)); 681 #else /* TCL_COMPILE_STATS */ 682 fprintf(stdout, "%d: %d ", iPtr->numLevels, stackTop); 683 #endif /* TCL_COMPILE_STATS */ 684 TclPrintInstruction(codePtr, pc); 685 fflush(stdout); 686 } 687 #endif /* TCL_COMPILE_DEBUG */ 688 515 689 opCode = *pc; 690 #ifdef TCL_COMPILE_STATS 691 instructionCount[opCode]++; 692 #endif /* TCL_COMPILE_STATS */ 516 693 517 694 switch (opCode) { … … 533 710 panic("TclExecuteByteCode execution failure: end stack top != start stack top"); 534 711 } 712 TRACE_WITH_OBJ(("done => return code=%d, result is ", result), 713 iPtr->objResultPtr); 535 714 goto done; 536 715 … … 538 717 valuePtr = objArrayPtr[TclGetUInt1AtPtr(pc+1)]; 539 718 PUSH_OBJECT(valuePtr); 719 TRACE_WITH_OBJ(("push1 %u => ", TclGetUInt1AtPtr(pc+1)), 720 valuePtr); 540 721 ADJUST_PC(2); 541 722 … … 543 724 valuePtr = objArrayPtr[TclGetUInt4AtPtr(pc+1)]; 544 725 PUSH_OBJECT(valuePtr); 726 TRACE_WITH_OBJ(("push4 %u => ", TclGetUInt4AtPtr(pc+1)), 727 valuePtr); 545 728 ADJUST_PC(5); 546 729 547 730 case INST_POP: 548 731 valuePtr = POP_OBJECT(); 732 TRACE_WITH_OBJ(("pop => discarding "), valuePtr); 549 733 TclDecrRefCount(valuePtr); /* finished with pop'ed object. */ 550 734 ADJUST_PC(1); … … 553 737 valuePtr = stackPtr[stackTop].o; 554 738 PUSH_OBJECT(Tcl_DuplicateObj(valuePtr)); 739 TRACE_WITH_OBJ(("dup => "), valuePtr); 555 740 ADJUST_PC(1); 556 741 … … 605 790 606 791 PUSH_OBJECT(concatObjPtr); 792 TRACE_WITH_OBJ(("concat %u => ", opnd), concatObjPtr); 607 793 ADJUST_PC(2); 608 794 } … … 629 815 * Init. to avoid compiler warning. */ 630 816 Tcl_Command cmd; 817 #ifdef TCL_COMPILE_DEBUG 818 int isUnknownCmd = 0; 819 char cmdNameBuf[30]; 820 #endif /* TCL_COMPILE_DEBUG */ 631 821 632 822 /* … … 677 867 "invalid command name \"", cmdName, "\"", 678 868 (char *) NULL); 869 TRACE(("%s %u => unknown proc not found: ", 870 opName[opCode], objc)); 679 871 result = TCL_ERROR; 680 872 goto checkForCatch; 681 873 } 682 874 cmdPtr = (Command *) cmd; 875 #ifdef TCL_COMPILE_DEBUG 876 isUnknownCmd = 1; 877 #endif /*TCL_COMPILE_DEBUG*/ 683 878 stackTop++; /* need room for new inserted objv[0] */ 684 879 for (i = objc; i >= 0; i--) { … … 723 918 Tcl_ResetResult(interp); 724 919 920 if (tclTraceExec >= 2) { 921 char buffer[50]; 922 923 sprintf(buffer, "%d: (%u) invoking ", iPtr->numLevels, 924 (unsigned int)(pc - codePtr->codeStart)); 925 Tcl_DStringAppend(&command, buffer, -1); 926 927 #ifdef TCL_COMPILE_DEBUG 928 if (traceInstructions) { /* tclTraceExec == 3 */ 929 strncpy(cmdNameBuf, cmdName, 20); 930 TRACE(("%s %u => call ", opName[opCode], 931 (isUnknownCmd? objc-1 : objc))); 932 } else { 933 fprintf(stdout, "%s", buffer); 934 } 935 #else /* TCL_COMPILE_DEBUG */ 936 fprintf(stdout, "%s", buffer); 937 #endif /*TCL_COMPILE_DEBUG*/ 938 939 for (i = 0; i < objc; i++) { 940 bytes = TclGetStringFromObj(objv[i], &length); 941 TclPrintSource(stdout, bytes, TclMin(length, 15)); 942 fprintf(stdout, " "); 943 944 sprintf(buffer, "\"%.*s\" ", TclMin(length, 15), bytes); 945 Tcl_DStringAppend(&command, buffer, -1); 946 } 947 fprintf(stdout, "\n"); 948 fflush(stdout); 949 950 Tcl_DStringFree(&command); 951 } 952 725 953 iPtr->cmdCount++; 726 954 DECACHE_STACK_INFO(); … … 768 996 */ 769 997 PUSH_OBJECT(Tcl_GetObjResult(interp)); 998 TRACE_WITH_OBJ(("%s %u => ...after \"%.20s\", result=", 999 opName[opCode], objc, cmdNameBuf), 1000 Tcl_GetObjResult(interp)); 770 1001 ADJUST_PC(pcAdjustment); 771 1002 … … 784 1015 /*catchOnly*/ 0, codePtr); 785 1016 if (rangePtr == NULL) { 1017 TRACE(("%s %u => ... after \"%.20s\", no encl. loop or catch, returning %s\n", 1018 opName[opCode], objc, cmdNameBuf, 1019 StringForResultCode(result))); 786 1020 goto abnormalReturn; /* no catch exists to check */ 787 1021 } … … 791 1025 newPcOffset = rangePtr->breakOffset; 792 1026 } else if (rangePtr->continueOffset == -1) { 1027 TRACE(("%s %u => ... after \"%.20s\", %s, loop w/o continue, checking for catch\n", 1028 opName[opCode], objc, cmdNameBuf, 1029 StringForResultCode(result))); 793 1030 goto checkForCatch; 794 1031 } else { 795 1032 newPcOffset = rangePtr->continueOffset; 796 1033 } 1034 TRACE(("%s %u => ... after \"%.20s\", %s, range at %d, new pc %d\n", 1035 opName[opCode], objc, cmdNameBuf, 1036 StringForResultCode(result), 1037 rangePtr->codeOffset, newPcOffset)); 797 1038 break; 798 1039 case CATCH_EXCEPTION_RANGE: 1040 TRACE(("%s %u => ... after \"%.20s\", %s...\n", 1041 opName[opCode], objc, cmdNameBuf, 1042 StringForResultCode(result))); 799 1043 goto processCatch; /* it will use rangePtr */ 800 1044 default: … … 810 1054 * enclosing catch exception range, if any. 811 1055 */ 1056 TRACE_WITH_OBJ(("%s %u => ... after \"%.20s\", TCL_ERROR ", 1057 opName[opCode], objc, cmdNameBuf), 1058 Tcl_GetObjResult(interp)); 812 1059 goto checkForCatch; 813 1060 … … 818 1065 * for an enclosing catch exception range, if any. 819 1066 */ 1067 TRACE(("%s %u => ... after \"%.20s\", TCL_RETURN\n", 1068 opName[opCode], objc, cmdNameBuf)); 820 1069 goto checkForCatch; 821 1070 822 1071 default: 1072 TRACE_WITH_OBJ(("%s %u => ... after \"%.20s\", OTHER RETURN CODE %d ", 1073 opName[opCode], objc, cmdNameBuf, result), 1074 Tcl_GetObjResult(interp)); 823 1075 goto checkForCatch; 824 1076 } /* end of switch on result from invoke instruction */ … … 836 1088 837 1089 PUSH_OBJECT(Tcl_GetObjResult(interp)); 1090 TRACE_WITH_OBJ(("evalStk \"%.30s\" => ", O2S(objPtr)), 1091 Tcl_GetObjResult(interp)); 838 1092 TclDecrRefCount(objPtr); 839 1093 ADJUST_PC(1); … … 855 1109 codePtr); 856 1110 if (rangePtr == NULL) { 1111 TRACE(("evalStk \"%.30s\" => no encl. loop or catch, returning %s\n", 1112 O2S(objPtr), StringForResultCode(result))); 857 1113 Tcl_DecrRefCount(objPtr); 858 1114 goto abnormalReturn; /* no catch exists to check */ … … 863 1119 newPcOffset = rangePtr->breakOffset; 864 1120 } else if (rangePtr->continueOffset == -1) { 1121 TRACE(("evalStk \"%.30s\" => %s, loop w/o continue, checking for catch\n", 1122 O2S(objPtr), StringForResultCode(result))); 865 1123 Tcl_DecrRefCount(objPtr); 866 1124 goto checkForCatch; … … 869 1127 } 870 1128 result = TCL_OK; 1129 TRACE_WITH_OBJ(("evalStk \"%.30s\" => %s, range at %d, new pc %d ", 1130 O2S(objPtr), StringForResultCode(result), 1131 rangePtr->codeOffset, newPcOffset), valuePtr); 871 1132 break; 872 1133 case CATCH_EXCEPTION_RANGE: 1134 TRACE_WITH_OBJ(("evalStk \"%.30s\" => %s ", 1135 O2S(objPtr), StringForResultCode(result)), 1136 valuePtr); 873 1137 Tcl_DecrRefCount(objPtr); 874 1138 goto processCatch; /* it will use rangePtr */ … … 880 1144 continue; /* restart outer instruction loop at pc */ 881 1145 } else { /* eval returned TCL_ERROR, TCL_RETURN, unknown code */ 1146 TRACE_WITH_OBJ(("evalStk \"%.30s\" => ERROR: ", O2S(objPtr)), 1147 Tcl_GetObjResult(interp)); 882 1148 Tcl_DecrRefCount(objPtr); 883 1149 goto checkForCatch; … … 891 1157 CACHE_STACK_INFO(); 892 1158 if (result != TCL_OK) { 1159 TRACE_WITH_OBJ(("exprStk \"%.30s\" => ERROR: ", 1160 O2S(objPtr)), Tcl_GetObjResult(interp)); 893 1161 Tcl_DecrRefCount(objPtr); 894 1162 goto checkForCatch; 895 1163 } 896 1164 stackPtr[++stackTop].o = valuePtr; /* already has right refct */ 1165 TRACE_WITH_OBJ(("exprStk \"%.30s\" => ", O2S(objPtr)), valuePtr); 897 1166 TclDecrRefCount(objPtr); 898 1167 ADJUST_PC(1); … … 913 1182 CACHE_STACK_INFO(); 914 1183 if (valuePtr == NULL) { 1184 TRACE_WITH_OBJ(("%s %u => ERROR: ", opName[opCode], opnd), 1185 Tcl_GetObjResult(interp)); 915 1186 result = TCL_ERROR; 916 1187 goto checkForCatch; 917 1188 } 918 1189 PUSH_OBJECT(valuePtr); 1190 TRACE_WITH_OBJ(("%s %u => ", opName[opCode], opnd), valuePtr); 919 1191 ADJUST_PC(pcAdjustment); 920 1192 … … 926 1198 CACHE_STACK_INFO(); 927 1199 if (valuePtr == NULL) { 1200 TRACE_WITH_OBJ(("loadScalarStk \"%.30s\" => ERROR: ", 1201 O2S(namePtr)), Tcl_GetObjResult(interp)); 928 1202 Tcl_DecrRefCount(namePtr); 929 1203 result = TCL_ERROR; … … 931 1205 } 932 1206 PUSH_OBJECT(valuePtr); 1207 TRACE_WITH_OBJ(("loadScalarStk \"%.30s\" => ", 1208 O2S(namePtr)), valuePtr); 933 1209 TclDecrRefCount(namePtr); 934 1210 ADJUST_PC(1); … … 952 1228 CACHE_STACK_INFO(); 953 1229 if (valuePtr == NULL) { 1230 TRACE_WITH_OBJ(("%s %u \"%.30s\" => ERROR: ", 1231 opName[opCode], opnd, O2S(elemPtr)), 1232 Tcl_GetObjResult(interp)); 954 1233 Tcl_DecrRefCount(elemPtr); 955 1234 result = TCL_ERROR; … … 957 1236 } 958 1237 PUSH_OBJECT(valuePtr); 1238 TRACE_WITH_OBJ(("%s %u \"%.30s\" => ", 1239 opName[opCode], opnd, O2S(elemPtr)), valuePtr); 959 1240 TclDecrRefCount(elemPtr); 960 1241 } … … 971 1252 CACHE_STACK_INFO(); 972 1253 if (valuePtr == NULL) { 1254 TRACE_WITH_OBJ(("loadArrayStk \"%.30s(%.30s)\" => ERROR: ", 1255 O2S(namePtr), O2S(elemPtr)), 1256 Tcl_GetObjResult(interp)); 973 1257 Tcl_DecrRefCount(namePtr); 974 1258 Tcl_DecrRefCount(elemPtr); … … 977 1261 } 978 1262 PUSH_OBJECT(valuePtr); 1263 TRACE_WITH_OBJ(("loadArrayStk \"%.30s(%.30s)\" => ", 1264 O2S(namePtr), O2S(elemPtr)), valuePtr); 979 1265 TclDecrRefCount(namePtr); 980 1266 TclDecrRefCount(elemPtr); … … 989 1275 CACHE_STACK_INFO(); 990 1276 if (valuePtr == NULL) { 1277 TRACE_WITH_OBJ(("loadStk \"%.30s\" => ERROR: ", 1278 O2S(namePtr)), Tcl_GetObjResult(interp)); 991 1279 Tcl_DecrRefCount(namePtr); 992 1280 result = TCL_ERROR; … … 994 1282 } 995 1283 PUSH_OBJECT(valuePtr); 1284 TRACE_WITH_OBJ(("loadStk \"%.30s\" => ", O2S(namePtr)), 1285 valuePtr); 996 1286 TclDecrRefCount(namePtr); 997 1287 ADJUST_PC(1); … … 1013 1303 CACHE_STACK_INFO(); 1014 1304 if (value2Ptr == NULL) { 1305 TRACE_WITH_OBJ(("%s %u <- \"%.30s\" => ERROR: ", 1306 opName[opCode], opnd, O2S(valuePtr)), 1307 Tcl_GetObjResult(interp)); 1015 1308 Tcl_DecrRefCount(valuePtr); 1016 1309 result = TCL_ERROR; … … 1018 1311 } 1019 1312 PUSH_OBJECT(value2Ptr); 1313 TRACE_WITH_OBJ(("%s %u <- \"%.30s\" => ", 1314 opName[opCode], opnd, O2S(valuePtr)), value2Ptr); 1020 1315 TclDecrRefCount(valuePtr); 1021 1316 ADJUST_PC(pcAdjustment); … … 1029 1324 CACHE_STACK_INFO(); 1030 1325 if (value2Ptr == NULL) { 1326 TRACE_WITH_OBJ( 1327 ("storeScalarStk \"%.30s\" <- \"%.30s\" => ERROR: ", 1328 O2S(namePtr), O2S(valuePtr)), 1329 Tcl_GetObjResult(interp)); 1031 1330 Tcl_DecrRefCount(namePtr); 1032 1331 Tcl_DecrRefCount(valuePtr); … … 1035 1334 } 1036 1335 PUSH_OBJECT(value2Ptr); 1336 TRACE_WITH_OBJ( 1337 ("storeScalarStk \"%.30s\" <- \"%.30s\" => ", 1338 O2S(namePtr), 1339 O2S(valuePtr)), 1340 value2Ptr); 1037 1341 TclDecrRefCount(namePtr); 1038 1342 TclDecrRefCount(valuePtr); … … 1059 1363 CACHE_STACK_INFO(); 1060 1364 if (value2Ptr == NULL) { 1365 TRACE_WITH_OBJ( 1366 ("%s %u \"%.30s\" <- \"%.30s\" => ERROR: ", 1367 opName[opCode], opnd, O2S(elemPtr), 1368 O2S(valuePtr)), Tcl_GetObjResult(interp)); 1061 1369 Tcl_DecrRefCount(elemPtr); 1062 1370 Tcl_DecrRefCount(valuePtr); … … 1065 1373 } 1066 1374 PUSH_OBJECT(value2Ptr); 1375 TRACE_WITH_OBJ(("%s %u \"%.30s\" <- \"%.30s\" => ", 1376 opName[opCode], opnd, O2S(elemPtr), O2S(valuePtr)), 1377 value2Ptr); 1067 1378 TclDecrRefCount(elemPtr); 1068 1379 TclDecrRefCount(valuePtr); … … 1082 1393 CACHE_STACK_INFO(); 1083 1394 if (value2Ptr == NULL) { 1395 TRACE_WITH_OBJ(("storeArrayStk \"%.30s(%.30s)\" <- \"%.30s\" => ERROR: ", 1396 O2S(namePtr), O2S(elemPtr), O2S(valuePtr)), 1397 Tcl_GetObjResult(interp)); 1084 1398 Tcl_DecrRefCount(namePtr); 1085 1399 Tcl_DecrRefCount(elemPtr); … … 1089 1403 } 1090 1404 PUSH_OBJECT(value2Ptr); 1405 TRACE_WITH_OBJ(("storeArrayStk \"%.30s(%.30s)\" <- \"%.30s\" => ", 1406 O2S(namePtr), O2S(elemPtr), O2S(valuePtr)), 1407 value2Ptr); 1091 1408 TclDecrRefCount(namePtr); 1092 1409 TclDecrRefCount(elemPtr); … … 1103 1420 CACHE_STACK_INFO(); 1104 1421 if (value2Ptr == NULL) { 1422 TRACE_WITH_OBJ(("storeStk \"%.30s\" <- \"%.30s\" => ERROR: ", 1423 O2S(namePtr), O2S(valuePtr)), 1424 Tcl_GetObjResult(interp)); 1105 1425 Tcl_DecrRefCount(namePtr); 1106 1426 Tcl_DecrRefCount(valuePtr); … … 1109 1429 } 1110 1430 PUSH_OBJECT(value2Ptr); 1431 TRACE_WITH_OBJ(("storeStk \"%.30s\" <- \"%.30s\" => ", 1432 O2S(namePtr), O2S(valuePtr)), value2Ptr); 1111 1433 TclDecrRefCount(namePtr); 1112 1434 TclDecrRefCount(valuePtr); … … 1119 1441 result = tclIntType.setFromAnyProc(interp, valuePtr); 1120 1442 if (result != TCL_OK) { 1443 TRACE_WITH_OBJ(("incrScalar1 %u (by %s) => ERROR converting increment amount to int: ", 1444 opnd, O2S(valuePtr)), Tcl_GetObjResult(interp)); 1121 1445 Tcl_DecrRefCount(valuePtr); 1122 1446 goto checkForCatch; … … 1128 1452 CACHE_STACK_INFO(); 1129 1453 if (value2Ptr == NULL) { 1454 TRACE_WITH_OBJ(("incrScalar1 %u (by %ld) => ERROR: ", 1455 opnd, i), Tcl_GetObjResult(interp)); 1130 1456 Tcl_DecrRefCount(valuePtr); 1131 1457 result = TCL_ERROR; … … 1133 1459 } 1134 1460 PUSH_OBJECT(value2Ptr); 1461 TRACE_WITH_OBJ(("incrScalar1 %u (by %ld) => ", opnd, i), 1462 value2Ptr); 1135 1463 TclDecrRefCount(valuePtr); 1136 1464 ADJUST_PC(2); … … 1143 1471 result = tclIntType.setFromAnyProc(interp, valuePtr); 1144 1472 if (result != TCL_OK) { 1473 TRACE_WITH_OBJ(("%s \"%.30s\" (by %s) => ERROR converting increment amount to int: ", 1474 opName[opCode], O2S(namePtr), O2S(valuePtr)), 1475 Tcl_GetObjResult(interp)); 1145 1476 Tcl_DecrRefCount(namePtr); 1146 1477 Tcl_DecrRefCount(valuePtr); … … 1154 1485 CACHE_STACK_INFO(); 1155 1486 if (value2Ptr == NULL) { 1487 TRACE_WITH_OBJ(("%s \"%.30s\" (by %ld) => ERROR: ", 1488 opName[opCode], O2S(namePtr), i), 1489 Tcl_GetObjResult(interp)); 1156 1490 Tcl_DecrRefCount(namePtr); 1157 1491 Tcl_DecrRefCount(valuePtr); … … 1160 1494 } 1161 1495 PUSH_OBJECT(value2Ptr); 1496 TRACE_WITH_OBJ(("%s \"%.30s\" (by %ld) => ", 1497 opName[opCode], O2S(namePtr), i), value2Ptr); 1162 1498 Tcl_DecrRefCount(namePtr); 1163 1499 Tcl_DecrRefCount(valuePtr); … … 1174 1510 result = tclIntType.setFromAnyProc(interp, valuePtr); 1175 1511 if (result != TCL_OK) { 1512 TRACE_WITH_OBJ(("incrArray1 %u \"%.30s\" (by %s) => ERROR converting increment amount to int: ", 1513 opnd, O2S(elemPtr), O2S(valuePtr)), 1514 Tcl_GetObjResult(interp)); 1176 1515 Tcl_DecrRefCount(elemPtr); 1177 1516 Tcl_DecrRefCount(valuePtr); … … 1185 1524 CACHE_STACK_INFO(); 1186 1525 if (value2Ptr == NULL) { 1526 TRACE_WITH_OBJ(("incrArray1 %u \"%.30s\" (by %ld) => ERROR: ", 1527 opnd, O2S(elemPtr), i), 1528 Tcl_GetObjResult(interp)); 1187 1529 Tcl_DecrRefCount(elemPtr); 1188 1530 Tcl_DecrRefCount(valuePtr); … … 1191 1533 } 1192 1534 PUSH_OBJECT(value2Ptr); 1535 TRACE_WITH_OBJ(("incrArray1 %u \"%.30s\" (by %ld) => ", 1536 opnd, O2S(elemPtr), i), value2Ptr); 1193 1537 Tcl_DecrRefCount(elemPtr); 1194 1538 Tcl_DecrRefCount(valuePtr); … … 1206 1550 result = tclIntType.setFromAnyProc(interp, valuePtr); 1207 1551 if (result != TCL_OK) { 1552 TRACE_WITH_OBJ(("incrArrayStk \"%.30s(%.30s)\" (by %s) => ERROR converting increment amount to int: ", 1553 O2S(namePtr), O2S(elemPtr), O2S(valuePtr)), 1554 Tcl_GetObjResult(interp)); 1208 1555 Tcl_DecrRefCount(namePtr); 1209 1556 Tcl_DecrRefCount(elemPtr); … … 1218 1565 CACHE_STACK_INFO(); 1219 1566 if (value2Ptr == NULL) { 1567 TRACE_WITH_OBJ(("incrArrayStk \"%.30s(%.30s)\" (by %ld) => ERROR: ", 1568 O2S(namePtr), O2S(elemPtr), i), 1569 Tcl_GetObjResult(interp)); 1220 1570 Tcl_DecrRefCount(namePtr); 1221 1571 Tcl_DecrRefCount(elemPtr); … … 1225 1575 } 1226 1576 PUSH_OBJECT(value2Ptr); 1577 TRACE_WITH_OBJ(("incrArrayStk \"%.30s(%.30s)\" (by %ld) => ", 1578 O2S(namePtr), O2S(elemPtr), i), value2Ptr); 1227 1579 Tcl_DecrRefCount(namePtr); 1228 1580 Tcl_DecrRefCount(elemPtr); … … 1238 1590 CACHE_STACK_INFO(); 1239 1591 if (value2Ptr == NULL) { 1592 TRACE_WITH_OBJ(("incrScalar1Imm %u %ld => ERROR: ", 1593 opnd, i), Tcl_GetObjResult(interp)); 1240 1594 result = TCL_ERROR; 1241 1595 goto checkForCatch; 1242 1596 } 1243 1597 PUSH_OBJECT(value2Ptr); 1598 TRACE_WITH_OBJ(("incrScalar1Imm %u %ld => ", opnd, i), 1599 value2Ptr); 1244 1600 ADJUST_PC(3); 1245 1601 … … 1253 1609 CACHE_STACK_INFO(); 1254 1610 if (value2Ptr == NULL) { 1611 TRACE_WITH_OBJ(("%s \"%.30s\" %ld => ERROR: ", 1612 opName[opCode], O2S(namePtr), i), 1613 Tcl_GetObjResult(interp)); 1255 1614 result = TCL_ERROR; 1256 1615 Tcl_DecrRefCount(namePtr); … … 1258 1617 } 1259 1618 PUSH_OBJECT(value2Ptr); 1619 TRACE_WITH_OBJ(("%s \"%.30s\" %ld => ", 1620 opName[opCode], O2S(namePtr), i), value2Ptr); 1260 1621 TclDecrRefCount(namePtr); 1261 1622 ADJUST_PC(2); … … 1273 1634 CACHE_STACK_INFO(); 1274 1635 if (value2Ptr == NULL) { 1636 TRACE_WITH_OBJ(("incrArray1Imm %u \"%.30s\" (by %ld) => ERROR: ", 1637 opnd, O2S(elemPtr), i), 1638 Tcl_GetObjResult(interp)); 1275 1639 Tcl_DecrRefCount(elemPtr); 1276 1640 result = TCL_ERROR; … … 1278 1642 } 1279 1643 PUSH_OBJECT(value2Ptr); 1644 TRACE_WITH_OBJ(("incrArray1Imm %u \"%.30s\" (by %ld) => ", 1645 opnd, O2S(elemPtr), i), value2Ptr); 1280 1646 Tcl_DecrRefCount(elemPtr); 1281 1647 } … … 1294 1660 CACHE_STACK_INFO(); 1295 1661 if (value2Ptr == NULL) { 1662 TRACE_WITH_OBJ(("incrArrayStkImm \"%.30s(%.30s)\" (by %ld) => ERROR: ", 1663 O2S(namePtr), O2S(elemPtr), i), 1664 Tcl_GetObjResult(interp)); 1296 1665 Tcl_DecrRefCount(namePtr); 1297 1666 Tcl_DecrRefCount(elemPtr); … … 1300 1669 } 1301 1670 PUSH_OBJECT(value2Ptr); 1671 TRACE_WITH_OBJ(("incrArrayStkImm \"%.30s(%.30s)\" (by %ld) => ", 1672 O2S(namePtr), O2S(elemPtr), i), value2Ptr); 1302 1673 Tcl_DecrRefCount(namePtr); 1303 1674 Tcl_DecrRefCount(elemPtr); … … 1307 1678 case INST_JUMP1: 1308 1679 opnd = TclGetInt1AtPtr(pc+1); 1680 TRACE(("jump1 %d => new pc %u\n", opnd, 1681 (unsigned int)(pc + opnd - codePtr->codeStart))); 1309 1682 ADJUST_PC(opnd); 1310 1683 1311 1684 case INST_JUMP4: 1312 1685 opnd = TclGetInt4AtPtr(pc+1); 1686 TRACE(("jump4 %d => new pc %u\n", opnd, 1687 (unsigned int)(pc + opnd - codePtr->codeStart))); 1313 1688 ADJUST_PC(opnd); 1314 1689 … … 1334 1709 result = Tcl_GetBooleanFromObj(interp, valuePtr, &b); 1335 1710 if (result != TCL_OK) { 1711 TRACE_WITH_OBJ(("%s %d => ERROR: ", opName[opCode], 1712 opnd), Tcl_GetObjResult(interp)); 1336 1713 Tcl_DecrRefCount(valuePtr); 1337 1714 goto checkForCatch; … … 1339 1716 } 1340 1717 if (b) { 1718 TRACE(("%s %d => %.20s true, new pc %u\n", 1719 opName[opCode], opnd, O2S(valuePtr), 1720 (unsigned int)(pc+opnd - codePtr->codeStart))); 1341 1721 TclDecrRefCount(valuePtr); 1342 1722 ADJUST_PC(opnd); 1343 1723 } else { 1724 TRACE(("%s %d => %.20s false\n", opName[opCode], opnd, 1725 O2S(valuePtr))); 1344 1726 TclDecrRefCount(valuePtr); 1345 1727 ADJUST_PC(pcAdjustment); … … 1368 1750 result = Tcl_GetBooleanFromObj(interp, valuePtr, &b); 1369 1751 if (result != TCL_OK) { 1752 TRACE_WITH_OBJ(("%s %d => ERROR: ", opName[opCode], 1753 opnd), Tcl_GetObjResult(interp)); 1370 1754 Tcl_DecrRefCount(valuePtr); 1371 1755 goto checkForCatch; … … 1373 1757 } 1374 1758 if (b) { 1759 TRACE(("%s %d => %.20s true\n", opName[opCode], opnd, 1760 O2S(valuePtr))); 1375 1761 TclDecrRefCount(valuePtr); 1376 1762 ADJUST_PC(pcAdjustment); 1377 1763 } else { 1764 TRACE(("%s %d => %.20s false, new pc %u\n", 1765 opName[opCode], opnd, O2S(valuePtr), 1766 (unsigned int)(pc + opnd - codePtr->codeStart))); 1378 1767 TclDecrRefCount(valuePtr); 1379 1768 ADJUST_PC(opnd); … … 1415 1804 } 1416 1805 if (result != TCL_OK) { 1806 TRACE(("%s \"%.20s\" => ILLEGAL TYPE %s \n", 1807 opName[opCode], O2S(valuePtr), 1808 (t1Ptr? t1Ptr->name : "null"))); 1417 1809 IllegalExprOperandType(interp, opCode, valuePtr); 1418 1810 Tcl_DecrRefCount(valuePtr); … … 1438 1830 } 1439 1831 if (result != TCL_OK) { 1832 TRACE(("%s \"%.20s\" => ILLEGAL TYPE %s \n", 1833 opName[opCode], O2S(value2Ptr), 1834 (t2Ptr? t2Ptr->name : "null"))); 1440 1835 IllegalExprOperandType(interp, opCode, value2Ptr); 1441 1836 Tcl_DecrRefCount(valuePtr); … … 1456 1851 if (Tcl_IsShared(valuePtr)) { 1457 1852 PUSH_OBJECT(Tcl_NewLongObj(iResult)); 1853 TRACE(("%s %.20s %.20s => %d\n", opName[opCode], 1854 O2S(valuePtr), O2S(value2Ptr), iResult)); 1458 1855 TclDecrRefCount(valuePtr); 1459 1856 } else { /* reuse the valuePtr object */ 1857 TRACE(("%s %.20s %.20s => %d\n", 1858 opName[opCode], /* NB: stack top is off by 1 */ 1859 O2S(valuePtr), O2S(value2Ptr), iResult)); 1460 1860 Tcl_SetLongObj(valuePtr, iResult); 1461 1861 ++stackTop; /* valuePtr now on stk top has right r.c. */ … … 1613 2013 if (Tcl_IsShared(valuePtr)) { 1614 2014 PUSH_OBJECT(Tcl_NewLongObj(iResult)); 2015 TRACE(("%s %.20s %.20s => %ld\n", opName[opCode], 2016 O2S(valuePtr), O2S(value2Ptr), iResult)); 1615 2017 TclDecrRefCount(valuePtr); 1616 2018 } else { /* reuse the valuePtr object */ 2019 TRACE(("%s %.20s %.20s => %ld\n", 2020 opName[opCode], /* NB: stack top is off by 1 */ 2021 O2S(valuePtr), O2S(value2Ptr), iResult)); 1617 2022 Tcl_SetLongObj(valuePtr, iResult); 1618 2023 ++stackTop; /* valuePtr now on stk top has right r.c. */ … … 1644 2049 valuePtr, &i); 1645 2050 if (result != TCL_OK) { 2051 TRACE(("%s %.20s %.20s => ILLEGAL 1st TYPE %s\n", 2052 opName[opCode], O2S(valuePtr), O2S(value2Ptr), 2053 (valuePtr->typePtr? 2054 valuePtr->typePtr->name : "null"))); 1646 2055 IllegalExprOperandType(interp, opCode, valuePtr); 1647 2056 Tcl_DecrRefCount(valuePtr); … … 1656 2065 value2Ptr, &i2); 1657 2066 if (result != TCL_OK) { 2067 TRACE(("%s %.20s %.20s => ILLEGAL 2nd TYPE %s\n", 2068 opName[opCode], O2S(valuePtr), O2S(value2Ptr), 2069 (value2Ptr->typePtr? 2070 value2Ptr->typePtr->name : "null"))); 1658 2071 IllegalExprOperandType(interp, opCode, value2Ptr); 1659 2072 Tcl_DecrRefCount(valuePtr); … … 1672 2085 */ 1673 2086 if (i2 == 0) { 2087 TRACE(("mod %ld %ld => DIVIDE BY ZERO\n", i, i2)); 1674 2088 Tcl_DecrRefCount(valuePtr); 1675 2089 Tcl_DecrRefCount(value2Ptr); … … 1723 2137 if (Tcl_IsShared(valuePtr)) { 1724 2138 PUSH_OBJECT(Tcl_NewLongObj(iResult)); 2139 TRACE(("%s %ld %ld => %ld\n", opName[opCode], i, i2, 2140 iResult)); 1725 2141 TclDecrRefCount(valuePtr); 1726 2142 } else { /* reuse the valuePtr object */ 2143 TRACE(("%s %ld %ld => %ld\n", opName[opCode], i, i2, 2144 iResult)); /* NB: stack top is off by 1 */ 1727 2145 Tcl_SetLongObj(valuePtr, iResult); 1728 2146 ++stackTop; /* valuePtr now on stk top has right r.c. */ … … 1768 2186 } 1769 2187 if (result != TCL_OK) { 2188 TRACE(("%s %.20s %.20s => ILLEGAL 1st TYPE %s\n", 2189 opName[opCode], s, O2S(value2Ptr), 2190 (valuePtr->typePtr? 2191 valuePtr->typePtr->name : "null"))); 1770 2192 IllegalExprOperandType(interp, opCode, valuePtr); 1771 2193 Tcl_DecrRefCount(valuePtr); … … 1790 2212 } 1791 2213 if (result != TCL_OK) { 2214 TRACE(("%s %.20s %.20s => ILLEGAL 2nd TYPE %s\n", 2215 opName[opCode], O2S(valuePtr), s, 2216 (value2Ptr->typePtr? 2217 value2Ptr->typePtr->name : "null"))); 1792 2218 IllegalExprOperandType(interp, opCode, value2Ptr); 1793 2219 Tcl_DecrRefCount(valuePtr); … … 1820 2246 case INST_DIV: 1821 2247 if (d2 == 0.0) { 2248 TRACE(("div %.6g %.6g => DIVIDE BY ZERO\n", 2249 d1, d2)); 1822 2250 Tcl_DecrRefCount(valuePtr); 1823 2251 Tcl_DecrRefCount(value2Ptr); … … 1833 2261 1834 2262 if (IS_NAN(dResult) || IS_INF(dResult)) { 2263 TRACE(("%s %.20s %.20s => IEEE FLOATING PT ERROR\n", 2264 opName[opCode], O2S(valuePtr), O2S(value2Ptr))); 1835 2265 TclExprFloatError(interp, dResult); 1836 2266 result = TCL_ERROR; … … 1861 2291 */ 1862 2292 if (i2 == 0) { 2293 TRACE(("div %ld %ld => DIVIDE BY ZERO\n", 2294 i, i2)); 1863 2295 Tcl_DecrRefCount(valuePtr); 1864 2296 Tcl_DecrRefCount(value2Ptr); … … 1886 2318 if (doDouble) { 1887 2319 PUSH_OBJECT(Tcl_NewDoubleObj(dResult)); 2320 TRACE(("%s %.6g %.6g => %.6g\n", opName[opCode], 2321 d1, d2, dResult)); 1888 2322 } else { 1889 2323 PUSH_OBJECT(Tcl_NewLongObj(iResult)); 2324 TRACE(("%s %ld %ld => %ld\n", opName[opCode], 2325 i, i2, iResult)); 1890 2326 } 1891 2327 TclDecrRefCount(valuePtr); 1892 2328 } else { /* reuse the valuePtr object */ 1893 2329 if (doDouble) { /* NB: stack top is off by 1 */ 2330 TRACE(("%s %.6g %.6g => %.6g\n", opName[opCode], 2331 d1, d2, dResult)); 1894 2332 Tcl_SetDoubleObj(valuePtr, dResult); 1895 2333 } else { 2334 TRACE(("%s %ld %ld => %ld\n", opName[opCode], 2335 i, i2, iResult)); 1896 2336 Tcl_SetLongObj(valuePtr, iResult); 1897 2337 } … … 1923 2363 } 1924 2364 if (result != TCL_OK) { 2365 TRACE(("%s \"%.20s\" => ILLEGAL TYPE %s \n", 2366 opName[opCode], s, 2367 (tPtr? tPtr->name : "null"))); 1925 2368 IllegalExprOperandType(interp, opCode, valuePtr); 1926 2369 goto checkForCatch; 1927 2370 } 1928 2371 } 2372 TRACE_WITH_OBJ(("uplus %s => ", O2S(valuePtr)), valuePtr); 1929 2373 } 1930 2374 ADJUST_PC(1); … … 1955 2399 } 1956 2400 if (result != TCL_OK) { 2401 TRACE(("%s \"%.20s\" => ILLEGAL TYPE %s\n", 2402 opName[opCode], s, 2403 (tPtr? tPtr->name : "null"))); 1957 2404 IllegalExprOperandType(interp, opCode, valuePtr); 1958 2405 Tcl_DecrRefCount(valuePtr); … … 1970 2417 objPtr = Tcl_NewLongObj( 1971 2418 (opCode == INST_UMINUS)? -i : !i); 2419 TRACE_WITH_OBJ(("%s %ld => ", opName[opCode], i), 2420 objPtr); /* NB: stack top is off by 1 */ 1972 2421 } else { 1973 2422 d = valuePtr->internalRep.doubleValue; … … 1981 2430 objPtr = Tcl_NewLongObj((d==0.0)? 1 : 0); 1982 2431 } 2432 TRACE_WITH_OBJ(("%s %.6g => ", opName[opCode], d), 2433 objPtr); /* NB: stack top is off by 1 */ 1983 2434 } 1984 2435 PUSH_OBJECT(objPtr); … … 1992 2443 Tcl_SetLongObj(valuePtr, 1993 2444 (opCode == INST_UMINUS)? -i : !i); 2445 TRACE_WITH_OBJ(("%s %ld => ", opName[opCode], i), 2446 valuePtr); /* NB: stack top is off by 1 */ 1994 2447 } else { 1995 2448 d = valuePtr->internalRep.doubleValue; … … 2003 2456 Tcl_SetLongObj(valuePtr, (d==0.0)? 1 : 0); 2004 2457 } 2458 TRACE_WITH_OBJ(("%s %.6g => ", opName[opCode], d), 2459 valuePtr); /* NB: stack top is off by 1 */ 2005 2460 } 2006 2461 ++stackTop; /* valuePtr now on stk top has right r.c. */ … … 2026 2481 valuePtr, &i); 2027 2482 if (result != TCL_OK) { /* try to convert to double */ 2483 TRACE(("bitnot \"%.20s\" => ILLEGAL TYPE %s\n", 2484 O2S(valuePtr), (tPtr? tPtr->name : "null"))); 2028 2485 IllegalExprOperandType(interp, opCode, valuePtr); 2029 2486 Tcl_DecrRefCount(valuePtr); … … 2035 2492 if (Tcl_IsShared(valuePtr)) { 2036 2493 PUSH_OBJECT(Tcl_NewLongObj(~i)); 2494 TRACE(("bitnot 0x%lx => (%lu)\n", i, ~i)); 2037 2495 TclDecrRefCount(valuePtr); 2038 2496 } else { … … 2042 2500 Tcl_SetLongObj(valuePtr, ~i); 2043 2501 ++stackTop; /* valuePtr now on stk top has right r.c. */ 2502 TRACE(("bitnot 0x%lx => (%lu)\n", i, ~i)); 2044 2503 } 2045 2504 } … … 2056 2515 2057 2516 if ((opnd < 0) || (opnd > LAST_BUILTIN_FUNC)) { 2517 TRACE(("UNRECOGNIZED BUILTIN FUNC CODE %d\n", opnd)); 2058 2518 panic("TclExecuteByteCode: unrecognized builtin function code %d", opnd); 2059 2519 } … … 2068 2528 goto checkForCatch; 2069 2529 } 2530 TRACE_WITH_OBJ(("callBuiltinFunc1 %d => ", opnd), 2531 stackPtr[stackTop].o); 2070 2532 } 2071 2533 ADJUST_PC(2); … … 2093 2555 goto checkForCatch; 2094 2556 } 2557 TRACE_WITH_OBJ(("callFunc1 %d => ", objc), 2558 stackPtr[stackTop].o); 2095 2559 ADJUST_PC(2); 2096 2560 } … … 2163 2627 d = valuePtr->internalRep.doubleValue; 2164 2628 if (IS_NAN(d) || IS_INF(d)) { 2629 TRACE(("tryCvtToNumeric \"%.20s\" => IEEE FLOATING PT ERROR\n", 2630 O2S(valuePtr))); 2165 2631 TclExprFloatError(interp, d); 2166 2632 result = TCL_ERROR; … … 2170 2636 shared = shared; /* lint, shared not used. */ 2171 2637 converted = converted; /* lint, converted not used. */ 2638 TRACE(("tryCvtToNumeric \"%.20s\" => numeric, %s, %s\n", 2639 O2S(valuePtr), 2640 (converted? "converted" : "not converted"), 2641 (shared? "shared" : "not shared"))); 2642 } else { 2643 TRACE(("tryCvtToNumeric \"%.20s\" => not numeric\n", 2644 O2S(valuePtr))); 2172 2645 } 2173 2646 } … … 2187 2660 codePtr); 2188 2661 if (rangePtr == NULL) { 2662 TRACE(("break => no encl. loop or catch, returning TCL_BREAK\n")); 2189 2663 result = TCL_BREAK; 2190 2664 goto abnormalReturn; /* no catch exists to check */ … … 2193 2667 case LOOP_EXCEPTION_RANGE: 2194 2668 result = TCL_OK; 2669 TRACE(("break => range at %d, new pc %d\n", 2670 rangePtr->codeOffset, rangePtr->breakOffset)); 2195 2671 break; 2196 2672 case CATCH_EXCEPTION_RANGE: 2197 2673 result = TCL_BREAK; 2674 TRACE(("break => ...\n")); 2198 2675 goto processCatch; /* it will use rangePtr */ 2199 2676 default: … … 2216 2693 codePtr); 2217 2694 if (rangePtr == NULL) { 2695 TRACE(("continue => no encl. loop or catch, returning TCL_CONTINUE\n")); 2218 2696 result = TCL_CONTINUE; 2219 2697 goto abnormalReturn; … … 2222 2700 case LOOP_EXCEPTION_RANGE: 2223 2701 if (rangePtr->continueOffset == -1) { 2702 TRACE(("continue => loop w/o continue, checking for catch\n")); 2224 2703 goto checkForCatch; 2225 2704 } else { 2226 2705 result = TCL_OK; 2706 TRACE(("continue => range at %d, new pc %d\n", 2707 rangePtr->codeOffset, rangePtr->continueOffset)); 2227 2708 } 2228 2709 break; 2229 2710 case CATCH_EXCEPTION_RANGE: 2230 2711 result = TCL_CONTINUE; 2712 TRACE(("continue => ...\n")); 2231 2713 goto processCatch; /* it will use rangePtr */ 2232 2714 default: … … 2262 2744 TclSetVarScalar(iterVarPtr); 2263 2745 TclClearVarUndefined(iterVarPtr); 2746 TRACE(("foreach_start4 %u => loop iter count temp %d\n", 2747 opnd, iterTmpIndex)); 2264 2748 } 2265 2749 ADJUST_PC(5); … … 2310 2794 result = Tcl_ListObjLength(interp, listPtr, &listLen); 2311 2795 if (result != TCL_OK) { 2796 TRACE_WITH_OBJ(("foreach_step4 %u => ERROR converting list %ld, \"%s\": ", 2797 opnd, i, O2S(listPtr)), 2798 Tcl_GetObjResult(interp)); 2312 2799 goto checkForCatch; 2313 2800 } … … 2353 2840 CACHE_STACK_INFO(); 2354 2841 if (value2Ptr == NULL) { 2842 TRACE_WITH_OBJ(("foreach_step4 %u => ERROR init. index temp %d: ", 2843 opnd, varIndex), 2844 Tcl_GetObjResult(interp)); 2355 2845 if (setEmptyStr) { 2356 2846 Tcl_DecrRefCount(elemPtr); /* unneeded */ … … 2372 2862 2373 2863 PUSH_OBJECT(Tcl_NewLongObj(continueLoop)); 2864 TRACE(("foreach_step4 %u => %d lists, iter %d, %s loop\n", 2865 opnd, numLists, iterNum, 2866 (continueLoop? "continue" : "exit"))); 2374 2867 } 2375 2868 ADJUST_PC(5); … … 2382 2875 */ 2383 2876 catchStackPtr[++catchTop] = stackTop; 2877 TRACE(("beginCatch4 %u => catchTop=%d, stackTop=%d\n", 2878 TclGetUInt4AtPtr(pc+1), catchTop, stackTop)); 2384 2879 ADJUST_PC(5); 2385 2880 … … 2387 2882 catchTop--; 2388 2883 result = TCL_OK; 2884 TRACE(("endCatch => catchTop=%d\n", catchTop)); 2389 2885 ADJUST_PC(1); 2390 2886 2391 2887 case INST_PUSH_RESULT: 2392 2888 PUSH_OBJECT(Tcl_GetObjResult(interp)); 2889 TRACE_WITH_OBJ(("pushResult => "), Tcl_GetObjResult(interp)); 2393 2890 ADJUST_PC(1); 2394 2891 2395 2892 case INST_PUSH_RETURN_CODE: 2396 2893 PUSH_OBJECT(Tcl_NewLongObj(result)); 2894 TRACE(("pushReturnCode => %u\n", result)); 2397 2895 ADJUST_PC(1); 2398 2896 2399 2897 default: 2898 TRACE(("UNRECOGNIZED INSTRUCTION %u\n", opCode)); 2400 2899 panic("TclExecuteByteCode: unrecognized opCode %u", opCode); 2401 2900 } /* end of switch on opCode */ … … 2427 2926 rangePtr = TclGetExceptionRangeForPc(pc, /*catchOnly*/ 1, codePtr); 2428 2927 if (rangePtr == NULL) { 2928 TRACE((" ... no enclosing catch, returning %s\n", 2929 StringForResultCode(result))); 2429 2930 goto abnormalReturn; 2430 2931 } … … 2444 2945 TclDecrRefCount(valuePtr); 2445 2946 } 2947 TRACE((" ... found catch at %d, catchTop=%d, unwound to %d, new pc %u\n", 2948 rangePtr->codeOffset, catchTop, catchStackPtr[catchTop], 2949 (unsigned int)(rangePtr->catchOffset))); 2446 2950 pc = (codePtr->codeStart + rangePtr->catchOffset); 2447 2951 continue; /* restart the execution loop at pc */ … … 2471 2975 #undef STATIC_CATCH_STACK_SIZE 2472 2976 } 2977 2978 2979 /* 2980 *---------------------------------------------------------------------- 2981 * 2982 * PrintByteCodeInfo -- 2983 * 2984 * This procedure prints a summary about a bytecode object to stdout. 2985 * It is called by TclExecuteByteCode when starting to execute the 2986 * bytecode object if tclTraceExec has the value 2 or more. 2987 * 2988 * Results: 2989 * None. 2990 * 2991 * Side effects: 2992 * None. 2993 * 2994 *---------------------------------------------------------------------- 2995 */ 2996 2997 static void 2998 PrintByteCodeInfo(codePtr) 2999 register ByteCode *codePtr; /* The bytecode whose summary is printed 3000 * to stdout. */ 3001 { 3002 Proc *procPtr = codePtr->procPtr; 3003 int numCmds = codePtr->numCommands; 3004 int numObjs = codePtr->numObjects; 3005 int objBytes, i; 3006 3007 objBytes = (numObjs * sizeof(Tcl_Obj)); 3008 for (i = 0; i < numObjs; i++) { 3009 Tcl_Obj *litObjPtr = codePtr->objArrayPtr[i]; 3010 if (litObjPtr->bytes != NULL) { 3011 objBytes += litObjPtr->length; 3012 } 3013 } 3014 3015 fprintf(stdout, "\nExecuting ByteCode 0x%x, ref ct %u, epoch %u, interp 0x%x(epoch %u)\n", 3016 (unsigned int) codePtr, codePtr->refCount, 3017 codePtr->compileEpoch, (unsigned int) codePtr->iPtr, 3018 codePtr->iPtr->compileEpoch); 3019 3020 fprintf(stdout, " Source: "); 3021 TclPrintSource(stdout, codePtr->source, 70); 3022 3023 fprintf(stdout, "\n Cmds %d, chars %d, inst %u, objs %u, aux %d, stk depth %u, code/src %.2fn", 3024 numCmds, codePtr->numSrcChars, codePtr->numCodeBytes, numObjs, 3025 codePtr->numAuxDataItems, codePtr->maxStackDepth, 3026 (codePtr->numSrcChars? 3027 ((float)codePtr->totalSize)/((float)codePtr->numSrcChars) : 0.0)); 3028 3029 fprintf(stdout, " Code %zu = %u(header)+%d(inst)+%d(objs)+%u(exc)+%u(aux)+%d(cmd map)\n", 3030 codePtr->totalSize, sizeof(ByteCode), codePtr->numCodeBytes, 3031 objBytes, (codePtr->numExcRanges * sizeof(ExceptionRange)), 3032 (codePtr->numAuxDataItems * sizeof(AuxData)), 3033 codePtr->numCmdLocBytes); 3034 3035 if (procPtr != NULL) { 3036 fprintf(stdout, 3037 " Proc 0x%x, ref ct %d, args %d, compiled locals %d\n", 3038 (unsigned int) procPtr, procPtr->refCount, 3039 procPtr->numArgs, procPtr->numCompiledLocals); 3040 } 3041 } 3042 3043 3044 /* 3045 *---------------------------------------------------------------------- 3046 * 3047 * ValidatePcAndStackTop -- 3048 * 3049 * This procedure is called by TclExecuteByteCode when debugging to 3050 * verify that the program counter and stack top are valid during 3051 * execution. 3052 * 3053 * Results: 3054 * None. 3055 * 3056 * Side effects: 3057 * Prints a message to stderr and panics if either the pc or stack 3058 * top are invalid. 3059 * 3060 *---------------------------------------------------------------------- 3061 */ 3062 3063 #ifdef TCL_COMPILE_DEBUG 3064 static void 3065 ValidatePcAndStackTop(codePtr, pc, stackTop, stackLowerBound, stackUpperBound) 3066 register ByteCode *codePtr; /* The bytecode whose summary is printed 3067 * to stdout. */ 3068 unsigned char *pc; /* Points to first byte of a bytecode 3069 * instruction. The program counter. */ 3070 int stackTop; /* Current stack top. Must be between 3071 * stackLowerBound and stackUpperBound 3072 * (inclusive). */ 3073 int stackLowerBound; /* Smallest legal value for stackTop. */ 3074 int stackUpperBound; /* Greatest legal value for stackTop. */ 3075 { 3076 unsigned int relativePc = (unsigned int) (pc - codePtr->codeStart); 3077 unsigned int codeStart = (unsigned int) codePtr->codeStart; 3078 unsigned int codeEnd = (unsigned int) 3079 (codePtr->codeStart + codePtr->numCodeBytes); 3080 unsigned char opCode = *pc; 3081 3082 if (((unsigned int) pc < codeStart) || ((unsigned int) pc > codeEnd)) { 3083 fprintf(stderr, "\nBad instruction pc 0x%x in TclExecuteByteCode\n", 3084 (unsigned int) pc); 3085 panic("TclExecuteByteCode execution failure: bad pc"); 3086 } 3087 if ((unsigned int) opCode > LAST_INST_OPCODE) { 3088 fprintf(stderr, "\nBad opcode %d at pc %u in TclExecuteByteCode\n", 3089 (unsigned int) opCode, relativePc); 3090 panic("TclExecuteByteCode execution failure: bad opcode"); 3091 } 3092 if ((stackTop < stackLowerBound) || (stackTop > stackUpperBound)) { 3093 int numChars; 3094 char *cmd = GetSrcInfoForPc(pc, codePtr, &numChars); 3095 char *ellipsis = ""; 3096 3097 fprintf(stderr, "\nBad stack top %d at pc %u in TclExecuteByteCode", 3098 stackTop, relativePc); 3099 if (cmd != NULL) { 3100 if (numChars > 100) { 3101 numChars = 100; 3102 ellipsis = "..."; 3103 } 3104 fprintf(stderr, "\n executing %.*s%s\n", numChars, cmd, 3105 ellipsis); 3106 } else { 3107 fprintf(stderr, "\n"); 3108 } 3109 panic("TclExecuteByteCode execution failure: bad stack top"); 3110 } 3111 } 3112 #endif /* TCL_COMPILE_DEBUG */ 2473 3113 2474 3114 … … 3631 4271 3632 4272 4273 #ifdef TCL_COMPILE_STATS 4274 /* 4275 *---------------------------------------------------------------------- 4276 * 4277 * TclLog2 -- 4278 * 4279 * Procedure used while collecting compilation statistics to determine 4280 * the log base 2 of an integer. 4281 * 4282 * Results: 4283 * Returns the log base 2 of the operand. If the argument is less 4284 * than or equal to zero, a zero is returned. 4285 * 4286 * Side effects: 4287 * None. 4288 * 4289 *---------------------------------------------------------------------- 4290 */ 4291 4292 int 4293 TclLog2(value) 4294 register int value; /* The integer for which to compute the 4295 * log base 2. */ 4296 { 4297 register int n = value; 4298 register int result = 0; 4299 4300 while (n > 1) { 4301 n = n >> 1; 4302 result++; 4303 } 4304 return result; 4305 } 4306 4307 4308 /* 4309 *---------------------------------------------------------------------- 4310 * 4311 * EvalStatsCmd -- 4312 * 4313 * Implements the "evalstats" command that prints instruction execution 4314 * counts to stdout. 4315 * 4316 * Results: 4317 * Standard Tcl results. 4318 * 4319 * Side effects: 4320 * None. 4321 * 4322 *---------------------------------------------------------------------- 4323 */ 4324 4325 static int 4326 EvalStatsCmd(unused, interp, argc, argv) 4327 ClientData unused; /* Unused. */ 4328 Tcl_Interp *interp; /* The current interpreter. */ 4329 int argc; /* The number of arguments. */ 4330 char **argv; /* The argument strings. */ 4331 { 4332 register double total = 0.0; 4333 register int i; 4334 int maxSizeDecade = 0; 4335 double totalHeaderBytes = (tclNumCompilations * sizeof(ByteCode)); 4336 4337 for (i = 0; i < 256; i++) { 4338 if (instructionCount[i] != 0) { 4339 total += instructionCount[i]; 4340 } 4341 } 4342 4343 for (i = 31; i >= 0; i--) { 4344 if ((tclSourceCount[i] > 0) && (tclByteCodeCount[i] > 0)) { 4345 maxSizeDecade = i; 4346 break; 4347 } 4348 } 4349 4350 fprintf(stdout, "\nNumber of compilations %ld\n", 4351 tclNumCompilations); 4352 fprintf(stdout, "Number of executions %ld\n", 4353 numExecutions); 4354 fprintf(stdout, "Average executions/compilation %.0f\n", 4355 ((float) numExecutions/tclNumCompilations)); 4356 4357 fprintf(stdout, "\nInstructions executed %.0f\n", 4358 total); 4359 fprintf(stdout, "Average instructions/compile %.0f\n", 4360 total/tclNumCompilations); 4361 fprintf(stdout, "Average instructions/execution %.0f\n", 4362 total/numExecutions); 4363 4364 fprintf(stdout, "\nTotal source bytes %.6g\n", 4365 tclTotalSourceBytes); 4366 fprintf(stdout, "Total code bytes %.6g\n", 4367 tclTotalCodeBytes); 4368 fprintf(stdout, "Average code/compilation %.0f\n", 4369 tclTotalCodeBytes/tclNumCompilations); 4370 fprintf(stdout, "Average code/source %.2f\n", 4371 tclTotalCodeBytes/tclTotalSourceBytes); 4372 fprintf(stdout, "Current source bytes %.6g\n", 4373 tclCurrentSourceBytes); 4374 fprintf(stdout, "Current code bytes %.6g\n", 4375 tclCurrentCodeBytes); 4376 fprintf(stdout, "Current code/source %.2f\n", 4377 tclCurrentCodeBytes/tclCurrentSourceBytes); 4378 4379 fprintf(stdout, "\nTotal objects allocated %ld\n", 4380 tclObjsAlloced); 4381 fprintf(stdout, "Total objects freed %ld\n", 4382 tclObjsFreed); 4383 fprintf(stdout, "Current objects: %ld\n", 4384 (tclObjsAlloced - tclObjsFreed)); 4385 4386 fprintf(stdout, "\nBreakdown of code byte requirements:\n"); 4387 fprintf(stdout, " Total bytes Pct of Avg per\n"); 4388 fprintf(stdout, " all code compile\n"); 4389 fprintf(stdout, "Total code %12.6g 100%% %8.2f\n", 4390 tclTotalCodeBytes, tclTotalCodeBytes/tclNumCompilations); 4391 fprintf(stdout, "Header %12.6g %8.2f%% %8.2f\n", 4392 totalHeaderBytes, 4393 ((totalHeaderBytes * 100.0) / tclTotalCodeBytes), 4394 totalHeaderBytes/tclNumCompilations); 4395 fprintf(stdout, "Instructions %12.6g %8.2f%% %8.2f\n", 4396 tclTotalInstBytes, 4397 ((tclTotalInstBytes * 100.0) / tclTotalCodeBytes), 4398 tclTotalInstBytes/tclNumCompilations); 4399 fprintf(stdout, "Objects %12.6g %8.2f%% %8.2f\n", 4400 tclTotalObjBytes, 4401 ((tclTotalObjBytes * 100.0) / tclTotalCodeBytes), 4402 tclTotalObjBytes/tclNumCompilations); 4403 fprintf(stdout, "Exception table %12.6g %8.2f%% %8.2f\n", 4404 tclTotalExceptBytes, 4405 ((tclTotalExceptBytes * 100.0) / tclTotalCodeBytes), 4406 tclTotalExceptBytes/tclNumCompilations); 4407 fprintf(stdout, "Auxiliary data %12.6g %8.2f%% %8.2f\n", 4408 tclTotalAuxBytes, 4409 ((tclTotalAuxBytes * 100.0) / tclTotalCodeBytes), 4410 tclTotalAuxBytes/tclNumCompilations); 4411 fprintf(stdout, "Command map %12.6g %8.2f%% %8.2f\n", 4412 tclTotalCmdMapBytes, 4413 ((tclTotalCmdMapBytes * 100.0) / tclTotalCodeBytes), 4414 tclTotalCmdMapBytes/tclNumCompilations); 4415 4416 fprintf(stdout, "\nSource and ByteCode size distributions:\n"); 4417 fprintf(stdout, " binary decade source code\n"); 4418 for (i = 0; i <= maxSizeDecade; i++) { 4419 int decadeLow, decadeHigh; 4420 4421 if (i == 0) { 4422 decadeLow = 0; 4423 } else { 4424 decadeLow = 1 << i; 4425 } 4426 decadeHigh = (1 << (i+1)) - 1; 4427 fprintf(stdout, " %6d -%6d %6d %6d\n", 4428 decadeLow, decadeHigh, 4429 tclSourceCount[i], tclByteCodeCount[i]); 4430 } 4431 4432 fprintf(stdout, "\nInstruction counts:\n"); 4433 for (i = 0; i < 256; i++) { 4434 if (instructionCount[i]) { 4435 fprintf(stdout, "%20s %8d %6.2f%%\n", 4436 opName[i], instructionCount[i], 4437 (instructionCount[i] * 100.0)/total); 4438 } 4439 } 4440 4441 #ifdef TCL_MEM_DEBUG 4442 fprintf(stdout, "\nHeap Statistics:\n"); 4443 TclDumpMemoryInfo(stdout); 4444 #endif /* TCL_MEM_DEBUG */ 4445 4446 return TCL_OK; 4447 } 4448 #endif /* TCL_COMPILE_STATS */ 4449 4450 3633 4451 /* 3634 4452 *---------------------------------------------------------------------- … … 3940 4758 panic("UpdateStringOfCmdName should never be invoked"); 3941 4759 } 4760 4761 4762 #ifdef TCL_COMPILE_DEBUG 4763 /* 4764 *---------------------------------------------------------------------- 4765 * 4766 * StringForResultCode -- 4767 * 4768 * Procedure that returns a human-readable string representing a 4769 * Tcl result code such as TCL_ERROR. 4770 * 4771 * Results: 4772 * If the result code is one of the standard Tcl return codes, the 4773 * result is a string representing that code such as "TCL_ERROR". 4774 * Otherwise, the result string is that code formatted as a 4775 * sequence of decimal digit characters. Note that the resulting 4776 * string must not be modified by the caller. 4777 * 4778 * Side effects: 4779 * None. 4780 * 4781 *---------------------------------------------------------------------- 4782 */ 4783 4784 static char * 4785 StringForResultCode(result) 4786 int result; /* The Tcl result code for which to 4787 * generate a string. */ 4788 { 4789 static char buf[20]; 4790 4791 if ((result >= TCL_OK) && (result <= TCL_CONTINUE)) { 4792 return resultStrings[result]; 4793 } 4794 TclFormatInt(buf, result); 4795 return buf; 4796 } 4797 #endif /* TCL_COMPILE_DEBUG */
Note:
See TracChangeset
for help on using the changeset viewer.