d50c24f5927522082384d0d734955fcd59754bb5
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.
36 #include <netinet/in.h>
39 #include <sys/ptrace.h>
40 #include <sys/socket.h>
41 #include <sys/types.h>
46 #include "tracechild.hh"
50 void printUsage(const char * execName
)
52 cout
<< execName
<< " <options> -- <command> <arguments>" << endl
;
53 cout
<< "options:" << endl
;
54 cout
<< " -h print this help" << endl
;
55 cout
<< " --host remote m5 host to connect to" << endl
;
56 cout
<< " -r print register names" << endl
;
57 cout
<< " -i print initial stack state" << endl
;
58 cout
<< " -nt don't print an instruction trace" << endl
;
61 int main(int argc
, char * argv
[], char * envp
[])
63 TraceChild
* child
= genTraceChild();
67 //Parse the command line arguments
68 bool printInitial
= false;
69 bool printTrace
= true;
70 string host
= "localhost";
76 for(int x
= 1; x
< argc
; x
++)
78 if(!strcmp(argv
[x
], "-h"))
83 if(!strcmp(argv
[x
], "--host"))
88 cerr
<< "Incorrect usage.\n" << endl
;
94 else if(!strcmp(argv
[x
], "-r"))
96 cout
<< "Legal register names:" << endl
;
97 int numRegs
= child
->getNumRegs();
98 for(unsigned int x
= 0; x
< numRegs
; x
++)
100 cout
<< "\t" << child
->getRegName(x
) << endl
;
104 else if(!strcmp(argv
[x
], "-i"))
108 else if(!strcmp(argv
[x
], "-nt"))
112 else if(!strcmp(argv
[x
], "--"))
117 cerr
<< "Incorrect usage.\n" << endl
;
121 startProgramArgs
= x
;
126 cerr
<< "Incorrect usage.\n" << endl
;
131 if(!child
->startTracing(argv
[startProgramArgs
],
132 argv
+ startProgramArgs
))
134 cerr
<< "Couldn't start target program" << endl
;
140 child
->outputStartState(cout
);
145 bool portSet
= false;
147 int sock
= socket(AF_INET
, SOCK_STREAM
, 0);
150 cerr
<< "Error opening socket! " << strerror(errno
) << endl
;
153 struct hostent
*server
;
154 server
= gethostbyname(host
.c_str());
157 cerr
<< "Couldn't get host ip! " << strerror(errno
) << endl
;
160 struct sockaddr_in serv_addr
;
161 bzero((char *)&serv_addr
, sizeof(serv_addr
));
162 serv_addr
.sin_family
= AF_INET
;
163 bcopy((char *)server
->h_addr
,
164 (char *)&serv_addr
.sin_addr
.s_addr
,
166 serv_addr
.sin_port
= htons(8000);
167 if(connect(sock
, (sockaddr
*)&serv_addr
, sizeof(serv_addr
)) < 0)
169 cerr
<< "Couldn't connect to server! " << strerror(errno
) << endl
;
172 while(child
->isTracing())
174 if(!child
->sendState(sock
))
179 if(!child
->stopTracing())
181 cerr
<< "Couldn't stop child" << endl
;