Update copyright to LGPL on all files
[dyninst.git] / testsuite / src / dyninst / dyninst_comp.h
1 /*
2  * Copyright (c) 1996-2009 Barton P. Miller
3  * 
4  * We provide the Paradyn Parallel Performance Tools (below
5  * described as "Paradyn") on an AS IS basis, and do not warrant its
6  * validity or performance.  We reserve the right to update, modify,
7  * or discontinue this software at any time.  We shall have no
8  * obligation to supply such updates or modifications or any other
9  * form of support to you.
10  * 
11  * By your use of Paradyn, you understand and agree that we (or any
12  * other person or entity with proprietary rights in Paradyn) are
13  * under no obligation to provide either maintenance services,
14  * update services, notices of latent defects, or correction of
15  * defects for Paradyn.
16  * 
17  * This library is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU Lesser General Public
19  * License as published by the Free Software Foundation; either
20  * version 2.1 of the License, or (at your option) any later version.
21  * 
22  * This library is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  * Lesser General Public License for more details.
26  * 
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30  */
31
32 #if !defined(dyninst_comp_h_)
33 #define dyninst_comp_h
34
35 #include "test_lib.h"
36 #include "TestMutator.h"
37 #include "BPatch.h"
38 #include "BPatch_thread.h"
39 #include "BPatch_process.h"
40 #include "BPatch_function.h"
41
42 #define BINEDIT_DIR "./binaries"
43
44 // Base class for the mutator part of a test
45 class COMPLIB_DLL_EXPORT DyninstMutator : public TestMutator {
46 public:
47   BPatch_thread *appThread;
48   BPatch_addressSpace *appAddrSpace;
49   BPatch_binaryEdit *appBinEdit;
50   BPatch_process *appProc;
51   // FIXME This field (appImage) probably isn't necessary.  It looks looks like
52   // appImage is easily derivable from appThread.
53   BPatch_image *appImage;
54
55   create_mode_t runmode;
56
57   DyninstMutator();
58   virtual test_results_t setup(ParameterDict &param);
59   virtual ~DyninstMutator();
60 };
61 extern "C" {
62         TEST_DLL_EXPORT TestMutator *TestMutator_factory();
63 }
64
65 COMPLIB_DLL_EXPORT int waitUntilStopped(BPatch *, BPatch_thread *appThread, 
66                       int testnum, const char *testname);
67 COMPLIB_DLL_EXPORT bool signalAttached(BPatch_thread *appThread, BPatch_image *appImage);
68
69 COMPLIB_DLL_EXPORT void checkCost(BPatch_snippet snippet);
70
71 // Wrapper function to find variables
72 // For Fortran, will look for lowercase variable, if mixed case not found
73 COMPLIB_DLL_EXPORT BPatch_variableExpr *findVariable(BPatch_image *appImage, 
74                                   const char* var,
75                                   BPatch_Vector <BPatch_point *> *point);
76
77
78 //
79 //
80 // Replace all calls in "inFunction" to "callTo" with calls to "replacement."
81 // If "replacement" is NULL, them use removeFunctionCall instead of
82 // replaceFunctionCall.
83 // Returns the number of replacements that were performed.
84 //
85 COMPLIB_DLL_EXPORT int replaceFunctionCalls(BPatch_addressSpace *appAddrSpace, BPatch_image *appImage,
86                          const char *inFunction, const char *callTo, 
87                          const char *replacement, int testNo, 
88                          const char *testName, int callsExpected);
89 //
90 //
91 // Insert "snippet" at the location "loc" in the function "inFunction."
92 // Returns the value returned by BPatch_thread::insertSnippet.
93 //
94 COMPLIB_DLL_EXPORT BPatchSnippetHandle *insertSnippetAt(BPatch_addressSpace *appThread,
95                                BPatch_image *appImage, const char *inFunction, 
96                                BPatch_procedureLocation loc, 
97                                BPatch_snippet &snippet,
98                                int testNo, const char *testName);
99
100 //
101 // Insert a snippet to call function "funcName" with no arguments into the
102 // procedure "inFunction" at the points given by "loc."
103 //
104 COMPLIB_DLL_EXPORT int insertCallSnippetAt(BPatch_addressSpace *appAddrSpace,
105                             BPatch_image *appImage, const char *inFunction,
106                             BPatch_procedureLocation loc, const char *funcName,
107                             int testNo, const char *testName);
108
109
110 COMPLIB_DLL_EXPORT BPatch_Vector<BPatch_snippet *> genLongExpr(BPatch_arithExpr *tail);
111
112
113
114 // Function to preload some libraries for test1_21 and test1_22
115 COMPLIB_DLL_EXPORT int readyTest21or22(BPatch_thread *appThread, 
116       char *libNameA, char *libNameB, int mutateeFortran);
117
118 COMPLIB_DLL_EXPORT int strcmpcase(char *s1, char *s2);
119
120 COMPLIB_DLL_EXPORT void instrument_entry_points( BPatch_addressSpace * app_thread,
121                               BPatch_image * ,
122                               BPatch_function * func,
123                               BPatch_snippet * code );
124
125
126 COMPLIB_DLL_EXPORT void instrument_exit_points( BPatch_addressSpace * app_thread,
127                              BPatch_image * ,
128                              BPatch_function * func,
129                              BPatch_snippet * code );
130
131 // Tests to see if the mutatee has defined the mutateeCplusplus flag
132 COMPLIB_DLL_EXPORT int isMutateeCxx(BPatch_image *appImage);
133 // Tests to see if the mutatee has defined the mutateeFortran flag
134 COMPLIB_DLL_EXPORT int isMutateeFortran(BPatch_image *appImage);
135 // Tests to see if the mutatee has defined the mutateeF77 flag
136 int isMutateeF77(BPatch_image *appImage);
137
138 COMPLIB_DLL_EXPORT void MopUpMutatees(const unsigned int mutatees, BPatch_thread *appThread[]);
139
140 COMPLIB_DLL_EXPORT void contAndWaitForAllThreads(BPatch *bpatch, BPatch_thread *appThread, 
141       BPatch_thread **mythreads, int *threadCount);
142
143 /*
144  * Given a string variable name and an expected value, lookup the varaible
145  *    in the child process, and verify that the value matches.
146  *
147  */
148 COMPLIB_DLL_EXPORT bool verifyChildMemory(BPatch_thread *appThread, 
149                        const char *name, int expectedVal);
150
151
152 COMPLIB_DLL_EXPORT void dumpvect(BPatch_Vector<BPatch_point*>* res, const char* msg);
153
154 COMPLIB_DLL_EXPORT bool validate(BPatch_Vector<BPatch_point*>* res,
155                             BPatch_memoryAccess* acc[], const char* msg);
156
157 COMPLIB_DLL_EXPORT BPatch_callWhen instrumentWhere(  const BPatch_memoryAccess* memAccess);
158
159 COMPLIB_DLL_EXPORT int instCall(BPatch_thread* bpthr, const char* fname,
160                                 const BPatch_Vector<BPatch_point*>* res);
161
162
163 COMPLIB_DLL_EXPORT int instEffAddr(BPatch_thread* bpthr, const char* fname,
164                  const BPatch_Vector<BPatch_point*>* res,
165                  bool conditional);
166
167 COMPLIB_DLL_EXPORT int instByteCnt(BPatch_thread* bpthr, const char* fname,
168                  const BPatch_Vector<BPatch_point*>* res,
169                  bool conditional);
170
171 COMPLIB_DLL_EXPORT int pointerSize(BPatch_image *img);
172
173 typedef struct {
174     bool             valid;
175     bool             optional;
176     BPatch_frameType type;
177     const char      *function_name;
178 } frameInfo_t;
179
180 COMPLIB_DLL_EXPORT bool checkStack(BPatch_thread *appThread,
181                 const frameInfo_t correct_frame_info[],
182                 unsigned num_correct_names,
183                 int test_num, const char *test_name);
184
185 COMPLIB_DLL_EXPORT void buildArgs(const char** child_argv, char *pathname, int testNo);
186
187
188 COMPLIB_DLL_EXPORT bool createNewProcess(BPatch *bpatch, BPatch_thread *&appThread, 
189                                          BPatch_image *&appImage, char *pathname, 
190                                          const char** child_argv);
191
192
193 COMPLIB_DLL_EXPORT int instrumentToCallZeroArg(BPatch_thread *appThread, 
194                                                BPatch_image *appImage, 
195                                                char *instrumentee, char*patch, 
196                                                int testNo, char *testName);
197
198
199 COMPLIB_DLL_EXPORT char* saveWorld(BPatch_thread *appThread);
200
201 COMPLIB_DLL_EXPORT int letOriginalMutateeFinish(BPatch_thread *appThread);
202
203 COMPLIB_DLL_EXPORT BPatch_function *findFunction(const char *fname, BPatch_image *appImage, int testno, const char *testname);
204 COMPLIB_DLL_EXPORT BPatch_function *findFunction(const char *fname, BPatch_module *inmod, int testno, const char *testname);
205
206 COMPLIB_DLL_EXPORT bool setVar(BPatch_image *appImage, const char *vname, void *addr, int testno, const char *testname);
207 COMPLIB_DLL_EXPORT bool getVar(BPatch_image *appImage, const char *vname, void *addr, int testno, const char *testname);
208
209 // Functions in test_lib_soExecution.C below
210 //           or test_lib_dllExecution.C
211
212 // Function in MutateeStart.C
213 COMPLIB_DLL_EXPORT BPatch_thread *startMutateeTestGeneric(BPatch *bpatch, const char *pathname, const char **child_argv, bool useAttach);
214
215 COMPLIB_DLL_EXPORT BPatch_thread *startMutateeTest(BPatch *bpatch, const char *mutatee, const char *testname, bool useAttach, char *logfilename, char *humanlogname);
216
217 COMPLIB_DLL_EXPORT BPatch_thread *startMutateeTest(BPatch *bpatch, RunGroup *group, char *logfilename, char *humanlogname, bool verboseFormat, bool printLabels, int debugPrint, char *pidfilename);
218
219 COMPLIB_DLL_EXPORT BPatch_thread *startMutateeTest(BPatch *bpatch, RunGroup *group, char *logfilename, char *humanlogname, bool verboseFormat, bool printLabels, int debugPrint, char *pidfilename);
220
221 COMPLIB_DLL_EXPORT BPatch_binaryEdit *startBinaryTest(BPatch *bpatch, RunGroup *group);
222
223 COMPLIB_DLL_EXPORT bool runBinaryTest(BPatch *bpatch, RunGroup *group,
224                                       BPatch_binaryEdit *binEdit,
225                                       char *logfilename, char *humanlogname,
226                                       bool verboseFormat, bool printLabels,
227                                       int debugPrint, 
228                                       char *pidfilename,
229                                       bool noClean,
230                                       test_results_t &test_result);
231
232 // COMPLIB_DLL_EXPORT BPatch_thread *startMutateeTestSet(BPatch *bpatch, char *pathname, 
233 //                                 test_data_t tests[],
234 //                                 int first_test, int last_test,
235 //                                 bool useAttach, ProcessList &procList,
236 //                                 char *logfilename, bool runAllTests,
237 //                                 std::vector<char *> test_list);
238
239 // COMPLIB_DLL_EXPORT BPatch_thread *startMutateeEnabledTests(BPatch *bpatch, char *pathname, bool useAttach, test_data_t tests[], unsigned int num_tests, int oldtest, char *logfilename);
240
241 COMPLIB_DLL_EXPORT void killMutatee(BPatch_thread *appThread);
242
243 #endif
244
245