3 # Build the server/trace.c and include/server/request.h files
4 # from the contents of include/server.h.
6 # Copyright (C) 1998 Alexandre Julliard
12 "unsigned int" => "%08x",
19 open(SERVER
,"include/server.h") or die "Can't open include/server.h";
20 open(TRACE
,">server/trace.c") or die "Can't create server/trace.c";
21 open(REQUESTS
,">include/server/request.h") or die "Can't create include/server/request.h";
23 ### Generate the header
26 /* File generated automatically by $0; DO NOT EDIT!! */
29 #include <sys/types.h>
32 #include "server/thread.h"
35 ### Parse server.h to find request/reply structure definitions
39 if (/^struct +(\w+)_request/) { &DO_REQUEST
($1); }
40 if (/^struct +(\w+)_reply/) { &DO_REPLY
($1); }
43 ### Output the dumping function tables
54 static const struct dumper dumpers[REQ_NB_REQUESTS] =
58 foreach $req (@requests)
60 $request = $req . "_request";
61 $reply = $replies{$req} ?
"dump_${req}_reply" : "0";
62 print TRACE
" { (void(*)())dump_$request,\n";
63 print TRACE
" (void(*)())$reply,\n";
64 print TRACE
" sizeof(struct $request) },\n";
70 static const char * const req_names[REQ_NB_REQUESTS] =
73 foreach $req (@requests)
75 print TRACE
" \"$req\",\n";
78 ### Output the tracing functions
83 void trace_request( enum request req, void *data, int len, int fd )
85 current->last_req = req;
86 printf( "%08x: %s(", (unsigned int)current, req_names[req] );
87 dumpers[req].dump_req( data );
88 if (len > dumpers[req].size)
90 unsigned char *ptr = (unsigned char *)data + dumpers[req].size;
91 len -= dumpers[req].size;
92 while (len--) printf( ", %02x", *ptr++ );
94 if (fd != -1) printf( " ) fd=%d\\n", fd );
95 else printf( " )\\n" );
98 void trace_timeout(void)
100 printf( "%08x: *timeout*\\n", (unsigned int)current );
103 void trace_kill( int exit_code )
105 printf( "%08x: *killed* exit_code=%d\\n",
106 (unsigned int)current, exit_code );
109 void trace_reply( struct thread *thread, int type, int pass_fd,
110 struct iovec *vec, int veclen )
113 printf( "%08x: %s() = %d",
114 (unsigned int)thread, req_names[thread->last_req], type );
118 if (dumpers[thread->last_req].dump_reply)
120 dumpers[thread->last_req].dump_reply( vec->iov_base );
124 for (; veclen; veclen--, vec++)
126 unsigned char *ptr = vec->iov_base;
127 int len = vec->iov_len;
128 while (len--) printf( ", %02x", *ptr++ );
132 if (pass_fd != -1) printf( " fd=%d\\n", pass_fd );
133 else printf( "\\n" );
137 ### Output the requests list
139 print REQUESTS
<<EOF;
140 /* File generated automatically by $0; DO NOT EDIT!! */
142 #ifndef __WINE_SERVER_REQUEST_H
143 #define __WINE_SERVER_REQUEST_H
149 foreach $req (@requests)
151 print REQUESTS
" REQ_\U$req,\n";
154 print REQUESTS
<<EOF;
158 #ifdef WANT_REQUEST_HANDLERS
160 #define DECL_HANDLER(name) \\
161 static void req_##name( struct name##_request *req, void *data, int len, int fd )
165 foreach $req (@requests) { print REQUESTS
"DECL_HANDLER($req);\n"; }
167 print REQUESTS
<<EOF;
169 static const struct handler {
171 unsigned int min_size;
172 } req_handlers[REQ_NB_REQUESTS] = {
175 foreach $req (@requests)
177 print REQUESTS
" { (void(*)())req_$req, sizeof(struct ${req}_request) },\n";
180 print REQUESTS
<<EOF;
182 #endif /* WANT_REQUEST_HANDLERS */
184 #endif /* __WINE_SERVER_REQUEST_H */
187 ### Handle a request structure definition
199 / *(\w+\**( +\w+\**)*) +(\w+);/ or die "Unrecognized syntax $_";
202 die "Unrecognized type $type" unless defined($formats{$type});
203 push @struct, $type, $var;
205 push @requests, $name;
206 &DO_DUMP_FUNC
( $name . "_request",@struct);
209 ### Handle a reply structure definition
221 / *(\w+\**( +\w+\**)*) +(\w+);/ or die "Unrecognized syntax $_";
224 die "Unrecognized type $type" unless defined($formats{$type});
225 push @struct, $type, $var;
228 &DO_DUMP_FUNC
( $name . "_reply" ,@struct);
231 ### Generate a dumping function
236 print TRACE
"\nstatic void dump_$name( struct $name *req )\n{\n";
241 print TRACE
" printf( \" $var=$formats{$type}";
242 print TRACE
"," if ($#_ > 0);
243 print TRACE
"\", req->$var );\n";