OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [proc-api.c] - Blame information for rev 1783

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
/* Machine independent support for SVR4 /proc (process file system) for GDB.
2
   Copyright 1999 Free Software Foundation, Inc.
3
   Written by Michael Snyder at Cygnus Solutions.
4
   Based on work by Fred Fish, Stu Grossman, Geoff Noer, and others.
5
 
6
This file is part of GDB.
7
 
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
12
 
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software Foundation,
20
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
21
 
22
/*
23
 * Pretty-print trace of api calls to the /proc api
24
 * (ioctl or read/write calls).
25
 *
26
 */
27
 
28
#include "defs.h"
29
#include "gdbcmd.h"
30
 
31
#if defined (NEW_PROC_API)
32
#define _STRUCTURED_PROC 1
33
#endif
34
 
35
#include <stdio.h>
36
#include <sys/types.h>
37
#include <sys/procfs.h>
38
#include <sys/proc.h>   /* for struct proc */
39
#ifdef HAVE_SYS_USER_H
40
#include <sys/user.h>   /* for struct user */
41
#endif
42
#include <fcntl.h>      /* for O_RDWR etc. */
43
#include <sys/wait.h>
44
 
45
#include "proc-utils.h"
46
 
47
/*  Much of the information used in the /proc interface, particularly for
48
    printing status information, is kept as tables of structures of the
49
    following form.  These tables can be used to map numeric values to
50
    their symbolic names and to a string that describes their specific use. */
51
 
52
struct trans {
53
  long value;                   /* The numeric value */
54
  char *name;                   /* The equivalent symbolic value */
55
  char *desc;                   /* Short description of value */
56
};
57
 
58
static int   procfs_trace    = 1;
59
/*static int   info_verbose    = 1;*/   /* kludge */
60
static FILE *procfs_file     = NULL;
61
static char *procfs_filename = "procfs_trace";
62
 
63
static void
64
set_procfs_trace_cmd (args, from_tty, c)
65
     char *args;
66
     int from_tty;
67
     struct cmd_list_element *c;
68
{
69
#if 0   /* not sure what I might actually need to do here, if anything */
70
  if (procfs_file)
71
    fflush (procfs_file);
72
#endif
73
}
74
 
75
static void
76
set_procfs_file_cmd (args, from_tty, c)
77
     char *args;
78
     int from_tty;
79
     struct cmd_list_element *c;
80
{
81
  /* Just changed the filename for procfs tracing.
82
     If a file was already open, close it.  */
83
  if (procfs_file)
84
    fclose (procfs_file);
85
  procfs_file = NULL;
86
}
87
 
88
 
89
#ifndef NEW_PROC_API
90
 
