dbgif_print.c
17.8 KB
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
/*
* ==========================================================================
* Copyright (c) 1993, Silicon Graphics, Inc. All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied
* or duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished
* rights reserved under the Copyright Laws of the United States.
* ==========================================================================
* Module : Implementation of tracing routines
*
* Author : First Last (login)
* Owner : First Last (login)
* Reviewer : First Last (login)
*
* $Source: /root/leakn64/depot/rf/sw/bbplayer/debugger/dbgif/dbgif_print.c,v $
* $Revision: 1.1.1.2 $
* $Date: 2002/10/29 08:06:26 $
* ==========================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "rkfsn.h"
#include "dbgproto.h"
#include "dbgif_print.h"
extern FILE *fp;
static char *RequestStringTable[] = {
"Load Executable",
"List Processes",
"Get Executable Name",
"List Threads",
"Thread Status",
"Stop Process",
"Stop Thread",
"Run Thread",
"Run Process",
"Kill Process",
"Set Fault",
"Get Fault",
"Number of Regions",
"Get Regions",
"Get General Purpose Registers",
"Set General Purpose Registers",
"Get Floating Point Registers",
"Set Floating Point Registers",
"Read Memory",
"Write Memory",
"Set Breakpoint",
"Clear Breakpoint",
"List Breakpoints",
"Number of Watchpoints",
"Set Watchpoints",
"Get Watchpoints",
"Thread Resource Usage",
"Get Path List",
"Get Frame Buffer",
"Reboot System",
"Set Comm Link",
"Set System Call Entry List",
"Get System Call Entry List",
"Set System Call Exit List",
"Get System Call Exit List",
"Enable Log Events",
"Disable Log Events",
"Flush Log Events",
"New Log File",
"Get Mask",
"AppMgr Cmd",
"Remote",
"Log Control",
"Log Status",
"Get Log File",
"Get System Usage",
"Set Trpt",
"Clear Trpt",
"List Trpts",
"Get Scalar Regs",
"Set Scalar Regs",
"Get Vector Regs",
"Set Vector Regs",
0
};
prPrintFunc PrintDispatchTable[] = {
prObject,
prObjectList,
prObject,
prObjectList,
prThreadStatus,
prObject,
prThreadStatus,
prObject,
prObject,
prObject,
prObject,
prFault,
prNumber,
prRegions,
prGregs,
prObject,
prFPregs,
prObject,
prObject,
prObject,
prBkpt,
prObject,
prObjectList,
prNumber,
prObject,
prRegions,
prUsage,
prString,
prObject,
prObject,
prObject,
prSyscall,
prSyscall,
prSyscall,
prSyscall,
prLogEventSets,
prLogEventSets,
prFlushLog,
prNewLogFile,
prObject,
prUsage,
prUsage,
prUsage,
prUsage,
prUsage,
prUsage,
prUsage,
prUsage,
prUsage,
prSregs,
prObject,
prVregs,
prObject
};
static char *tverrormsgs [] = {
"no error", /* 0 */
"illegal call", /* 1 */
"invalid id", /* 2 */
"invalid type", /* 3 */
"operations protected", /* 4 */
"invalid address", /* 5 */
"invalid priority", /* 6 */
"invalid flags", /* 7 */
"invalid capability", /* 8 */
"no handler", /* 9 */
"no more ids", /* 10 */
"no more messages", /* 11 */
"no more processes", /* 12 */
"no more threads", /* 13 */
"no more regions", /* 14 */
"no more timers", /* 15 */
"no more locks", /* 16 */
"no more queues", /* 17 */
"no more sets", /* 18 */
"no more memory", /* 19 */
"not locked", /* 20 */
"", /* 21 */
"", /* 22 */
"", /* 23 */
"", /* 24 */
"", /* 25 */
"", /* 26 */
"", /* 27 */
"", /* 28 */
"", /* 29 */
"region already mapped", /* 30 */
"address already mapped", /* 31 */
"not mapped", /* 32 */
"invalid size", /* 33 */
"invalid physical address", /* 34 */
"", /* 35 */
"", /* 36 */
"", /* 37 */
"", /* 38 */
"", /* 39 */
"reserved message type", /* 40 */
"queue full", /* 41 */
"", /* 42 */
"", /* 43 */
"", /* 44 */
"", /* 45 */
"", /* 46 */
"", /* 47 */
"", /* 48 */
"", /* 49 */
"full set", /* 50 */
"empty set", /* 51 */
"", /* 52 */
"", /* 53 */
"", /* 54 */
"", /* 55 */
"", /* 56 */
"", /* 57 */
"", /* 58 */
"", /* 59 */
"devise busy", /* 60 */
"not navigator", /* 61 */
"no exectuable", /* 62 */
"devise init", /* 63 */
"devise notopen", /* 64 */
"devise config", /* 65 */
"invalid arg", /* 66 */
"not ready", /* 67 */
"" /* 68 */
};
#define MAX_NEG_ERROR -68
/* return error code */
int prHeader(KKHeader *packet, int type)
{
int len;
char str[1024];
int error = packet->error;
if (fp) {
if ((packet->code < 0) || (packet->code >= _KK_REQ_COUNT)) {
printf("unknown event code 0x%x type %d\n\r", packet->code, type);
fprintf(fp, "unknown event code %x type %d\n",
packet->code, type);
fflush (fp);
return (-1);
}
switch (packet->type) {
case _KK_REQUEST:
sprintf (str, "REQUEST : ");
error = 0; /* error field in request not initialized */
break;
case _KK_REPLY:
sprintf (str, "REPLY : ");
break;
case _KK_EXCEPTION:
sprintf (str, "EXCEPTION : ");
break;
case _KK_THREAD_EXIT:
sprintf (str, "THREAD_EXIT : ");
break;
case _KK_PROCESS_EXIT:
sprintf (str, "PROCESS_EXIT : ");
break;
case _KK_CONSOLE:
sprintf (str, "CONSOLE : ");
break;
}
len = strlen (str);
if (error == 0) {
if (packet->type == _KK_THREAD_EXIT)
sprintf (&str[len], "%s", "THREAD EXITTED");
else if (packet->type == _KK_PROCESS_EXIT)
sprintf (&str[len], "%s", "PROCESS EXITTED");
else
sprintf (&str[len], "%s", RequestStringTable[packet->code]);
} else {
if ((error < 0) && (error > MAX_NEG_ERROR)) {
sprintf (&str[len],
"***** error: %d, [%s] *****\n\n",
error, tverrormsgs[-error]);
}
}
fprintf (fp, "%s \n", str);
if (packet->rev != TV_DBGPROTO_REV)
fprintf(fp,
"dbgif version mismatch: expected %d got %d from settop\n",
TV_DBGPROTO_REV, packet->rev);
fflush (fp);
}
return (error);
}
void prEvent (KKHeader *event)
{
if (fp) {
if ((event->code < 0) || (event->code >= _KK_REQ_COUNT)) {
fprintf(fp, "unknown event code 0x%x\n", event->code);
fflush (fp);
} else {
(*PrintDispatchTable[event->code])(event, PR_EVENT);
}
}
}
void prExecutable (KKHeader *packet, int type)
{
KKLoadExecutableRequest *request = (KKLoadExecutableRequest *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\texecutable = %s\n", request->str);
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prString (KKHeader *packet, int type)
{
KKBufferEvent *request = (KKBufferEvent *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tstring = %s\n", request->buffer);
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prObject (KKHeader *packet, int type)
{
KKObjectRequest *request = (KKObjectRequest *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tid = %d\n", request->object);
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prThreadStatus (KKHeader *packet, int type)
{
KKStatusEvent *event = (KKStatusEvent *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tflags = 0x%x\n", event->status.flags);
fprintf (fp, "\twhy = %d\n", event->status.why);
fprintf (fp, "\ttid = %d\n", event->status.tid);
fprintf (fp, "\tpid = %d\n", event->status.pid);
fprintf (fp, "\tstart = 0x%x\n", event->status.start);
fprintf (fp, "\twhat = %d\n", event->status.what);
fprintf (fp, "\trv = 0x%x\n", event->status.rv);
fprintf (fp, "\tinstr = 0x%x\n", event->status.instr);
fprintf (fp, "\tfault info\n");
fprintf (fp, "\t\taddr = 0x%x\n", event->status.info.addr);
fprintf (fp, "\t\tmajor = 0x%x\n", event->status.info.major);
fprintf (fp, "\t\tminor = 0x%x\n", event->status.info.minor);
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prRunThread (KKHeader *packet, int type)
{
KKRunThreadRequest *request = (KKRunThreadRequest *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\ttid = %d\n", request->tid);
fprintf (fp, "\trun info\n");
fprintf (fp, "\t\tflags = 0x%x\n", request->actions.flags);
fprintf (fp, "\t\tvaddr = 0x%x\n", request->actions.vaddr);
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prFault (KKHeader *packet, int type)
{
KKFaultRequest *request = (KKFaultRequest *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tthread id = %d\n", request->tid);
fprintf (fp, "\tfault masks\n");
fprintf (fp, "\t\tmajor = 0x%x\n", request->fault.majorMask);
fprintf (fp, "\t\tminor = 0x%x\n", request->fault.minorMask);
fprintf (fp, "\tstopAllThreads = %d\n", request->stopAllThreads);
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prNumber (KKHeader *packet, int type)
{
KKNumberEvent *event = (KKNumberEvent *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tobject = %d\n", event->object);
fprintf (fp, "\tnumber = %d\n", event->number);
fprintf (fp, "\n\n");
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prRegions (KKHeader *packet, int type)
{
int i;
KKRegionEvent *event = (KKRegionEvent *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tobject = %d\n", event->object);
fprintf (fp, "\tnumber = %d\n", event->number);
for (i = 0; i < event->number; i++) {
fprintf (fp, "\tregion %d\n", i);
fprintf (fp, "\t\tvirtual addr = 0x%x\n", event->regions[i].vaddr);
fprintf (fp, "\t\tsize = %d\n", event->regions[i].size);
fprintf (fp, "\t\tflags = 0x%x\n", event->regions[i].flags);
fprintf (fp, "\t\tpaddr = 0x%x\n", event->regions[i].paddr);
}
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prGregs (KKHeader *packet, int type)
{
int i;
KKGregEvent *event = (KKGregEvent *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tthread = %d\n", event->tid);
fprintf (fp, "\tgeneral purpose registers\n");
for (i = 0; i < KK_NGREGS; i++) {
fprintf (fp, "\t\tregister[%d] = 0x%x\n",
i, event->registers.gregs[i]);
}
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prFPregs (KKHeader *packet, int type)
{
int i;
KKFPregEvent *event = (KKFPregEvent *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tthread = %d\n", event->tid);
fprintf (fp, "\tfloating point registers\n");
for (i = 0; i < 32; i++) {
fprintf (fp, "\t\tregister[%d] = %f\n", i,
event->registers.fpregs.fregs[i]);
}
fprintf (fp, "\tstatus register = 0x%x\n", event->registers.fpcsr);
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prMem (KKHeader *packet, int type)
{
KKReadRequest *request = (KKReadRequest *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tprocess = %d\n", request->object);
fprintf (fp, "\taddress = 0x%x\n", request->addr);
fprintf (fp, "\tnbytes = %d\n", request->nbytes);
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prSetBkpt (KKHeader *packet, int type)
{
KKSetBkptRequest *request = (KKSetBkptRequest *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tobject = %d\n", request->object);
fprintf (fp, "\taddress = 0x%x\n", request->addr);
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prBkpt (KKHeader *packet, int type)
{
KKSetBkptRequest *setRequest;
KKClrBkptRequest *clrRequest;
KKBkptEvent *event;
if (fp && (prHeader(packet, type) == 0)) {
if (type == PR_REQUEST) {
switch (packet->code) {
case _KK_REQ_SETBKPT:
setRequest = (KKSetBkptRequest *)packet;
fprintf (fp, "\tobject = %d\n", setRequest->object);
fprintf (fp, "\taddress = 0x%x\n", setRequest->addr);
break;
case _KK_REQ_CLRBKPT:
clrRequest = (KKClrBkptRequest *)packet;
fprintf (fp, "\tobject = %d\n", clrRequest->object);
fprintf (fp, "\tbreakpoint id = %d\n", clrRequest->bp);
break;
default:
break;
}
} else {
KKBkptEvent *event = (KKBkptEvent *)packet;
fprintf (fp, "\tobject = %d\n", event->object);
fprintf (fp, "\tbreakpoint = %d\n", event->bp);
}
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prObjectList (KKHeader *packet, int type)
{
int i, number;
KKObjsEvent *event = (KKObjsEvent *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tobject = %d\n", event->object);
number = event->objs.number;
fprintf (fp, "\tnumber = %d (0x%x)\n", number, number);
fprintf (fp, "\tObject List\n");
for (i = 0; i < number; i++) {
fprintf (fp, "\t\tobject[%d] = 0x%x\n", i, event->objs.objects[i]);
}
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prSregs (KKHeader *packet, int type)
{
int i;
KKCpSregEvent *event = (KKCpSregEvent *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tthread = %d\n", event->tid);
fprintf (fp, "\tRCP scalar registers\n");
for (i = 0; i < KK_NSREGS; i++) {
fprintf (fp, "\t\tregister[%d] = 0x%x\n",
i, event->registers.sregs[i]);
}
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prVregs (KKHeader *packet, int type)
{
int i;
KKCpVregEvent *event = (KKCpVregEvent *)packet;
if (fp && (prHeader(packet, type) == 0)) {
fprintf (fp, "\tthread = %d\n", event->tid);
fprintf (fp, "\tRCP vector registers\n");
for (i = 0; i < (4 * KK_VREGS); i += 4) {
fprintf (fp, "\t\tregister[%d] = 0x%x 0x%x 0x%x 0x%x\n",
i >> 2, event->registers.vregs[i], event->registers.vregs[i+1],
event->registers.vregs[i+2], event->registers.vregs[i+3]);
}
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prUsage (KKHeader *packet, int type)
{
}
char *commset[] = { "tty", "tcp" , "nop" };
void prComm (KKHeader *packet, int type)
{
if (fp && (prHeader(packet, type) == 0)) {
switch (type) {
case PR_REQUEST:
{
KKSetCommRequest *req = (KKSetCommRequest *)packet;
int n = req->how;
fprintf (fp, "\dhow = %d, %s; addr 0x%x\n",
n,
(n >= 0 && n <= KK_NOP) ? commset[n] : "",
req->addr);
}
break;
case PR_EVENT:
{
KKNumberEvent *event = (KKNumberEvent *)packet;
int n = event->number;
fprintf (fp, "\toldhow = %d, %s\n",
n, (n >= 0 && n < KK_NOP) ? commset[n] : "");
}
break;
}
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prSyscall (KKHeader *packet, int type)
{
int index;
if (fp && (prHeader(packet, type) == 0)) {
switch (type) {
case PR_REQUEST:
{
KKSysCallRequest *req = (KKSysCallRequest *)packet;
for(index = 0; index < sizeof(KKSysCallRequest)/4; index++) {
fprintf(fp, "buf[%d] = 0x%x\n", index, *(int*)((int*)req+index));
}
fflush(fp);
}
break;
case PR_EVENT:
{
KKSysCallEvent *event = (KKSysCallEvent *)packet;
for(index = 0; index < sizeof(KKSysCallRequest)/4; index++) {
fprintf(fp, "buf[%d] = 0x%x\n", index, *(int*)((int*)event+index));
}
fflush(fp);
}
break;
}
}
}
void prLogEventSets (KKHeader *packet, int type)
{
int i;
KKLogEventRequest *request = (KKLogEventRequest *)packet;
if (fp && (prHeader(packet, type) == 0) && (type == PR_REQUEST)) {
#if 0
fprintf (fp, "\tprocess = %d, number of sets = %d\n",
request->pid, request->numSet);
#endif
for (i = 0; i < request->numSet; i++) {
fprintf (fp, "%d-%d\n", request->set[i].from, request->set[i].to);
}
fprintf (fp, "\n\n");
fflush (fp);
}
}
void prFlushLog (KKHeader *packet, int type)
{
int i;
KKFlushEvent *event = (KKFlushEvent *)packet;
if (fp && (prHeader(packet, type) == 0) && (type == PR_EVENT) &&
(packet->type == _KK_CONSOLE)) {
fprintf (fp, "\ttype = %d, size = %d\n\n",
event->bufferType, event->header.length-sizeof(KKFlushEvent)+4);
fflush (fp);
}
}
void prNewLogFile (KKHeader *packet, int type)
{
int i;
KKNewLogRequest *request = (KKNewLogRequest *)packet;
if (fp && (prHeader(packet, type) == 0) && (type == PR_REQUEST)) {
if (*request->str) {
fprintf (fp, "log file name = %s\n", request->str);
fflush (fp);
}
}
}