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!! */
31 #include "server/thread.h"
34 ### Parse server.h to find request/reply structure definitions
38 if (/^struct +(\w+)_request/) { &DO_REQUEST($1); }
39 if (/^struct +(\w+)_reply/) { &DO_REPLY($1); }
42 ### Output the dumping function tables
53 static const struct dumper dumpers[REQ_NB_REQUESTS] =
57 foreach $req (@requests)
59 $request = $req . "_request";
60 $reply = $replies{$req} ? "dump_${req}_reply" : "0";
61 print TRACE " { (void(*)())dump_$request,\n";
62 print TRACE " (void(*)())$reply,\n";
63 print TRACE " sizeof(struct $request) },\n";
69 static const char * const req_names[REQ_NB_REQUESTS] =
72 foreach $req (@requests)
74 print TRACE " \"$req\",\n";
77 ### Output the tracing functions
82 void trace_request( enum request req, void *data, int len, int fd )
84 current->last_req = req;
85 printf( "%08x: %s(", (unsigned int)current, req_names[req] );
86 dumpers[req].dump_req( data );
87 if (len > dumpers[req].size)
89 unsigned char *ptr = (unsigned char *)data + dumpers[req].size;
90 len -= dumpers[req].size;
91 while (len--) printf( ", %02x", *ptr++ );
93 if (fd != -1) printf( " ) fd=%d\\n", fd );
94 else printf( " )\\n" );
97 void trace_timeout(void)
99 printf( "%08x: *timeout*\\n", (unsigned int)current );
102 void trace_kill( int exit_code )
104 printf( "%08x: *killed* exit_code=%d\\n",
105 (unsigned int)current, exit_code );
108 void trace_reply( struct thread *thread, int type, int pass_fd,
109 struct iovec *vec, int veclen )
112 printf( "%08x: %s() = %d",
113 (unsigned int)thread, req_names[thread->last_req], type );
117 if (dumpers[thread->last_req].dump_reply)
119 dumpers[thread->last_req].dump_reply( vec->iov_base );
123 for (; veclen; veclen--, vec++)
125 unsigned char *ptr = vec->iov_base;
126 int len = vec->iov_len;
127 while (len--) printf( ", %02x", *ptr++ );
131 if (pass_fd != -1) printf( " fd=%d\\n", pass_fd );
132 else printf( "\\n" );
136 ### Output the requests list
138 print REQUESTS <<EOF;
139 /* File generated automatically by $0; DO NOT EDIT!! */
141 #ifndef __WINE_SERVER_REQUEST_H
142 #define __WINE_SERVER_REQUEST_H
148 foreach $req (@requests)
150 print REQUESTS " REQ_\U$req,\n";
153 print REQUESTS <<EOF;
157 #ifdef WANT_REQUEST_HANDLERS
159 #define DECL_HANDLER(name) \\
160 static void req_##name( struct name##_request *req, void *data, int len, int fd )
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
197 / *(\w+\**( +\w+\**)*) +(\w+);/ or die "Unrecognized syntax $_";
200 die "Unrecognized type $type" unless defined($formats{$type});
201 push @struct, $type, $var;
203 push @requests, $name;
204 &DO_DUMP_FUNC( $name . "_request",@struct);
207 ### Handle a reply structure definition
218 / *(\w+\**( +\w+\**)*) +(\w+);/ or die "Unrecognized syntax $_";
221 die "Unrecognized type $type" unless defined($formats{$type});
222 push @struct, $type, $var;
225 &DO_DUMP_FUNC( $name . "_reply" ,@struct);
228 ### Generate a dumping function
233 print TRACE "\nstatic void dump_$name( struct $name *req )\n{\n";
238 print TRACE " printf( \" $var=$formats{$type}";
239 print TRACE "," if ($#_ > 0);
240 print TRACE "\", req->$var );\n";
241 $size .= "+sizeof($type)";