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>
36 #include "server/thread.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
162 #define DECL_HANDLER(name) \\
163 static void req_##name( struct name##_request *req, void *data, int len, int fd )
167 foreach $req (@requests) { print REQUESTS "DECL_HANDLER($req);\n"; }
169 print REQUESTS <<EOF;
171 static const struct handler {
173 unsigned int min_size;
174 } req_handlers[REQ_NB_REQUESTS] = {
177 foreach $req (@requests)
179 print REQUESTS " { (void(*)())req_$req, sizeof(struct ${req}_request) },\n";
182 print REQUESTS <<EOF;
184 #endif /* WANT_REQUEST_HANDLERS */
186 #endif /* __WINE_SERVER_REQUEST_H */
189 ### Handle a request structure definition
201 / *(\w+\**( +\w+\**)*) +(\w+)(\[0\])?;/ or die "Unrecognized syntax $_";
202 my $type = $1 . ($4 || "");
204 die "Unrecognized type $type" unless defined($formats{$type});
205 push @struct, $type, $var;
207 push @requests, $name;
208 &DO_DUMP_FUNC( $name . "_request",@struct);
211 ### Handle a reply structure definition
223 / *(\w+\**( +\w+\**)*) +(\w+);/ or die "Unrecognized syntax $_";
226 die "Unrecognized type $type" unless defined($formats{$type});
227 push @struct, $type, $var;
230 &DO_DUMP_FUNC( $name . "_reply" ,@struct);
233 ### Generate a dumping function
239 print TRACE "\nstatic int dump_$name( struct $name *req, int len )\n{\n";
244 print TRACE " fprintf( stderr, \" $var=$formats{$type}";
245 print TRACE "," if ($#_ > 0);
247 if ($type =~ s/\[0\]$//g) # vararg type?
250 print TRACE "len - (int)sizeof(*req), ($type *)(req+1) );\n";
254 print TRACE "req->$var );\n";
257 print TRACE " return ", $vararg ? "len" : "(int)sizeof(*req)", ";\n}\n";