uwx_trace.c revision 117392
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
28#ifdef UWX_TRACE_ENABLE
29
30void uwx_trace_init(struct uwx_env *env)
31{
32    char *tstr;
33
34    tstr = getenv("UWX_TRACE");
35    if (tstr != NULL) {
36	while (*tstr != '\0') {
37	    switch (*tstr) {
38		case 'i': env->trace |= UWX_TRACE_UINFO; break;
39		case 't': env->trace |= UWX_TRACE_UTABLE; break;
40		case 'b': env->trace |= UWX_TRACE_SB; break;
41		case 'r': env->trace |= UWX_TRACE_RSTATE; break;
42		case 's': env->trace |= UWX_TRACE_STEP; break;
43		case 'c': env->trace |= UWX_TRACE_CONTEXT; break;
44		case 'C': env->trace |= UWX_TRACE_COPYIN; break;
45		case 'L': env->trace |= UWX_TRACE_LOOKUPIP; break;
46		case '?':
47#ifdef _KERNEL
48		    printf("UWX_TRACE flag `%c' unknown.\n", *tstr);
49#else
50		    fprintf(stderr, "UWX_TRACE flags:\n");
51		    fprintf(stderr, "  i: unwind info\n");
52		    fprintf(stderr, "  t: unwind table searching\n");
53		    fprintf(stderr, "  b: scoreboard management\n");
54		    fprintf(stderr, "  r: register state vector\n");
55		    fprintf(stderr, "  s: step\n");
56		    fprintf(stderr, "  c: context\n");
57		    fprintf(stderr, "  C: copyin callback\n");
58		    fprintf(stderr, "  L: lookup ip callback\n");
59		    exit(1);
60#endif
61	    }
62	    tstr++;
63	}
64    }
65}
66
67char *uwx_sb_rnames[] = {
68    "RP", "PSP", "PFS",
69    "PREDS", "UNAT", "PRIUNAT", "RNAT", "LC", "FPSR",
70    "GR4", "GR5", "GR6", "GR7",
71    "BR1", "BR2", "BR3", "BR4", "BR5",
72    "FR2", "FR3", "FR4", "FR5",
73    "FR16", "FR17", "FR18", "FR19",
74    "FR20", "FR21", "FR22", "FR23",
75    "FR24", "FR25", "FR26", "FR27",
76    "FR28", "FR29", "FR30", "FR31",
77};
78
79void uwx_dump_rstate(int regid, uint64_t rstate)
80{
81    int reg;
82
83    if (rstate == UWX_DISP_NONE)
84	return;
85    printf("    %-7s", uwx_sb_rnames[regid]);
86    switch (UWX_GET_DISP_CODE(rstate)) {
87	case UWX_DISP_NONE:
88	    printf("    unchanged\n");
89	    break;
90	case UWX_DISP_SPPLUS(0):
91	    printf("    SP + %d\n", (int)rstate & ~0x07);
92	    break;
93	case UWX_DISP_SPREL(0):
94	    printf("    [SP + %d]\n", (int)rstate & ~0x07);
95	    break;
96	case UWX_DISP_PSPREL(0):
97	    printf("    [PSP + 16 - %d]\n", (int)rstate & ~0x07);
98	    break;
99	case UWX_DISP_REG(0):
100	    reg = UWX_GET_DISP_REGID(rstate);
101	    if (reg == UWX_REG_PFS)
102		printf("    [AR.PFS]\n");
103	    else if (reg == UWX_REG_UNAT)
104		printf("    [AR.UNAT]\n");
105	    else if (reg >= UWX_REG_GR(0) && reg < UWX_REG_GR(128))
106		printf("    [GR%d]\n", reg - UWX_REG_GR(0));
107	    else if (reg >= UWX_REG_FR(0) && reg < UWX_REG_FR(128))
108		printf("    [FR%d]\n", reg - UWX_REG_FR(0));
109	    else if (reg >= UWX_REG_BR(0) && reg < UWX_REG_BR(8))
110		printf("    [BR%d]\n", reg - UWX_REG_BR(0));
111	    else
112		printf("    [reg %d]\n", reg);
113	    break;
114	default:
115	    printf("    <%08llx>\n", (unsigned long long)rstate);
116	    break;
117    }
118}
119
120void uwx_dump_scoreboard(
121    struct uwx_scoreboard *scoreboard,
122    int nsbreg,
123    struct uwx_rhdr *rhdr,
124    int cur_slot,
125    int ip_slot)
126{
127    int i;
128
129    if (rhdr->is_prologue)
130	printf("  Prologue region (start = %d, length = %d)\n",
131		    (int)cur_slot, (int)rhdr->rlen);
132    else
133	printf("  Body region (start = %d, length = %d, ecount = %d)\n",
134		    cur_slot, (int)rhdr->rlen, rhdr->ecount);
135    if (ip_slot < rhdr->rlen)
136	printf("    IP is in this region (offset = %d)\n", ip_slot);
137    for (i = 0; i < nsbreg; i++)
138	uwx_dump_rstate(i, scoreboard->rstate[i]);
139}
140
141#endif /* UWX_TRACE_ENABLE */
142