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 "unsigned int" => "%08x",
17 "char[0]" => "dump_chars",
18 "int[0]" => "dump_ints",
19 "void*[0]" => "dump_ptrs"
25 open(SERVER
,"include/server.h") or die "Can't open include/server.h";
26 open(TRACE
,">server/trace.c") or die "Can't create server/trace.c";
27 open(REQUESTS
,">include/server/request.h") or die "Can't create include/server/request.h";
29 ### Generate the header
32 /* File generated automatically by $0; DO NOT EDIT!! */
35 #include <sys/types.h>
40 static int dump_chars( void *ptr, int len )
42 fprintf( stderr, "\\\"%.*s\\\"", len, (char *)ptr );
46 static int dump_ints( void *ptr, int len )
49 if (!(len /= sizeof(int)))
51 fprintf( stderr, "{}" );
54 for (i = 0; i < len; i++)
55 fprintf( stderr, "%c%d", i ? ',' : '{', *((int *)ptr + i) );
56 fprintf( stderr, "}" );
57 return len * sizeof(int);
60 static int dump_ptrs( void *ptr, int len )
63 if (!(len /= sizeof(void*)))
65 fprintf( stderr, "{}" );
68 for (i = 0; i < len; i++)
69 fprintf( stderr, "%c%p", i ? ',' : '{', *((void **)ptr + i) );
70 fprintf( stderr, "}" );
71 return len * sizeof(void*);
75 ### Parse server.h to find request/reply structure definitions
79 if (/^struct +(\w+)_request/) { &DO_REQUEST
($1); }
80 if (/^struct +(\w+)_reply/) { &DO_REPLY
($1); }
83 ### Output the dumping function tables
85 print TRACE
"typedef int (*dump_func)( void *req, int len );\n\n";
86 print TRACE
"static const dump_func req_dumpers[REQ_NB_REQUESTS] = {\n";
87 foreach $req (@requests)
89 print TRACE
" (dump_func)dump_${req}_request,\n";
93 print TRACE
"static const dump_func reply_dumpers[REQ_NB_REQUESTS] = {\n";
94 foreach $req (@requests)
96 print TRACE
" (dump_func)", $replies{$req} ?
"dump_${req}_reply,\n" : "0,\n";
101 static const char * const req_names[REQ_NB_REQUESTS] =
104 foreach $req (@requests)
106 print TRACE
" \"$req\",\n";
109 ### Output the tracing functions
114 void trace_request( enum request req, void *data, int len, int fd )
117 current->last_req = req;
118 fprintf( stderr, "%08x: %s(", (unsigned int)current, req_names[req] );
119 size = req_dumpers[req]( data, len );
120 if ((len -= size) > 0)
122 unsigned char *ptr = (unsigned char *)data + size;
123 while (len--) fprintf( stderr, ", %02x", *ptr++ );
125 if (fd != -1) fprintf( stderr, " ) fd=%d\\n", fd );
126 else fprintf( stderr, " )\\n" );
129 void trace_timeout(void)
131 fprintf( stderr, "%08x: *timeout*\\n", (unsigned int)current );
134 void trace_kill( int exit_code )
136 fprintf( stderr,"%08x: *killed* exit_code=%d\\n",
137 (unsigned int)current, exit_code );
140 void trace_reply( struct thread *thread, int type, int pass_fd,
141 struct iovec *vec, int veclen )
143 static char buffer[MAX_MSG_LENGTH];
146 fprintf( stderr, "%08x: %s() = %d",
147 (unsigned int)thread, req_names[thread->last_req], type );
152 for (; veclen; veclen--, vec++)
154 memcpy( p, vec->iov_base, vec->iov_len );
157 fprintf( stderr, " {" );
159 if (reply_dumpers[thread->last_req])
160 len -= reply_dumpers[thread->last_req]( buffer, len );
162 while (len--) fprintf( stderr, ", %02x", *p++ );
163 fprintf( stderr, " }" );
165 if (pass_fd != -1) fprintf( stderr, " fd=%d\\n", pass_fd );
166 else fprintf( stderr, "\\n" );
170 ### Output the requests list
172 print REQUESTS
<<EOF;
173 /* File generated automatically by $0; DO NOT EDIT!! */
175 #ifndef __WINE_SERVER_REQUEST_H
176 #define __WINE_SERVER_REQUEST_H
182 foreach $req (@requests)
184 print REQUESTS
" REQ_\U$req,\n";
187 print REQUESTS
<<EOF;
191 #ifdef WANT_REQUEST_HANDLERS
195 foreach $req (@requests) { print REQUESTS
"DECL_HANDLER($req);\n"; }
197 print REQUESTS
<<EOF;
199 static const struct handler {
201 unsigned int min_size;
202 } req_handlers[REQ_NB_REQUESTS] = {
205 foreach $req (@requests)
207 print REQUESTS
" { (void(*)())req_$req, sizeof(struct ${req}_request) },\n";
210 print REQUESTS
<<EOF;
212 #endif /* WANT_REQUEST_HANDLERS */
214 #endif /* __WINE_SERVER_REQUEST_H */
217 ### Handle a request structure definition
229 / *(\w+\**( +\w+\**)*) +(\w+)(\[0\])?;/ or die "Unrecognized syntax $_";
230 my $type = $1 . ($4 || "");
232 die "Unrecognized type $type" unless defined($formats{$type});
233 push @struct, $type, $var;
235 push @requests, $name;
236 &DO_DUMP_FUNC
( $name . "_request",@struct);
239 ### Handle a reply structure definition
251 / *(\w+\**( +\w+\**)*) +(\w+)(\[0\])?;/ or die "Unrecognized syntax $_";
252 my $type = $1 . ($4 || "");
254 die "Unrecognized type $type" unless defined($formats{$type});
255 push @struct, $type, $var;
258 &DO_DUMP_FUNC
( $name . "_reply" ,@struct);
261 ### Generate a dumping function
267 print TRACE
"\nstatic int dump_$name( struct $name *req, int len )\n{\n";
272 if ($type =~ /\[0\]$/) # vararg type?
275 print TRACE
" fprintf( stderr, \" $var=\" );\n";
276 print TRACE
" return $formats{$type}( req+1, len - (int)sizeof(*req) ) + sizeof(*req);\n";
280 print TRACE
" fprintf( stderr, \" $var=$formats{$type}";
281 print TRACE
"," if ($#_ > 0);
283 print TRACE
"req->$var );\n";
286 print TRACE
" return (int)sizeof(*req);\n" unless $vararg;