91
static struct trans ioctl_table[] = {
92
#ifdef PIOCACINFO                       /* irix */
93
  { PIOCACINFO,    "PIOCACINFO",   "get process account info" },
94
#endif
95
  { PIOCACTION,    "PIOCACTION",   "get signal action structs" },
96
#ifdef PIOCARGUMENTS                    /* osf */
97
  { PIOCARGUMENTS, "PIOCARGUMENTS", "command line args" },
98
#endif
99
#ifdef PIOCAUXV                         /* solaris aux vectors */
100
  { PIOCAUXV,      "PIOCAUXV",     "get aux vector" },
101
  { PIOCNAUXV,     "PIOCNAUXV",    "get number of aux vector entries" },
102
#endif /* AUXV */
103
  { PIOCCFAULT,    "PIOCCFAULT",   "clear current fault" },
104
  { PIOCCRED,      "PIOCCRED",     "get process credentials" },
105
#ifdef PIOCENEVCTRS                     /* irix event counters */
106
  { PIOCENEVCTRS,    "PIOCENEVCTRS",    "acquire and start event counters" },
107
  { PIOCGETEVCTRL,   "PIOCGETEVCTRL",   "get control info of event counters" },
108
  { PIOCGETEVCTRS,   "PIOCGETEVCTRS",   "dump event counters" },
109
  { PIOCGETPREVCTRS, "PIOCGETPREVCTRS", "dump event counters & prusage info" },
110
  { PIOCRELEVCTRS,   "PIOCRELEVCTRS",   "release/stop event counters" },
111
  { PIOCSETEVCTRL,   "PIOCSETEVCTRL",   "set control info of event counters" },
112
  { PIOCGETPTIMER,   "PIOCGETPTIMER",   "get process timers" },
113
#endif  /* irix event counters */
114
  { PIOCGENTRY,    "PIOCGENTRY",   "get traced syscall entry set" },
115
#if defined (PIOCGETPR)
116
  { PIOCGETPR,     "PIOCGETPR",    "read struct proc" },
117
#endif
118
#if defined (PIOCGETU)
119
  { PIOCGETU,      "PIOCGETU",     "read user area" },
120
#endif
121
#if defined (PIOCGETUTK) && (defined(KERNEL) || defined(SHOW_UTT)) /* osf */
122
  { PIOCGETUTK,  "PIOCGETUTK", "get the utask struct" },
123
#endif
124
  { PIOCGEXIT,     "PIOCGEXIT",    "get traced syscall exit  set" },
125
  { PIOCGFAULT,    "PIOCGFAULT",   "get traced fault set" },
126
#ifdef PIOCGFPCR                        /* osf */
127
  { PIOCGFPCR,     "PIOCGFPCR",    "get FP control register" },
128
  { PIOCSFPCR,     "PIOCSFPCR",    "set FP conrtol register" },
129
#endif
130
  { PIOCGFPREG,    "PIOCGFPREG",   "get floating point registers" },
131
  { PIOCGHOLD,     "PIOCGHOLD",    "get held signal set" },
132
  { PIOCGREG,      "PIOCGREG",     "get general registers" },
133
  { PIOCGROUPS,    "PIOCGROUPS",   "get supplementary groups" },
134
#ifdef PIOCGSPCACT                      /* osf */
135
  { PIOCGSPCACT,   "PIOCGSPCACT",  "get special action" },
136
  { PIOCSSPCACT,   "PIOCSSPCACT",  "set special action" },
137
#endif
138
  { PIOCGTRACE,    "PIOCGTRACE",   "get traced signal set" },
139
#ifdef PIOCGWATCH                       /* irix watchpoints */
140
  { PIOCGWATCH,    "PIOCGWATCH",   "get watchpoint" },
141
  { PIOCSWATCH,    "PIOCSWATCH",   "set watchpoint" },
142
  { PIOCNWATCH,    "PIOCNWATCH",   "get number of watchpoints" },
143
#endif  /* irix watchpoints */
144
#ifdef PIOCGWIN                         /* solaris sparc */
145
  { PIOCGWIN,      "PIOCGWIN",     "get gwindows_t" },
146
#endif
147
#ifdef PIOCGXREG                        /* solaris sparc extra regs */
148
  { PIOCGXREGSIZE, "PIOCXREGSIZE", "get extra register state size" },
149
  { PIOCGXREG,     "PIOCGXREG",    "get extra register state" },
150
  { PIOCSXREG,     "PIOCSXREG",    "set extra register state" },
151
#endif /* XREG */
152
  { PIOCKILL,      "PIOCKILL",     "send signal" },
153
#ifdef PIOCLDT                          /* solaris i386 */
154
  { PIOCLDT,       "PIOCLDT",      "get LDT" },
155
  { PIOCNLDT,      "PIOCNLDT",     "get number of LDT entries" },
156
#endif
157
#ifdef PIOCLSTATUS                      /* solaris and unixware */
158
  { PIOCLSTATUS,   "PIOCLSTATUS",  "get status of all lwps" },
159
  { PIOCLUSAGE,    "PIOCLUSAGE",   "get resource usage of all lwps" },
160
  { PIOCOPENLWP,   "PIOCOPENLWP",  "get lwp file descriptor" },
161
  { PIOCLWPIDS,    "PIOCLWPIDS",   "get lwp identifiers" },
162
#endif /* LWP */
163
  { PIOCMAP,       "PIOCMAP",      "get memory map information" },
164
  { PIOCMAXSIG,    "PIOCMAXSIG",   "get max signal number" },
165
  { PIOCNICE,      "PIOCNICE",     "set nice priority" },
166
  { PIOCNMAP,      "PIOCNMAP",     "get number of memory mappings" },
167
  { PIOCOPENM,     "PIOCOPENM",    "open mapped object for reading" },
168
#ifdef PIOCOPENMOBS                     /* osf */
169
  { PIOCOPENMOBS,  "PIOCOPENMOBS", "open mapped object" },
170
#endif
171
#ifdef PIOCOPENPD       /* solaris */
172
  { PIOCOPENPD,    "PIOCOPENPD",   "get page data file descriptor" },
173
#endif
174
  { PIOCPSINFO,    "PIOCPSINFO",   "get ps(1) information" },
175
  { PIOCRESET,     "PIOCRESET",    "reset process flags" },
176
  { PIOCRFORK,     "PIOCRFORK",    "reset inherit-on-fork flag" },
177
  { PIOCRRLC,      "PIOCRRLC",     "reset run-on-last-close flag" },
178
  { PIOCRUN,       "PIOCRUN",      "make process runnable" },
179
#ifdef PIOCSAVECCNTRS                   /* irix */
180
  { PIOCSAVECCNTRS, "PIOCSAVECCNTRS", "parent gets child cntrs" },
181
#endif
182
  { PIOCSENTRY,    "PIOCSENTRY",   "set traced syscall entry set" },
183
  { PIOCSET,       "PIOCSET",      "set process flags" },
184
  { PIOCSEXIT,     "PIOCSEXIT",    "set traced syscall exit  set" },
185
  { PIOCSFAULT,    "PIOCSFAULT",   "set traced fault set" },
186
  { PIOCSFORK,     "PIOCSFORK",    "set inherit-on-fork flag" },
187
  { PIOCSFPREG,    "PIOCSFPREG",   "set floating point registers" },
188
  { PIOCSHOLD,     "PIOCSHOLD",    "set held signal set" },
189
  { PIOCSREG,      "PIOCSREG",     "set general registers" },
190
  { PIOCSRLC,      "PIOCSRLC",     "set run-on-last-close flag" },
191
  { PIOCSSIG,      "PIOCSSIG",     "set current signal" },
192
  { PIOCSTATUS,    "PIOCSTATUS",   "get process status" },
193
  { PIOCSTOP,      "PIOCSTOP",     "post stop request" },
194
  { PIOCSTRACE,    "PIOCSTRACE",   "set traced signal set" },
195
  { PIOCUNKILL,    "PIOCUNKILL",   "delete a signal" },
196
#ifdef PIOCUSAGE        /* solaris */
197
  { PIOCUSAGE,     "PIOCUSAGE",    "get resource usage" },
198
#endif
199
  { PIOCWSTOP,     "PIOCWSTOP",    "wait for process to stop" },
200
 
201
#ifdef PIOCNTHR                         /* osf threads */
202
  { PIOCNTHR,      "PIOCNTHR",     "get thread count" },
203
  { PIOCRTINH,     "PIOCRTINH",    "reset inherit-on-thread-creation" },
204
  { PIOCSTINH,     "PIOCSTINH",    "set   inherit-on-thread-creation" },
205
  { PIOCTLIST,     "PIOCTLIST",    "get thread ids" },
206
  { PIOCXPTH,      "PIOCXPTH",     "translate port to thread handle" },
207
  { PIOCTRUN,      "PIOCTRUN",     "make thread runnable" },
208
  { PIOCTSTATUS,   "PIOCTSTATUS",  "get thread status" },
209
  { PIOCTSTOP,     "PIOCTSTOP",    "stop a thread" },
210
  /* ... TGTRACE TSTRACE TSSIG TKILL TUNKILL TCFAULT TGFAULT TSFAULT
211
     TGFPREG TSFPREG TGREG TSREG TACTION TTERM TABRUN TGENTRY TSENTRY
212
     TGEXIT TSEXIT TSHOLD ... thread functions */
213
#endif /* osf threads */
214
  { -1,            NULL,           NULL }
215
};
216
 
