"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

ptrace.c

Go to the documentation of this file.
00001 /*
00002  * ptrace.c - pipeline tracing routines
00003  *
00004  * This file is a part of the SimpleScalar tool suite written by
00005  * Todd M. Austin as a part of the Multiscalar Research Project.
00006  *  
00007  * The tool suite is currently maintained by Doug Burger and Todd M. Austin.
00008  * 
00009  * Copyright (C) 1994, 1995, 1996, 1997, 1998 by Todd M. Austin
00010  *
00011  * This source file is distributed "as is" in the hope that it will be
00012  * useful.  The tool set comes with no warranty, and no author or
00013  * distributor accepts any responsibility for the consequences of its
00014  * use. 
00015  * 
00016  * Everyone is granted permission to copy, modify and redistribute
00017  * this tool set under the following conditions:
00018  * 
00019  *    This source code is distributed for non-commercial use only. 
00020  *    Please contact the maintainer for restrictions applying to 
00021  *    commercial use.
00022  *
00023  *    Permission is granted to anyone to make or distribute copies
00024  *    of this source code, either as received or modified, in any
00025  *    medium, provided that all copyright notices, permission and
00026  *    nonwarranty notices are preserved, and that the distributor
00027  *    grants the recipient permission for further redistribution as
00028  *    permitted by this document.
00029  *
00030  *    Permission is granted to distribute this file in compiled
00031  *    or executable form under the same conditions that apply for
00032  *    source code, provided that either:
00033  *
00034  *    A. it is accompanied by the corresponding machine-readable
00035  *       source code,
00036  *    B. it is accompanied by a written offer, with no time limit,
00037  *       to give anyone a machine-readable copy of the corresponding
00038  *       source code in return for reimbursement of the cost of
00039  *       distribution.  This written offer must permit verbatim
00040  *       duplication by anyone, or
00041  *    C. it is distributed by someone who received only the
00042  *       executable form, and is accompanied by a copy of the
00043  *       written offer of source code that they received concurrently.
00044  *
00045  * In other words, you are welcome to use, share and improve this
00046  * source file.  You are forbidden to forbid anyone else to use, share
00047  * and improve what you give them.
00048  *
00049  * INTERNET: dburger@cs.wisc.edu
00050  * US Mail:  1210 W. Dayton Street, Madison, WI 53706
00051  *
00052  * $Id: ptrace.c,v 1.1.1.1 2000/05/26 15:18:59 taustin Exp $
00053  *
00054  * $Log: ptrace.c,v $
00055  * Revision 1.1.1.1  2000/05/26 15:18:59  taustin
00056  * SimpleScalar Tool Set
00057  *
00058  *
00059  * Revision 1.2  1998/08/27 15:49:17  taustin
00060  * implemented host interface description in host.h
00061  * added target interface support
00062  * using new target-dependent myprintf() package
00063  *
00064  * Revision 1.1  1997/03/11  01:32:15  taustin
00065  * Initial revision
00066  *
00067  *
00068  */
00069 
00070 #include <stdio.h>
00071 #include <stdlib.h>
00072 
00073 #include "host.h"
00074 #include "misc.h"
00075 #include "machine.h"
00076 #include "range.h"
00077 #include "ptrace.h"
00078 
00079 /* pipetrace file */
00080 FILE *ptrace_outfd = NULL;
00081 
00082 /* pipetracing is active */
00083 int ptrace_active = FALSE;
00084 
00085 /* pipetracing range */
00086 struct range_range_t ptrace_range;
00087 
00088 /* one-shot switch for pipetracing */
00089 int ptrace_oneshot = FALSE;
00090 
00091 /* open pipeline trace */
00092 void
00093 ptrace_open(char *fname,                /* output filename */
00094             char *range)                /* trace range */
00095 {
00096   char *errstr;
00097 
00098   /* parse the output range */
00099   if (!range)
00100     {
00101       /* no range */
00102       errstr = range_parse_range(":", &ptrace_range);
00103       if (errstr)
00104         panic("cannot parse pipetrace range, use: {<start>}:{<end>}");
00105       ptrace_active = TRUE;
00106     }
00107   else
00108     {
00109       errstr = range_parse_range(range, &ptrace_range);
00110       if (errstr)
00111         fatal("cannot parse pipetrace range, use: {<start>}:{<end>}");
00112       ptrace_active = FALSE;
00113     }
00114 
00115   if (ptrace_range.start.ptype != ptrace_range.end.ptype)
00116     fatal("range endpoints are not of the same type");
00117 
00118   /* open output trace file */
00119   if (!fname || !strcmp(fname, "-") || !strcmp(fname, "stderr"))
00120     ptrace_outfd = stderr;
00121   else if (!strcmp(fname, "stdout"))
00122     ptrace_outfd = stdout;
00123   else
00124     {
00125       ptrace_outfd = fopen(fname, "w");
00126       if (!ptrace_outfd)
00127         fatal("cannot open pipetrace output file `%s'", fname);
00128     }
00129 }
00130 
00131 /* close pipeline trace */
00132 void
00133 ptrace_close(void)
00134 {
00135   if (ptrace_outfd != NULL && ptrace_outfd != stderr && ptrace_outfd != stdout)
00136     fclose(ptrace_outfd);
00137 }
00138 
00139 /* declare a new instruction */
00140 void
00141 __ptrace_newinst(unsigned int iseq,     /* instruction sequence number */
00142                  md_inst_t inst,        /* new instruction */
00143                  md_addr_t pc,          /* program counter of instruction */
00144                  md_addr_t addr)        /* address referenced, if load/store */
00145 {
00146   myfprintf(ptrace_outfd, "+ %u 0x%08p 0x%08p ", iseq, pc, addr);
00147   md_print_insn(inst, addr, ptrace_outfd);
00148   fprintf(ptrace_outfd, "\n");
00149 
00150   if (ptrace_outfd == stderr || ptrace_outfd == stdout)
00151     fflush(ptrace_outfd);
00152 }
00153 
00154 /* declare a new uop */
00155 void
00156 __ptrace_newuop(unsigned int iseq,      /* instruction sequence number */
00157                 char *uop_desc,         /* new uop description */
00158                 md_addr_t pc,           /* program counter of instruction */
00159                 md_addr_t addr)         /* address referenced, if load/store */
00160 {
00161   myfprintf(ptrace_outfd,
00162             "+ %u 0x%08p 0x%08p [%s]\n", iseq, pc, addr, uop_desc);
00163 
00164   if (ptrace_outfd == stderr || ptrace_outfd == stdout)
00165     fflush(ptrace_outfd);
00166 }
00167 
00168 /* declare instruction retirement or squash */
00169 void
00170 __ptrace_endinst(unsigned int iseq)     /* instruction sequence number */
00171 {
00172   fprintf(ptrace_outfd, "- %u\n", iseq);
00173 
00174   if (ptrace_outfd == stderr || ptrace_outfd == stdout)
00175     fflush(ptrace_outfd);
00176 }
00177 
00178 /* declare a new cycle */
00179 void
00180 __ptrace_newcycle(tick_t cycle)         /* new cycle */
00181 {
00182   fprintf(ptrace_outfd, "@ %.0f\n", (double)cycle);
00183 
00184   if (ptrace_outfd == stderr || ptrace_outfd == stdout)
00185     fflush(ptrace_outfd);
00186 }
00187 
00188 /* indicate instruction transition to a new pipeline stage */
00189 void
00190 __ptrace_newstage(unsigned int iseq,    /* instruction sequence number */
00191                   char *pstage,         /* pipeline stage entered */
00192                   unsigned int pevents)/* pipeline events while in stage */
00193 {
00194   fprintf(ptrace_outfd, "* %u %s 0x%08x\n", iseq, pstage, pevents);
00195 
00196   if (ptrace_outfd == stderr || ptrace_outfd == stdout)
00197     fflush(ptrace_outfd);
00198 }


UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214