uwx_trace.c revision 121642
1/* 2Copyright (c) 2003 Hewlett-Packard Development Company, L.P. 3Permission is hereby granted, free of charge, to any person 4obtaining a copy of this software and associated documentation 5files (the "Software"), to deal in the Software without 6restriction, including without limitation the rights to use, 7copy, modify, merge, publish, distribute, sublicense, and/or sell 8copies of the Software, and to permit persons to whom the 9Software is furnished to do so, subject to the following 10conditions: 11 12The above copyright notice and this permission notice shall be 13included in all copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22OTHER DEALINGS IN THE SOFTWARE. 23*/ 24 25#include "uwx_env.h" 26#include "uwx_uinfo.h" 27#include "uwx_scoreboard.h" 28#include "uwx_trace.h" 29 30#ifdef UWX_TRACE_ENABLE 31 32void uwx_trace_init(struct uwx_env *env) 33{ 34 char *tstr; 35 36 tstr = getenv("UWX_TRACE"); 37 if (tstr != NULL) { 38 while (*tstr != '\0') { 39 switch (*tstr) { 40 case 'i': env->trace |= UWX_TRACE_UINFO; break; 41 case 't': env->trace |= UWX_TRACE_UTABLE; break; 42 case 'b': env->trace |= UWX_TRACE_SB; break; 43 case 'r': env->trace |= UWX_TRACE_RSTATE; break; 44 case 's': env->trace |= UWX_TRACE_STEP; break; 45 case 'c': env->trace |= UWX_TRACE_CONTEXT; break; 46 case 'C': env->trace |= UWX_TRACE_COPYIN; break; 47 case 'L': env->trace |= UWX_TRACE_LOOKUPIP; break; 48 case '?': 49#ifdef _KERNEL 50 printf("UWX_TRACE flag `%c' unknown.\n", *tstr); 51#else 52 fprintf(stderr, "UWX_TRACE flags:\n"); 53 fprintf(stderr, " i: unwind info\n"); 54 fprintf(stderr, " t: unwind table searching\n"); 55 fprintf(stderr, " b: scoreboard management\n"); 56 fprintf(stderr, " r: register state vector\n"); 57 fprintf(stderr, " s: step\n"); 58 fprintf(stderr, " c: context\n"); 59 fprintf(stderr, " C: copyin callback\n"); 60 fprintf(stderr, " L: lookup ip callback\n"); 61 exit(1); 62#endif 63 } 64 tstr++; 65 } 66 } 67} 68 69char *uwx_sb_rnames[] = { 70 "RP", "PSP", "PFS", 71 "PREDS", "UNAT", "PRIUNAT", "RNAT", "LC", "FPSR", 72 "GR4", "GR5", "GR6", "GR7", 73 "BR1", "BR2", "BR3", "BR4", "BR5", 74 "FR2", "FR3", "FR4", "FR5", 75 "FR16", "FR17", "FR18", "FR19", 76 "FR20", "FR21", "FR22", "FR23", 77 "FR24", "FR25", "FR26", "FR27", 78 "FR28", "FR29", "FR30", "FR31", 79}; 80 81void uwx_dump_rstate(int regid, uint64_t rstate) 82{ 83 int reg; 84 85 if (rstate == UWX_DISP_NONE) 86 return; 87 printf(" %-7s", uwx_sb_rnames[regid]); 88 switch (UWX_GET_DISP_CODE(rstate)) { 89 case UWX_DISP_NONE: 90 printf(" unchanged\n"); 91 break; 92 case UWX_DISP_SPPLUS(0): 93 printf(" SP + %d\n", (int)rstate & ~0x07); 94 break; 95 case UWX_DISP_SPREL(0): 96 printf(" [SP + %d]\n", (int)rstate & ~0x07); 97 break; 98 case UWX_DISP_PSPREL(0): 99 printf(" [PSP + 16 - %d]\n", (int)rstate & ~0x07); 100 break; 101 case UWX_DISP_REG(0): 102 reg = UWX_GET_DISP_REGID(rstate); 103 if (reg == UWX_REG_AR_PFS) 104 printf(" [AR.PFS]\n"); 105 else if (reg == UWX_REG_AR_UNAT) 106 printf(" [AR.UNAT]\n"); 107 else if (reg >= UWX_REG_GR(0) && reg < UWX_REG_GR(128)) 108 printf(" [GR%d]\n", reg - UWX_REG_GR(0)); 109 else if (reg >= UWX_REG_FR(0) && reg < UWX_REG_FR(128)) 110 printf(" [FR%d]\n", reg - UWX_REG_FR(0)); 111 else if (reg >= UWX_REG_BR(0) && reg < UWX_REG_BR(8)) 112 printf(" [BR%d]\n", reg - UWX_REG_BR(0)); 113 else 114 printf(" [reg %d]\n", reg); 115 break; 116 default: 117 printf(" <%08llx>\n", (unsigned long long)rstate); 118 break; 119 } 120} 121 122void uwx_dump_scoreboard( 123 struct uwx_scoreboard *scoreboard, 124 int nsbreg, 125 struct uwx_rhdr *rhdr, 126 int cur_slot, 127 int ip_slot) 128{ 129 int i; 130 131 if (rhdr->is_prologue) 132 printf(" Prologue region (start = %d, length = %d)\n", 133 (int)cur_slot, (int)rhdr->rlen); 134 else 135 printf(" Body region (start = %d, length = %d, ecount = %d)\n", 136 cur_slot, (int)rhdr->rlen, rhdr->ecount); 137 if (ip_slot < rhdr->rlen) 138 printf(" IP is in this region (offset = %d)\n", ip_slot); 139 for (i = 0; i < nsbreg; i++) 140 uwx_dump_rstate(i, scoreboard->rstate[i]); 141} 142 143#endif /* UWX_TRACE_ENABLE */ 144