217
int
218
ioctl_with_trace (fd, opcode, ptr, file, line)
219
     int  fd;
220
     long opcode;
221
     void *ptr;
222
     char *file;
223
     int  line;
224
{
225
  int i, ret, arg1;
226
 
227
  if (procfs_trace)
228
    {
229
      if (procfs_file == NULL && procfs_filename != NULL)
230
        procfs_file = fopen (procfs_filename, "a");
231
 
232
      for (i = 0; ioctl_table[i].name != NULL; i++)
233
        if (ioctl_table[i].value == opcode)
234
          break;
235
 
236
      if (info_verbose)
237
        fprintf (procfs_file ? procfs_file : stdout,
238
                 "%s:%d -- ", file, line);
239
      switch (opcode) {
240
      case PIOCSET:
241
        arg1 = ptr ? *(long *) ptr : 0;
242
        fprintf (procfs_file ? procfs_file : stdout,
243
                 "ioctl (PIOCSET,   %s) %s\n",
244
                 arg1 == PR_FORK  ? "PR_FORK"  :
245
                 arg1 == PR_RLC   ? "PR_RLC"   :
246
#ifdef PR_ASYNC
247
                 arg1 == PR_ASYNC ? "PR_ASYNC" :
248
#endif
249
                 "<unknown flag>",
250
                 info_verbose ? ioctl_table[i].desc : "");
251
        break;
252
      case PIOCRESET:
253
        arg1 = ptr ? *(long *) ptr : 0;
254
        fprintf (procfs_file ? procfs_file : stdout,
255
                 "ioctl (PIOCRESET, %s) %s\n",
256
                 arg1 == PR_FORK  ? "PR_FORK"  :
257
                 arg1 == PR_RLC   ? "PR_RLC"   :
258
#ifdef PR_ASYNC
259
                 arg1 == PR_ASYNC ? "PR_ASYNC" :
260
#endif
261
                 "<unknown flag>",
262
                 info_verbose ? ioctl_table[i].desc : "");
263
        break;
264
      case PIOCSTRACE:
265
        fprintf (procfs_file ? procfs_file : stdout,
266
                 "ioctl (PIOCSTRACE) ");
267
        proc_prettyfprint_signalset (procfs_file ? procfs_file : stdout,
268
                                     (sigset_t *) ptr, 0);
269
        break;
270
      case PIOCSFAULT:
271
        fprintf (procfs_file ? procfs_file : stdout,
272
                 "ioctl (%s) ",
273
                 opcode == PIOCSFAULT ? "PIOCSFAULT" : "PIOCGFAULT");
274
        proc_prettyfprint_faultset (procfs_file ? procfs_file : stdout,
275
                                    (fltset_t *) ptr, 0);
276
        break;
277
      case PIOCSENTRY:
278
        fprintf (procfs_file ? procfs_file : stdout,
279
                 "ioctl (%s) ",
280
                 opcode == PIOCSENTRY ? "PIOCSENTRY" : "PIOCGENTRY");
281
        proc_prettyfprint_syscalls (procfs_file ? procfs_file : stdout,
282
                                    (sysset_t *) ptr, 0);
283
        break;
284
      case PIOCSEXIT:
285
        fprintf (procfs_file ? procfs_file : stdout,
286
                 "ioctl (%s) ",
287
                 opcode == PIOCSEXIT ? "PIOCSEXIT" : "PIOCGEXIT");
288
        proc_prettyfprint_syscalls (procfs_file ? procfs_file : stdout,
289
                                    (sysset_t *) ptr, 0);
290
        break;
291
      case PIOCSHOLD:
292
        fprintf (procfs_file ? procfs_file : stdout,
293
                 "ioctl (%s) ",
294
                 opcode == PIOCSHOLD ? "PIOCSHOLD" : "PIOCGHOLD");
295
        proc_prettyfprint_signalset (procfs_file ? procfs_file : stdout,
296
                                     (sigset_t *) ptr, 0);
297
        break;
298
      case PIOCSSIG:
299
        fprintf (procfs_file ? procfs_file : stdout,
300
                 "ioctl (PIOCSSIG) ");
301
        proc_prettyfprint_signal (procfs_file ? procfs_file : stdout,
302
                                  ptr ? ((siginfo_t *) ptr)->si_signo : 0,
303
                                  0);
304
        fprintf (procfs_file ? procfs_file : stdout, "\n");
305
        break;
306
      case PIOCRUN:
307
        fprintf (procfs_file ? procfs_file : stdout,
308
                 "ioctl (PIOCRUN) ");
309
 
310
        arg1 = ptr ? *(long *) ptr : 0;
311
        if (arg1 & PRCSIG)
312
          fprintf (procfs_file ? procfs_file : stdout, "clearSig ");
313
        if (arg1 & PRCFAULT)
314
          fprintf (procfs_file ? procfs_file : stdout, "clearFlt ");
315
        if (arg1 & PRSTRACE)
316
          fprintf (procfs_file ? procfs_file : stdout, "setTrace ");
317
        if (arg1 & PRSHOLD)
318
          fprintf (procfs_file ? procfs_file : stdout, "setHold ");
319
        if (arg1 & PRSFAULT)
320
          fprintf (procfs_file ? procfs_file : stdout, "setFlt ");
321
        if (arg1 & PRSVADDR)
322
          fprintf (procfs_file ? procfs_file : stdout, "setVaddr ");
323
        if (arg1 & PRSTEP)
324
          fprintf (procfs_file ? procfs_file : stdout, "step ");
325
        if (arg1 & PRSABORT)
326
          fprintf (procfs_file ? procfs_file : stdout, "syscallAbort ");
327
        if (arg1 & PRSTOP)
328
          fprintf (procfs_file ? procfs_file : stdout, "stopReq ");
329
 
330
        fprintf (procfs_file ? procfs_file : stdout, "\n");
331
        break;
332
      case PIOCKILL:
333
        fprintf (procfs_file ? procfs_file : stdout,
334
                 "ioctl (PIOCKILL) ");
335
        proc_prettyfprint_signal (procfs_file ? procfs_file : stdout,
336
                                  ptr ? *(long *) ptr : 0, 0);
337
        fprintf (procfs_file ? procfs_file : stdout, "\n");
338
        break;
339
#ifdef PIOCSSPCACT
340
      case PIOCSSPCACT:
341
        fprintf (procfs_file ? procfs_file : stdout,
342
                 "ioctl (PIOCSSPCACT) ");
343
        arg1 = ptr ? *(long *) ptr : 0;
344
        if (arg1 & PRFS_STOPFORK)
345
          fprintf (procfs_file ? procfs_file : stdout, "stopFork ");
346
        if (arg1 & PRFS_STOPEXEC)
347
          fprintf (procfs_file ? procfs_file : stdout, "stopExec ");
348
        if (arg1 & PRFS_STOPTERM)
349
          fprintf (procfs_file ? procfs_file : stdout, "stopTerm ");
350
        if (arg1 & PRFS_STOPTCR)
351
          fprintf (procfs_file ? procfs_file : stdout, "stopThreadCreate ");
352
        if (arg1 & PRFS_STOPTTERM)
353
          fprintf (procfs_file ? procfs_file : stdout, "stopThreadTerm ");
354
        if (arg1 & PRFS_KOLC)
355
          fprintf (procfs_file ? procfs_file : stdout, "killOnLastClose ");
356
        fprintf (procfs_file ? procfs_file : stdout, "\n");
357
        break;
358
#endif /* PIOCSSPCACT */
359
      default:
360
        if (ioctl_table[i].name)
361
          fprintf (procfs_file ? procfs_file : stdout,
362
                   "ioctl (%s) %s\n",
363
                   ioctl_table[i].name,
364
                   info_verbose ? ioctl_table[i].desc : "");
365
        else
366
          fprintf (procfs_file ? procfs_file : stdout,
367
                   "ioctl (<unknown %ld (0x%lx)) \n", opcode, opcode);
368
        break;
369
      }
370
      if (procfs_file)
371
        fflush (procfs_file);
372
    }
373
  ret = ioctl (fd, opcode, ptr);
374
  if (procfs_trace && ret < 0)
375
    {
376
      fprintf (procfs_file ? procfs_file : stdout,
377
               "[ioctl (%s) FAILED!]\n",
378
               ioctl_table[i].name != NULL ?
379
               ioctl_table[i].name : "<unknown>");
380
      if (procfs_file)
381
        fflush (procfs_file);
382
    }
383
 
384
  return ret;
385
}
386
 
