2 * Copyright (c) 2006-2007 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
36 #include <sys/ptrace.h>
39 #include "tracechild.hh"
44 void printUsage(const char * execName
)
46 cout
<< execName
<< " -f <output format file> | -h | -r -- <command> <arguments>" << endl
;
49 int main(int argc
, char * argv
[], char * envp
[])
51 TraceChild
* child
= genTraceChild();
52 NestingPrinter
printer(child
);
56 //Parse the command line arguments
57 bool formatStringSet
= false;
58 bool printInitial
= false;
59 bool printTrace
= true;
61 for(int x
= 1; x
< argc
; x
++)
63 if(!strcmp(argv
[x
], "-f"))
67 cerr
<< "Attempted to set format twice!"
72 formatStringSet
= true;
76 cerr
<< "Incorrect usage.\n" << endl
;
80 ifstream
formatFile(argv
[x
]);
83 cerr
<< "Problem opening file "
84 << argv
[x
] << "." << endl
;
91 getline(formatFile
, line
);
99 cerr
<< "Problem reading from file "
100 << argv
[x
] << "." << endl
;
103 format
+= line
+ '\n';
106 else if(!strcmp(argv
[x
], "-h"))
111 else if(!strcmp(argv
[x
], "-r"))
113 cout
<< "Legal register names:" << endl
;
114 int numRegs
= child
->getNumRegs();
115 for(unsigned int x
= 0; x
< numRegs
; x
++)
117 cout
<< "\t" << child
->getRegName(x
) << endl
;
121 else if(!strcmp(argv
[x
], "-i"))
125 else if(!strcmp(argv
[x
], "-nt"))
129 else if(!strcmp(argv
[x
], "--"))
134 cerr
<< "Incorrect usage.\n" << endl
;
138 startProgramArgs
= x
;
143 cerr
<< "Incorrect usage.\n" << endl
;
148 /*for(unsigned int x = startProgramArgs; x < argc; x++)
150 cout << "Adding argument " << argv[x];
151 args += string(" ") + argv[x];
153 if(!child
->startTracing(argv
[startProgramArgs
],
154 argv
+ startProgramArgs
))
156 cerr
<< "Couldn't start target program" << endl
;
161 child
->outputStartState(cout
);
167 cerr
<< "No output format set!" << endl
;
168 child
->stopTracing();
172 if(!printer
.configure(format
))
174 cerr
<< "Problem in the output format" << endl
;
175 child
->stopTracing();
179 while(child
->isTracing())
186 if(!child
->stopTracing())
188 cerr
<< "Couldn't stop child" << endl
;