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