387
#else   /* NEW_PROC_API */
388
 
389
static struct trans rw_table[] = {
390
#ifdef PCAGENT                  /* solaris */
391
  { PCAGENT,  "PCAGENT",  "create agent lwp with regs from argument" },
392
#endif
393
  { PCCFAULT, "PCCFAULT", "clear current fault" },
394
#ifdef PCCSIG                   /* solaris */
395
  { PCCSIG,   "PCCSIG",   "clear current signal" },
396
#endif
397
  { PCDSTOP,  "PCDSTOP",  "post stop request" },
398
  { PCKILL,   "PCKILL",   "post a signal" },
399
  { PCNICE,   "PCNICE",   "set nice priority" },
400
#ifdef PCREAD                   /* solaris */
401
  { PCREAD,   "PCREAD",   "read from the address space" },
402
  { PCWRITE,  "PCWRITE",  "write to the address space" },
403
#endif
404
#ifdef PCRESET                  /* unixware */
405
  { PCRESET,  "PCRESET",  "unset modes" },
406
#endif
407
  { PCRUN,    "PCRUN",    "make process/lwp runnable" },
408
#ifdef PCSASRS                  /* solaris 2.7 only */
409
  { PCSASRS,  "PCSASRS",  "set ancillary state registers" },
410
#endif
411
#ifdef PCSCRED                  /* solaris */
412
  { PCSCRED,  "PCSCRED",  "set process credentials" },
413
#endif
414
  { PCSENTRY, "PCSENTRY", "set traced syscall entry set" },
415
  { PCSET,    "PCSET",    "set modes" },
416
  { PCSEXIT,  "PCSEXIT",  "set traced syscall exit  set" },
417
  { PCSFAULT, "PCSFAULT", "set traced fault set" },
418
  { PCSFPREG, "PCSFPREG", "set floating point registers" },
419
  { PCSHOLD,  "PCSHOLD",  "set signal mask" },
420
  { PCSREG,   "PCSREG",   "set general registers" },
421
  { PCSSIG,   "PCSSIG",   "set current signal" },
422
  { PCSTOP,   "PCSTOP",   "post stop request and wait" },
423
  { PCSTRACE, "PCSTRACE", "set traced signal set" },
424
#ifdef PCSVADDR                 /* solaris */
425
  { PCSVADDR, "PCSVADDR", "set pc virtual address" },
426
#endif
427
#ifdef PCSXREG                  /* solaris sparc only */
428
  { PCSXREG,  "PCSXREG",  "set extra registers" },
429
#endif
430
#ifdef PCTWSTOP                 /* solaris */
431
  { PCTWSTOP, "PCTWSTOP", "wait for stop, with timeout arg" },
432
#endif
433
  { PCUNKILL, "PCUNKILL", "delete a pending signal" },
434
#ifdef PCUNSET                  /* solaris */
435
  { PCUNSET,  "PCUNSET",  "unset modes" },
436
#endif
437
#ifdef PCWATCH                  /* solaris */
438
  { PCWATCH,  "PCWATCH",  "set/unset watched memory area" },
439
#endif
440
  { PCWSTOP,  "PCWSTOP",  "wait for process/lwp to stop, no timeout" },
441
  { 0,        NULL,      NULL }
442
};
443
 
