/* Copyright (C) 1989, Digital Equipment Corporation */ /* All rights reserved. */ /* See the file COPYRIGHT for a full description. */ /* Last modified on Mon Feb 12 17:35:40 1990 by kalsow */ /* modified on Fri Nov 3 11:27:47 1989 by muller */ #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define max(x,y) ((x)>(y)?(x):(y)) #define MAX_LINES 100000 #include "marker.h" char c; char line [500]; int p, i, zero; int new_instruction = FALSE, new_proc = FALSE; int opcode; char buffer [500]; char file_name [MAXPATHLEN+1]; char symbol_name [MAXPATHLEN+1]; int highest_line, line_number; int first_line = -1; int n_lines = 0; int* init_lines; typedef struct a { char *name; struct a *next; } proc_struct, *proc_entry; proc_entry procs = NULL; int nb_procs = 0; struct stat buf; FILE *input_file, *output_file; main (argc, argv) int argc; char **argv; { switch (argc) { case 1: { input_file = stdin; output_file = stdout; break; } case 2: { input_file = fopen (argv[1], "r"); if (input_file == NULL) { fprintf (stderr, "%s: Cannot open the input file %s\n", argv[0], argv[1]); exit (1); } output_file = stdout; break; } case 3: { input_file = fopen (argv[1], "r"); if (input_file == NULL) { fprintf (stderr, "%s: Cannot open the input file %s\n", argv[0], argv[1]); exit (1); } output_file = fopen (argv[2], "w"); if (output_file == NULL) { fprintf (stderr, "%s: Cannot open the output file %s\n", argv[0], argv[2]); exit (1); } break; } default: { fprintf (stderr, "%s: improper usage; %s [ input_file [ output_file ]]", argv[0], argv[0]); exit (1); }} highest_line = -1; init_lines = (int*) malloc ((MAX_LINES+1) * sizeof (int)); for (i = 1; i <= MAX_LINES; i++) init_lines [i] = -1; while (! feof (input_file)) { c = getc (input_file); p = 0; while (c != EOF && c != '\n') { line [p++] = c; c = getc (input_file); } line [p] = '\0'; if (strncmp (line, "\t.stab", 6) == 0) { switch (line[6]) { case 's': { int start_string, stop_string, colon; if ((sscanf (line+8, "\"%[^\"]\",0x%x", buffer, &opcode) == 2 || sscanf (line+8, "\"%[^\"]\",0%o", buffer, &opcode) == 2 || sscanf (line+8, "\"%[^\"]\",%d", buffer, &opcode) == 2) && opcode == 0144) { strcpy (file_name, buffer); for (i = 0; i < strlen (file_name); i++) { if (file_name[i] == '.') { symbol_name[i] = '_'; } else { symbol_name[i] = file_name[i]; }}} else if (( sscanf (line+8, "\"%[^:\"]:%*[^\"]\",0x%x", buffer, &opcode) == 2|| sscanf (line+8, "\"%[^:\"]:%*[^\"]\",0%o", buffer, &opcode) == 2 || sscanf (line+8, "\"%[^:\"]:%*[^\"]\",%d", buffer, &opcode) == 2) && opcode == 0x24) { proc_entry p = (proc_entry) malloc (sizeof (proc_struct)); p->name = (char *)malloc (strlen(buffer) + 1); strcpy (p->name, buffer); p->next = procs; procs = p; nb_procs += 1; new_proc = TRUE; } break; } case 'd': { if ((sscanf (line+7, "0%o,%d,0%o", &opcode, &zero, &p) == 3 || sscanf (line+7, "%d,%d,%d", &opcode, &zero, &p) == 3) && opcode == 0104) { if (p != line_number) { new_instruction = TRUE; line_number = p; }} break; }}} else { if (new_instruction) { if (new_proc) { fprintf (output_file, "\tincl coverage_%s\n", procs->name); new_proc = FALSE; } if (first_line == -1) { first_line = line_number; }; fprintf (output_file, "\tincl line_coverage+%d\n", (line_number-first_line) * sizeof (int)); highest_line = max (highest_line, line_number); init_lines [line_number] = 0; new_instruction = FALSE; }} fprintf (output_file, "%s\n", line); } /* Find the modification date of the source file */ if (stat (file_name, &buf) == -1) { fprintf (stderr, "%s: cannot obtain the modification date of %s\n", argv[0], file_name); exit (1); } n_lines = highest_line - first_line + 1; if (n_lines < 1) n_lines = 1; fprintf (output_file, "\t.data\n"); fprintf (output_file, "\t.align 2\n"); fprintf (output_file, "\t.ascii \"%s\"\n", header); fprintf (output_file, "\t.long 0x%x\n", buf.st_mtime); fprintf (output_file, "\t.long %d\n", strlen (file_name)); fprintf (output_file, "\t.ascii \"%s\"\n", file_name); fprintf (output_file, "\t.align 2\n"); fprintf (output_file, "\t.long %d\n", first_line); fprintf (output_file, "\t.long %d\n", n_lines); fprintf (output_file, "line_coverage:\n"); for (i = first_line; i < first_line + n_lines; i++) { fprintf (output_file, "\t.long %d\n", init_lines[i]); } fprintf (output_file, "\t.long %d\n", nb_procs); while (procs) { fprintf (output_file, "\t.long %d\n", strlen (procs->name)); fprintf (output_file, "\t.ascii \"%s\"\n", procs->name); fprintf (output_file, "\t.align 2\n"); fprintf (output_file, "coverage_%s:\n", procs->name); fprintf (output_file, "\t.long 0\n"); procs = procs->next; } fprintf (output_file, "\t.ascii \"%s\"\n", trailer); fclose (input_file); fclose (output_file); }