I have added the capability for a user to specify an additional RPC Name <-> ID association file on the command line using a -i flag, or --input=FILE. Updated the --help output to reflect this new option. Generalized the file parsing function to accept filename argument.
Both an incremental diff (to my patch on 01/25) and a full diff to the CVS version is included below. Also, browsing the MiG sources I noticed an option of -list, that should output an associations file suitable for rpctrace. I have been unable to get the file created on my system, if anyone has successfully created this file, please post it. I run: `mig -list msgids /include/hurd/*.defs /include/mach/*.defs` and get the following error: "mig: fatal: no SubSystem declaration" But I perl'd through all of the above .defs files and each had a leading 'subsystem' declaration. The msgids file contains only 10 lines of output, all from the fsys_reply subsystem. Regards, Michael Oberg [EMAIL PROTECTED] ---------------------------------------------------------- Full Diff against CVS Version: --- ./rpctrace.c.orig Mon Jan 28 19:14:05 2002 +++ ./rpctrace.c Mon Jan 28 19:14:32 2002 @@ -37,6 +37,7 @@ static const struct argp_option options[] = { {"output", 'o', "FILE", 0, "Send trace output to FILE instead of stderr."}, + {"input", 'i', "FILE", 0, "Parse FILE for additional RPC name<->id associations."}, {0} }; @@ -44,7 +45,69 @@ static const char *doc = "Trace Mach Remote Procedure Calls." "\v."; - + +static const char *system_msgids_filename = "/etc/rpctrace/msgids"; +ihash_t msgids; + +/* Parse the system /etc/rpctrace/msgids file. + syntax: '[routine_name] [routine_id]\n' */ +void +parse_msgids (char *msgids_filename) +{ + FILE *msgids_file; + error_t err; + char *linebuf = NULL; + size_t linebufsize = 0; + char routine_name_buf[256]; + int routine_id; + int linenum; + + /* Open msgids file */ + msgids_file = fopen (msgids_filename, "r"); + if (!msgids_file) + error (1, errno, "%s", msgids_filename); + + /* Parse msgids file line by line, adding each routine->id pair into + the msgids ihash. */ + linenum = 0; + while (getline(&linebuf, &linebufsize, msgids_file) != EOF) + { + linenum++; + if (sscanf(linebuf, "%s %d", routine_name_buf, &routine_id) == 2) + { + /* Allocate storage for each new routine_name, plus null termination */ + /* 7 extra chars in reply to account for "(reply)", postpended below */ + char *routine_name = (char *) malloc (strlen(routine_name_buf)+1); + char *routine_name_reply = (char *) malloc (strlen(routine_name_buf)+8); + + /* Copy the buffer's contents into each new string */ + strcpy(routine_name, routine_name_buf); + strcpy(routine_name_reply, routine_name_buf); + + /* Add the text "(reply)" to differentiate the reply routine name */ + strcat(routine_name_reply, "(reply)"); + + /* Add null termination to the end of the strings */ + routine_name[strlen(routine_name)] = '\0'; + routine_name_reply[strlen(routine_name_reply)] = '\0'; + + /* Add routine and routine_id to msgids hash */ + err = ihash_add (msgids, routine_id, routine_name, NULL); + assert_perror(err); + + /* Add "routine(reply)" and routine_id+100 to msgids hash */ + routine_id += 100; + err = ihash_add (msgids, routine_id, routine_name_reply, NULL); + assert_perror(err); + } + else + { + fprintf (stdout, "Bad input line:%d, in file: %s\n", + linenum, msgids_filename); + } + } +} + /* We keep one of these structures for each port right we are tracing. */ struct traced_info { @@ -692,10 +755,13 @@ expected_reply_port = msg->msgh_local_port; if (receiver->name != 0) - fprintf (ostream, "%4s->%5u (", receiver->name, msg->msgh_id); + fprintf (ostream, "%4s->%s(%4u) (", + receiver->name, + (char *)ihash_find(msgids, msg->msgh_id), msg->msgh_id); else - fprintf (ostream, "%4u->%5u (", - (unsigned int) receiver->pi.port_right, msg->msgh_id); + fprintf (ostream, "%4u->%s(%4u) (", + (unsigned int) receiver->pi.port_right, + (char *)ihash_find(msgids, msg->msgh_id), msg->msgh_id); } static void @@ -742,7 +808,7 @@ fprintf (ostream, " > "); else /* Weirdo. */ - fprintf (ostream, " >(%u) ", reply->Head.msgh_id); + fprintf (ostream, " >(%s) ", (char *)ihash_find(msgids, reply->Head.msgh_id)); } if (reply->RetCode == 0) @@ -905,6 +971,7 @@ main (int argc, char **argv, char **envp) { const char *outfile = 0; + const char *user_msgids_filename = 0; char **cmd_argv = 0; error_t err; @@ -917,6 +984,10 @@ outfile = arg; break; + case 'i': + user_msgids_filename = arg; + break; + case ARGP_KEY_NO_ARGS: argp_usage (state); return EINVAL; @@ -945,6 +1016,17 @@ else ostream = stderr; setlinebuf (ostream); + + /* Parse system msgids file */ + err = ihash_create (&msgids); + assert_perror (err); + parse_msgids(system_msgids_filename); + + /* Parse user-supplied msgids file */ + if (user_msgids_filename) + { + parse_msgids(user_msgids_filename); + } traced_bucket = ports_create_bucket (); traced_class = ports_create_class (0, &traced_dropweak); ---------------------------------------------------------- Partial Diff against 01/25 Version: --- rpctrace.c.orig Mon Jan 28 19:25:57 2002 +++ rpctrace.c Mon Jan 28 19:25:18 2002 @@ -37,6 +37,7 @@ static const struct argp_option options[] = { {"output", 'o', "FILE", 0, "Send trace output to FILE instead of stderr."}, + {"input", 'i', "FILE", 0, "Parse FILE for additional RPC name<->id associations."}, {0} }; @@ -44,13 +45,14 @@ static const char *doc = "Trace Mach Remote Procedure Calls." "\v."; -static const char *msgids_filename = "/etc/rpctrace/msgids"; + +static const char *system_msgids_filename = "/etc/rpctrace/msgids"; ihash_t msgids; /* Parse the system /etc/rpctrace/msgids file. syntax: '[routine_name] [routine_id]\n' */ void -parse_system_msgids (void) +parse_msgids (char *msgids_filename) { FILE *msgids_file; error_t err; @@ -59,17 +61,11 @@ char routine_name_buf[256]; int routine_id; int linenum; - void **loco; /* crazyness */ - void *locp = &loco; - /* Open system msgids file */ + /* Open msgids file */ msgids_file = fopen (msgids_filename, "r"); if (!msgids_file) error (1, errno, "%s", msgids_filename); - - /* Create ihash */ - err = ihash_create (&msgids); - assert_perror (err); /* Parse msgids file line by line, adding each routine->id pair into the msgids ihash. */ @@ -79,7 +75,7 @@ linenum++; if (sscanf(linebuf, "%s %d", routine_name_buf, &routine_id) == 2) { - /* Allocate storage for each new routine_name */ + /* Allocate storage for each new routine_name, plus null termination */ /* 7 extra chars in reply to account for "(reply)", postpended below */ char *routine_name = (char *) malloc (strlen(routine_name_buf)+1); char *routine_name_reply = (char *) malloc (strlen(routine_name_buf)+8); @@ -96,12 +92,12 @@ routine_name_reply[strlen(routine_name_reply)] = '\0'; /* Add routine and routine_id to msgids hash */ - err = ihash_add (msgids, routine_id, routine_name, locp); + err = ihash_add (msgids, routine_id, routine_name, NULL); assert_perror(err); /* Add "routine(reply)" and routine_id+100 to msgids hash */ routine_id += 100; - err = ihash_add (msgids, routine_id, routine_name_reply, locp); + err = ihash_add (msgids, routine_id, routine_name_reply, NULL); assert_perror(err); } else @@ -761,11 +757,11 @@ if (receiver->name != 0) fprintf (ostream, "%4s->%s(%4u) (", receiver->name, - ihash_find(msgids, msg->msgh_id), msg->msgh_id); + (char *)ihash_find(msgids, msg->msgh_id), msg->msgh_id); else fprintf (ostream, "%4u->%s(%4u) (", (unsigned int) receiver->pi.port_right, - ihash_find(msgids, msg->msgh_id), msg->msgh_id); + (char *)ihash_find(msgids, msg->msgh_id), msg->msgh_id); } static void @@ -812,7 +808,7 @@ fprintf (ostream, " > "); else /* Weirdo. */ - fprintf (ostream, " >(%s) ", ihash_find(msgids, reply->Head.msgh_id)); + fprintf (ostream, " >(%s) ", (char *)ihash_find(msgids, reply->Head.msgh_id)); } if (reply->RetCode == 0) @@ -975,6 +971,7 @@ main (int argc, char **argv, char **envp) { const char *outfile = 0; + const char *user_msgids_filename = 0; char **cmd_argv = 0; error_t err; @@ -987,6 +984,10 @@ outfile = arg; break; + case 'i': + user_msgids_filename = arg; + break; + case ARGP_KEY_NO_ARGS: argp_usage (state); return EINVAL; @@ -1016,9 +1017,16 @@ ostream = stderr; setlinebuf (ostream); - /* Parse /etc/rpctrace/msgids file */ - parse_system_msgids(); - /* Parse user-supplied msgids file(s) */ + /* Parse system msgids file */ + err = ihash_create (&msgids); + assert_perror (err); + parse_msgids(system_msgids_filename); + + /* Parse user-supplied msgids file */ + if (user_msgids_filename) + { + parse_msgids(user_msgids_filename); + } traced_bucket = ports_create_bucket (); traced_class = ports_create_class (0, &traced_dropweak); _______________________________________________ Bug-hurd mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/bug-hurd