444
static off_t lseek_offset;
445
 
446
int
447
write_with_trace (fd, arg, len, file, line)
448
     int  fd;
449
     long *arg;
450
     size_t len;
451
     char *file;
452
     int  line;
453
{
454
  int  i;
455
  long opcode = arg[0];
456
  int ret;
457
 
458
  if (procfs_trace)
459
    {
460
      if (procfs_file == NULL && procfs_filename != NULL)
461
        procfs_file = fopen (procfs_filename, "a");
462
 
463
      for (i = 0; rw_table[i].name != NULL; i++)
464
        if (rw_table[i].value == opcode)
465
          break;
466
 
467
      if (info_verbose)
468
        fprintf (procfs_file ? procfs_file : stdout,
469
                 "%s:%d -- ", file, line);
470
      switch (opcode) {
471
      case PCSET:
472
        fprintf (procfs_file ? procfs_file : stdout,
473
                 "write (PCSET,   %s) %s\n",
474
                 arg[1] == PR_FORK  ? "PR_FORK"  :
475
                 arg[1] == PR_RLC   ? "PR_RLC"   :
476
#ifdef PR_ASYNC
477
                 arg[1] == PR_ASYNC ? "PR_ASYNC" :
478
#endif
479
                 "<unknown flag>",
480
                 info_verbose ? rw_table[i].desc : "");
481
        break;
482
#ifdef PCUNSET
483
      case PCUNSET:
484
#endif
485
#ifdef PCRESET
486
      case PCRESET:
487
#endif
488
        fprintf (procfs_file ? procfs_file : stdout,
489
                 "write (PCRESET, %s) %s\n",
490
                 arg[1] == PR_FORK  ? "PR_FORK"  :
491
                 arg[1] == PR_RLC   ? "PR_RLC"   :
492
#ifdef PR_ASYNC
493
                 arg[1] == PR_ASYNC ? "PR_ASYNC" :
494
#endif
495
                 "<unknown flag>",
496
                 info_verbose ? rw_table[i].desc : "");
497
        break;
498
      case PCSTRACE:
499
        fprintf (procfs_file ? procfs_file : stdout,
500
                 "write (PCSTRACE) ");
501
        proc_prettyfprint_signalset (procfs_file ? procfs_file : stdout,
502
                                     (sigset_t *) &arg[1], 0);
503
        break;
504
      case PCSFAULT:
505
        fprintf (procfs_file ? procfs_file : stdout,
506
                 "write (PCSFAULT) ");
507
        proc_prettyfprint_faultset (procfs_file ? procfs_file : stdout,
508
                                    (fltset_t *) &arg[1], 0);
509
        break;
510
      case PCSENTRY:
511
        fprintf (procfs_file ? procfs_file : stdout,
512
                 "write (PCSENTRY) ");
513
        proc_prettyfprint_syscalls (procfs_file ? procfs_file : stdout,
514
                                    (sysset_t *) &arg[1], 0);
515
        break;
516
      case PCSEXIT:
517
        fprintf (procfs_file ? procfs_file : stdout,
518
                 "write (PCSEXIT) ");
519
        proc_prettyfprint_syscalls (procfs_file ? procfs_file : stdout,
520
                                    (sysset_t *) &arg[1], 0);
521
        break;
522
      case PCSHOLD:
523
        fprintf (procfs_file ? procfs_file : stdout,
524
                 "write (PCSHOLD) ");
525
        proc_prettyfprint_signalset (procfs_file ? procfs_file : stdout,
526
                                     (sigset_t *) &arg[1], 0);
527
        break;
528
      case PCSSIG:
529
        fprintf (procfs_file ? procfs_file : stdout,
530
                 "write (PCSSIG) ");
531
        proc_prettyfprint_signal (procfs_file ? procfs_file : stdout,
532
                                  arg[1] ? ((siginfo_t *) &arg[1])->si_signo
533
                                         : 0,
534
                                  0);
535
        fprintf (procfs_file ? procfs_file : stdout, "\n");
536
        break;
537
      case PCRUN:
538
        fprintf (procfs_file ? procfs_file : stdout,
539
                 "write (PCRUN) ");
540
        if (arg[1] & PRCSIG)
541
          fprintf (procfs_file ? procfs_file : stdout, "clearSig ");
542
        if (arg[1] & PRCFAULT)
543
          fprintf (procfs_file ? procfs_file : stdout, "clearFlt ");
544
        if (arg[1] & PRSTEP)
545
          fprintf (procfs_file ? procfs_file : stdout, "step ");
546
        if (arg[1] & PRSABORT)
547
          fprintf (procfs_file ? procfs_file : stdout, "syscallAbort ");
548
        if (arg[1] & PRSTOP)
549
          fprintf (procfs_file ? procfs_file : stdout, "stopReq ");
550
 
551
        fprintf (procfs_file ? procfs_file : stdout, "\n");
552
        break;
553
      case PCKILL:
554
        fprintf (procfs_file ? procfs_file : stdout,
555
                 "write (PCKILL) ");
556
        proc_prettyfprint_signal (procfs_file ? procfs_file : stdout,
557
                                  arg[1], 0);
558
        fprintf (procfs_file ? procfs_file : stdout, "\n");
559
        break;
560
      default:
561
        {
562
          static unsigned char break_insn[] = BREAKPOINT;
563
 
564
          if (len == sizeof (break_insn) &&
565
              memcmp (arg, &break_insn, len) == 0)
566
            fprintf (procfs_file ? procfs_file : stdout,
567
                     "write (<breakpoint at 0x%08x>) \n", lseek_offset);
568
          else if (rw_table[i].name)
569
            fprintf (procfs_file ? procfs_file : stdout,
570
                     "write (%s) %s\n",
571
                     rw_table[i].name,
572
                     info_verbose ? rw_table[i].desc : "");
573
          else
574
            {
575
              if (lseek_offset != -1)
576
                fprintf (procfs_file ? procfs_file : stdout,
577
                         "write (<unknown>, %d bytes at 0x%08x) \n",
578
                         len, lseek_offset);
579
              else
580
                fprintf (procfs_file ? procfs_file : stdout,
581
                         "write (<unknown>, %d bytes) \n", len);
582
            }
583
          break;
584
        }
585
      }
586
      if (procfs_file)
587
        fflush (procfs_file);
588
    }
589
  ret = write (fd, arg, len);
590
  if (procfs_trace && ret != len)
591
    {
592
      fprintf (procfs_file ? procfs_file : stdout,
593
               "[write (%s) FAILED!\n",
594
               rw_table[i].name != NULL ?
595
               rw_table[i].name : "<unknown>");
596
      if (procfs_file)
597
        fflush (procfs_file);
598
    }
599
 
600
  lseek_offset = -1;
601
  return ret;
602
}
603
 
