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
13 "char[0]" => "\\\"%.*s\\\"",
14 "unsigned int" => "%08x",
22 open(SERVER
,"include/server.h") or die "Can't open include/server.h";
23 open(TRACE
,">server/trace.c") or die "Can't create server/trace.c";
24 open(REQUESTS
,">include/server/request.h") or die "Can't create include/server/request.h";
26 ### Generate the header
29 /* File generated automatically by $0; DO NOT EDIT!! */
32 #include <sys/types.h>
35 #include "server/thread.h"
38 ### Parse server.h to find request/reply structure definitions
42 if (/^struct +(\w+)_request/) { &DO_REQUEST
($1); }
43 if (/^struct +(\w+)_reply/) { &DO_REPLY
($1); }
46 ### Output the dumping function tables
52 int (*dump_req)( void *data, int len );
53 void (*dump_reply)( void *data );
56 static const struct dumper dumpers[REQ_NB_REQUESTS] =
60 foreach $req (@requests)
62 $request = $req . "_request";
63 $reply = $replies{$req} ?
"dump_${req}_reply" : "0";
64 print TRACE
" { (int(*)(void *,int))dump_$request,\n";
65 print TRACE
" (void(*)())$reply },\n";
71 static const char * const req_names[REQ_NB_REQUESTS] =
74 foreach $req (@requests)
76 print TRACE
" \"$req\",\n";
79 ### Output the tracing functions
84 void trace_request( enum request req, void *data, int len, int fd )
87 current->last_req = req;
88 printf( "%08x: %s(", (unsigned int)current, req_names[req] );
89 size = dumpers[req].dump_req( data, len );
90 if ((len -= size) > 0)
92 unsigned char *ptr = (unsigned char *)data + size;
93 while (len--) printf( ", %02x", *ptr++ );
95 if (fd != -1) printf( " ) fd=%d\\n", fd );
96 else printf( " )\\n" );
99 void trace_timeout(void)
101 printf( "%08x: *timeout*\\n", (unsigned int)current );
104 void trace_kill( int exit_code )
106 printf( "%08x: *killed* exit_code=%d\\n",
107 (unsigned int)current, exit_code );
110 void trace_reply( struct thread *thread, int type, int pass_fd,
111 struct iovec *vec, int veclen )
114 printf( "%08x: %s() = %d",
115 (unsigned int)thread, req_names[thread->last_req], type );
119 if (dumpers[thread->last_req].dump_reply)
121 dumpers[thread->last_req].dump_reply( vec->iov_base );
125 for (; veclen; veclen--, vec++)
127 unsigned char *ptr = vec->iov_base;
128 int len = vec->iov_len;
129 while (len--) printf( ", %02x", *ptr++ );
133 if (pass_fd != -1) printf( " fd=%d\\n", pass_fd );
134 else printf( "\\n" );
138 ### Output the requests list
140 print REQUESTS
<<EOF;
141 /* File generated automatically by $0; DO NOT EDIT!! */
143 #ifndef __WINE_SERVER_REQUEST_H
144 #define __WINE_SERVER_REQUEST_H
150 foreach $req (@requests)
152 print REQUESTS
" REQ_\U$req,\n";
155 print REQUESTS
<<EOF;
159 #ifdef WANT_REQUEST_HANDLERS
161 #define DECL_HANDLER(name) \\
162 static void req_##name( struct name##_request *req, void *data, int len, int fd )
166 foreach $req (@requests) { print REQUESTS
"DECL_HANDLER($req);\n"; }
168 print REQUESTS
<<EOF;
170 static const struct handler {
172 unsigned int min_size;
173 } req_handlers[REQ_NB_REQUESTS] = {
176 foreach $req (@requests)
178 print REQUESTS
" { (void(*)())req_$req, sizeof(struct ${req}_request) },\n";
181 print REQUESTS
<<EOF;
183 #endif /* WANT_REQUEST_HANDLERS */
185 #endif /* __WINE_SERVER_REQUEST_H */
188 ### Handle a request structure definition
200 / *(\w+\**( +\w+\**)*) +(\w+)(\[0\])?;/ or die "Unrecognized syntax $_";
201 my $type = $1 . ($4 || "");
203 die "Unrecognized type $type" unless defined($formats{$type});
204 push @struct, $type, $var;
206 push @requests, $name;
207 &DO_DUMP_FUNC
( $name . "_request",@struct);
210 ### Handle a reply structure definition
222 / *(\w+\**( +\w+\**)*) +(\w+);/ or die "Unrecognized syntax $_";
225 die "Unrecognized type $type" unless defined($formats{$type});
226 push @struct, $type, $var;
229 &DO_DUMP_FUNC
( $name . "_reply" ,@struct);
232 ### Generate a dumping function
238 print TRACE
"\nstatic int dump_$name( struct $name *req, int len )\n{\n";
243 print TRACE
" printf( \" $var=$formats{$type}";
244 print TRACE
"," if ($#_ > 0);
246 if ($type =~ s/\[0\]$//g) # vararg type?
249 print TRACE
"len - (int)sizeof(*req), ($type *)(req+1) );\n";
253 print TRACE
"req->$var );\n";
256 print TRACE
" return ", $vararg ?
"len" : "(int)sizeof(*req)", ";\n}\n";