]> granicus.if.org Git - strace/blob - bjm.c
strace_log_merge: new file. Helper to merge timestamped strace -ff logs
[strace] / bjm.c
1 /*
2  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  *      $Id$
31  */
32 #include "defs.h"
33
34 #include <fcntl.h>
35 #include <sys/stat.h>
36 #include <sys/time.h>
37 #include <sys/wait.h>
38 #include <sys/resource.h>
39 #include <sys/utsname.h>
40 #include <sys/user.h>
41 #include <sys/syscall.h>
42 #include <signal.h>
43
44 /* Bits of module.flags.  */
45
46 #define MOD_UNINITIALIZED       0
47 #define MOD_RUNNING             1
48 #define MOD_DELETED             2
49 #define MOD_AUTOCLEAN           4
50 #define MOD_VISITED             8
51 #define MOD_USED_ONCE           16
52 #define MOD_JUST_FREED          32
53 #define MOD_INITIALIZING        64
54
55 /* Values for query_module's which.  */
56
57 #define QM_MODULES      1
58 #define QM_DEPS         2
59 #define QM_REFS         3
60 #define QM_SYMBOLS      4
61 #define QM_INFO         5
62
63 struct module_symbol
64 {
65         unsigned long value;
66         const char *name;
67 };
68
69 struct module_info
70 {
71         unsigned long addr;
72         unsigned long size;
73         unsigned long flags;
74         long usecount;
75 };
76
77 static const struct xlat which[] = {
78         { 0,            "0"             },
79         { QM_MODULES,   "QM_MODULES"    },
80         { QM_DEPS,      "QM_DEPS"       },
81         { QM_REFS,      "QM_REFS"       },
82         { QM_SYMBOLS,   "QM_SYMBOLS"    },
83         { QM_INFO,      "QM_INFO"       },
84         { 0,            NULL            },
85 };
86
87 static const struct xlat modflags[] = {
88         { MOD_UNINITIALIZED,    "MOD_UNINITIALIZED"     },
89         { MOD_RUNNING,          "MOD_RUNNING"           },
90         { MOD_DELETED,          "MOD_DELETED"           },
91         { MOD_AUTOCLEAN,        "MOD_AUTOCLEAN"         },
92         { MOD_VISITED,          "MOD_VISITED"           },
93         { MOD_USED_ONCE,        "MOD_USED_ONCE"         },
94         { MOD_JUST_FREED,       "MOD_JUST_FREED"        },
95         { 0,                    NULL                    },
96 };
97
98 int
99 sys_query_module(struct tcb *tcp)
100 {
101         if (entering(tcp)) {
102                 printstr(tcp, tcp->u_arg[0], -1);
103                 tprints(", ");
104                 printxval(which, tcp->u_arg[1], "QM_???");
105                 tprints(", ");
106         } else {
107                 size_t ret;
108
109                 if (!verbose(tcp) || syserror(tcp) ||
110                     umove(tcp, tcp->u_arg[4], &ret) < 0) {
111                         tprintf("%#lx, %lu, %#lx", tcp->u_arg[2],
112                                 tcp->u_arg[3], tcp->u_arg[4]);
113                 } else if (tcp->u_arg[1]==QM_INFO) {
114                         struct module_info      mi;
115                         if (umove(tcp, tcp->u_arg[2], &mi) < 0) {
116                                 tprintf("%#lx, ", tcp->u_arg[2]);
117                         } else {
118                                 tprintf("{address=%#lx, size=%lu, flags=",
119                                         mi.addr, mi.size);
120                                 printflags(modflags, mi.flags, "MOD_???");
121                                 tprintf(", usecount=%lu}, ", mi.usecount);
122                         }
123                         tprintf("%Zu", ret);
124                 } else if ((tcp->u_arg[1]==QM_MODULES) ||
125                            (tcp->u_arg[1]==QM_DEPS) ||
126                            (tcp->u_arg[1]==QM_REFS)) {
127                         tprints("{");
128                         if (!abbrev(tcp)) {
129                                 char*   data    = malloc(tcp->u_arg[3]);
130                                 char*   mod     = data;
131                                 size_t  idx;
132
133                                 if (!data) {
134                                         fprintf(stderr, "out of memory\n");
135                                         tprintf(" /* %Zu entries */ ", ret);
136                                 } else {
137                                         if (umoven(tcp, tcp->u_arg[2],
138                                                 tcp->u_arg[3], data) < 0) {
139                                                 tprintf(" /* %Zu entries */ ", ret);
140                                         } else {
141                                                 for (idx = 0; idx < ret; idx++) {
142                                                         tprintf("%s%s",
143                                                                 (idx ? ", " : ""),
144                                                                 mod);
145                                                         mod += strlen(mod)+1;
146                                                 }
147                                         }
148                                         free(data);
149                                 }
150                         } else
151                                 tprintf(" /* %Zu entries */ ", ret);
152                         tprintf("}, %Zu", ret);
153                 } else if (tcp->u_arg[1]==QM_SYMBOLS) {
154                         tprints("{");
155                         if (!abbrev(tcp)) {
156                                 char*                   data    = malloc(tcp->u_arg[3]);
157                                 struct module_symbol*   sym     = (struct module_symbol*)data;
158                                 size_t                  idx;
159
160                                 if (!data) {
161                                         fprintf(stderr, "out of memory\n");
162                                         tprintf(" /* %Zu entries */ ", ret);
163                                 } else {
164                                         if (umoven(tcp, tcp->u_arg[2],
165                                                 tcp->u_arg[3], data) < 0) {
166                                                 tprintf(" /* %Zu entries */ ", ret);
167                                         } else {
168                                                 for (idx = 0; idx < ret; idx++) {
169                                                         tprintf("%s{name=%s, value=%lu}",
170                                                                 (idx ? " " : ""),
171                                                                 data+(long)sym->name,
172                                                                 sym->value);
173                                                         sym++;
174                                                 }
175                                         }
176                                         free(data);
177                                 }
178                         } else
179                                 tprintf(" /* %Zu entries */ ", ret);
180                         tprintf("}, %Zd", ret);
181                 } else {
182                         printstr(tcp, tcp->u_arg[2], tcp->u_arg[3]);
183                         tprintf(", %#lx", tcp->u_arg[4]);
184                 }
185         }
186         return 0;
187 }
188
189 int
190 sys_create_module(struct tcb *tcp)
191 {
192         if (entering(tcp)) {
193                 printpath(tcp, tcp->u_arg[0]);
194                 tprintf(", %lu", tcp->u_arg[1]);
195         }
196         return RVAL_HEX;
197 }
198
199 int
200 sys_init_module(struct tcb *tcp)
201 {
202         if (entering(tcp)) {
203                 tprintf("%#lx, ", tcp->u_arg[0]);
204                 tprintf("%lu, ", tcp->u_arg[1]);
205                 printstr(tcp, tcp->u_arg[2], -1);
206         }
207         return 0;
208 }