604
off_t
605
lseek_with_trace (fd, offset, whence, file, line)
606
     int fd;
607
     off_t offset;
608
     int whence;
609
     char *file;
610
     int line;
611
{
612
  off_t ret;
613
 
614
#if 0   /* don't need output, just need address */
615
  if (procfs_trace)
616
    {
617
      if (procfs_file == NULL && procfs_filename != NULL)
618
        procfs_file = fopen (procfs_filename, "a");
619
 
620
      if (info_verbose)
621
        fprintf (procfs_file ? procfs_file : stdout,
622
                 "%s:%d -- ", file, line);
623
      fprintf (procfs_file ? procfs_file : stdout,
624
               "lseek (0x%08x, %s) \n", offset,
625
               whence == SEEK_SET ? "SEEK_SET" :
626
               whence == SEEK_CUR ? "SEEK_CUR" :
627
               whence == SEEK_END ? "SEEK_END" :
628
               "<unknown whence>");
629
      if (procfs_file)
630
        fflush (procfs_file);
631
    }
632
#endif
633
  ret = lseek (fd, offset, whence);
634
  lseek_offset = ret;
635
  if (procfs_trace && ret == -1)
636
    {
637
      if (procfs_file == NULL && procfs_filename != NULL)
638
        procfs_file = fopen (procfs_filename, "a");
639
 
640
      fprintf (procfs_file ? procfs_file : stdout,
641
               "[lseek (0x%08x) FAILED!\n", offset);
642
      if (procfs_file)
643
        fflush (procfs_file);
644
    }
645
 
646
  return ret;
647
}
648
 
