#! /usr/bin/perl -w # # Build the server/trace.c and include/server/request.h files # from the contents of include/server.h. # # Copyright (C) 1998 Alexandre Julliard # %formats = ( "int" => "%d", "unsigned int" => "%08x", "void*" => "%p" ); my @requests = (); my %replies = (); open(SERVER,"include/server.h") or die "Can't open include/server.h"; open(TRACE,">server/trace.c") or die "Can't create server/trace.c"; open(REQUESTS,">include/server/request.h") or die "Can't create include/server/request.h"; ### Generate the header print TRACE < #include #include #include "server.h" #include "server/thread.h" EOF ### Parse server.h to find request/reply structure definitions while () { if (/^struct +(\w+)_request/) { &DO_REQUEST($1); } if (/^struct +(\w+)_reply/) { &DO_REPLY($1); } } ### Output the dumping function tables print TRACE<last_req = req; printf( "%08x: %s(", (unsigned int)current, req_names[req] ); dumpers[req].dump_req( data ); if (len > dumpers[req].size) { unsigned char *ptr = (unsigned char *)data + dumpers[req].size; len -= dumpers[req].size; while (len--) printf( ", %02x", *ptr++ ); } if (fd != -1) printf( " ) fd=%d\\n", fd ); else printf( " )\\n" ); } void trace_timeout(void) { printf( "%08x: *timeout*\\n", (unsigned int)current ); } void trace_kill( int exit_code ) { printf( "%08x: *killed* exit_code=%d\\n", (unsigned int)current, exit_code ); } void trace_reply( struct thread *thread, int type, int pass_fd, struct iovec *vec, int veclen ) { if (!thread) return; printf( "%08x: %s() = %d", (unsigned int)thread, req_names[thread->last_req], type ); if (veclen) { printf( " {" ); if (dumpers[thread->last_req].dump_reply) { dumpers[thread->last_req].dump_reply( vec->iov_base ); vec++; veclen--; } for (; veclen; veclen--, vec++) { unsigned char *ptr = vec->iov_base; int len = vec->iov_len; while (len--) printf( ", %02x", *ptr++ ); } printf( " }" ); } if (pass_fd != -1) printf( " fd=%d\\n", pass_fd ); else printf( "\\n" ); } EOF ### Output the requests list print REQUESTS <) { last if /^};$/; next if /^{$/; s!/\*.*\*/!!g; next if /^\s*$/; / *(\w+\**( +\w+\**)*) +(\w+);/ or die "Unrecognized syntax $_"; my $type = $1; my $var = $3; die "Unrecognized type $type" unless defined($formats{$type}); push @struct, $type, $var; } push @requests, $name; &DO_DUMP_FUNC( $name . "_request",@struct); } ### Handle a reply structure definition sub DO_REPLY { my $name = shift; my @struct = (); while () { last if /^};$/; next if /^{$/; s!/\*.*\*/!!g; next if /^\s*$/; / *(\w+\**( +\w+\**)*) +(\w+);/ or die "Unrecognized syntax $_"; my $type = $1; my $var = $3; die "Unrecognized type $type" unless defined($formats{$type}); push @struct, $type, $var; } $replies{$name} = 1; &DO_DUMP_FUNC( $name . "_reply" ,@struct); } ### Generate a dumping function sub DO_DUMP_FUNC { my $name = shift; print TRACE "\nstatic void dump_$name( struct $name *req )\n{\n"; while ($#_ >= 0) { my $type = shift; my $var = shift; print TRACE " printf( \" $var=$formats{$type}"; print TRACE "," if ($#_ > 0); print TRACE "\", req->$var );\n"; } print TRACE "}\n"; }