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
14 "char[0]" => "\\\"%.*s\\\"",
15 "unsigned int" => "%08x",
23 open(SERVER
,"include/server.h") or die "Can't open include/server.h";
24 open(TRACE
,">server/trace.c") or die "Can't create server/trace.c";
25 open(REQUESTS
,">include/server/request.h") or die "Can't create include/server/request.h";
27 ### Generate the header
30 /* File generated automatically by $0; DO NOT EDIT!! */
33 #include <sys/types.h>
39 ### Parse server.h to find request/reply structure definitions
43 if (/^struct +(\w+)_request/) { &DO_REQUEST
($1); }
44 if (/^struct +(\w+)_reply/) { &DO_REPLY
($1); }
47 ### Output the dumping function tables
53 int (*dump_req)( void *data, int len );
54 void (*dump_reply)( void *data );
57 static const struct dumper dumpers[REQ_NB_REQUESTS] =
61 foreach $req (@requests)
63 $request = $req . "_request";
64 $reply = $replies{$req} ?
"dump_${req}_reply" : "0";
65 print TRACE
" { (int(*)(void *,int))dump_$request,\n";
66 print TRACE
" (void(*)())$reply },\n";
72 static const char * const req_names[REQ_NB_REQUESTS] =
75 foreach $req (@requests)
77 print TRACE
" \"$req\",\n";
80 ### Output the tracing functions
85 void trace_request( enum request req, void *data, int len, int fd )
88 current->last_req = req;
89 fprintf( stderr, "%08x: %s(", (unsigned int)current, req_names[req] );
90 size = dumpers[req].dump_req( data, len );
91 if ((len -= size) > 0)
93 unsigned char *ptr = (unsigned char *)data + size;
94 while (len--) fprintf( stderr, ", %02x", *ptr++ );
96 if (fd != -1) fprintf( stderr, " ) fd=%d\\n", fd );
97 else fprintf( stderr, " )\\n" );
100 void trace_timeout(void)
102 fprintf( stderr, "%08x: *timeout*\\n", (unsigned int)current );
105 void trace_kill( int exit_code )
107 fprintf( stderr,"%08x: *killed* exit_code=%d\\n",
108 (unsigned int)current, exit_code );
111 void trace_reply( struct thread *thread, int type, int pass_fd,
112 struct iovec *vec, int veclen )
115 fprintf( stderr, "%08x: %s() = %d",
116 (unsigned int)thread, req_names[thread->last_req], type );
119 fprintf( stderr, " {" );
120 if (dumpers[thread->last_req].dump_reply)
122 dumpers[thread->last_req].dump_reply( vec->iov_base );
126 for (; veclen; veclen--, vec++)
128 unsigned char *ptr = vec->iov_base;
129 int len = vec->iov_len;
130 while (len--) fprintf( stderr, ", %02x", *ptr++ );
132 fprintf( stderr, " }" );
134 if (pass_fd != -1) fprintf( stderr, " fd=%d\\n", pass_fd );
135 else fprintf( stderr, "\\n" );
139 ### Output the requests list
141 print REQUESTS
<<EOF;
142 /* File generated automatically by $0; DO NOT EDIT!! */
144 #ifndef __WINE_SERVER_REQUEST_H
145 #define __WINE_SERVER_REQUEST_H
151 foreach $req (@requests)
153 print REQUESTS
" REQ_\U$req,\n";
156 print REQUESTS
<<EOF;
160 #ifdef WANT_REQUEST_HANDLERS
164 foreach $req (@requests) { print REQUESTS
"DECL_HANDLER($req);\n"; }
166 print REQUESTS
<<EOF;
168 static const struct handler {
170 unsigned int min_size;
171 } req_handlers[REQ_NB_REQUESTS] = {
174 foreach $req (@requests)
176 print REQUESTS
" { (void(*)())req_$req, sizeof(struct ${req}_request) },\n";
179 print REQUESTS
<<EOF;
181 #endif /* WANT_REQUEST_HANDLERS */
183 #endif /* __WINE_SERVER_REQUEST_H */
186 ### Handle a request structure definition
198 / *(\w+\**( +\w+\**)*) +(\w+)(\[0\])?;/ or die "Unrecognized syntax $_";
199 my $type = $1 . ($4 || "");
201 die "Unrecognized type $type" unless defined($formats{$type});
202 push @struct, $type, $var;
204 push @requests, $name;
205 &DO_DUMP_FUNC
( $name . "_request",@struct);
208 ### Handle a reply structure definition
220 / *(\w+\**( +\w+\**)*) +(\w+)(\[0\])?;/ or die "Unrecognized syntax $_";
221 my $type = $1 . ($4 || "");
223 die "Unrecognized type $type" unless defined($formats{$type});
224 push @struct, $type, $var;
227 &DO_DUMP_FUNC
( $name . "_reply" ,@struct);
230 ### Generate a dumping function
236 print TRACE
"\nstatic int dump_$name( struct $name *req, int len )\n{\n";
241 print TRACE
" fprintf( stderr, \" $var=$formats{$type}";
242 print TRACE
"," if ($#_ > 0);
244 if ($type =~ s/\[0\]$//g) # vararg type?
247 print TRACE
"len - (int)sizeof(*req), ($type *)(req+1) );\n";
251 print TRACE
"req->$var );\n";
254 print TRACE
" return ", $vararg ?
"len" : "(int)sizeof(*req)", ";\n}\n";