649
#endif /* NEW_PROC_API */
650
 
651
int
652
open_with_trace (filename, mode, file, line)
653
     char *filename;
654
     int   mode;
655
     char *file;
656
     int   line;
657
{
658
  int ret = open (filename, mode);
659
 
660
  if (procfs_trace)
661
    {
662
      if (procfs_file == NULL && procfs_filename != NULL)
663
        procfs_file = fopen (procfs_filename, "a");
664
 
665
      if (info_verbose)
666
        fprintf (procfs_file ? procfs_file : stdout,
667
                 "%s:%d -- ", file, line);
668
      fprintf (procfs_file ? procfs_file : stdout,
669
               "%d = open (%s, ", ret, filename);
670
      if (mode == O_RDONLY)
671
        fprintf (procfs_file ? procfs_file : stdout, "O_RDONLY) %d\n", line);
672
      else if (mode == O_WRONLY)
673
        fprintf (procfs_file ? procfs_file : stdout, "O_WRONLY) %d\n", line);
674
      else if (mode == O_RDWR)
675
        fprintf (procfs_file ? procfs_file : stdout, "O_RDWR)   %d\n", line);
676
      if (procfs_file)
677
        fflush (procfs_file);
678
    }
679
 
680
  return ret;
681
}
682
 
683
int
684
close_with_trace (fd, file, line)
685
     int   fd;
686
     char *file;
687
     int   line;
688
{
689
  int ret = close (fd);
690
 
691
  if (procfs_trace)
692
    {
693
      if (procfs_file == NULL && procfs_filename != NULL)
694
        procfs_file = fopen (procfs_filename, "a");
695
 
696
      if (info_verbose)
697
        fprintf (procfs_file ? procfs_file : stdout,
698
                 "%s:%d -- ", file, line);
699
      fprintf (procfs_file ? procfs_file : stdout,
700
               "%d = close (%d)\n", ret, fd);
701
      if (procfs_file)
702
        fflush (procfs_file);
703
    }
704
 
705
  return ret;
706
}
707
 
708
int
709
wait_with_trace (wstat, file, line)
710
     int  *wstat;
711
     char *file;
712
     int   line;
713
{
714
  int ret, lstat = 0;
715
 
716
  if (procfs_trace)
717
    {
718
      if (procfs_file == NULL && procfs_filename != NULL)
719
        procfs_file = fopen (procfs_filename, "a");
720
 
721
      if (info_verbose)
722
        fprintf (procfs_file ? procfs_file : stdout,
723
                 "%s:%d -- ", file, line);
724
      fprintf (procfs_file ? procfs_file : stdout,
725
               "wait (line %d) ", line);
726
      if (procfs_file)
727
        fflush (procfs_file);
728
    }
729
  ret = wait (&lstat);
730
  if (procfs_trace)
731
    {
732
      fprintf (procfs_file ? procfs_file : stdout,
733
               "returned pid %d, status 0x%x\n", ret, lstat);
734
      if (procfs_file)
735
        fflush (procfs_file);
736
    }
737
  if (wstat)
738
    *wstat = lstat;
739
 
740
  return ret;
741
}
742
 
743
void
744
procfs_note (msg, file, line)
745
     char *msg;
746
     char *file;
747
     int   line;
748
{
749
  if (procfs_trace)
750
    {
751
      if (procfs_file == NULL && procfs_filename != NULL)
752
        procfs_file = fopen (procfs_filename, "a");
753
 
754
      if (info_verbose)
755
        fprintf (procfs_file ? procfs_file : stdout,
756
                 "%s:%d -- ", file, line);
757
      fprintf (procfs_file ? procfs_file : stdout, msg);
758
      if (procfs_file)
759
        fflush (procfs_file);
760
    }
761
}
762
 
763
void
764
proc_prettyfprint_status (flags, why, what, thread)
765
     long flags;
766
     int  why;
767
     int  what;
768
     int  thread;
769
{
770
  if (procfs_trace)
771
    {
772
      if (procfs_file == NULL && procfs_filename != NULL)
773
        procfs_file = fopen (procfs_filename, "a");
774
 
775
      if (thread)
776
        fprintf (procfs_file ? procfs_file : stdout,
777
                 "Thread %d: ", thread);
778
 
779
      proc_prettyfprint_flags (procfs_file ? procfs_file : stdout,
780
                               flags, 0);
781
 
782
      if (flags & (PR_STOPPED | PR_ISTOP))
783
        proc_prettyfprint_why (procfs_file ? procfs_file : stdout,
784
                               why, what, 0);
785
      if (procfs_file)
786
        fflush (procfs_file);
787
    }
788
}
789
 
790
 
791
void
792
_initialize_proc_api ()
793
{
794
  struct cmd_list_element *c;
795
 
796
  c = add_set_cmd ("procfs-trace", no_class,
797
                   var_boolean, (char *) &procfs_trace,
798
                   "Set tracing for /proc ioctl calls.\n", &setlist);
799
 
800
  add_show_from_set (c, &showlist);
801
  c->function.sfunc = set_procfs_trace_cmd;
802
 
803
  c = add_set_cmd ("procfs-file", no_class, var_filename,
804
                   (char *) &procfs_filename,
805
                   "Set filename for /proc tracefile.\n", &setlist);
806
 
807
  add_show_from_set (c, &showlist);
808
  c->function.sfunc = set_procfs_file_cmd;
809
 
810
#ifdef TRACE_PROCFS
811
  if (procfs_file == NULL && procfs_filename != NULL)
812
    procfs_file = fopen (procfs_filename, "a");
813
#endif
814
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.